This file is indexed.

/usr/share/elmerfront/tcl/ecif_tk_procsWidget.tcl is in elmer-common 6.1.0.svn.5396.dfsg-2ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
#/*****************************************************************************/
# *
# *  Elmer, A Finite Element Software for Multiphysical Problems
# *
# *  Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland
# * 
# *  This program is free software; you can redistribute it and/or
# *  modify it under the terms of the GNU General Public License
# *  as published by the Free Software Foundation; either version 2
# *  of the License, or (at your option) any later version.
# * 
# *  This program is distributed in the hope that it will be useful,
# *  but WITHOUT ANY WARRANTY; without even the implied warranty of
# *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# *  GNU General Public License for more details.
# *
# *  You should have received a copy of the GNU General Public License
# *  along with this program (in file fem/GPL-2); if not, write to the 
# *  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 
# *  Boston, MA 02110-1301, USA.
# *
# *****************************************************************************/

#***********************************************************************
#Program:   ELMER Front 
#Module:    ecif_tk_procsWidget.tcl
#Language:  Tcl
#Date:      04.02.98
#Version:   1.00
#Author(s): Martti Verho
#Revisions: 
#
#Abstract:  Generic event handlers and procs for combibed widgets
#
#************************************************************************

#=========#
# Generic #
#=========#


# Check if a widget exist
#
proc Widget::exists { wdg } {
  upvar $wdg theWdg

  if { ![info exist $wdg] ||
       ![winfo exist $theWdg] 
     } {
    return 0
  } else {
    return 1
  }
}


# Check if an array widget exist
#
proc Widget::arrayWidgetExists { globArray fld } {
  upvar #0 $globArray theArray

  if { ![info exists theArray(allWidgets,$fld)] } {
    return 0
  }

  # First in the (possible) list must exists and also enough!
  #
  if { ![winfo exists [lindex $theArray(allWidgets,$fld) 0] ] } {
    return 0
  } else {
    return 1
  }
}

  
# Configure one widget and one option
#
proc Widget::configure1 { wdg option value } {

  set msg ""
  catch { $wdg configure $option $value} msg

  if { $msg != "" } {
    Message::showMessage "Illegal widget configure option ($option) in Widget::configure1 because: $msg"
  }
}


# Configure many widgets and one option
#
proc Widget::configureN { widgets option value } {

  set wdgs [join $widgets]

  foreach wdg $wdgs {

    set msg ""
    catch { $wdg configure $option $value} msg

    if { $msg != "" } {
      Message::showMessage "Illegal widget configure option ($option) in Widget::configure1 because: $msg"
      break
    }
  }
}


# Set widgets' state normal
#
proc Widget::activate {widgets} {
  set wdgs [join $widgets]
  foreach wdg $wdgs {
    set msg ""
    catch { $wdg configure -state normal} msg
    if { $msg != "" } {
      Message::showMessage "Illegal widget configure option (state) in Widget::deactivate because: $msg"
      break
    }
  }
}


# Set widgets's state disabled
#
proc Widget::deactivate {widgets} {
  set wdgs [join $widgets]
  foreach wdg $wdgs {
    set msg ""
    catch { $wdg configure -state disabled} msg
    if { $msg != "" } {
      Message::showMessage "Illegal widget configure option (state) in Widget::deactivate because: $msg"
      break
    }
  }
}


# Configure widgets State
#
proc Widget::configureS { wdg state } {

  set msg ""

  catch { $wdg configure -state $state} msg

  if { $msg != "" } {
    Message::showMessage "Illegal widget configure option in Widget::configureS because: $msg"
  }
}


# Configure widgets State, Background
#
proc Widget::configureSB { wdg state bg } {

  set msg ""

  catch { $wdg configure -state $state -bg $bg } msg

  if { $msg != "" } {
    Message::showMessage "Illegal widget configure option in Widget::configureSB because: $msg"
  }
}


# Configure widgets State, Background and Relief
#
proc Widget::configureSBR { wdg state bg relief } {

  set msg ""

  catch { $wdg configure -state $state -bg $bg -relief $relief } msg

  if { $msg != "" } {
    Message::showMessage "Illegal widget configure option in Widget::configureSBR because: $msg"
  }
}


# Configure widgets State, Background, Foreground and Relief
#
proc Widget::configureSBFR { wdg state bg fg relief } {

  set msg ""

  catch { $wdg configure -state $state -bg $bg -fg $fg -relief $relief } msg

  if { $msg != "" } {
    Message::showMessage "Illegal widget configure option in Widget::configureSBFR because: $msg"
  }
}


# ====================
# ARRAY field handling
# ====================

# Configure: (state, background etc.)
# ===================================

# Find widget for the field "fld" in the array "globArray"
# configure ist state (disabled, background etc)
#
proc Widget::configureField {globArray fld {wtype ""} } {
  upvar #0 $globArray theArray

  # Widget does not exist
  # =====================
  if { ![Widget::arrayWidgetExists $globArray $fld] } {
    return "Widget for the field=$fld does not exist!"
  }

  if { $theArray($fld,act) } {
    set mode "normal"
  } else {
    set mode "disabled"
  }

  if { $wtype == "" } {
    set wtype [DataField::getFieldProperty $globArray $fld WidgetType]
  }
  
  set wdg $theArray(allWidgets,$fld)

  # Call proper handler by widget type
  # If field not identified, return 0
  #
  switch $wtype {
    BrowsableDirectory    { Widget::configureBrowsableDirectory $globArray $fld $wdg $mode}
    BrowsableFile         { Widget::configureBrowsableFile $globArray $fld $wdg $mode}
    Entry                 { Widget::configureEntry $wdg $mode}
    Button                { Widget::configureButton $wdg $mode}
    IncludeFile           { Widget::configureIncludeFile $globArray $fld $wdg $mode}
    ListBox               { Widget::configureListBox $wdg $mode}
    OptionMenu            { Widget::configureOptionMenu $wdg $mode}
    CheckBox              { Widget::configureCheckBox $wdg $mode}
    RadioButton           { Widget::configureRadioButton $wdg $mode}
    RadioButtonOptionMenu { Widget::configureRadioButtonOptionMenu $wdg $mode}
    SelectionBox          { Widget::configureSelectionBox $wdg $mode}
    Text                  { Widget::configureText $wdg $mode}
    default               { return 0}
  }

  # Ok, field found and configured
  # ==============================
  return ""
}


# Configures one button widget according to
# the "mode" argument
#
proc Widget::configureButton {wdg mode} {
  global Info

  #--Set button foreground
  #-Normal mode
  if {$mode == "Normal" || $mode == "normal"} {
    Widget::configure1 $wdg -activeforeground black
  #-Disabled mode
  } elseif {$mode == "Disabled" || $mode == "disabled"} {
    Widget::configure1 $wdg -disabledforeground $Info(nonActiveFg)
  }

  Widget::configureS $wdg $mode

}


# Configures one browsable directory widget state according to
# the "mode" argument
#
proc Widget::configureBrowsableDirectory {globArray fld wdg mode} {
  global Info
  upvar #0 $globArray theArray

  # Directory entry
  # ----------
  Widget::configureEntry $wdg $mode

  # Browse button
  # -------------
  if { [info exists theArray(allWidgets,$fld,Browse)] } {
    Widget::configureButton $theArray(allWidgets,$fld,Browse) $mode
  }

  # Abs checkbox
  # ------------
  if { [info exists theArray(allWidgets,$fld,Abs)] } {
    Widget::configureButton $theArray(allWidgets,$fld,Abs) $mode
  }
}


# Configures one browsable file widget state according to
# the "mode" argument
#
proc Widget::configureBrowsableFile {globArray fld wdg mode} {
  global Info
  upvar #0 $globArray theArray

  # File entry
  # ----------
  Widget::configureEntry $wdg $mode

  # Browse button
  # -------------
  if { [info exists theArray(allWidgets,$fld,Browse)] } {
    Widget::configureButton $theArray(allWidgets,$fld,Browse) $mode
  }

  # Abs checkbox
  # ------------
  if { [info exists theArray(allWidgets,$fld,Abs)] } {
    Widget::configureButton $theArray(allWidgets,$fld,Abs) $mode
  }
}


# Configures one checkbox widget according to
# the "mode" argument
#
proc Widget::configureCheckBox {wdg mode} {
  global Info

  #-Normal mode
  if {$mode == "Normal" || $mode == "normal"} {
    Widget::configure1 $wdg -state normal
    Widget::configure1 $wdg -fg black

  #-Disabled mode
  } elseif {$mode == "Disabled" || $mode == "disabled"} {
    Widget::configure1 $wdg -state disabled
    Widget::configure1 $wdg -fg gray
    #Widget::configure1 $wdg -fg $Info(nonActiveFg)
  }
}


# Configures one entry widget state according to
# the "mode" argument
#
proc Widget::configureEntry {wdg mode} {
  global Info

  #-Normal mode
  if {$mode == "Normal" || $mode == "normal"} {
    Widget::configureSBFR $wdg normal white black groove 

  #-Disabled mode
  } elseif {$mode == "Disabled" || $mode == "disabled" } {
    Widget::configureSBFR $wdg disabled $Info(nonActiveBg) $Info(nonActiveFg) groove 
  }
}


# Configures one include file widget state according to
# the "mode" argument
#
proc Widget::configureIncludeFile {globArray fld wdg mode} {
  global Info
  upvar #0 $globArray theArray

  # NOTE: use-checkbox is not controilled here, that
  # would block the whole widget!!!
  # Use $fld,Use instead (like INCLUDE,Use)
  
  # Browse button
  # -------------
  if { [info exists theArray(allWidgets,$fld,Browse)] } {
    Widget::configureButton $theArray(allWidgets,$fld,Browse) $mode
  }

  # File entry
  # ----------
  #
  # Use-checkbox controls entry state
  if { [info exists theArray(allWidgets,$fld,Use)] } {

    # If normal mode and checkbox is clicked --> entry to normal state
    if { $mode == "normal" && $theArray($fld,Use) && $theArray($fld,Use,act) } {
      Widget::configureEntry $wdg "normal"

    # Otherwise entry to disabled state
    } else {
      Widget::configureEntry $wdg "disabled"
    }

  # No use-checkbox, set entry state by "mode"
  } else {
    Widget::configureEntry $wdg $mode
  }
}


# Configures one listBox widget according to
# the "mode" argument
#
proc Widget::configureListBox {wdg mode} {
  global Info

  # Listbox does not have a -state option!
  #Widget::configureS $wdg $mode
}


# Configures one optionMenu widget according to
# the "mode" argument
#
proc Widget::configureOptionMenu {wdg mode} {
  global Info
  Widget::configureS $wdg $mode
}


# Configures one radiobutton widget according to
# the "mode" argument
#
proc Widget::configureRadioButton {wdg mode} {
  global Info
  Widget::configureS $wdg $mode
}


# Configures one radioButtonOptionMenu widget according to
# the "mode" argument
# NOTE: Only OptionMenu part configured
#
proc Widget::configureRadioButtonOptionMenu {wdg mode} {
  global Info

  set rb_wdg [lindex $wdg 0]
  set om_wdg [lindex $wdg 1]

  Widget::configureOptionMenu $om_wdg $mode
}


# Configures one selectionBox widget according to
# the "mode" argument
#
# NOTE: A listbox does not have a -state option!
#
proc Widget::configureSelectionBox {wdg mode} {
  global Info

  #-Normal mode
  if {$mode == "Normal" || $mode == "normal"} {
    Widget::configure1 $wdg -fg black

  #-Disabled mode
  } elseif {$mode == "Disabled" || $mode == "disabled" } {
    Widget::configure1 $wdg -fg $Info(nonActiveFg)
  }
}


# Configures one text widget according to
# the "mode" argument
#
proc Widget::configureText {wdg mode} {
  global Info

  #-Normal mode
  if {$mode == "Normal" || $mode == "normal"} {
    Widget::configureSBFR $wdg normal white black groove 

  #-Disabled mode
  } elseif {$mode == "Disabled" || $mode == "disabled" } {
    Widget::configureSBFR $wdg disabled $Info(nonActiveBg) $Info(nonActiveFg) groove 
  }
}


# Field status: modified, error color etc.
# ========================================

# Find widget for the field "fld" in the array "globArray"
# and set its status (error/mofified etc.)
#
proc Widget::setFieldStatus {globArray fld {wtype ""} } {
  upvar #0 $globArray theArray

  # Widget does not exist
  # =====================
  if { ![Widget::arrayWidgetExists $globArray $fld] } {
    return -1
  }

  if { $wtype == "" } {
    set wtype [DataField::getFieldProperty $globArray $fld WidgetType]
  }
  
  set wdg $theArray(allWidgets,$fld)

  # Call proper handler by widget type
  # Return 0 if widget not identified
  #
  switch $wtype {
    BrowsableDirectory    { Widget::setEntryStatus $globArray $fld $wdg }
    BrowsableFile         { Widget::setEntryStatus $globArray $fld $wdg }
    Entry                 { Widget::setEntryStatus $globArray $fld $wdg }
    IncludeFile           { Widget::setEntryStatus $globArray $fld $wdg }
    OptionMenu            { Widget::setOptionMenuStatus $globArray $fld $wdg }
    RadioButtonOptionMenu { Widget::setRadioButtonOptionMenuStatus $globArray $fld $wdg }
    CheckBox              { Widget::setCheckBoxStatus $globArray $fld $wdg }
    RadioButton           { Widget::setRadioButtonStatus $globArray $fld $wdg }
    default               { return 0 }
  }

  # Ok, field found anf handled
  # ===========================
  return 1
}


# Entry widget status
#
proc Widget::setEntryStatus {globArray fld wdg} {
  global Info
  upvar #0 $globArray theArray

  if { [catch {
    #---Error status
    if { $theArray($fld,err) } {
      Widget::configure1 $wdg $Info(en_err_option) $Info(en_err_color) 

    #---Modified status
    } elseif { $theArray($fld,mod) } {
      Widget::configure1 $wdg $Info(en_mod_option) $Info(en_mod_color) 

    #---Normal status
    } else {
      Widget::configure1 $wdg $Info(en_err_option) $Info(en_nerr_color)
      Widget::configure1 $wdg $Info(en_mod_option) $Info(en_nmod_color)
    }
  } msg ] } {
    tk_messageBox -message $msg
  }
  
}


# CheckBox widget status
#
proc Widget::setCheckBoxStatus {globArray fld wdg} {
  global Info
  upvar #0 $globArray theArray

  if { [catch {
    #---Error status
    if { $theArray($fld,err) } {
      Widget::configure1 $wdg $Info(cb_err_option) $Info(cb_err_color) 

    #---Modified status
    } elseif { $theArray($fld,mod) } {
      Widget::configure1 $wdg $Info(cb_mod_option) $Info(cb_mod_color) 

    #---Normal status
    } else {
      Widget::configure1 $wdg $Info(cb_err_option) $Info(cb_nerr_color)
      Widget::configure1 $wdg $Info(cb_mod_option) $Info(cb_nmod_color)
    }
  } msg ] } {
    tk_messageBox -message $msg
  }
}


# OptionMenu widget status
#
proc Widget::setOptionMenuStatus {globArray fld wdg} {
  global Info
  upvar #0 $globArray theArray

  if { [catch {
    #---Error status
    if { $theArray($fld,err) } {
      Widget::configure1 $wdg $Info(om_err_option) $Info(om_err_color) 

    #---Modified status
    } elseif { $theArray($fld,mod) } {
      Widget::configure1 $wdg $Info(om_mod_option) $Info(om_mod_color) 

    #---Normal status
    } else {
      Widget::configure1 $wdg $Info(om_err_option) $Info(om_nerr_color)
      Widget::configure1 $wdg $Info(om_mod_option) $Info(om_nmod_color)
    }
  } msg ] } {
    tk_messageBox -message $msg
  }
  
}


# RadioButton widget status
#
proc Widget::setRadioButtonStatus {globArray fld wdg} {
  global Info
  upvar #0 $globArray theArray

  if { [catch {
    #---Error status
    if { $theArray($fld,err) } {
      Widget::configure1 $wdg $Info(rb_err_option) $Info(rb_err_color) 

    #---Modified status
    } elseif { $theArray($fld,mod) } {
      Widget::configure1 $wdg $Info(rb_mod_option) $Info(rb_mod_color) 

    #---Normal status
    } else {
      Widget::configure1 $wdg $Info(rb_err_option) $Info(rb_nerr_color)
      Widget::configure1 $wdg $Info(rb_mod_option) $Info(rb_nmod_color)
    }
  } msg ] } {
    tk_messageBox -message $msg
  }
  
}


# OptionMenu widget status
#
proc Widget::setRadioButtonOptionMenuStatus {globArray fld wdg} {
  global Info
  upvar #0 $globArray theArray

  set rb_wdg [lindex $wdg 0]
  set om_wdg [lindex $wdg 1]

  if { [catch {
    #---Error status
    if { $theArray($fld,err) } {
      Widget::configure1 $om_wdg $Info(om_err_option) $Info(om_err_color) 

    #---Modified status
    } elseif { $theArray($fld,mod) } {
      Widget::configure1 $om_wdg $Info(om_mod_option) $Info(om_mod_color) 

    #---Normal status
    } else {
      Widget::configure1 $om_wdg $Info(om_err_option) $Info(om_nerr_color)
      Widget::configure1 $om_wdg $Info(om_mod_option) $Info(om_nmod_color)
    }
  } msg ] } {
    tk_messageBox -message $msg
  }
}


################
### BINDINGS ###
################


proc Widget::setPanelBindings {globArray win} {
  upvar #0 $globArray theArray

  set events {
    Activate Deactivate
    FocusIn FocusOut
  }

  # Bind events to procs (named according to the event symbol)
  foreach event $events {
    bind $win <$event> "+Widget::panel$event $globArray"
  }
}


proc Widget::setLabelBindings {globArray {fields ""} } {
  upvar #0 $globArray theArray

  if { $fields == "" && [info exists theArray(allFields)] } {
    set fields $theArray(allFields)
  }

  foreach fld $fields {

    if { [info exists theArray(allWidgets,label,$fld)] &&
         [winfo exists $theArray(allWidgets,label,$fld)]
       } {
      set wdg $theArray(allWidgets,label,$fld)
      
      set lbl [string trim [$wdg cget -text]]

      # If field has a visible label, set bindings (for help)
      if { $lbl != "" } {
        bind $wdg <Button-3> "+Widget::genericButton-3 $globArray $fld $wdg"
      }
    }
  }
}



proc Widget::setEntryBindings { binding_grp globArray fld wdg } {

  # Select events by binding-group
  #
  switch $binding_grp {

    standard {
      set events {
        Button-1 Double-1
        Button-3 KeyPress-F1
        KeyPress-Return KeyPress-Down KeyPress-Up
        KeyPress-Escape Control-i Control-m
        KeyPress KeyRelease 
        FocusIn FocusOut
        Enter Leave 
      }
    }

    non_standard {
      set events {
        Button-3 KeyPress-F1
        KeyRelease
        KeyPress-Return KeyPress-Down KeyPress-Up KeyPress-Escape
      }
    }

    non_standard_single {
      set events {
        Button-3 KeyPress-F1
        KeyRelease
        KeyPress-Escape
      }
    }

    default {
      set events ""
      Message::showMessage "Unknown event group: $binding_grp"
    }

  }

  # Bind events to procs (named according to the event symbol)
  foreach event $events {
    bind $wdg <$event> "+Widget::entryEvent $event $globArray $fld $wdg {%A %K}"
  }
}


proc Widget::setCheckBoxBindings { binding_grp globArray fld wdg } {

  # Select events by binding-group
  #
  switch $binding_grp {

    standard {
      set events {
        Button-1 KeyPress-space KeyPress-Return
      }
    }

    non_standard {
      set events {
        Button-1 KeyPress-space KeyPress-Return
      }
    }


  }

  # Bind events to procs (named according to event symbol)
  foreach event $events {
    bind $wdg <$event> "+Widget::checkBox_generic $globArray $fld $wdg {%A %K}"
  }
}


proc Widget::setRadioButtonBindings { binding_grp globArray fld wdg } {

  # Select events by binding-group
  #
  switch $binding_grp {

    standard {
      set events {
        Button-1 KeyPress-space KeyPress-Return
      }
    }

    non_standard {
      set events {
        Button-1 KeyPress-space KeyPress-Return
      }
    }


  }

  # Bind events to procs (named according to event symbol)
  foreach event $events {
    bind $wdg <$event> "+Widget::radioButton_generic $globArray $fld $wdg {%A %K}"
  }
}



#########################
### EVENT classifiers ###
#########################

proc Widget::isEditingEvent {event_info} {

  set ascii [lindex $event_info 0]
  set symb  [lindex $event_info 1]

#-If uncommented, one way to see keycodes!
#print "ascii=$ascii symb=$symb"

  # If not an ascii-key or Delete, BackSpace, Ctrl+v (paste)
  if { $ascii == "" &&
       $symb != "Delete" &&
       $symb != "BackSpace" &&
       $symb != "v"
     } {
    return 0
  }
   
  # Tab or Enter are not editing events
  switch $symb {
    Return -
    Tab {
      return 0
    }
  }

  # Otherwise editing
  return 1
}


proc Widget::bindEditingEvent {action event_info} {

  if { [Widget::isEditingEvent $event_info] } {
    eval $action
  }
}


################### 
### EVENT procs ###
###################


# =================
# Panel event procs
# =================

proc Widget::panelFocusIn {globArray} {
  upvar #0 $globArray theArray

  set theArray(isActive) 1
}


proc Widget::panelFocusOut {globArray} {
  upvar #0 $globArray theArray

  set theArray(isActive) 0
}

proc Widget::panelFocusIn {globArray} {
  upvar #0 $globArray theArray

  set theArray(hasFocus) 1
}


proc Widget::panelFocusOut {globArray} {
  upvar #0 $globArray theArray

  set theArray(hasFocus) 0
}


# ===================
# Generic event procs
# ===================

# Help for a field
#
proc Widget::genericButton-3 { globArray fld wdg  {event_info ""} } {

  set parent [winfo parent $wdg]

  Message::helpMessage $globArray $fld $parent
}


# =================
# Entry event procs
# =================

proc Widget::entryEvent {event_name globArray fld wdg {event_info ""} } {

  set msg ""
  if { [catch {Widget::entry$event_name $globArray $fld $wdg $event_info } msg] } {
    Message::showMessage "$msg fld=$fld event=$event_name"
  }
}


# KeyPress in an entry-widget
#
proc Widget::entryKeyPress { globArray fld wdg {event_info ""} } {
  global Info
  upvar #0 $globArray theArray
  
  if { $event_info == "" } {
    return
  }

  if { $event_info != "" &&
       ![Widget::isEditingEvent $event_info]
     } {
    return
  }
  
  # A procedure or table-mode entry cannot be edited
  # (or of course can be, but only via Proc and Table widgets!)
  #
  if { $wdg != "" &&
       ( ([info exist theArray($fld,proc)] && $theArray($fld,proc)) ||
         ([info exist theArray($fld,table)] && $theArray($fld,table))
       )
     } {
    Widget::configureS $wdg disabled
  }

}


# KeyRelease in an entry-widget
#
proc Widget::entryKeyRelease { globArray fld wdg {event_info ""} } {
  global Info
  upvar #0 $globArray theArray
  
  if { $event_info == "" } {
    return
  }

  if { $event_info != "" &&
       ![Widget::isEditingEvent $event_info]
     } {
    return
  }

  # Show in normal model, although procedure or table-mode entry cannot
  # be edited
  #
  if { $wdg != "" &&
       ( ([info exist theArray($fld,proc)] && $theArray($fld,proc)) ||
         ([info exist theArray($fld,table)] && $theArray($fld,table))
       )
     } {
    Widget::configureS $wdg normal
    return
  }

  if { $theArray($fld,err) } {
    return
  }

  set theArray($fld,mod) 1

  Widget::setEntryStatus $globArray $fld $wdg
}


# ButtonClick event for an entry-widget
#
# NOTE: This is a trick to activate Pro/Table buttons
# when they are inactivated (eg. by selecting a body or parameter)
# and cursor is still in the entry whose FocusIn activated them!
#
proc Widget::entryButton-1 { globArray fld wdg {event_info ""} } {
  Widget::entryFocusIn $globArray $fld $wdg $event_info 
}


# Help for a field
# ----------------
#
proc Widget::entryButton-3 {globArray fld wdg  {event_info ""} } {

  set parent [winfo parent $wdg]
  Message::helpMessage $globArray $fld $parent
}

proc Widget::entryKeyPress-F1 {globArray fld wdg {event_info ""} } {

  set parent [winfo parent $wdg]
  Message::helpMessage $globArray $fld $parent
}


# Ctrl-i: Set initial value for the entry field
#
proc Widget::entryControl-i {globArray fld wdg {event_info ""} } {
  global Common Solver
  upvar #0 $globArray theArray

  set system_index ""

  if { $globArray == $Common(panelArray,SL) &&
       [info exist Solver(equationIndex)]
     } {
    set system_index $Solver(equationIndex)
  }

  set iv [DataField::getInitialValue $globArray $fld $system_index]

  if { $iv != "" } {
    set theArray($fld) $iv
  }

}

# Ctrl-m: Toggle with a possibl Matc-script and field value
#
proc Widget::entryControl-m {globArray fld wdg {event_info ""} } {
  global Solver
  upvar #0 $globArray theArray

	if { ![info exists theArray($fld,matc)] || $theArray($fld,matc) == "" } {
		return
	}
	
	# Swap values
	set tmp $theArray($fld)
	set theArray($fld) $theArray($fld,matc)
	set theArray($fld,matc) $tmp
}


# DoubleClick event for an entry-widget
#
proc Widget::entryDouble-1 { globArray fld wdg {event_info ""} } {
  global Info

  #-If entry is not active, do not open any
  # edit box
  if { "disabled" == [$wdg cget -state ] } {
    return
  }

  upvar #0 $globArray theArray

  #-Procedure editor
  if { [info exist theArray($fld,proc)]  &&
       $theArray($fld,proc)
     } {
    Panel::editProcedure $globArray $fld $wdg

  #-Table editor
  } elseif { [info exist theArray($fld,table)]  &&
       $theArray($fld,table)
     } {
    Panel::editTable $globArray $fld $wdg

  #-Normal (scalar) field, do nothing!
  } else {
    return
  }

}


# Enter (= Return) key pressed in an entry-widget
#
proc Widget::entryKeyPress-Return { globArray fld wdg {event_info ""} } {
  global Info
  upvar #0 $globArray theArray

  if { "" != [PanelCheck::checkField $globArray $fld] } {
    Widget::configure1 $wdg $Info(en_err_option) $Info(en_err_color) 
    return
  }

  Widget::configure1 $wdg $Info(en_err_option) $Info(en_nerr_color) 

  if { $theArray($fld) != $theArray($fld,prev) } {
    Widget::configure1 $wdg $Info(en_mod_option) $Info(en_mod_color) 
  } else {
    Widget::configure1 $wdg $Info(en_mod_option) $Info(en_nmod_color)
  } 

}


# Escape (Esc) key pressed in an entry-widget
#
proc Widget::entryKeyPress-Escape { globArray fld wdg {event_info ""} } {
  upvar #0 $globArray theArray

  if { ![info exists theArray($fld,prev)] } {
    return
  }

  set theArray($fld) $theArray($fld,prev)  
  set theArray($fld,mod) 0
  Widget::setEntryStatus $globArray $fld $wdg

  if { ![Panel::panelHasModifiedStatus $globArray] } {
    Panel::panelDataModified 0 $globArray
  }
}



# Arrow Down key pressed in an entry-widget
#
proc Widget::entryKeyPress-Down { globArray fld wdg {event_info ""} } {
  global Info
  upvar #0 $globArray theArray

  event generate $wdg <KeyPress-Tab> 
}


# Arrow Up key pressed in an entry-widget
#
proc Widget::entryKeyPress-Up { globArray fld wdg {event_info ""} } {
  global Info
  upvar #0 $globArray theArray

  event generate $wdg <Shift-KeyPress-Tab> 
}



# FocusIn event for an entry-widget
#
proc Widget::entryFocusIn {globArray fld wdg {event_info ""} } {
  global Info
  upvar #0 $globArray theArray

  if { $event_info != ""  && $wdg != ""} {

    #--Arrow cursor to mark a non-editable entry for proc/table modes
    if { ([info exist theArray($fld,proc)] && $theArray($fld,proc)) ||
         ([info exist theArray($fld,table)] && $theArray($fld,table))
       } {
     Widget::configure1 $wdg -cursor $Info(arrowCursor)

    #--Otherwise normal insert cursor
    } else {
     Widget::configure1 $wdg -cursor $Info(insertCursor)
    }
  }

  set theArray(currentEntryField) $fld

  # Activate proc and Table buttons, if needed
  #
  if { $theArray(hasProcButton) } {

    if { [DataField::getFieldProperty $globArray $fld Procedurable] } {
      set theArray(PROCEDURE_BUTTON,act) 1
      Widget::configureField $globArray PROCEDURE_BUTTON

      set f_var $globArray; append f_var "($fld,proc)"
      Widget::configure1 $theArray(allWidgets,PROCEDURE_BUTTON) -variable $f_var

    } else {
      set theArray(PROCEDURE_BUTTON,act) 0
      Widget::configureField $globArray PROCEDURE_BUTTON
    }
  }

  if { $theArray(hasTableButton) } {

    if { [DataField::getFieldProperty $globArray $fld Tableable] } {
      set theArray(TABLE_BUTTON,act) 1
      Widget::configureField $globArray TABLE_BUTTON

      set f_var $globArray; append f_var "($fld,table)"
      Widget::configure1 $theArray(allWidgets,TABLE_BUTTON) -variable $f_var

    } else {
      set theArray(TABLE_BUTTON,act) 0
      Widget::configureField $globArray TABLE_BUTTON
    }
  }
}


# FocusOut event for an entry-widget
#
proc Widget::entryFocusOut {globArray fld wdg {event_info ""} } {
  global Info
  upvar #0 $globArray theArray

  # Nothing currently!
  # ==================
  return


  if { [info exist theArray(hasFocus)] && !$theArray(hasFocus) } {
    return
  }

  if { [info exist theArray(isActive)] && !$theArray(isActive) } {
    return
  }
  
  if { $theArray($fld,err) } {
    return
  }

  set msg [PanelCheck::checkField $globArray $fld]

  if { $msg != "" } {
    Widget::configure1 $wdg $Info(en_err_option) $Info(en_err_color) 
    return
  }

  Widget::configure1 $wdg $Info(en_err_option) $Info(en_nerr_color) 

  #if { $theArray($fld) != $theArray($fld,prev) } {
  #  Widget::configure1 $wdg $Info(en_mod_option) $Info(en_mod_color) 
  #}
}


# Enter (into the widget) event for an entry-widget
#
proc Widget::entryEnter {globArray fld wdg {event_info ""} } {
  upvar #0 $globArray theArray

  if { ![info exists theArray(entryInfoLabel)] } {
    return
  }

  if { ![info exist theArray($fld,dataSize)] } {
    return
  }
  
  set vr ""
  set ne ""
  set sz ""
  set blanks "                    "

  if { [info exist theArray($fld,variables)] &&
    $theArray($fld,variables) != ""
  } {
    set vr $theArray($fld,variables)
    regsub -all "_" $vr " " vr
    append vr $blanks
    set vr [string range $vr 0 19]
  }

  if { [info exist theArray($fld,nofEntries)] &&
       $theArray($fld,nofEntries) != "" &&
       $theArray($fld,nofEntries) > 1
     } {
    set ne $theArray($fld,nofEntries)
    append ne $blanks
    set ne [string range $ne 0 19]
  }

  set size $theArray($fld,dataSize)
#MSG "sixe=$size"
  if { $size != "" &&
       1 != [expr [join $size *]]
     } {
    set sz $size
    append sz $blanks
    set sz [string range $sz 0 19]
  }

  set txt ""

  if { $vr != "" } {
    append txt "Var: $vr\n"
  }

  if { $ne != "" } {
    append txt "Nof entries: $ne\n"
  }
 
  if { $sz != "" } {
    append txt "Size: $sz"
  }

  Widget::configure1 $theArray(entryInfoLabel) -text $txt
}

 
# Leave event for an entry-widget
#
proc Widget::entryLeave {globArray fld wdg {event_info ""} } {
  upvar #0 $globArray theArray

  if { ![info exist theArray(entryInfoLabel)] } {
    return
  }
  
  Widget::configure1 $theArray(entryInfoLabel) -text ""
}


# ============= 
# Generic procs
# =============


# Generic for radio button
#
proc Widget::radioButton_generic { globArray fld wdg event_info} {
  global Info
  upvar #0 $globArray theArray

  if { $theArray($fld,err) } {
    return
  }

  # NOTE: Here current value is "lagging", so we do the equal
  # test to see the modification
  if { $theArray($fld) == $theArray($fld,old) } {
    set theArray($fld,mod) 1  
  } else {
    set theArray($fld,mod) 0
  }

  Widget::setRadioButtonStatus $globArray $fld $wdg
}


# Generic for check box
#
proc Widget::checkBox_generic { globArray fld wdg event_info} {
  global Info
  upvar #0 $globArray theArray

  if { $theArray($fld,err) } {
    return
  }

  # NOTE: Here current value is "lagging", so we do the equal
  # test to see the modification
  if { $theArray($fld) == $theArray($fld,old) } {
    set theArray($fld,mod) 1  
  } else {
    set theArray($fld,mod) 0
  }

  Widget::setCheckBoxStatus $globArray $fld $wdg
}



#=========================================================#
#=========================================================#
#              Combined widgets                           # 
#=========================================================#
#=========================================================#


# ========================================================#
#                      TableEntry
# ========================================================#

# Displays a table entry with unique widget id:
#
#-Entry widget for new rows
#-Listbox for all rows
#-Add,Insert,Update,Delete buttons
#-Ok,Cancel,Apply buttons
#
proc TableEntry::create { parent_id
                          frame
                          data_list
                          sort sort_marker
                          accept_multi_x
                          lb_width lb_height
                          entry_check_proc
                          datalist_pre_check_proc
                          datalist_post_check_proc
                          {globArray ""}
                        } {
  global Info

  variable id
  incr id

  # We need a unique id for these
  # variables, because multiple tables can exist
  #
  variable acceptMultiX$id
  variable dataListPreCheckProc$id
  variable dataListPostCheckProc$id
  variable entry$id
  variable entryCheckProc$id
  variable frame$id
  variable globArray$id
  variable listbox$id
  variable nofEntries$id
  variable parentId$id
  variable showIndex$id 0
  variable showLineNumbers$id 0
  variable sort$id
  variable sortMarker$id
  variable updated$id 0

  set acceptMultiX$id $accept_multi_x
  set dataListPreCheckProc$id $datalist_pre_check_proc
  set dataListPostCheckProc$id $datalist_post_check_proc
  set entryCheckProc$id $entry_check_proc
  set frame$id          $frame
  set globArray$id      $globArray
  set parentId$id       $parent_id
  set sort$id           $sort
  set sortMarker$id     $sort_marker

  set m [set frame$id]

  frame $m.ef   ;# Entry frame
  frame $m.bbf  ;# Box & buttons frame
  frame $m.lbf  ;# Listbox frame
  frame $m.btnf ;# Add etc. buttons frame

  # NOTE This entry is with table-font!
  entry $m.e -width $lb_width -font $Info(tableFont)
  set entry$id $m.e
  set wdg [set entry$id]
  bind $wdg <KeyPress-Return> "TableEntry::addListEntry $id"

  listbox $m.lb -width $lb_width -height $lb_height \
                -relief sunken -selectmode extended \
                -xscrollcommand [list $m.scrollbar_x set] \
                -yscrollcommand [list $m.scrollbar_y set] \
                -exportselection 0 -font $Info(tableFont)
  scrollbar $m.scrollbar_x -orient horizont -command [list $m.lb xview]
  scrollbar $m.scrollbar_y -orient vertical -command [list $m.lb yview]

  set listbox$id $m.lb
  set wdg [set listbox$id]
  bind $wdg <Double-1> "TableEntry::copyListEntry $id"

  button $m.add    -text "Add"     -width 8 \
                   -command "TableEntry::addListEntry $id"
  button $m.insert -text "Insert"  -width 8 \
                   -command "TableEntry::insertListEntry $id"
  button $m.update -text "Update"  -width 8 \
                   -command "TableEntry::updateListEntry $id"
  button $m.delete -text "Delete"  -width 8 \
                   -command "TableEntry::deleteListEntry $id"
  
  checkbutton $m.lines -text "Line nbrs" -command "TableEntry::toggleLineNumbers $id" \
                       -variable "TableEntry::showLineNumbers$id"

   
  #-----WIDGET PACKING
  set fpx1 $Info(framePadX1)
  set fpy1 $Info(framePadY1)
  set fpx2 $Info(framePadX2)
  set fpy2 $Info(framePadY2)
  set fpx3 $Info(framePadX3)
  set fpy3 $Info(framePadY3)

  #-Frames
  set m $frame
  pack $m.ef $m.bbf -side top  -anchor w
  pack $m.lbf $m.btnf -in $m.bbf -side left -expand 1 -fill both
  
  #-Entry field
  pack $m.e -in $m.ef

  #-Listbox
  pack  $m.scrollbar_x -in $m.lbf -side bottom -fill x     
  pack  $m.lb $m.scrollbar_y -in $m.lbf -side left -expand 1 -fill y     

  #-Buttons
  pack  $m.lines -in $m.btnf -side bottom -anchor s -padx $fpx1 -pady $fpy1
  pack  $m.add $m.insert $m.update $m.delete \
                 -in $m.btnf -side top -expand 1 -anchor n -padx $fpx1 -pady $fpy1

  #-All
  pack $m -side top  -anchor nw -fill x -expand 1 -padx $fpx1 -pady $fpy1


  TableEntry::updateDataList $id $data_list 0

  return $id
}


# Delete TableEntry instance with id
#
proc TableEntry::delete {id} {
}


# Add a new row at the end listbox
#
proc TableEntry::addListEntry {id} {

  set pid [set TableEntry::parentId$id]

  #--Check entry
  #
  set wdg [set TableEntry::entry$id]

  set data_entry [$wdg get]

  $wdg icursor 0
  $wdg selection range 0 end

  set data_entry [[set TableEntry::entryCheckProc$id] $pid "add" $data_entry]

  if { $data_entry == "" } {
    return
  }

  #--Precheck data list
  #
  if { ![[set TableEntry::dataListPreCheckProc$id] $pid "add"] } {
    return
  } 

  #--Update datalist
  #
  set data_list [TableEntry::getDataList $id]

  set sort [set TableEntry::sort$id]
  set show_index end

  if {$sort} {
    set show_index -1
    append data_entry [set TableEntry::sortMarker$id]
  }
  
  lappend data_list $data_entry

  set TableEntry::showIndex$id $show_index

  TableEntry::updateDataList $id $data_list $sort

  #--Postcheck datalist
  #
  if { ![[set TableEntry::dataListPostCheckProc$id] $pid "add"] } {
    return
  }
}


proc TableEntry::copyListEntry {id} {
  global Timestep Info

  set index [[set TableEntry::listbox$id] curselection]

  if { $index == "" || [llength $index] > 1 } {

    set Info(messageIcon) info
    Message::dispOkMessage {"Select first one entry to be copied!"}                    
    return
  }

  set data_list [TableEntry::getDataList $id]

  #set new_row [string trim [lindex $data_list $index]]
  set new_row [lindex $data_list $index]

  set wdg [set TableEntry::entry$id]

  set old_row [$wdg get]
  set old_row [string trim $old_row]

  if { $old_row != "" } {
    set msg [list "NOTE: Current entry data will be replaced by the selected row!\n\n" \
                  $Info(continueOk) ]

    if { ![Message::verifyAction $Info(noviceUser) $msg] } {
      return
    }
  }

  $wdg delete 0 end
  $wdg insert 0 $new_row

}


# Delete current selection from the list
#
proc TableEntry::deleteListEntry {id} {
  global Info

  set pid [set TableEntry::parentId$id]

  set indices [[set TableEntry::listbox$id] curselection]

  if { $indices == "" } {

    set Info(messageIcon) info
    Message::dispOkMessage {"Select first the listrow(s) to be deleted!"} 
    return
  }

  #--Precheck datalist
  #
  if { ![[set TableEntry::dataListPreCheckProc$id] $pid "delete"] } {
    return
  } 

  #--Update datalist
  #
  set reversed_indices ""

  foreach index $indices {
    set reversed_indices [linsert $reversed_indices 0 $index]
  }

  set show_index [lindex $indices 0]


  set data_list [TableEntry::getDataList $id]

  foreach index $reversed_indices {
    set data_list [lreplace $data_list $index $index ]
  }

  set sort 0
  set TableEntry::showIndex$id $show_index

  TableEntry::updateDataList $id $data_list $sort

  #--Postcheck datalist
  #
  if { ![[set TableEntry::dataListPostCheckProc$id] $pid "delete"] } {
    return
  }

}


# Insert a new row into list above the current selection
#
proc TableEntry::insertListEntry {id} {
  global Info

  set pid [set TableEntry::parentId$id]

  set index [[set TableEntry::listbox$id] curselection]

  if {$index == ""} {
    set Info(messageIcon) info
    Message::dispOkMessage {"Select first the listrow above which data is to be inserted!"}
    return
  }
  
  #--Check entry
  #
  set data_entry [[set TableEntry::entry$id] get]
  set data_entry [[set TableEntry::entryCheckProc$id] $pid "insert" $data_entry]

  if { $data_entry == ""} {
    return
  }

  #--Precheck datalist
  #
  if { ![[set TableEntry::dataListPreCheckProc$id] $pid "insert"] } {
    return
  } 

  #--Update datalist
  #
  set show_index $index

  set sort [set TableEntry::sort$id]

  if {$sort} {
    set show_index -1
    append data_entry [set TableEntry::sortMarker$id]
  }

  set data_list [TableEntry::getDataList $id]
  set data_list [linsert $data_list $index $data_entry]

  set TableEntry::showIndex$id $show_index

  TableEntry::updateDataList $id $data_list $sort

  #--Postcheck datalist
  #
  if { ![[set TableEntry::dataListPostCheckProc$id] $pid "insert"] } {
    return
  }

}


# Updates current selection in the list using the value
# in the entry field
#
proc TableEntry::updateListEntry {id} {
  global Info

  set pid [set TableEntry::parentId$id]

  set index [[set TableEntry::listbox$id] curselection]

  if {$index == ""} {
    set Info(messageIcon) info
    Message::dispOkMessage {"Select first the listrow to be updated!"}                   
    return
  }
  
  #--Check entry
  #
  set data_entry [[set TableEntry::entry$id] get]
  set data_entry [[set TableEntry::entryCheckProc$id] $pid "update" $data_entry]

  if { $data_entry == ""} {
    return
  }

  #--Precheck datalist
  #
  if { ![[set TableEntry::dataListPreCheckProc$id] $pid "update"] } {
    return
  } 

  #--Update datalist
  #
  set show_index $index

  set sort [set TableEntry::sort$id]

  if {$sort} {
    set show_index -1
    append data_entry [set TableEntry::sortMarker$id]
  }
  
  set data_list [TableEntry::getDataList $id]
  set data_list [lreplace $data_list $index $index $data_entry]
  set TableEntry::showIndex$id $show_index

  TableEntry::updateDataList $id $data_list $sort

  #--Postcheck datalist
  #
  if { ![[set TableEntry::dataListPostCheckProc$id] $pid "update"] } {
    return
  }

}


# Update list box view
#
proc TableEntry::updateDataList { id data_list {sort 0} } {
  
  upvar #0 [set TableEntry::globArray$id] theArray

  set TableEntry::updated$id 1

  set marker [set TableEntry::sortMarker$id]

  if {$sort} {
    set data_list [lsort -index 0 -real $data_list]
  }

  set show_index [set TableEntry::showIndex$id]

  # If we should show a "marked" line
  #
  if {$show_index == -1 && $marker != ""} {

    set show_index [lsearch -regexp $data_list $marker]

    if {$show_index != -1} {
      set old_row [lindex $data_list $show_index]
      regsub -all $marker $old_row "" new_row

      set data_list [lreplace $data_list $show_index $show_index $new_row]
    }
  }

  # Add line numbers. if needed
  #
  if { 1 == [set TableEntry::showLineNumbers$id] } {
    set counter 0
    set new_list ""
    foreach row $data_list {
      incr counter
      lappend new_list "$counter  $row"
    }
    set data_list $new_list
  }

  set TableEntry::nofEntries$id [llength $data_list]

  ListBox::fill [set TableEntry::listbox$id]  $data_list

  [set TableEntry::listbox$id] see $show_index

}


# Get data list, so that possible line numbers
# are cleaned off
#
proc TableEntry::getDataList { id } {

  if { ![winfo exists [set TableEntry::listbox$id] ] } {
    return ""
  }

  set data_list [[set TableEntry::listbox$id] get 0 end]

  if { 0 == [set TableEntry::showLineNumbers$id] } {
    return $data_list
  }

  set new_list ""
  # Remove line numbers before returning "pure" data list
  foreach row $data_list {
    lappend new_list [lrange $row 1 end ]
  }

  return $new_list
}


# Toggles the display of line numbers
# Updates list view
#
proc TableEntry::toggleLineNumbers { id } {

  # NOTE: We have to temporarily change teh flag value
  # before we read the current data list, because
  # flag value was just changed when checkbutton was
  # clicked!
  #
  set sln [set TableEntry::showLineNumbers$id] 

  if { $sln == 1 } { 
    set TableEntry::showLineNumbers$id 0
  } else {
    set TableEntry::showLineNumbers$id 1
  }

  set data_list [TableEntry::getDataList $id]

  # Ok, now we have to restore to the current value!
  set TableEntry::showLineNumbers$id $sln

  TableEntry::updateDataList $id $data_list 0
}



# ========================================================#
#                        Data Entry
# ========================================================#

# Displays a dialog with one entry field.
# Result is put into variable referenced by argument
# 'resultvar'. It should be a global variable, because
# ok-button as a command-procedure works in global scope.
#
proc Widget::dispDataEntry  {
          {resultvar "entryResult"}
          {default ""} 
          {title "Data entry"}
          {label "Enter value: "}
                } {

  toplevel .w
  set w .w
  wm title $w $title
  frame $w.f1
  frame $w.f2
  label $w.l -text $label
  entry $w.e -width 50 
  $w.e insert 0 $default

  eval "button $w.ok -text OK -command {set " $resultvar "\[.w.e get\];destroy .w}"
  eval "button $w.cancel -text Cancel -command {set " $resultvar "\"!cancel!\";destroy .w}"

  pack $w.f1 $w.f2 -side top -fill y -expand 1 -padx 10 -pady 15
  pack $w.l -side left -in $w.f1
  pack $w.e -side left -in $w.f1 -fill x
  pack $w.ok $w.cancel -side left -in $w.f2 -padx 10
}



# ========================================================#
#                   Directory Entry
# ========================================================#

# Procedure displays a dialog with one entry field and
# directory browse button
# Result is put into variable referenced by argument
# 'resultvar'. It should be a global variable, because
# ok-button as a command-procedure works in global scope.
#
proc Widget::dispDirectoryEntry  {
          wname
          {resultvar "entryResult"}
          {default ""} 
          {title "Directory name entry"}
          {label "Enter name: "}
                } {
  global Info

  # Check that wname is a correct root window name
  #
  set wname [Util::stringTrim $wname]
  if { "." != [string index $wname 0] } {
    set wname ".$wname"
  }

  if { [winfo exists $wname] } {
    return
  }

  toplevel $wname
  set w $wname

  wm title $w $title
  frame $w.f1
  frame $w.f2

  label $w.l -text $label
  set wdg [entry $w.e -width 50 ]
  button $w.b -text "..." -width 1 \
              -command "Util::fillDirectoryEntry $wdg"

  $wdg insert 0 $default

  eval "button $w.ok -text OK -command {set " $resultvar "\[$w.e get\];destroy $w}"
  eval "button $w.cancel -text Cancel -command {set " $resultvar "\"!cancel!\";destroy $w}"

  pack $w.f1 $w.f2 -side top -fill y -expand 1 -padx 10 -pady 15
  pack $w.l -side left -in $w.f1
  pack $w.e -side left -in $w.f1 -fill x
  pack $w.b -side left -in $w.f1 -fill x -padx 10
  pack $w.ok $w.cancel -side left -in $w.f2 -padx 10
}



# ========================================================#
#                    File Entry
# ========================================================#

# Procedure displays a dialog with one entry field and
# file browse button
# Result is put into variable referenced by argument
# 'resultvar'. It should be a global variable, because
# ok-button as a command-procedure works in global scope.
#
proc Widget::dispFileEntry  {
          wname
          {resultvar "entryResult"}
          {default ""} 
          {title "File name entry"}
          {label "Enter name: "}
                } {
  global Info
  
  # Check that wname is a correct root window name
  #
  set wname [Util::stringTrim $wname]
  if { "." != [string index $wname 0] } {
    set wname ".$wname"
  }

  if { [winfo exists $wname] } {
    return
  }

  toplevel $wname
  set w $wname

  wm title $w $title
  frame $w.f1
  frame $w.f2

  label $w.l -text $label
  set wdg [entry $w.e -width 50 ]
  button $w.b -text "..." -width 1 \
              -command "Util::fillFileEntry $wdg"

  $wdg insert 0 $default

  eval "button $w.ok -text OK -command {set " $resultvar "\[$w.e get\];destroy $w}"
  eval "button $w.cancel -text Cancel -command {set " $resultvar "\"!cancel!\";destroy $w}"

  pack $w.f1 $w.f2 -side top -fill y -expand 1 -padx 10 -pady 10
  pack $w.l -side left -in $w.f1
  pack $w.e -side left -in $w.f1 -fill x
  pack $w.b -side left -in $w.f1 -fill x -padx 10
  pack $w.ok $w.cancel -side left -in $w.f2 -padx 10
}


# ========================================================#
#                  File Select Panel
# ========================================================#

# Procedure displays a dialog with one entry field and
# file browse button. In addition there is a list of radiobuttons
# where the user can spefify the input file type
#
# Result-file and selected-type-index (0,1,...) are put into global variables referenced
# by arguments: 'resultfile' and 'resulttype'.
# They should be global variables, because ok-button as a command-procedure works in global scope.
#
proc Widget::dispFileSelectPanel  {
          wname
          {wtitle "Select File"}
          {hdr "Select file type"}
          {resultpath "entryResult"}
          {resulttype "radioResult"}
          {filetypes "" }
          {extensions { {{Any} {*.* }} } }
          {default_type 0} 
          {default_dir ""} 
          {default_file ""} 
          {default_idx ""} 
                } {
  global Info $resultpath $resulttype
  upvar #0 $resultpath respath $resulttype restype
  
  # Check that wname is a correct root window name
  #
  set wname [Util::stringTrim $wname]
  if { "." != [string index $wname 0] } {
    set wname ".$wname"
  }

  if { [winfo exists $wname] } {
    return
  }

  toplevel $wname
  set w $wname
  
  wm title $w $wtitle
  frame $w.f1
  frame $w.f2
  frame $w.f3
  frame $w.f4

  # Create panel widgets
  # ====================

  # Panel header
  #
  label $w.hdr -text $hdr

  # Radiobuttons frames
  #
  frame $w.f2.sf1
  frame $w.f2.sf2

  #--Radiobuttons
  #
  # NOTE: Radiobuttons variable is the global tcl-variable name given in 'resultype'
  # Its value will be the index of the button selected (0,1,...)
  #
  set rbuttons ""
  set idx -1
  foreach ftp $filetypes {
    incr idx
    set wdg [radiobutton $w.rb$idx -anchor w \
              -indicatoron 1 -state normal -text $ftp \
              -selectcolor $Info(select_color) \
              -variable $resulttype -value $idx \
            ]
    lappend rbuttons $wdg

    if { $idx == $default_idx } {
      $wdg select
    }
  }

  #--File entry field
  #
  label $w.l -text "Enter file name  "
  set wdg [entry $w.e -width 50 ]

  $wdg insert 0 $default_file

  #--Buttons
  
  # File Browser button (...)
  # -------------------------
  #
  # Well, this is tricky, but couldn't find better way to build an argument which would be
  # evaluated correctly and at proper time!!!
  #
  # NOTE: The proper extensions list is selected at run-time by the index value in the
  # global reference variable 'resulttype'
  #
  set extensions [list $extensions]
  set cmd "Util::fillFileEntry $wdg \[list "
  append cmd  "-extensions \[lindex $extensions \$"
  append cmd "$resulttype \] "
  append cmd "-initDir \"$default_dir\" "
  append cmd "-initFile \"$default_file\" "
  append cmd "\]"

  # NOTE: Browser button command defined here!
  #
  #  -command "Widget::deactivate $rbList; wm focusmodel $w passive; $cmd; Util::doWait 50; wm focusmodel $w active; Widget::activate $rbList"
  set rbList [list $rbuttons]
  button $w.b -text "..." -width 1 \
    -command "Widget::deactivate $rbList; $cmd; Util::doWait 50; Widget::activate $rbList"
  
  # These button commands are not 'built', but handled with eval!
  #
  # NOTE: The global reference variable 'resultpath' will store the path name
  # when these buttons are pressed!
  #
  # NOTE: 'resultpath' should be set only by these buttons, because client must poll the
  # change in this variable (via 'tkwait varaible') to conclude that panel is closed/applied!!!
  #
  eval "button $w.ok -text OK -command {set " $resultpath "\[$w.e get\];destroy $w}"
  eval "button $w.cancel -text Cancel -command {set " $resultpath "\"!cancel!\";destroy $w}"

  # Pack panel
  # ==========
  
  pack $w.f1 $w.f2 $w.f3 -side top -fill both -expand 1 -padx 10 -pady 10
  pack $w.f4 -side top -fill y -expand 0 -padx 10 -pady 10
 
  # Pack radiobutton frames and radiobuttons into proper subframe
  #
  pack $w.f2.sf1 $w.f2.sf2 -side left -fill both -expand 1 -in $w.f2
  
  set hcount [expr round([llength $rbuttons] / 2)]
  set idx 0

  foreach rbtn $rbuttons {
    incr idx
    if { 1 == [expr $idx % 2] } {
      set f $w.f2.sf1
    } else {
      set f $w.f2.sf2
    }
    pack $rbtn -side top -anchor nw -expand 0 -in $f
  }

  pack $w.hdr -side left -in $w.f1
  pack $w.l -side left -in $w.f3
  pack $w.e -side left -in $w.f3 -fill x
  pack $w.b -side left -in $w.f3 -fill x -padx 10
  pack $w.ok $w.cancel -side left -in $w.f4 -padx 10

}


# ========================================================#
#                    CheckBoxList
# ========================================================#

# Displays a listbox where each row has a 'checkbox'
#
#-Listbox for all rows
#-All, None buttons
#-Ok,Cancel,Apply buttons
#
# Return: selections  (0/1 flags for each row)
#
proc CheckBoxList::create { win
                            datalist
                            in_selections
                            lb_width lb_height
                          } {
  global Info

  set selections ""

  if { $in_selections == "" } {
    foreach item $datalist {
      lappend selections 0
    }
  } else {
    set selections $in_selections
  }

  variable id
  incr id

  # We need a unique id for these
  # variables, because multiple boxes can exist
  #
  variable win$id
  variable listbox$id
  variable datalist$id
  variable selections$id
  variable updated$id
  variable closed$id
  
  set win$id $win
  set updated$id 0
  set closed$id 0
  set datalist$id $datalist
  set selections$id $selections

  set m [frame $win.f]

  frame $m.bbf  ;# Box & All,None buttons frame
  frame $m.lbf  ;# Listbox frame
  frame $m.btnf1 ;# All, None buttons frame
  frame $m.btnf2 ;# Ok etc. buttons frame

  listbox $m.lb -width $lb_width -height $lb_height \
                -relief sunken -selectmode browse \
                -xscrollcommand [list $m.scrollbar_x set] \
                -yscrollcommand [list $m.scrollbar_y set] \
                -exportselection 0 -font $Info(tableFont)
  scrollbar $m.scrollbar_x -orient horizont -command [list $m.lb xview]
  scrollbar $m.scrollbar_y -orient vertical -command [list $m.lb yview]

  set listbox$id $m.lb

  set wdg [set listbox$id]
  bind $wdg <Button-1> "CheckBoxList::setSelection $id Button-1 %x %y"
  
 
  button $m.btnf1.all -text "All" -width 3 \
                  -command "CheckBoxList::all $id"

  button $m.btnf1.none -text "None" -width 3 \
                   -command "CheckBoxList::none $id"

  button $m.btnf2.ok -text "Ok" -width 5 \
                 -command "CheckBoxList::ok $id"

  button $m.btnf2.cancel -text "Cancel" -width 5 \
                     -command "CheckBoxList::cancel $id"

  #-----WIDGET PACKING
  set fpx1 $Info(framePadX1)
  set fpy1 $Info(framePadY1)
  set fpx2 $Info(framePadX2)
  set fpy2 $Info(framePadY2)
  set fpx3 $Info(framePadX3)
  set fpy3 $Info(framePadY3)

  #-Frames
  pack $m.bbf -side top -anchor w -expand 1 -fill both
  pack $m.lbf -in $m.bbf -side left -expand 1 -fill both
  pack $m.btnf1 -in $m.bbf -side left -expand 0 -fill x
  pack $m.btnf2 -side top -expand 0 -fill y
  
  #-Listbox
  pack  $m.scrollbar_x -in $m.lbf -side bottom -expand 0 -fill x     
  pack  $m.lb -in $m.lbf -side left -expand 1 -fill both     
  pack  $m.scrollbar_y -in $m.lbf -side left -expand 0 -fill y     

  #-Buttons
  pack  $m.btnf1.all $m.btnf1.none -side top -expand 0 -padx $fpx2 -pady $fpy3

  pack  $m.btnf2.ok $m.btnf2.cancel -side left -expand 0 -padx $fpx3 -pady $fpy2

  #-All
  pack $m -side top -anchor nw -fill both -expand 1 -padx $fpx1 -pady $fpy1

  # Fill list box
  #
  CheckBoxList::fillListBox $id 

  # Wait until window is closed
  #
  vwait CheckBoxList::closed$id
  
  if { 1 == [set CheckBoxList::updated$id] } {
    return [set CheckBoxList::selections$id]
  } else {
    return $in_selections
  }
}


# Fill listbox with current/updated contents
#
proc CheckBoxList::fillListBox {id} {
  global Info

  set wdg [set CheckBoxList::listbox$id]
  set dlist [set CheckBoxList::datalist$id]
  set sels [set CheckBoxList::selections$id]
  
  set rows ""

  set index 0
  foreach item $dlist dmode $sels {

    if { $dmode == 1 } {
      set row $Info(selectionBoxTrueMarker)
    } else {
      set row $Info(selectionBoxFalseMarker)
    }

    append row " $item"
    
    lappend rows $row

    incr index
  }

  ListBox::fill $wdg $rows
}


# NOTE: Tcl special arg-name 'args' <--> all aruments in one list!
#
proc CheckBoxList::setSelection {args} {

  set id [lindex $args 0] ;# Widget id

  set event_mode [lindex $args 1] ;# Button and keys pressed
  set lb_x [lindex $args 2] ;# Local lb x-coordinate for selection
  set lb_y [lindex $args 3] ;# Local lb y-coordinate for selection 

  set wdg [set CheckBoxList::listbox$id]
  set sels [set CheckBoxList::selections$id]

  #-Selected ("clicked") row
  set idx [$wdg index @$lb_x,$lb_y]

  if { $idx == "" || $idx < 0 } {
    return
  }

  set dmode [lindex $sels $idx]

  # Toggle selection
  if { $dmode == 1 } {
    set sels [lreplace $sels $idx $idx 0]
  } else {
    set sels [lreplace $sels $idx $idx 1]
  }

  set CheckBoxList::selections$id $sels

  CheckBoxList::fillListBox $id
}


# Set all selected
#
proc CheckBoxList::all {id} {

  set sels [set CheckBoxList::selections$id]
  
  set new_sels ""
  foreach dmode $sels {
    lappend new_sels 1
  }

  set CheckBoxList::selections$id $new_sels

  CheckBoxList::fillListBox $id

  set wdg [set CheckBoxList::listbox$id]
  $wdg selection clear 0 end
}


# Set none selected
#
proc CheckBoxList::none {id} {

  set sels [set CheckBoxList::selections$id]
  
  set new_sels ""
  foreach dmode $sels {
    lappend new_sels 0
  }

  set CheckBoxList::selections$id $new_sels

  CheckBoxList::fillListBox $id

  set wdg [set CheckBoxList::listbox$id]
  $wdg selection clear 0 end
}


# Save proc
#
proc CheckBoxList::save {id} {
  
  set CheckBoxList::updated$id 1
}


# Close proc
#
proc CheckBoxList::close {id} {
    
    set wdg [set CheckBoxList::win$id]
    destroy $wdg
    set CheckBoxList::closed$id 1
}


# Ok proc
#
proc CheckBoxList::ok {id} {

  CheckBoxList::save $id
  CheckBoxList::cancel $id
}


# Cancel proc
#
proc CheckBoxList::cancel {id} {
  
  CheckBoxList::close $id
}



# ========================================================#
#                     File Browser
# ========================================================#

# Procedure creates a file browser (or editor)
#
proc FileBrowser::browse {windowName 
                          filename
                          {file_must_exist 1}
                          {canEdit 0}
                          {canDeleteCancelled 0}
                          {line_parsing_call none}
                          {channel_id 0}
                          {process_nbr 0}
                          {canUseExternal 1}
                          {width 60}
                          {height 30}
                        } {

  global Info UserSetting ProcessTable

  #--If target file should exist
  if { $file_must_exist && $filename != "" } {

    if { ![file exists $filename] } {
      set msg "File:\n $filename\nnot found!\n\n"
      set Info(messageIcon) error
      Message::dispOkMessage $msg
      return ""
    }
  }

  set source_ok 0

  #--Try to open the file

  #-Try first the channel id
  if { $channel_id != "" &&
       $channel_id != 0 &&
       ![catch {eof $channel_id}]
     } {
    set in $channel_id
    set source_ok 1

  #-Next try the filename
  } elseif { ![catch {set channel_id [open $filename] } ] } {
    set in $channel_id
    set source_ok 1

  #-Next try source array
  } elseif { 2 == [llength $filename] } {

    set globSourceArray [lindex $filename 0]
    set theSourceVar  [lindex $filename 1]

    upvar #0 $globSourceArray theSourceArray

    if { [info exists theSourceArray($theSourceVar)] } {
      set source_ok 1
      set filename ""
      set in 0
    }
  }

  #-Ouch, no data!
  if { !$source_ok } {
    set msg "Cannot open file:\nFile: $filename\n or\n ChannelId: $channel_id"
    set Info(messageIcon) error
    Message::dispOkMessage $msg
    return ""
  }

  #--We check if we should and can use an external program
  set external_command ""
  set external_ok 1
  set external_msg ""

  if { $canUseExternal } {

    if { $canEdit } {
      set external_command $UserSetting(EDITOR_COMMAND)

    } else {
      set external_command $UserSetting(BROWSER_COMMAND)
    }
  }

  #--If external command given, try it
  if { $external_command != "" } {

    #-Reformat to correct platform format
    set fname [file nativename $filename]
    
    #-Create first proper execuable name (we try separate all flags!)
    set dir_part [file dirname $external_command]
    set exe_part [lindex [file tail $external_command] 0]
 
    if { $dir_part == "." } { 
      set dir_part ""
    }

    set external_exec_command [file join $dir_part $exe_part]

    set flags [join [lrange [file tail $external_command] 1 end] ]

#MSG "cmd=$external_exec_command flags=$flags"


    #-Create first proper executable name (we try separate all flags!)
    #set external_exec_command [lindex $external_command 0]
    #set flags [lindex $external_command 1]

    if { $flags != "" } {
      set code [ catch { exec $external_exec_command $flags $fname & } msg ]
    } else {
      set code [ catch { exec $external_exec_command $fname & } msg ]
    }

    #-if something went wrong
    if {$code != 0} {
      set external_ok 0
      set external_msg "External editor/browser was not run properly, because: $msg"
    }
  }


  #--If external command was given
  if { $external_command != "" } {
    
    #-If succes, we can stop here  
    if {$external_ok} {
      close $in
      return ""

    #-Otherwise we give message and continue with 
    # internal browser/editor
    } else {
      Message::showMessage $external_msg
    }
  }
  

  #--Process item: use the possible earlier browser id
  #
  if { $process_nbr > 0 } {

    #-Check if this reopened browser for an existing process
    #
    if { [info exists ProcessTable($process_nbr,bid)] &&
         $ProcessTable($process_nbr,bid) > 0
       } {
      set bid $ProcessTable($process_nbr,bid)

      # Cancel old delayed scripts
      after cancel $Info(browser,$bid,monitorId)
      after cancel $Info(browser,$bid,readHandlerId)

      # Start reading from the beginning of the logfile!!!
      seek $channel_id 0 start

      if { $line_parsing_call == "" } {
        set line_parsing_call $Info(browser,$bid,parser)
      }

    #-Create new unique browser id for process
    } else {
      set bid [incr Info(browser,id)]
      set ProcessTable($process_nbr,bid) $bid
    }
  
  #--Non-process item: always an unique broser id
  #
  } else {
    set bid [incr Info(browser,id)]
  }

  #--Data filling line at a time using fileevent
  # NOTE: Fileevent seems to be still blocking in NT!!!
  #fconfigure $in -blocking 0 -buffering line
  set Info(browser,$bid,filename) $filename
  set Info(browser,$bid,infile) $in
  set Info(browser,$bid,act) 1
  set Info(browser,$bid,processNbr) $process_nbr
  set Info(browser,$bid,parser) $line_parsing_call
  set Info(browser,$bid,readHandlerId) -1
  set Info(browser,$bid,monitorId) -1
  set Info(browser,$bid,update) 1
  set Info(browser,$bid,modified) 0
  set Info(browser,$bid,cancelled) 0
  set Info(browser,$bid,canDeleteCancelled) $canDeleteCancelled
  set Info(browser,$bid,charCount) 0

  set Info(browser,$bid,mtime) 0

  if { ![catch { set mtime [file mtime $filename] } ] } {
    set Info(browser,$bid,mtime) $mtime
  }
  
  set Info(browser,$bid,readFromStart) 1
  set Info(browser,$bid,writeFromStart) 1

  #--What is our window like?
  set w $windowName
  set wclass ""

  if {[winfo exists $w]} {
    set wclass [winfo class $w]
  }

  #---If our widget is a toplevel window
  if { $wclass != "Frame" } {

    #--Run number is used also as window id !!!
    set id $Info(browser,$bid,processNbr)
    set w $windowName$id

    if {[winfo exists $w]} {
      wm deiconify $w
      focus $w
      return $w.text
    }

    toplevel $w
    wm title $w $filename

    # Check also 'violent' closes!
    wm protocol $w WM_DELETE_WINDOW "FileBrowser::closed $w $bid"

    # Set process table related accelerators
    if { $Info(browser,$bid,processNbr) > 0 } {
      bind $w <Control-KeyPress-t> "Util::execProc ProcessTable::openPanel"
      bind $w <Control-KeyPress-T> "Util::execProc ProcessTable::openPanel"
      bind $w <Control-KeyPress-k> "Util::execProc ProcessTable::kill $Info(browser,$bid,processNbr); focus $w; focus $w.f2.fB.ok"
      bind $w <Control-KeyPress-K> "Util::execProc ProcessTable::kill $Info(browser,$bid,processNbr); focus $w; focus $w.f2.fB.ok"
    }

    set xpos [winfo x $Info(mainWindow)]
    incr xpos -40
    set ypos [winfo y $Info(mainWindow)]
    incr ypos 20
    wm geometry $w +$xpos+$ypos
  }

  set Info(browser,$bid,window) $w

  #---Frames, widgets and packing
  frame $w.f1
  frame $w.f2
  frame $w.f2.fB

  pack $w.f2 -side bottom -fill x -expand 0 -anchor c
  pack $w.f1 -side top -fill both -expand 1

  #--Text frame
  set m $w.f1
  text $m.text -width $width -height $height -font $Info(browserFont) \
    -setgrid true -wrap none \
    -xscrollcommand [list $m.xscroll set] \
    -yscrollcommand [list $m.yscroll set]
  scrollbar $m.xscroll -orient horizontal \
    -command [list $m.text xview]
  scrollbar $m.yscroll -orient vertical  \
    -command [list $m.text yview]
  pack $m -side top -fill both -expand true
  pack $m.xscroll -side bottom -fill x
  pack $m.yscroll -side right -fill y
  pack $m.text -side left -fill both -expand true
  
  #--Buttons frame
  pack $w.f2.fB
  set m $w.f2.fB

  button $m.ok -text OK -command "FileBrowser::closed $w $bid"
  button $m.refresh -text Refresh -command "FileBrowser::refresh $bid $w.f1.text $filename"
  button $m.updateMode -text Freeze -width 8 \
                       -command "FileBrowser::toggleUpdateMode $bid $m.updateMode"
  button $m.kill -text Kill -width 5 \
                       -command "Util::execProc ProcessTable::kill $Info(browser,$bid,processNbr); focus $w; focus $w.f2.fB.ok"

  set Info(browser,$bid,panelRefreshButton) $m.refresh
  $Info(browser,$bid,panelRefreshButton) configure -state disabled

  focus $m.ok

  set mT $w.f1
  set mB $w.f2.fB

  #--In browse mode
  if {!$canEdit} {
    if { $Info(browser,$bid,processNbr) <= 0 } {
      pack $mB.refresh $mB.ok -side left -padx 10
    } else {
     pack $mB.kill $mB.updateMode $mB.ok -side left -padx 10
    }

  #--In edit mode
  } else {
    button $mB.editOk -text Ok -command "FileBrowser::save $mT.text $bid $filename $in; FileBrowser::closed $w $bid"
    button $mB.editApply -text Apply -command "FileBrowser::save $mT.text $bid $filename $in"
    button $mB.cancel -text Cancel -command "set Info(browser,$bid,cancelled) 1 ;FileBrowser::closed $w $bid"

    set Info(browser,$bid,panelApplyButton) $mB.editApply
    $mB.editApply configure -state disabled

    bind $mT.text <KeyPress> "FileBrowser::markBrowserModified 1 $bid"

    bind $mT.text <Control-s> "FileBrowser::save $mT.text $bid $filename $in"
    bind $mT.text <Control-S> "FileBrowser::save $mT.text $bid $filename $in"

    pack $mB.refresh $mB.editOk $mB.cancel $mB.editApply  -side left -padx 10

  }

  # If we are reading some process output, we have to use
  # some delay time in after call
  #
  if { $Info(browser,$bid,processNbr) > 0 } {
    set delay [set ProcessTable($Info(browser,$bid,processNbr),browserDelay)]
  } else {
    set delay 0
  }

  #--Read data from the file using a read handler
  #   
  if { $in > 0 } {
    
    FileBrowser::readHandler $bid $delay $in $mT.text $line_parsing_call
    FileBrowser::monitor $bid
  
    #-Wait until browse job is done
    #tkwait variable Info(browser,$bid,act)

    #-Remove event handlers
    #fileevent [set Info(browser,$bid,infile)] readable ""
  
    #catch { close [set Info(browser,$bid,infile)] }

  #--Read data from an array
  #
  } else {
    
    Widget::configureS $mT.text normal
 
    foreach line $theSourceArray($theSourceVar) {
      $mT.text insert end $line
      $mT.text insert end \n
    }
 
    Widget::configureS $mT.text disabled
    Widget::configureS $Info(browser,$bid,panelRefreshButton) disabled
  }
          

  if {$canEdit} {
    Widget::configureS $mT.text normal
  }

  #--Return the text widget pointer
  return $mT.text
}


# ---------------
# BROWSER MONITOR
# ---------------
#
# Monitors when a browser can be detached from
# the file channel
#
proc FileBrowser::monitor { bid } {
  global Info

  if { ![info exists Info(browser,$bid,act)] } {
    return
  }

# Uncomment this to see 'lost' browser!
#MSG "Browser  bid=$bid  process=$Info(browser,$bid,processNbr) running!"

  FileBrowser::checkRefreshStatus $bid

  #--Inactive process, remove event handlers and close file
  if { -1 == $Info(browser,$bid,act) } {

    catch { fileevent [set Info(browser,$bid,infile)] readable "" }

    set msg ""
    set ch_id $Info(browser,$bid,infile)

		if { $Info(browser,$bid,cancelled) && $Info(browser,$bid,canDeleteCancelled) } {
			catch { [file delete -force $Info(browser,$bid,filename)] msg}
		}

    catch { [close $ch_id] msg}

# Uncomment this to see closing of a browser
#MSG "Browser bid=$bid  nbr=$Info(browser,$bid,processNbr) closed and unset!"

    # Remove browser info variables
    # =============================
    unset Info(browser,$bid,act)
    unset Info(browser,$bid,processNbr)
    unset Info(browser,$bid,parser)
    unset Info(browser,$bid,readHandlerId)
    unset Info(browser,$bid,monitorId)
    unset Info(browser,$bid,filename) 
    unset Info(browser,$bid,infile) 
    unset Info(browser,$bid,mtime) 
    unset Info(browser,$bid,modified) 
    unset Info(browser,$bid,update) 
    unset Info(browser,$bid,cancelled) 
    unset Info(browser,$bid,canDeleteCancelled) 
    unset Info(browser,$bid,window)
    unset Info(browser,$bid,charCount)

    catch { unset Info(browser,$bid,panelApplyButton) }
    catch { unset Info(browser,$bid,panelRefreshButton) }
    catch { unset Info(browser,$bid,readFromStart) }
    catch { unset Info(browser,$bid,writeFromStart) }


  # Otherwise continue monitoring
  } else {
    set Info(browser,$bid,monitorId) [after 500 "FileBrowser::monitor $bid"]
  }
}


proc FileBrowser::checkRefreshStatus {bid} {
  global Info
  
  set mtime0 $Info(browser,$bid,mtime)

  if { ![catch { set mtime [file mtime $Info(browser,$bid,filename)] } ] } {
    set Info(browser,$bid,mtime) $mtime
  }

  set mtime1 $Info(browser,$bid,mtime)

  if { $mtime0 != $mtime1 } {

    if { [info exists Info(browser,$bid,panelRefreshButton) ] &&
         [winfo exists $Info(browser,$bid,panelRefreshButton)]
       } {
      $Info(browser,$bid,panelRefreshButton) configure -state normal
      $Info(browser,$bid,panelRefreshButton) configure -fg red
    }
  }
}


# --------------------
# BROWSER READ HANDLER
# --------------------
#
# This proc is the browser update handler
# bid : browser id
#
proc FileBrowser::readHandler { bid delay infile text_widget line_parsing_call } {
  global Info ProcessTable

  # If browser unset or stop from outside
  if { ![info exist Info(browser,$bid,act)] ||
       -1 == $Info(browser,$bid,act)
     } {
    return
  }

#MSG "parser=$line_parsing_call"

  # If browser freezed, continue polling, but do not
  # update browser
  if { !$Info(browser,$bid,update) } {

    # STRANGE: This is needed to maintain list format
    # of the line-parser argument. It must be a list, otherwise
    # its possible (predefined) arguments would be arguments for
    # browseReadhandler!
    #
    if { [llength $line_parsing_call] > 1 } {
      set line_parsing_call [list "$line_parsing_call"]
    }

    after $delay "FileBrowser::readHandler $bid $delay $infile $text_widget $line_parsing_call"
    return
  }

  # If browser widget is closed
  #if { ![winfo exists $text_widget] } {
  #  Message::showMessage "FileBrowser::readHandler: $text_widget browser window closed!"
  #  set Info(browser,$bid,act) 0
  #  return
  #}

  # If process is dead, we can read the rest of the file
  # as quickly as possible!
  if { $Info(browser,$bid,processNbr) > 0 &&
       ![Process::exists $Info(browser,$bid,processNbr)]
     } {
    set delay 0
  }

  set count 0

  #-Try to (block) read data
  if { ![catch {set dataline [read -nonewline $infile]}] } {
    
    if { [catch {set count [llength $dataline]} ] } {
      set dataline [string map { \" \'} $dataline]
      catch {set count [llength $dataline]} 
    }
  }

  # Data available
  # ==============
  if { $count > 0 } {
    # Add new line(s) into the browser

    # Do we apply some line parsing proc
    if { $line_parsing_call != "none" } {
      set dataline [eval [join $line_parsing_call] [list $dataline]]
    }

    # If something left to insert into widget
    if { $dataline != "" && 
         [info exists text_widget] &&
         [winfo exists $text_widget]
       } {

      Widget::configureS $text_widget normal
      
      # Always start reading from the beginning of the data (which apprarenty is not
      # then output line by line)
      #
      if { $Info(browser,$bid,writeFromStart) } {
        $text_widget delete 0.0 end
        set Info(browser,$bid,writeFromStart) 0

      # If process browser's char-count limit is exceeded
      #
      } elseif { $Info(browser,$bid,processNbr) > 0 &&
                 $Info(browser,$bid,charCount) >= $Info(browser,maxCharCount)
               } {

        set del_count [expr round(0.1 * $Info(browser,maxCharCount))]
        set idx1 "0.0"
        set idx2 "0.0 +$del_count chars"

        $text_widget delete $idx1 $idx2
        incr Info(browser,$bid,charCount) -$del_count

        set msg "----- NOTE: Log truncated -----\n"
        $text_widget insert 0.0 $msg
        incr Info(browser,$bid,charCount) [string length $msg]
      }


      #--Insert the new line into browser data
      #
      $text_widget insert end $dataline
      $text_widget insert end \n
      incr Info(browser,$bid,charCount) [string length $dataline]
      incr Info(browser,$bid,charCount) 1
      #Widget::configureS $text_widget disabled

      if { $Info(browser,$bid,processNbr) > 0 } {
        $text_widget see end
      }
    }

  # No data available
  # =================
  } else {

    set pnbr $Info(browser,$bid,processNbr)

    #--A process started
    if { $pnbr > 0 } {

      #--Process ended
      if { ![Process::exists $pnbr] } {
        
        if { $Info(displayExecMessages) } {
          Message::showMessage "Process $pnbr at END!"
        }
        
        if { ![info exists ProcessTable($pnbr,pid)] } {
          set Info(browser,$bid,act) -1
        } else {
          set Info(browser,$bid,act) 0
        }

        return

      #--File at EOF state
      } elseif { $ProcessTable($pnbr,state) == "running" &&
                 $Info(browser,$bid,readFromStart)
               } {
        catch {close $infile}
        set infile [open $ProcessTable($pnbr,logfile)]
        set Info(browser,$bid,infile) $infile
        set Info(browser,$bid,readFromStart) 0
        #fileevent $infile readable "FileBrowser::readHandler $bid $delay $infile $text_widget $line_parsing_call"
      }

    #--Simple file read (no process started)
    } else {
      if { 1 == [eof $infile] } {
        catch { close $infile }
        set Info(browser,$bid,act) 0
        return
      }
    }
  }

  # Continue data polling
  # =====================
  
  # STRANGE: This is needed to maintain list format
  # of the line-parser argument. It must be a list, otherwise
  # its possible (predefined) arguments would be arguments for
  # browseReadhandler!
  #
  if { [llength $line_parsing_call] > 1 } {
    set line_parsing_call [list "$line_parsing_call"]
  }

  set Info(browser,$bid,readHandlerId) \
    [after $delay "FileBrowser::readHandler $bid $delay $infile $text_widget $line_parsing_call"]

  return
}


proc FileBrowser::closed { w bid } {
  global Info

  if { [info exists Info(browser,$bid,processNbr)] } {

    # NOTE: This will set the browser data to be deleted!!!
    #
    if { $Info(browser,$bid,processNbr) == 0 } {
      set Info(browser,$bid,act) -1

    # NOTE: This keeps browser data active and available to the process, although
    # it is not visible!!!
    #
    } else {
      set Info(browser,$bid,act) 0
    }
  }

  destroy $w
}


proc FileBrowser::save {text_widget bid filename channel_id} {
  global Info
	
  set Info(browser,$bid,canDeleteCancelled) 0

  if { !$Info(browser,$bid,modified) } {
    return
  }

  set success 0
  set counter 0

  # Try to open a temporary file for saving
  #
  while { !$success && $counter < 64 } {
    set tmp "ElmerFrontEdit_tmp.$counter"

    if { ![catch {set out [open $tmp "w+"] } msg] } {
      set success 1
    }

    incr counter
  }

  if { !$success } {
    Message::showMessage "Can not save the file because could not open a temporary file"
  }

  puts $out [$text_widget get 0.0 end]
  close $out

  set msg ""
  catch { close $Info(browser,$bid,infile) } msg

  if { $msg != "" } {
    Message::showMessage "Can not save the file because: $msg"
  }

  # Rename the temporary file
  set msg ""
  catch { file rename -force $tmp $filename } msg

  if { $msg != "" } {
    Message::dispMessage [list "Can not save the file because: $msg"]
    return
  }

  FileBrowser::markBrowserModified 0 $bid
}


proc FileBrowser::toggleUpdateMode {bid button_widget} {
  global Info

  if { ![info exists Info(browser,$bid,act)] ||
       -1 == $Info(browser,$bid,act) 
     } {
    Widget::configure1 $button_widget -state disabled
    return
  }

  set mode [set Info(browser,$bid,update)]

  # Toggle mode
  if { $mode == 1 } {
    set mode 0
    Widget::configure1 $button_widget -text "Unfreeze"
    $button_widget configure -fg red
  } else {
    set mode 1
    Widget::configure1 $button_widget -text "Freeze"
    $button_widget configure -fg black
  }

  set Info(browser,$bid,update) $mode
}


proc FileBrowser::refresh {bid text_widget filename {append 0} } {
  global Info

  if { ![file exists $filename] } {
    return
  }

  if { $Info(browser,$bid,modified) } {
    set msg [list "NOTE: Data has been modified in the editor!\n\nAre you sure to replace the modified data?\n\n"  \
             $Info(anywayOk) ]

    if { ![ Message::verifyAction $Info(advancedUser) $msg] } {
      return
    }
  }


  set in [open $filename ]
  #set in $channel

  set tw $text_widget

  set old_state [$tw cget -state]

  Widget::configureS $tw normal

  #--Pick the current top of the window x,y-position
  set xpos [lindex [$tw xview] 0]
  set ypos [lindex [$tw yview] 0]

  #--Clear old data
  if {!$append} {
    $text_widget delete 0.0 end
  }

  #---Data filling
  while {![eof $in]} {

    set count [gets $in dataline]

    if {$count != -1 } {
      $text_widget insert end $dataline
      $text_widget insert end \n
    }
  }
  
  #--Note: The previous insert command resets the window to the beginning
  #  of the text, so we try to restore the position...
  $tw xview moveto $xpos
  $tw yview moveto $ypos

  #$text_widget insert 0.0 [read $in]

  Widget::configureS $text_widget $old_state

  if { ![catch { set mtime [file mtime $filename] } ] } {
    set Info(browser,$bid,mtime) $mtime
  }

  $Info(browser,$bid,panelRefreshButton) configure -fg black
  $Info(browser,$bid,panelRefreshButton) configure -state disabled

  close $in

  FileBrowser::markBrowserModified 0 $bid
}


proc FileBrowser::markBrowserModified { is_modified bid } {
  global Info

    if { ($is_modified && $Info(browser,$bid,modified)) ||
         (!$is_modified && !$Info(browser,$bid,modified))
       } {
      return
    }

    # Apply widget state
    if { [info exists Info(browser,$bid,panelApplyButton)] &&
         [winfo exist $Info(browser,$bid,panelApplyButton)]
       } {
      
      if { $is_modified } {
        $Info(browser,$bid,panelApplyButton) configure -state normal
      } else {
        $Info(browser,$bid,panelApplyButton) configure -state disabled
      }
    }
    
    # Windows title *-marking
    set wtitle [string trimright [wm title $Info(browser,$bid,window)] "*"]

    if {$is_modified} {
      append wtitle "*"
    }

    wm title $Info(browser,$bid,window) $wtitle

    set Info(browser,$bid,modified) $is_modified

}



# ========================================================#
#                      Text Browser
# ========================================================#

# Procedure creates a text browser (or editor)
#
proc TextBrowser::browse {windowName 
                          {title ""} 
                          {data ""}
                          {canEdit 0}
                          {scrollToEnd 0}
                          {width 60}
                          {height 30}
                          {selected_butt_call ""}
                          {selected_butt_text "Show"}
                        } {

  global Info

  #--Unique broser session id
  set bid [incr Info(browser,id)]

  set Info(browser,$bid,act) 1
  set Info(browser,$bid,update) 1
  set Info(browser,$bid,modified) 0
  set Info(browser,$bid,cancelled) 0

  #--What is our window like?
  set w $windowName
  set wclass ""

  if {[winfo exists $w]} {
    set wclass [winfo class $w]
  }

  #---If our widget is a toplevel window
  if { $wclass != "Frame" } {

    #--Bid number is used also as window id !!!
    set id $bid
    set w $windowName$id

    if {[winfo exists $w]} {
      wm deiconify $w
      focus $w
      return $w.text
    }

    toplevel $w
    wm title $w $title

    set xpos [winfo x $Info(mainWindow)]
    incr xpos -40
    set ypos [winfo y $Info(mainWindow)]
    incr ypos 20
    wm geometry $w +$xpos+$ypos
  }

  set Info(browser,$bid,window) $w

  #---Frames, widgets and packing
  frame $w.f1
  frame $w.f2

  pack $w.f1 -side top -fill both -expand 1
  pack $w.f2 -side bottom -fill x -expand 0 -anchor c

  #--Text frame
  set m $w.f1
  text $m.text -width $width -height $height -font $Info(browserFont) \
    -setgrid true -wrap word \
    -xscrollcommand [list $m.xscroll set] \
    -yscrollcommand [list $m.yscroll set]
  scrollbar $m.xscroll -orient horizontal \
    -command [list $m.text xview]
  scrollbar $m.yscroll -orient vertical  \
    -command [list $m.text yview]
  pack $m -side top -fill both -expand 1
  pack $m.xscroll -side bottom -fill x
  pack $m.yscroll -side right -fill y
  pack $m.text -side left -fill both -expand 1

  set mT $w.f1
  set mB $w.f2
  
  set $mB.selected ""

  if { $selected_butt_call != "" } {
    button $mB.selected -text $selected_butt_text -command "TextBrowser::selectedTextCall $mT.text $selected_butt_call"
  }

  #--In browse mode
  if {!$canEdit} {
    button $mB.ok -text OK -command "TextBrowser::closed $w $mT.text $bid"

    if { [winfo exists $mB.selected] } {
      pack $mB.ok $mB.selected -side left -expand 1 -padx 10
    } else {
      pack $mB.ok -side left -expand 1 -padx 10
    }

    focus $mB.ok

  #--In edit mode
  } else {
    button $mB.editOk -text Ok -command "TextBrowser::save $mT.text $bid ; TextBrowser::closed $w $mT.text $bid"
    button $mB.editApply -text Apply -command "TextBrowser::save $mT.text $bid"
    button $mB.cancel -text Cancel -command "set Info(browser,$bid,cancelled) 1 ;TextBrowser::closed $w $mT.text $bid"

    set Info(browser,$bid,panelApplyButton) $mB.editApply
    $mB.editApply configure -state disabled

    bind $mT.text <KeyPress> "TextBrowser::markBrowserModified 1 $bid"

    bind $mT.text <Control-s> "TextBrowser::save $mT.text $bid"
    bind $mT.text <Control-S> "TextBrowser::save $mT.text $bid"

    if { [winfo exists $mB.selected] } {
      pack $mB.editOk $mB.cancel $mB.editApply $mB.selected -side left -expand 1 -padx 10
    } else {
      pack $mB.editOk $mB.cancel $mB.editApply -side left -expand 1 -padx 10
    }

  }


  #--Insert data 
  #
  Widget::configureS $mT.text normal
  $mT.text insert 0.0 $data

  if { $scrollToEnd } {
    $mT.text see end
  }
  
  if {$canEdit} {
    Widget::configureS $mT.text disabled
  } else {
    Widget::configureS $mT.text normal
  }

  #--Return the text widget pointer
  return $mT.text
}


proc TextBrowser::closed { w text_widget bid } {
  global Info

  set Info(browser,$bid,act) 0

  set data [$text_widget get 0.0 end]

  destroy $w

  return $data
}


proc TextBrowser::selectedTextCall {text_widget func} {
  global Info

  if { [catch {set data [$text_widget get sel.first sel.last]}] } {
    set data ""
  }

  $func $data
}


proc TextBrowser::save {text_widget bid}  {
  global Info
	
  set Info(browser,$bid,canDeleteCancelled) 0

  if { !$Info(browser,$bid,modified) } {
    return
  }

  TextBrowser::markBrowserModified 0 $bid
}


proc TextBrowser::markBrowserModified { is_modified bid } {
  global Info

  if { ($is_modified && $Info(browser,$bid,modified)) ||
       (!$is_modified && !$Info(browser,$bid,modified))
     } {
    return
  }

  # Apply widget state
  if { [info exists Info(browser,$bid,panelApplyButton)] &&
       [winfo exist $Info(browser,$bid,panelApplyButton)]
     } {
    
    if { $is_modified } {
      $Info(browser,$bid,panelApplyButton) configure -state normal
    } else {
      $Info(browser,$bid,panelApplyButton) configure -state disabled
    }
  }
  
  # Windows title *-marking
  set wtitle [string trimright [wm title $Info(browser,$bid,window)] "*"]

  if {$is_modified} {
    append wtitle "*"
  }

  wm title $Info(browser,$bid,window) $wtitle

  set Info(browser,$bid,modified) $is_modified

}


# end ecif_tk_procsWidget.tcl
# ********************