File: MainWindow.c

package info (click to toggle)
ltt 0.9.5pre6-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 3,256 kB
  • ctags: 1,630
  • sloc: ansic: 17,284; sh: 8,010; makefile: 252
file content (4398 lines) | stat: -rw-r--r-- 144,572 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
/*
   MainWindow.c : Windowing support for the linux trace toolkit.
   Copyright (C) 1999, 2000, 2001 Karim Yaghmour, Jean-Hugues Deschenes.
 
   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; version 2 of the License.

   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; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

   History :
      ROC   02/2000, Add Interrupt name printout
      K.Y., 22/08/2000, Added RTAI task analysis to process thumbnail
      K.Y., 10/05/2000, Added keyboard support.
      JH.D., 07/08/1999, Added Toolbar to interface.
      K.Y., 26/06/1999, Renamed file.
      K.Y., 02/06/1999, Initial typing.
*/

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <gdk/gdkkeysyms.h>

#include <Tables.h>
#include <EventDB.h>
#if SUPP_RTAI
#include <RTAIDB.h>
#endif /* SUPP_RTAI */

#include "MainWindow.h"
#include "Pixmap.h"
#include "ViewTime.h"

/* Main list of system views */
static systemView* sMainSystemViewList = NULL;

/* List of raw events displayed */
static event sRawEventsDisplayed[RTCLIST_NB_ROWS];

/* Scrolling of the raw trace */
enum eScrollRawTrace
{
  SRT_UP = 0,
  SRT_DOWN,
  SRT_PAGE_UP,
  SRT_PAGE_DOWN
};

/**********************************************************************************/
/**************************** Window internal functions ***************************/
/**********************************************************************************/
/******************************************************************
 * Function :
 *    WDStatusBarsClear()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void WDIStatusBarsClear(gpointer pmMainWindow)
{
  mainWindow*   pMainWindow = (mainWindow*) pmMainWindow;  /* Main window pointer */

  /* Pop the last message off the status bars */
  gtk_statusbar_pop(GTK_STATUSBAR(pMainWindow->MainSBar),
		     pMainWindow->MainSBarContextID);		    
  gtk_statusbar_pop(GTK_STATUSBAR(pMainWindow->BegTimeSBar),
		     pMainWindow->BegTimeSBarContextID);
  gtk_statusbar_pop(GTK_STATUSBAR(pMainWindow->EndTimeSBar),
		     pMainWindow->EndTimeSBarContextID);

#if 0 /* Not necessary since popping the status bar erases what was there before */
  /* Push the message down to the status bar */
  gtk_statusbar_push(GTK_STATUSBAR(pMainWindow->MainSBar),
		     pMainWindow->MainSBarContextID,
		     "");
  gtk_statusbar_push(GTK_STATUSBAR(pMainWindow->BegTimeSBar),
		     pMainWindow->BegTimeSBarContextID,
		     "");
  gtk_statusbar_push(GTK_STATUSBAR(pMainWindow->EndTimeSBar),
		     pMainWindow->EndTimeSBarContextID,
		     "");
#endif
}

/******************************************************************
 * Function :
 *    WDI_gtk_clist_set_last_row_data_full()
 * Description :
 *    Appends data to the last row of a GtkClist.
 * Parameters :
 * Return values :
 *    NONE.
 * History :
 *    J.H.D., 27/08/99, Initial typing.
 * Note :
 *    Based on gtk_clist_set_row_data_full() version 1.2.3.
 *    Much faster than using gtk_clist_set_row_data_full().
 ******************************************************************/
void WDI_gtk_clist_set_last_row_data_full(GtkCList*         pmClist,
					  gpointer          pmData,
					  GtkDestroyNotify  pmDestroy)
{
  GtkCListRow *pClistRow;

  g_return_if_fail (pmClist != NULL);
  g_return_if_fail (GTK_IS_CLIST (pmClist));
  g_return_if_fail (pmClist->row_list_end != NULL);

  pClistRow = pmClist->row_list_end->data;
  pClistRow->data    = pmData;
  pClistRow->destroy = pmDestroy;
}

/******************************************************************
 * Function :
 *    WDISetWindowIcon()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void WDISetWindowIcon(GtkWidget* pmWindow)
{
  GdkPixmap* pixmap;
  GdkBitmap* mask;
  pixmap = gdk_pixmap_create_from_xpm_d (pmWindow->window, 
					 &mask, 
					 &pmWindow->style->bg[GTK_STATE_NORMAL],
					 mini_LTT);
  gdk_window_set_icon (pmWindow->window, NULL, pixmap, mask);
}

/******************************************************************
 * Function :
 *    WDISearchSubTree()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
GtkTreeItem* WDISearchSubTree(GtkTree*     pmSubTreeToSearch,
			      const gchar* pmKey,
			      gpointer     pmDataToFind)
{
  GList*       Navigator;     /* Temporary pointer to a TreeItem */
  GtkTreeItem* pTempTreeItem; /* Temporary TreeItem pointer */

  /* Set the temporary pointer to the beginning of the children list */
  Navigator = pmSubTreeToSearch->children;

  /* Scroll through this tree's children */
  while(Navigator)
    {
    /* If this is the one, return its pointer */
    if(pmDataToFind == gtk_object_get_data(GTK_OBJECT(Navigator->data), pmKey))
      return GTK_TREE_ITEM(Navigator->data);

    /* If this item has a subtree */
    if(GTK_TREE_ITEM(Navigator->data)->subtree)

      /* Search this item's childern recursively */
      if((pTempTreeItem = WDISearchSubTree(GTK_TREE(GTK_TREE_ITEM(Navigator->data)->subtree),
					   pmKey, pmDataToFind)) != NULL)
	{
	/* If a match has been found within the children */

	/* Expand the parent of the match */
	gtk_tree_item_expand(GTK_TREE_ITEM(Navigator->data));
	
	/* return the match to the caller */
	return pTempTreeItem;
	}

    /* Check the next child */
    Navigator = Navigator->next;
    }
  return NULL;
}

/******************************************************************
 * Function :
 *    WDIClearSubTree()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void WDIClearSubTree(GtkTree* pmSubTreeToClear)
{
  GList*       Navigator;    /* Temporary pointer to a TreeItem */

  /* Set the temporary pointer to the beginning of the children list */
  Navigator = pmSubTreeToClear->children;

  /* Scroll through this tree's children */
  while(Navigator)
    {
    /* If this item has a subtree */
    if(GTK_TREE_ITEM(Navigator->data)->subtree)
      /* Clear the subtree recursively */
      WDIClearSubTree(GTK_TREE(GTK_TREE_ITEM(Navigator->data)->subtree));

    /* Check the next child */
    Navigator = Navigator->next;    
    }

  /* Remove all items from the subtree to clear */
  gtk_tree_clear_items(pmSubTreeToClear, 0, -1);      
}

/******************************************************************
 * Function :
 *    WDIIsInString()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
gboolean WDIIsInString(gchar* pmStringSearched, gchar* pmStringSought)
{
  gchar* pSoughtCurrPos;   /* Cursor in the sought string */
  gchar* pSearchedCurrPos; /* Position we are testing for in pmStringSearched */

  while(TRUE)
    {
    /* Set the cursor position to the beginning of the sought string */
    pSoughtCurrPos = pmStringSought;

    /* Locate the start of the string */
    while(*pSoughtCurrPos != *pmStringSearched)
      {
      /* return if we reach the end of the searched string */
      if(*pmStringSearched == '\0') return(FALSE);
      
      /* Search at the next position */
      ++pmStringSearched;
      }
    
    /* Remember where we left off in case matching fails*/
    pSearchedCurrPos = pmStringSearched;

    /* Try to find the same sequence of characters */
    while(*pSoughtCurrPos == *pSearchedCurrPos)
      {
      /* Compare the next character */
      ++pSearchedCurrPos;
      ++pSoughtCurrPos;

      /* At this point, if we reach the end of string sought,
	 this means that pmStringSought is completely in String Searched */ 
      if(*pSoughtCurrPos == '\0') return(TRUE);
      }

    /* Keep searching at the next pmStringSearched position */
    pmStringSearched++;
    }
}

/******************************************************************
 * Function :
 *    WDISearchEventField()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
event* WDISearchEventField(db*            pmDB,
			   systemInfo*    pmSystem,
			   event*         pmFirstEvent,
			   event*         pmFirstInList,
			   event*         pmEventFound,
			   GTESearchQuery pmSearchQuery)
{
  int              lForward;    /* Did we move forward */
  event            lEvent;      /* Event used to executed search */
  process*         pProcess;    /* Pointer to process */
  eventDescription lEventDesc;  /* Event description */

  /* Don't bother with an empty event list */
  if(!pmFirstInList) return(NULL);

  /* Did we get a first event */
  if(pmFirstEvent != NULL)
    lEvent = *pmFirstEvent;
  else
    lEvent = *pmFirstInList;
  
  /* Don't bother with empty strings */
  if((pmSearchQuery.SearchType == GOTO_EVENT_DESC) && (*pmSearchQuery.SearchString == '\0'))
    {
    *pmEventFound = lEvent;
    return NULL;
    }

  /* Navigate through the list of events */
  do
    {
    /* Get the event description */
    DBEventDescription(pmDB, &lEvent, TRUE, &lEventDesc);

    /* Depending on the search type */
    switch(pmSearchQuery.SearchType)
      {
      case GOTO_EVENT_DESC:
	/* return the event if it contains the description */
	if(WDIIsInString(lEventDesc.String, pmSearchQuery.SearchString) == TRUE)
	  {
	  /* Set the passed event and return it's address */
	  *pmEventFound = lEvent;
	  return pmEventFound;
	  }
	break;

      case GOTO_CPU_ID:
	/* return the event if it contains the CPU ID */
	if(lEventDesc.CPUID == pmSearchQuery.CPUID)
	  {
	  /* Set the passed event and return it's address */
	  *pmEventFound = lEvent;
	  return pmEventFound;
	  }
	break;

      case GOTO_EVENT_TYPE:
	/* return the event if it contains the Event Type */
	if(lEventDesc.ID == pmSearchQuery.EventType)
	  {
	  /* Set the passed event and return it's address */
	  *pmEventFound = lEvent;
	  return pmEventFound;
	  }
	break;

      case GOTO_PID:
	/* Get event's process */
	pProcess = DBEventProcess(pmDB, &lEvent, pmSystem, FALSE);

	/* Is there a Process associated? */
	if((pProcess != NULL) && (pProcess->PID == pmSearchQuery.PID))
	  {
	  /* Set the passed event and return it's address */
	  *pmEventFound = lEvent;
	  return pmEventFound;
	  }
	break;

      case GOTO_ENTRY_LENGTH:
	/* return the event if it contains the entry length */
	if(lEventDesc.Size == pmSearchQuery.EntryLength)
	  {
	  /* Set the passed event and return it's address */
	  *pmEventFound = lEvent;
	  return pmEventFound;
	  }
      }

    /* Check the next event */
    lForward = DBEventNext(pmDB, &lEvent);

    /* If we are at the end of the list, start over */
    if(lForward == FALSE)
      lEvent = *pmFirstInList;
    }
  while(!DBEventsEqual(lEvent, (*pmFirstInList)));

  /* if we reach this point, no event containing
     that description could be found */
  return NULL;
}

/******************************************************************
 * Function :
 *     WDIFreeTraceStructures()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void WDIFreeTraceStructures(systemView*  pmSysView)
{
  /* Destroy any open event graph dependant windows */
  /* The View time frame window */
  if(pmSysView->Window->ViewTimeFrameWindow) 
    gtk_widget_destroy(pmSysView->Window->ViewTimeFrameWindow->Window);
  /* The color selection window */
  if(pmSysView->Window->ColorSelectWindow)
    gtk_widget_destroy(pmSysView->Window->ColorSelectWindow->Window);
  /* The Go to event window */
  if(pmSysView->Window->GotoEventWindow)
    gtk_widget_destroy(pmSysView->Window->GotoEventWindow->Window);
  /* The DumpToFile window */
  if(pmSysView->Window->DumpToFileWindow)
    gtk_widget_destroy(pmSysView->Window->DumpToFileWindow->Window);

  /* Is there anything opened */
  if(pmSysView->EventDB)
    {
    /* Free memory used by System structures */
    DBDestroyTrace(pmSysView->System, pmSysView->EventDB);

    /* Clear the event graph */
    EGClearEventGraph(pmSysView->Window->GTEventGraph);
    }

  /* Free memory used by options */
  if(pmSysView->Options)
    DestroyOptions(pmSysView->Options);

  /* Reset system view pointers */
  pmSysView->Options = NULL;
  pmSysView->EventDB = NULL;
  pmSysView->System  = NULL;
}

/******************************************************************
 * Function :
 *     WDISelectRTEvent()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void WDISelectRTEvent(systemView*  pmSysView, event* pmEvent)
{
  gint        i;             /* Generic index */
  gint        CListRow = 0;  /* The Raw event list's row where the description was found */
  event       lEvent;        /* Event used for searching */
  guint32     Position;      /* Position at which the event was found */

  /* Set current position to the upper bound of the adjustment */
  Position = (guint32) pmSysView->Window->RTVAdjust->upper - 1;

  /* Start position search at the last event in the list */
  lEvent = pmSysView->EventDB->LastEvent;

  /* Search for that event's index */
  while(!DBEventsEqual(lEvent, (*pmEvent)))
    {
    /* Set the pointer to the previous in list */
    DBEventPrev(pmSysView->EventDB, &lEvent);

    /* decrement the position index */
    Position--;
    }

  /* Set the new adjustment position */
  gtk_adjustment_set_value(pmSysView->Window->RTVAdjust, (gfloat) (Position - 1));

  /* find the row to that event */
  for(i = 0; i < RTCLIST_NB_ROWS; i++)
    if(DBEventsEqual(sRawEventsDisplayed[i], lEvent))
      CListRow = i;

  /* Select it */
  gtk_clist_select_row(GTK_CLIST(pmSysView->Window->RTCList), CListRow, 0);

  /* Select the process tree notebook page */
  gtk_notebook_set_page(GTK_NOTEBOOK(pmSysView->Window->MNotebook), 2);
    
  /* Scroll the CList to that event
     - this call MUST be after gtk_notebook_set_page to react properly */
  gtk_clist_moveto(GTK_CLIST(pmSysView->Window->RTCList), CListRow, 0, 0, 0);
}

/******************************************************************
 * Function :
 *     WDIFormatTimeInReadableString()
 * Description :
 *     Takes a time value and inserts commas between every 3 digit
 *     in order to ease readability.
 * Parameters :
 *     pmFormatedString, String where the formatted time should be
 *                       written.
 *     pmTime, The time value to format.
 * Return values :
 *     NONE
 * History :
 * Note :
 ******************************************************************/
void WDIFormatTimeInReadableString(char* pmFormatedString, gdouble pmTime)
{
  char     lTempStr[TIME_STR_LEN];   /* Temporary string */
  guint    i, j;                     /* Generic indexes */
  guint    lStrLen;                  /* String length */
  guint    lExtraChars;              /* Characters more that the last triplet */
  guint    lFormatedStrStart;        /* Start of copying position into formated str */

  /* Print the time into the temporary string */
  sprintf(lTempStr, "%.0f", pmTime);

  /* How long is the string */
  lStrLen = strlen(lTempStr);

  /* How many digits are left after the last triplet */
  lFormatedStrStart = lExtraChars = lStrLen % 3;

  /* Are there any trailing characters */
  if(lExtraChars != 0)
    {
    /* Copy the trailing characters right away */
    for(i = 0; i < lExtraChars; i++)
      pmFormatedString[i] = lTempStr[i];

    /* Insert a comma */
    pmFormatedString[i] = ',';

    /* Start copying past the added comma */
    lFormatedStrStart += 1;
    }

  /* Copy the characters into the final string in groups of three */
  for(i = lFormatedStrStart, j = lExtraChars; j < lStrLen; i += 4, j += 3)
    {
    pmFormatedString[i]     = lTempStr[j];
    pmFormatedString[i + 1] = lTempStr[j + 1];
    pmFormatedString[i + 2] = lTempStr[j + 2];
    pmFormatedString[i + 3] = ',';
    }

  /* Insert the end of string marker */
  pmFormatedString[i - 1] = '\0';
}

/******************************************************************
 * Macro :
 *    WDITextInsert()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
#define WDITextInsert(pmWindow, pmFormat, pmArg...)\
do \
{\
  char  lText[100]; \
\
  sprintf(lText, pmFormat, ##pmArg);\
  gtk_text_insert(GTK_TEXT(pmWindow->PTProcessText), \
                  pmWindow->PTTextFont /* Font */, \
		  NULL  /* Foreground color */, \
		  NULL  /* Background color */, \
		  lText /* Text string to be inserted */, \
		  -1    /* Display it all */); \
} while(0)

/******************************************************************
 * Macro :
 *    WDIRTScroll()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void WDIRTScroll(systemView* pmSysView, gint pmScrolling)
{
  gfloat          lNewValue;     /* The new value for the adjustment */
  GtkAdjustment*  pAdjustment;   /* The vertical adjustment of the scrolled list */

  /* Get the vertical adjustment of the scrolled process list */
  pAdjustment = pmSysView->Window->RTVAdjust;

  /* Get the adjustment's current value */
  lNewValue = pAdjustment->value;

  /* Depending on the type of scrolling */
  switch(pmScrolling)
    {
    /* Scroll up */
    case SRT_UP :
      /* Set the new value to scroll up */
      lNewValue -= pAdjustment->step_increment;

      /* Confine the adjustment to reasonable values */
      if(lNewValue < pAdjustment->lower)
	lNewValue = pAdjustment->lower;
      break;

    /* Scroll down */
    case SRT_DOWN :
      /* Set the new value to scroll down */
      lNewValue += pAdjustment->step_increment;

      /* Confine the adjustment to reasonable values */
      if(lNewValue > pAdjustment->upper)
	lNewValue = pAdjustment->upper;
      break;

    /* Scroll page up */
    case SRT_PAGE_UP :
      /* Set the new value to scroll page up */
      lNewValue -= pAdjustment->page_increment;

      /* Confine the adjustment to reasonable values */
      if(lNewValue < pAdjustment->lower)
	lNewValue = pAdjustment->lower;
      break;

    /* Scroll page down */
    case SRT_PAGE_DOWN :
      /* Set the new value to scroll page down */
      lNewValue += pAdjustment->page_increment;

      /* Confine the adjustment to reasonable values */
      if(lNewValue > pAdjustment->upper)
	lNewValue = pAdjustment->upper;
      break;
    }

  /* Update the adjustment's value */
  gtk_adjustment_set_value(pAdjustment, lNewValue);

  /* Make sure the list is drawn correctly */
  gtk_widget_queue_resize(pmSysView->Window->RTVScroll);
}

/**********************************************************************************/
/*********************** Open Trace window callback functions **********************/
/**********************************************************************************/
/******************************************************************
 * Function :
 *    OTCBCancel()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void OTCBCancel(gpointer pmSysView)
{
  systemView*   pSysView;   /* The system view */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmSysView) == NULL)
    {
    g_print("Internal error: Cancel callback without system view \n");
    exit(1);
    }

  /* Destroy the window */
  OTDestroyOpenTraceWindow(pSysView->Window->OpenTraceWindow);

  /* Set the main window as free to open anothe open trace window */
  pSysView->Window->OpenTraceWindow = NULL;
}

/******************************************************************
 * Function :
 *    OTCBOK()
 * Description :
 *    Reacts to the click of the OK button on the Open Trace dialog.
 *    Opens the given trace files if valid into an appropriate window.
 * Parameters :
 *    pmSysView, The system view currently displayed in the window
 *               where the dialog was opened.
 *    pmTraceFileName, File containing binary trace.
 *    pmProcFileName, File containing /proc dump.
 * Return values :
 *    NONE.
 * History :
 * Note :
 ******************************************************************/
void OTCBOK(gpointer pmSysView, gchar* pmTraceFileName, gchar* pmProcFileName)
{
  int           lStrLen;        /* String length */
  int           lTraceFile;     /* File containing raw trace */
  int           lReadResult;    /* Result of reading the trace file */
  gchar         lString[256];   /* String to print on status bar */
  FILE*         lProcFile;      /* File containing proc information */
  db*           pEventDB;       /* Event database */
  systemInfo*   pSystem;        /* The system as is */
  options*      pOptions;       /* The options */
  systemView*   pSysView;       /* The system view */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmSysView) == NULL)
    {
    g_print("Internal error: OK callback without system view \n");
    exit(1);
    }

  /* For now don't go any further if no files are selected */
  if((pmTraceFileName == NULL) || (pmProcFileName == NULL)
   ||(strlen(pmTraceFileName) == 0) || (strlen(pmProcFileName) == 0))
    {
    WDStatusBarDisplay(pSysView->Window, "Must select Trace and Proc files ...");
    return;
    }

  /* Does the current System View contain a trace? */
  if((pSysView->EventDB != NULL) && (pSysView->EventDB->TraceStart != NULL))
    /* If so, create a new system view and window */
    pSysView = WDCreateSystemView(NULL, NULL, NULL);

  /* Create some options if we don't have any */
  if(pSysView->Options)
    pOptions = pSysView->Options;
  else
    pSysView->Options = pOptions = CreateOptions();

  /* Create an event database if we don't have one */
  if(pSysView->EventDB)
    pEventDB = pSysView->EventDB;
  else
    pSysView->EventDB = pEventDB = DBCreateDB();

  /* Create some system options if we don't have any */
  if(pSysView->System)
    pSystem = pSysView->System;
  else
    pSysView->System  = pSystem  = DBCreateSystem();

  /* Copy file names to options structure */
  lStrLen = strlen(pmTraceFileName);
  pOptions->InputFileName = (char*) g_malloc(lStrLen + 1);
  strcpy(pOptions->InputFileName, pmTraceFileName);
  lStrLen = strlen(pmProcFileName);
  pOptions->ProcFileName = (char*) g_malloc(lStrLen + 1);
  strcpy(pOptions->ProcFileName, pmProcFileName);
  
  /* Open the input file */
  if((lTraceFile = open(pOptions->InputFileName, O_RDONLY, 0)) < 0)
    {
    /* File ain't good */
    WDStatusBarDisplay(pSysView->Window, "Unable to open input data file");

    /* The filenames are wrong */
    g_free(pOptions->InputFileName);
    g_free(pOptions->ProcFileName);
    pOptions->InputFileName = NULL;
    pOptions->ProcFileName = NULL;

    /* Was this a newly created system view */
    if(pSysView != pmSysView)
      WDDestroySystemView(pSysView);
    return;
    }

  /* Open the /proc information file */
  if((lProcFile = fopen(pOptions->ProcFileName, "r")) == NULL)
    {
    /* File ain't good */
    WDStatusBarDisplay(pSysView->Window, "Unable to open /proc data file");

    /* Close the opened trace file */
    close(lTraceFile);

    /* The filenames are wrong */
    g_free(pOptions->InputFileName);
    g_free(pOptions->ProcFileName);
    pOptions->InputFileName = NULL;
    pOptions->ProcFileName = NULL;

    /* Was this a newly created system view */
    if(pSysView != pmSysView)
      WDDestroySystemView(pSysView);
    return;
    }

  /* Read the trace */
  lReadResult = DBReadTrace(lTraceFile, pEventDB);

  /* Was there any problem reading the trace? */
  if(lReadResult != 0)
    {
    /* Depending on the type of error */
    switch(lReadResult)
      {
      case 1:
      default:
	/* Something's wrong with the input file */
	WDStatusBarDisplay(pSysView->Window, "Input file isn't a valid trace file");
	break;

      case 2:
	/* Trace file format version not supported */
	sprintf(lString,
		"Trace file format version %d.%d not supported by visualizer",
		pEventDB->MajorVersion,
		pEventDB->MinorVersion);
	WDStatusBarDisplay(pSysView->Window, lString);
	break;
      }

    /* Close the opened files */
    close(lTraceFile);
    fclose(lProcFile);

    /* Destroy the db and the system since they were operated on */
    DBDestroyTrace(pSystem, pEventDB);
    pSysView->System  = NULL;
    pSysView->EventDB = NULL;

    /* Free filenames */
    g_free(pOptions->InputFileName);
    g_free(pOptions->ProcFileName);
    pOptions->InputFileName = NULL;
    pOptions->ProcFileName = NULL;

    /* Was this a newly created system view */
    if(pSysView != pmSysView)
      WDDestroySystemView(pSysView);
    return;
    }

  /* Process the /proc file */
  DBProcessProcInfo(lProcFile, pSystem);

  /* Close the opened files */
  close(lTraceFile);
  fclose(lProcFile);

  /* Process the trace per-se */
  switch(DBProcessTrace(pSystem, pEventDB, pOptions))
    {
    case ERR_UNKNOWN_TRACE_TYPE:
      WDStatusBarDisplay(pSysView->Window, "Can't process trace, unknown trace type");

      /* Destroy the db and the system since they were operated on */
      DBDestroyTrace(pSystem, pEventDB);
      pSysView->System  = NULL;
      pSysView->EventDB = NULL;

      /* Free filenames */
      g_free(pOptions->InputFileName);
      g_free(pOptions->ProcFileName);
      pOptions->InputFileName = NULL;
      pOptions->ProcFileName = NULL;

      /* Was this a newly created system view */
      if(pSysView != pmSysView)
	WDDestroySystemView(pSysView);
      return;
      break;

    case ERR_EMPTY_TRACE:
      WDStatusBarDisplay(pSysView->Window, "Trace is empty");

      /* Destroy the db and the system since they were operated on */
      DBDestroyTrace(pSystem, pEventDB);
      pSysView->System  = NULL;
      pSysView->EventDB = NULL;

      /* Free filenames */
      g_free(pOptions->InputFileName);
      g_free(pOptions->ProcFileName);
      pOptions->InputFileName = NULL;
      pOptions->ProcFileName = NULL;

      /* Was this a newly created system view */
      if(pSysView != pmSysView)
	WDDestroySystemView(pSysView);
      return;
      break;

    default:
      break;
    }

  /* Set the system that this window will display */
  pSysView->Window->SystemView = pSysView;

  /* Make sure the horizon is displayed if required the first time */
  pSysView->Window->GTEventGraph->ShowHorizon = 
                      GTK_CHECK_MENU_ITEM(pSysView->Window->ShowHorizon)->active;

  /* Was a new SystemView created ? */
  if(pmSysView != (gpointer) pSysView)
    {
    /* Display the newly created window */
    WDShowMainWindow(pSysView);
    }

  /* Display the trace */
  WDDisplayTrace(pSysView);
}

/**********************************************************************************/
/******************** View Time Frame window callback functions *******************/
/**********************************************************************************/
/******************************************************************
 * Function :
 *    VTFCBCancel()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void VTFCBCancel(gpointer pmSysView)
{
  systemView*   pSysView;   /* The system view */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmSysView) == NULL)
    {
    g_print("Internal error: Cancel callback without system view \n");
    exit(1);
    }

  /* Destroy the window */
  VTFDestroyViewTimeFrameWindow(pSysView->Window->ViewTimeFrameWindow);

  /* Set the main window as free to open another view time frame window */
  pSysView->Window->ViewTimeFrameWindow = NULL;
}

/******************************************************************
 * Function :
 *    VTFCBOK()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void VTFCBOK(gpointer pmSysView, gdouble pmStartTime, gdouble pmEndTime)
{
  systemView*   pSysView;   /* The system view */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmSysView) == NULL)
    {
    g_print("Internal error: OK callback without system view \n");
    exit(1);
    }

  EGZoomTimeFrame(pSysView->Window->GTEventGraph, pmStartTime, pmEndTime);
}

/**********************************************************************************/
/********************** Go to event window callback functions *********************/
/**********************************************************************************/
/******************************************************************
 * Function :
 *    GTECBCancel()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void GTECBCancel(gpointer pmSysView)
{
  systemView*   pSysView;   /* The system view */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmSysView) == NULL)
    {
    g_print("Internal error: Cancel callback without system view \n");
    exit(1);
    }

  /* Destroy the window */
  GTEDestroyGotoEventWindow(pSysView->Window->GotoEventWindow);

  /* Set the main window as free to open another view time frame window */
  pSysView->Window->GotoEventWindow = NULL;
}

/******************************************************************
 * Function :
 *    GTECBOK()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void GTECBOK(gpointer pmSysView, GTESearchQuery pmSearchQuery)
{
  gint        lCListRow;       /* The row after which searching should start */
  gchar       lString[256];    /* Temporary build string */
  event       lEventStart;     /* Event from which search should start */
  event       lEventFound;     /* Event to be filled by the search routine */
  event*      pEventFound;     /* The event found by the search */
  systemView* pSysView;        /* The system view */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmSysView) == NULL)
    {
    g_print("Internal error: OK callback without system view \n");
    exit(1);
    }

  /* Is there an event selected */
  if(GTK_CLIST(pSysView->Window->RTCList)->selection != NULL)
    {
    /* Start the search after the selected row */
    lCListRow = GPOINTER_TO_INT(((GList*) GTK_CLIST(pSysView->Window->RTCList)->selection)->data);
    lEventStart = *((event*) (gtk_clist_get_row_data(GTK_CLIST(pSysView->Window->RTCList), lCListRow)));
    DBEventNext(pSysView->EventDB, &lEventStart);
    }
  else
    /* Set the pointer to the first event in the list */
    lEventStart = pSysView->EventDB->FirstEvent;

  /* search the event database for pmSearchString */
  if((pEventFound = WDISearchEventField(pSysView->EventDB,
				       pSysView->System,
				       &lEventStart,
				       &(pSysView->EventDB->FirstEvent),
				       &lEventFound,
				       pmSearchQuery)) != NULL)
    /* Select the event found in the CList */
    WDISelectRTEvent(pSysView, pEventFound);
  else
    {
    /* Depending on the query type */
    switch(pmSearchQuery.SearchType)
      {
      case GOTO_EVENT_DESC:
	sprintf(lString, "No match found for description \"%s\"", pmSearchQuery.SearchString);
	break;

      case GOTO_CPU_ID:
	sprintf(lString, "No match found for CPU ID \"%d\"", pmSearchQuery.CPUID);
	break;

      case GOTO_EVENT_TYPE:
	sprintf(lString, "No match found for event type \"%d\"", pmSearchQuery.EventType);
	break;

      case GOTO_PID:
	sprintf(lString, "No match found for PID \"%d\"", pmSearchQuery.PID);
	break;

      case GOTO_ENTRY_LENGTH:
	sprintf(lString, "No match found for entry length \"%d\"", pmSearchQuery.EntryLength);

      }

    /* Display error message in status bar */
    WDStatusBarDisplay(pSysView->Window, lString);
    }
}

/**********************************************************************************/
/********************* Dump To File  window callback functions ********************/
/**********************************************************************************/
/******************************************************************
 * Function :
 *    DTFCBCancel()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void DTFCBCancel(gpointer pmSysView)
{
  systemView*   pSysView;   /* The system view */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmSysView) == NULL)
    {
    g_print("Internal error: Cancel callback without system view \n");
    exit(1);
    }

  /* Destroy the window */
  DTFDestroyDumpToFileWindow(pSysView->Window->DumpToFileWindow);

  /* Set the main window as free to open another dump to file window */
  pSysView->Window->DumpToFileWindow = NULL;
}

/******************************************************************
 * Function :
 *    DTFCBOK()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void DTFCBOK(gpointer pmSysView)
{
  systemView* pSysView;     /* The system view */
  int         lDumpFile;    /* The dumpfile ID */
  gchar       lString[256]; /* Temporary build string */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmSysView) == NULL)
    {
    g_print("Internal error: OK callback without system view \n");
    exit(1);
    }

  /* Did the user select a filename */
  if((!pSysView->Options->OutputFileName) || (strlen(pSysView->Options->OutputFileName) == 0))
    {
    WDStatusBarDisplay(pSysView->Window, "Must select file for output ...");
    return;
    }

  /* Open the output file */
  if((lDumpFile = creat(pSysView->Options->OutputFileName, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0)
    {
    /* File ain't good */
    sprintf(lString, "Unable to open %s for write!", pSysView->Options->OutputFileName);
    WDStatusBarDisplay(pSysView->Window, lString);
    return;
    }

  /* Print out the trace to the given file */
  DBPrintTrace(lDumpFile, pSysView->System, pSysView->EventDB, pSysView->Options);
}

/**********************************************************************************/
/*********************** About box Signal handling functions **********************/
/**********************************************************************************/
/******************************************************************
 * Function :
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
gint ABOUTSHDeleteEvent(GtkWidget* pmWidget, GdkEvent* pmEvent, gpointer pmData)
{
  /* Close it */
  return(FALSE);
}

/******************************************************************
 * Function :
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void ABOUTSHDestroy(GtkWidget* pmWidget, gpointer pmData)
{
  systemView*  pSysView;        /* The system being displayed */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    {
    g_print("Internal error: Callback without about box \n");
    exit(1);
    }

  /* Set the system view as not having an about box */
  pSysView->Window->AboutBox = NULL;
}

/**********************************************************************************/
/********************* Help contents Signal handling functions ********************/
/**********************************************************************************/
/******************************************************************
 * Function :
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
gint HELPSHDeleteEvent(GtkWidget* pmWidget, GdkEvent* pmEvent, gpointer pmData)
{
  /* Close it */
  return(FALSE);
}

/******************************************************************
 * Function :
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void HELPSHDestroy(GtkWidget* pmWidget, gpointer pmData)
{
  systemView*  pSysView;        /* The system being displayed */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    {
    g_print("Internal error: Callback without Help Window \n");
    exit(1);
    }

  /* Set the system view as not having a Help contents window */
  pSysView->Window->HelpContents = NULL;
}

/**********************************************************************************/
/******************** Color selection window callback functions *******************/
/**********************************************************************************/
/******************************************************************
 * Function :
 *    CSCBCancel()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void CSCBCancel(gpointer pmSysView)
{
  systemView*   pSysView;   /* The system view */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmSysView) == NULL)
    {
    g_print("Internal error: Cancel callback without system view \n");
    exit(1);
    }

  /* Destroy the window */
  CSDestroyColorSelectWindow(pSysView->Window->ColorSelectWindow);

  /* Set the main window as free to open another color selection window */
  pSysView->Window->ColorSelectWindow = NULL;
}

/******************************************************************
 * Function :
 *    CSCBOK()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void CSCBOK(GtkWidget* pmWidget, gpointer pmCSWin)
{
  systemView*        pSysView; /* The system view */
  colorSelectWindow* pCSWin;   /* The color selection window */
  eventGraph*        pEGraph;  /* The event graph to modify */

  /* Do we have anything meaningfull */
  if((pCSWin = (colorSelectWindow*) pmCSWin) == NULL)
    {
    g_print("Internal error: OK callback without color window \n");
    exit(1);
    }

  /*  Set temporary pointers for ease of use */
  pSysView = (systemView*) pCSWin->SysView;
  pEGraph = pSysView->Window->GTEventGraph;

  /* Bring back the modified GCs */
  gdk_gc_copy(pEGraph->BackgroundGC, pCSWin->BackgroundGC);
  gdk_gc_copy(pEGraph->HorizonGC,    pCSWin->HorizonGC);
  gdk_gc_copy(pEGraph->ProcessGC,    pCSWin->ProcessGC);
  gdk_gc_copy(pEGraph->Process0GC,   pCSWin->Process0GC);
  gdk_gc_copy(pEGraph->KernelGC,     pCSWin->KernelGC);
  gdk_gc_copy(pEGraph->SelectedGC,   pCSWin->SelectedGC);
  gdk_gc_copy(pEGraph->SysCallGC,    pCSWin->SysCallGC);
  gdk_gc_copy(pEGraph->TrapGC,       pCSWin->TrapGC);
  gdk_gc_copy(pEGraph->InterruptGC,  pCSWin->InterruptGC);
  gdk_gc_copy(pEGraph->TextGC,       pCSWin->TextGC);

  /* Redraw the event graph */
  EGForceTraceRedraw(pEGraph);
}

/**********************************************************************************/
/**************************** Signal handling functions ***************************/
/**********************************************************************************/
/******************************************************************
 * Function :
 *    SHDeleteEvent()
 * Description :
 *    Delete handler.
 * Parameters :
 *    pmWidget,
 *    pmEvent,
 *    pmData,
 * Return values :
 *    FALSE, Go ahead and kill us of, we're done.
 *    TRUE, We don't really want to quit.
 * History :
 * Note :
 *    This is called if the user clicks on the close button of the
 *    window of if he chooses close in the menu of window
 *    operations. 
 ******************************************************************/
gint SHDeleteEvent(GtkWidget* pmWidget, GdkEvent* pmEvent, gpointer pmData)
{
  /* Destroy the associated SystemView */
  WDDestroySystemView(pmData);

  /* We're done */
  return(FALSE);
}

/******************************************************************
 * Function :
 *    SHDestroy()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHDestroy(GtkWidget* pmWidget, gpointer pmData)
{
  /* DEBUG */
#if 0
  g_print("Destroy summoned \n");
#endif
  /* if we were the last opened window */
  if(!sMainSystemViewList)
    /* Exit from gtk_main() */
    gtk_main_quit();
}

/******************************************************************
 * Function :
 *    SHOpenTrace()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHOpenTrace(GtkWidget* pmWidget, gpointer pmData)
{
  systemView*      pSysView;        /* The system being displayed */
  openTraceWindow* pOTWin;          /* Open trace window */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    return;

  /* Is there a window already open */
  if(pSysView->Window->OpenTraceWindow != NULL)
    {
    OTSetFocus(pSysView->Window->OpenTraceWindow);
    return;
    }

  /* Create a new trace file selection window */
  pOTWin = pSysView->Window->OpenTraceWindow =
    OTCreateOpenTraceWindow(pSysView,
			    pSysView->Window->MWindow,
			    OTCBOK,
			    OTCBCancel);

  /* Connect the signals */
  OTConnectSignals(pOTWin);

  /* Show it all to the world */
  OTShowOpenTraceWindow(pOTWin);
}

/******************************************************************
 * Function :
 *    SHColorSelect()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHColorSelect(GtkWidget* pmWidget, gpointer pmData)
{
  systemView*        pSysView;        /* The system being displayed */
  colorSelectWindow* pCSWin;          /* Open trace window */


  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    return;

  /* Is there a window already open */
  if(pSysView->Window->ColorSelectWindow != NULL)
    return;

  /* Create a new Color selection window */
  pCSWin = pSysView->Window->ColorSelectWindow =
    CSCreateColorSelectWindow(pSysView,
			      pSysView->Window->MWindow,
			      CSCBOK,
			      CSCBCancel);

  /* Connect the signals */
  CSConnectSignals(pCSWin);

  /* Show it all to the world */
  CSShowColorSelectWindow(pCSWin, pSysView->Window->GTEventGraph);

}

/******************************************************************
 * Function :
 *    SHViewTimeFrame()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHViewTimeFrame(GtkWidget* pmWidget, gpointer pmData)
{
  systemView*          pSysView;  /* The system being displayed */
  viewTimeFrameWindow* pVTFWin;   /* View time frame window */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    return;

  /* Is there a window already open  - this should never happen */
  if(pSysView->Window->ViewTimeFrameWindow) return;

  /* Create a new trace file selection window */
  pVTFWin = pSysView->Window->ViewTimeFrameWindow =
    VTFCreateViewTimeFrameWindow(pSysView,
				 pSysView->Window->MWindow,
				 pSysView->Window->GTEventGraph,
				 VTFCBOK,
				 VTFCBCancel);

  /* Connect the signals */
  VTFConnectSignals(pVTFWin);

  /* Show it all to the world */
  VTFShowViewTimeFrameWindow(pVTFWin);
}

/******************************************************************
 * Function :
 *    SHGotoEvent()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHGotoEvent(GtkWidget* pmWidget, gpointer pmData)
{
  systemView*      pSysView;  /* The system being displayed */
  gotoEventWindow* pGTEWin;   /* Go to event window */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    return;

  /* Is there a window already open  - this should never happen */
  if(pSysView->Window->GotoEventWindow) return;

  /* Create a new trace file selection window */
  pGTEWin = pSysView->Window->GotoEventWindow =
    GTECreateGotoEventWindow(pSysView,
			     pSysView->Window->MWindow,
			     GTECBOK,
			     GTECBCancel);

  /* Connect the signals */
  GTEConnectSignals(pGTEWin);

  /* Show it all to the world */
  GTEShowGotoEventWindow(pGTEWin);
}

/******************************************************************
 * Function :
 *    SHCloseTrace()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHCloseTrace(GtkWidget* pmWidget, gpointer pmData)
{
  systemView*  pSysView;        /* The system being displayed */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    return;

  /* Clear the process tree */
  WDIClearSubTree(GTK_TREE(pSysView->Window->PTProcessTree));

  /* Erase text describing process */
  gtk_text_backward_delete(GTK_TEXT(pSysView->Window->PTProcessText),
			   gtk_text_get_length(GTK_TEXT(pSysView->Window->PTProcessText)));

  /*  Clear raw event trace */
  gtk_clist_clear(GTK_CLIST(pSysView->Window->RTCList));
  gtk_widget_queue_resize(pSysView->Window->RTCList);

#if 0
  g_list_free(GTK_CLIST(pSysView->Window->RTCList)->row_list);
  GTK_CLIST(pSysView->Window->RTCList)->rows = 0;
  g_mem_chunk_destroy(GTK_CLIST(pSysView->Window->RTCList)->row_mem_chunk);
  GTK_CLIST(pSysView->Window->RTCList)->row_mem_chunk = NULL;
#endif

#if 0
  gtk_widget_destroy(pSysView->Window->RTCList);
  /* Create raw trace list */
  pSysView->Window->RTCList  = gtk_clist_new_with_titles(RTCLIST_NB_COLUMNS, RTCListTitles);
  gtk_clist_set_selection_mode(GTK_CLIST(pSysView->Window->RTCList), GTK_SELECTION_SINGLE);

  /* DO NOT USE gtk_scrolled_window_add_with_viewport() here, it doesn't work! */
  gtk_container_add(GTK_CONTAINER(pSysView->Window->RTScrolledCList), pSysView->Window->RTCList);

  /* Configure the columns of the list */
  gtk_clist_set_column_justification(GTK_CLIST(pSysView->Window->RTCList), 0, GTK_JUSTIFY_LEFT);
  gtk_clist_set_column_justification(GTK_CLIST(pSysView->Window->RTCList), 1, GTK_JUSTIFY_RIGHT);
  gtk_clist_set_column_justification(GTK_CLIST(pSysView->Window->RTCList), 2, GTK_JUSTIFY_RIGHT);
  gtk_clist_set_column_justification(GTK_CLIST(pSysView->Window->RTCList), 3, GTK_JUSTIFY_RIGHT);
  gtk_clist_set_column_justification(GTK_CLIST(pSysView->Window->RTCList), 4, GTK_JUSTIFY_LEFT);
  gtk_clist_set_column_width(GTK_CLIST(pSysView->Window->RTCList), 0, 80);
  gtk_clist_set_column_width(GTK_CLIST(pSysView->Window->RTCList), 1, 65);
  gtk_clist_set_column_width(GTK_CLIST(pSysView->Window->RTCList), 2, 65);
  gtk_clist_set_column_width(GTK_CLIST(pSysView->Window->RTCList), 3, 60);
  gtk_clist_set_column_width(GTK_CLIST(pSysView->Window->RTCList), 4, 250);
#endif

  /* Is this the only systemView left? */
  if(sMainSystemViewList->Next)
    {
    /* store the pointer to the window to destroy */
    pmWidget = pSysView->Window->MWindow;

    /* Destroy the associated SystemView */
    WDDestroySystemView(pSysView);

    /* Destroy the window which contains this trace */
    gtk_widget_destroy(pmWidget);
    }
  else
    {
    /* Simply free the TraceStructures */
    WDIFreeTraceStructures(pSysView);

    /* Reset the CList adjustment */
    pSysView->Window->RTVAdjust->lower          = 0;
    pSysView->Window->RTVAdjust->upper          = 0;
    pSysView->Window->RTVAdjust->step_increment = 0;
    pSysView->Window->RTVAdjust->page_increment = 0;
    pSysView->Window->RTVAdjust->page_size      = 0;
    gtk_adjustment_changed(GTK_ADJUSTMENT(pSysView->Window->RTVAdjust));

    /* Disable relevant menu items */
    WDSetMenusSensitivity(pSysView, FALSE);

    /* Set Main window title */
    gtk_window_set_title(GTK_WINDOW(pSysView->Window->MWindow), "Trace Visualizer");

    /* Clear the status bar */
    WDIStatusBarsClear(pSysView->Window);
    }
}

/******************************************************************
 * Function :
 *    SHDumpToFile()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHDumpToFile(GtkWidget* pmWidget, gpointer pmData)
{
  systemView*       pSysView;  /* The system being displayed */
  dumpToFileWindow* pDTFWin;   /* Dump to file window */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    return;

  /* Is there a window already open  - this should never happen */
  if(pSysView->Window->DumpToFileWindow) return;

  /* Create a new trace file selection window */
  pDTFWin = pSysView->Window->DumpToFileWindow =
    DTFCreateDumpToFileWindow(pSysView,
			      pSysView->Window->MWindow,
			      DTFCBOK,
			      DTFCBCancel);

  /* Connect the signals */
  DTFConnectSignals(pDTFWin);

  /* Show it all to the world */
  DTFShowDumpToFileWindow(pDTFWin);
}

/******************************************************************
 * Function :
 *    SHQuit()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHQuit(GtkWidget* pmWidget, gpointer pmData)
{
  /* Exit from gtk_main() */
  gtk_main_quit();
}

/******************************************************************
 * Function :
 *    SHClistInfo()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 *    For debugging purposes
 ******************************************************************/
#if 0 /* This isn't used */
void SHClistInfo(GtkWidget* pmWidget, gpointer pmData)
{
  systemView*  pSysView;        /* The system being displayed */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    return;

  g_print("************** \n");
  g_print(" CLIST INFO\n");
  g_print("**************\n");
  g_print("Number of rows: %d\n", GTK_CLIST(pSysView->Window->RTCList)->rows);
  g_print("Adjustment; upper: %f, lower: %f, value: %f \n", 
	  GTK_ADJUSTMENT(GTK_CLIST(pSysView->Window->RTCList)->hadjustment)->upper,
	  GTK_ADJUSTMENT(GTK_CLIST(pSysView->Window->RTCList)->hadjustment)->lower,
	  GTK_ADJUSTMENT(GTK_CLIST(pSysView->Window->RTCList)->hadjustment)->value);
  g_print("**************\n");

  WDFillEventList(pSysView->Window->RTCList, pSysView->EventDB, pSysView->System, NULL, NULL);
}
#endif

/******************************************************************
 * Function :
 *    SHZoomIn()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHZoomIn(GtkWidget* pmWidget, gpointer pmData)
{
  systemView*  pSysView;        /* The system being displayed */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    return;

  /* Is there anything opened */
  if(pSysView->EventDB == NULL)
    return;
  if(pSysView->EventDB->TraceStart == NULL)
    return;

  /* Zoom in on the event graph */
  EGZoomIn(pSysView->Window->GTEventGraph);
}


/******************************************************************
 * Function :
 *    SHZoomOut()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHZoomOut(GtkWidget* pmWidget, gpointer pmData)
{
  systemView*  pSysView;        /* The system being displayed */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    return;

  /* Is there anything opened */
  if(pSysView->EventDB == NULL)
    return;
  if(pSysView->EventDB->TraceStart == NULL)
    return;

  /* Zoom out on the event graph */
  EGZoomOut(pSysView->Window->GTEventGraph);
}

/******************************************************************
 * Function :
 *    SHShowHorizon()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHShowHorizon(GtkWidget* pmWidget, gpointer pmData)
{
  systemView*  pSysView;        /* The system being displayed */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    return;

  /* Is there anything opened */
  if(pSysView->EventDB == NULL)
    return;
  if(pSysView->EventDB->TraceStart == NULL)
    return;

  /* Was this called from the menu, or the toolbar? */
  if(pSysView->Window->tlbShowHorizon == pmWidget)
    /* Synchronize the menu accordingly */
    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(pSysView->Window->ShowHorizon),
       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pSysView->Window->tlbShowHorizon)));

  else
    /* Synchronize the toolbar accordingly */
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pSysView->Window->tlbShowHorizon),
				 GTK_CHECK_MENU_ITEM(pSysView->Window->ShowHorizon)->active);

  /* Set the horizon's view */
  pSysView->Window->GTEventGraph->ShowHorizon = 
           gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pSysView->Window->tlbShowHorizon));
  EGSetHorizonView(pSysView->Window->GTEventGraph);
}

/******************************************************************
 * Function :
 *    SHConfigureDaemon()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHConfigureDaemon(GtkWidget* pmWidget, gpointer pmData)
{
}

/******************************************************************
 * Function :
 *    SHContents()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHContents(GtkWidget* pmWidget, gpointer pmData)
{
  GtkWidget*   pContentText;      /* Help contents text */
  GtkWidget*   pContentOKButton;  /* OK button in the help contents */
  GtkWidget*   pContentWindow;    /* The Help contents window */
  systemView*  pSysView;          /* The system being displayed */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    return;

  /* Get the Contents window */
  pContentWindow = pSysView->Window->HelpContents;

  /* Is there acontents window already opened */
  if(pContentWindow != NULL)
    {
    /* Put the contents window on top */
    gtk_widget_hide(pContentWindow);
    gtk_widget_show(pContentWindow);
    return;
    }

  /* Build the Help contents window */
  pContentWindow   = gtk_dialog_new();
  pContentText     = gtk_label_new(HELP_CONTENTS_TEXT);
  pContentOKButton = gtk_button_new_with_label("OK");
  gtk_container_set_border_width(GTK_CONTAINER(pContentWindow), 5);
  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pContentWindow)->vbox),
		     pContentText,
		     TRUE,
		     TRUE,
		     0);
  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pContentWindow)->action_area),
		     pContentOKButton,
		     TRUE,
		     TRUE,
		     0);

  /* Connect the signals to the box */
  gtk_signal_connect(GTK_OBJECT(pContentWindow),
		     "delete_event",
		     GTK_SIGNAL_FUNC(HELPSHDeleteEvent),
		     pContentWindow);
  gtk_signal_connect(GTK_OBJECT(pContentWindow),
		     "destroy",
		     GTK_SIGNAL_FUNC(HELPSHDestroy),
		     pSysView);
  gtk_signal_connect_object(GTK_OBJECT(pContentOKButton),
			    "clicked",
			    GTK_SIGNAL_FUNC(gtk_widget_destroy),
			    GTK_OBJECT(pContentWindow));

  /* Set the window's title */
  gtk_window_set_title(GTK_WINDOW(pContentWindow), "Help: contents");
  
  /* Place the window in the middle of the screen */
  gtk_window_set_position(GTK_WINDOW(pContentWindow), GTK_WIN_POS_CENTER);

  /* Show the window */
  gtk_widget_show_all(pContentWindow);

  /* Update the Help contents window pointer*/
  pSysView->Window->HelpContents = pContentWindow;
}

/******************************************************************
 * Function :
 *    SHAbout()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHAbout(GtkWidget* pmWidget, gpointer pmData)
{
  GtkWidget*   pAboutText;      /* Text in about box */
  GtkWidget*   pAboutOKButton;  /* OK button in the about box */
  GtkWidget*   pAboutBox;       /* The about box */
  systemView*  pSysView;        /* The system being displayed */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    return;

  /* Get the about box */
  pAboutBox = pSysView->Window->AboutBox;

  /* Is there an about box already opened */
  if(pAboutBox != NULL)
    {
    /* Put the about box up top */
    gtk_widget_hide(pAboutBox);
    gtk_widget_show(pAboutBox);
    return;
    }

  /* Build the about box */
  pAboutBox      = gtk_dialog_new();
  pAboutText     = gtk_label_new(ABOUT_BOX_TEXT);
  pAboutOKButton = gtk_button_new_with_label("OK");
  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pAboutBox)->vbox),
		     pAboutText,
		     TRUE,
		     TRUE,
		     0);
  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pAboutBox)->action_area),
		     pAboutOKButton,
		     TRUE,
		     TRUE,
		     0);

  /* Connect the signals to the box */
  gtk_signal_connect(GTK_OBJECT(pAboutBox),
		     "delete_event",
		     GTK_SIGNAL_FUNC(ABOUTSHDeleteEvent),
		     pAboutBox);
  gtk_signal_connect(GTK_OBJECT(pAboutBox),
		     "destroy",
		     GTK_SIGNAL_FUNC(ABOUTSHDestroy),
		     pSysView);
  gtk_signal_connect_object(GTK_OBJECT(pAboutOKButton),
			    "clicked",
			    GTK_SIGNAL_FUNC(gtk_widget_destroy),
			    GTK_OBJECT(pAboutBox));

  /* Set the box's title */
  gtk_window_set_title(GTK_WINDOW(pAboutBox), "About");
  
  /* Place the box in the middle of the screen */
  gtk_window_set_position(GTK_WINDOW(pAboutBox), GTK_WIN_POS_CENTER);

  /* Set window size */
  gtk_widget_set_usize(GTK_WIDGET(pAboutBox), 300, 250);

  /* Show the box */
  gtk_widget_show_all(pAboutBox);

  /* Update the about box */
  pSysView->Window->AboutBox = pAboutBox;
}

/******************************************************************
 * Function : SHKeyReleased()
 * Description :
 *     Takes care of the keys released by the user.
 * Parameters :
 * Return values :
 * History :
 * Note :
 *     This funciton doesn't always get called. For some reason,
 *     if the window is resized, then the callback isn't called
 *     anymore. GTK bug???
 ******************************************************************/
gint SHKeyReleased(GtkWidget* pmWidget, GdkEventKey* pmKeyEvent, gpointer pmData)
{
  systemView*  pSysView;        /* The system being displayed */

#if 0
  g_print("LTT: key released \n");
#endif

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    return TRUE;

  /* Depending on the key pressed */
  switch(pmKeyEvent->keyval)
    {
    case GDK_Control_L :
    case GDK_Control_R :
      break;
    }

  /* We're done */
  return TRUE;
}

/******************************************************************
 * Function : SHKeyPressed()
 * Description :
 *     Takes care of the keys pressed by the user.
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
gint SHKeyPressed(GtkWidget* pmWidget, GdkEventKey* pmKeyEvent, gpointer pmData)
{
  gint         lCurrentPage;    /* Current page in notebook */
  systemView*  pSysView;        /* The system being displayed */

#if 0
  g_print("LTT: Key pressed \n");
#endif

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    return TRUE;

  /* If the user presses ESC, free the ctrl button press stuff */
  if(pmKeyEvent->state & GDK_CONTROL_MASK)
    return TRUE;

  /* Get the current page being viewed in the notebook */
  lCurrentPage = gtk_notebook_get_current_page(GTK_NOTEBOOK(pSysView->Window->MNotebook));

  /* Depending on the key pressed */
  switch(pmKeyEvent->keyval)
    {
    /* Left arrow */
    case GDK_Left :
      /* Depending on the current notebook page */
      switch(lCurrentPage)
	{
	/* Event Graph */
	case 0 :
	  EGScrollLeft(pSysView->Window->GTEventGraph);
	  break;
	}
      break;

    /* Right arrow */
    case GDK_Right :
      /* Depending on the current notebook page */
      switch(lCurrentPage)
	{
	/* Event Graph */
	case 0 :
	  EGScrollRight(pSysView->Window->GTEventGraph);	  
	  break;
	}
      break;

    /* Up arrow */
    case GDK_Up :
      /* Depending on the current notebook page */
      switch(lCurrentPage)
	{
	/* Event Graph */
	case 0 :
	  EGScrollUp(pSysView->Window->GTEventGraph);	  
	  break;

	/* Raw trace */
	case 2 :
	  WDIRTScroll(pSysView, SRT_UP);
	  break;
	}
      break;

    /* Down arrow */
    case GDK_Down :
      /* Depending on the current notebook page */
      switch(lCurrentPage)
	{
	/* Event Graph */
	case 0 :
       	  EGScrollDown(pSysView->Window->GTEventGraph);
	  break;

	/* Raw trace */
	case 2 :
	  WDIRTScroll(pSysView, SRT_DOWN);
	  break;
	}
      break;

    /* Page up */
    case GDK_Page_Up :
      /* Depending on the current notebook page */
      switch(lCurrentPage)
	{
	/* Event Graph */
	case 0 :
	  EGPageUp(pSysView->Window->GTEventGraph);	  
	  break;

	/* Raw trace */
	case 2 :
	  WDIRTScroll(pSysView, SRT_PAGE_UP);
	  break;
	}
      break;

    /* Page down */
    case GDK_Page_Down :
      /* Depending on the current notebook page */
      switch(lCurrentPage)
	{
	/* Event Graph */
	case 0 :
	  EGPageDown(pSysView->Window->GTEventGraph);
	  break;

	/* Raw trace */
	case 2 :
	  WDIRTScroll(pSysView, SRT_PAGE_DOWN);
	  break;
	}
      break;

    /* G or g */
    case 'g' :
    case 'G' :
      gtk_notebook_set_page(GTK_NOTEBOOK(pSysView->Window->MNotebook), 0);
      break;

    /* P or p */
    case 'p' :
    case 'P' :
      gtk_notebook_set_page(GTK_NOTEBOOK(pSysView->Window->MNotebook), 1);
      break;

    /* R or r */
    case 'r' :
    case 'R' :
      gtk_notebook_set_page(GTK_NOTEBOOK(pSysView->Window->MNotebook), 2);
      break;
    }

  return TRUE;
}

/******************************************************************
 * Function :
 *    SHToggleTBIcon()
 * Description : 
 *   Clearinghouse for several toolbar icons that forces a redraw.
 *   EGIEventInfo (the icon drawing routine) checks the toolbar value
 *   directly.  This provides tighter coupling, less code, smaller
 *   data structures and fewer errors.  
 * Parameters :
 * Return values :
 * History : 
 *   02/01	ROC, removed superfluous data structures and copying
 *   01/01	ROC, initial typing
 * Note :
 ******************************************************************/
void SHToggleTBIcon(GtkWidget* pmWidget, gpointer pmData)
{
  systemView*  pSysView;    /* The system view */

  /* Is this a valid event */
  if((pSysView = (systemView*) pmData) == NULL)
    {
    g_print("Toggle Toolbar Icon without valid SystemView pointer! \n");
    exit(1);
    }

   /* The redraw takes a kick (ie, event) to display.  See a similar (?) 
      comment in EGClearEventGraph.  This call was copied from EGZoomIn 
      (also in EGSetHorizonView).  What about EGShowEventGraph?  FYI,
      a hide/show pair seems to flash really bad */
   EGForceTraceRedraw(pSysView->Window->GTEventGraph);

   /* Update the draw area */
   gtk_widget_queue_resize(pSysView->Window->GTEventGraph->DrawArea);
}

/******************************************************************
 * Function :
 *    SHEGIconButtonPress()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHEGIconButtonPress(GtkWidget*      pmDrawArea,
			 GdkEventButton* pmEventButton,
			 gpointer        pmEGraph)
{
  eventGraph* pEGraph;   /* Pointer to the event graph */
  GSList*     Navigator; /* Temporary pointer to the EventIcons list */

  /* Fool-proof the function */
  if(!(pEGraph = (eventGraph*) pmEGraph))
    {
    g_print("Null Event Graph in function SHEGIconButtonPress! \n");
    exit(1);
    }

  /* Is this the first button */
  if (pmEventButton->button == 1)
    {
    /* Zoom in */
    EGOneClickZoom(pEGraph, pmEventButton->x, TRUE);
    return;
    }

  /* if we have a right-click event */
  if(pmEventButton->button == 3)
    {
    /* Set temporary list navigation item */
    Navigator = pEGraph->EventIcons;

    /* Go through the list of icon coordinates */
    while(Navigator)
      {
      if( EGMouseOnIcon((gint) pmEventButton->x, 
			(gint) pmEventButton->y,
			(eventInfo*) Navigator->data ) )
	{
	/* Memorize selected event */
	((mainWindow*) pEGraph->MainWindow)->LastSelectedEvent =
	               ((eventInfo*) Navigator->data)->Event;
	((mainWindow*) pEGraph->MainWindow)->EventSelected = TRUE;

	/* Display the popup menu */
	gtk_menu_popup(GTK_MENU(((mainWindow*) pEGraph->MainWindow)->EventGraphPopup),
		       NULL, NULL, NULL, NULL,
		       pmEventButton->button, GDK_CURRENT_TIME);

	return;
	}

      /* Go to the next item in list */
      Navigator = Navigator->next;
      }

    /* No matching event icon so fall through to zoom out */
    EGOneClickZoom(pEGraph, pmEventButton->x, FALSE);
    }
    /* If no corresponding icon was found, no menu will have been displayed */
}

/******************************************************************
 * Function :
 *    SHPTProcessSelect()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHPTProcessSelect(GtkWidget* pmWidget, gpointer pmData)
{
  gint           i;                       /* Generic index */
  gchar          lTabing[10];             /* Tab distance between syscall name and time */
  gchar          lTimeStr[TIME_STR_LEN];  /* Time string */
  process*       pProcess;                /* Process selected */
  syscallInfo*   pSyscall;                /* Syscall who's information is to be displayed */
  systemView*    pSysView = NULL;         /* System viewed */
  systemView*    pSysViewPtr;             /* System view pointer */
  GtkWidget*     pTextArea;               /* Text area where process information is to be printed */
  struct timeval lTraceDuration;          /* Duration of trace */

  /* Is there anything to be visualized */
  if((pProcess = (process*) pmData) == NULL)
    return;

  /* Get the system to which this process belongs */
  for(pSysViewPtr = sMainSystemViewList; pSysViewPtr != NULL; pSysViewPtr = pSysViewPtr->Next)
    if(pSysViewPtr->System == pProcess->System)
      pSysView = pSysViewPtr;

  /* Is there any such thing */
  if(pSysView == NULL)
    {
    /* Now I'm lost .... */
    g_print("Internal error: Process doesn't have valid parent system");
    exit(1);
    }

  /* Get the text area where information is to be displayed */
  pTextArea = pSysView->Window->PTProcessText;

  /* Freeze text area */
  gtk_text_freeze(GTK_TEXT(pTextArea));

  /* Erase current text content */
  gtk_text_backward_delete(GTK_TEXT(pTextArea), gtk_text_get_length(GTK_TEXT(pTextArea)));

  /*  Duration */
  DBTimeSub(lTraceDuration, pSysView->EventDB->EndTime, pSysView->EventDB->StartTime);

  /* If the user selected process 0, then show the system-wide analysis */
  if(pProcess->PID == 0)
    {
    /* Main trace characteristics */
    WDITextInsert(pSysView->Window,
		  "Main trace characteristics :\n");
    WDITextInsert(pSysView->Window,
		  "----------------------------\n");
    /*  Start time*/
    DBFormatTimeInReadableString(lTimeStr,
				 pSysView->EventDB->StartTime.tv_sec,
				 pSysView->EventDB->StartTime.tv_usec);
    WDITextInsert(pSysView->Window,
		  "Trace start time: \t %s \n",
		  lTimeStr);

    /*  End time */
    DBFormatTimeInReadableString(lTimeStr,
				 pSysView->EventDB->EndTime.tv_sec,
				 pSysView->EventDB->EndTime.tv_usec);
    WDITextInsert(pSysView->Window,
		  "Trace end time: \t %s \n",
		  lTimeStr);

    /*  Duration */
    DBFormatTimeInReadableString(lTimeStr,
				 lTraceDuration.tv_sec,
				 lTraceDuration.tv_usec);
    WDITextInsert(pSysView->Window,
		  "Trace duration: \t %s \n",
		  lTimeStr);

    /*  Time during which we were runing idle */
    DBFormatTimeInReadableString(lTimeStr,
				 pProcess->TimeRuning.tv_sec,
				 pProcess->TimeRuning.tv_usec);
    WDITextInsert(pSysView->Window,
		  "System idle: \t\t %s => %2.2f %% \n\n",
		  lTimeStr,
		  (float) 100 * (DBGetTimeInDouble(pProcess->TimeRuning) / DBGetTimeInDouble(lTraceDuration)));

    /*  Number of occurences of some events */
    WDITextInsert(pSysView->Window,
		  "Number of occurrences of some key events :\n");
    WDITextInsert(pSysView->Window,
		  "------------------------------------------\n");
    WDITextInsert(pSysView->Window,
		  "Events: \t\t\t %ld \n",
		  pSysView->EventDB->Nb);
    WDITextInsert(pSysView->Window,
		  "Scheduling changes: \t %ld \n",
		  pSysView->System->SchedChange);
    WDITextInsert(pSysView->Window,
		  "Kernel timer tics: \t\t %ld \n",
		  pSysView->System->KernelTimer);
    WDITextInsert(pSysView->Window,
		  "System call entries: \t %ld \n",
		  pSysView->System->SyscallEntry);
    WDITextInsert(pSysView->Window,
		  "System call exits: \t\t %ld \n",
		  pSysView->System->SyscallExit);
    WDITextInsert(pSysView->Window,
		  "Trap entries: \t\t\t %ld \n",
		  pSysView->System->TrapEntry);
    WDITextInsert(pSysView->Window,
		  "Trap exits: \t\t\t %ld \n",
		  pSysView->System->TrapExit);
    WDITextInsert(pSysView->Window,
		  "IRQ entries: \t\t\t %ld \n",
		  pSysView->System->IRQEntry);
    WDITextInsert(pSysView->Window,
		  "IRQ exits: \t\t\t %ld \n",
		  pSysView->System->IRQExit);
    WDITextInsert(pSysView->Window,
		  "Bottom halves: \t\t\t %ld \n",
		  pSysView->System->BH);
    WDITextInsert(pSysView->Window,
		  "Timer expiries: \t\t %ld \n",
		  pSysView->System->TimerExpire);
    WDITextInsert(pSysView->Window,
		  "Page allocations: \t\t %ld \n",
		  pSysView->System->PageAlloc);
    WDITextInsert(pSysView->Window,
		  "Page frees: \t\t\t %ld \n",
		  pSysView->System->PageFree);
    WDITextInsert(pSysView->Window,
		  "Packets Out: \t\t\t %ld \n",
		  pSysView->System->PacketOut);
    WDITextInsert(pSysView->Window,
		  "Packets In: \t\t\t %ld \n\n",
		  pSysView->System->PacketIn);

    /* Print out interrupt information header */
    WDITextInsert(pSysView->Window,"\nSystem Interrupts :\n");
    WDITextInsert(pSysView->Window,"-------------------\n");

    /* Print out interrupt information */
    for (i = 0; i < MAX_NB_INTERRUPTS; i++)
      if(pSysView->System->Interrupts[i] != NULL)
	WDITextInsert(pSysView->Window, "%d: \t %s\n", i, 
		      pSysView->System->Interrupts[i]) ;

    /* Leave a space between interrupts and syscall accounting */
    WDITextInsert(pSysView->Window,"\n");
    
    /* Show system-wide system call analysis */
    pSyscall = pSysView->System->Syscalls;
    }
  else
    {
    /* Process characteristics */
    WDITextInsert(pSysView->Window,
		  "Process characteristics :\n");
    WDITextInsert(pSysView->Window,
		  "-------------------------\n");

    /* Print detailed process information */
    WDITextInsert(pSysView->Window,
		  "Number of system calls: \t\t\t %d \n",
		  pProcess->NbSyscalls);
    WDITextInsert(pSysView->Window,
		  "Number of traps: \t\t\t\t\t %d \n",
		  pProcess->NbTraps);
    WDITextInsert(pSysView->Window,
		  "Quantity of data read from files: \t %d \n",
		  pProcess->QFileRead);
    WDITextInsert(pSysView->Window,
		  "Quantity of data written to files: \t %d \n",
		  pProcess->QFileWrite);
    DBFormatTimeInReadableString(lTimeStr,
				 pProcess->TimeProcCode.tv_sec,
				 pProcess->TimeProcCode.tv_usec);
    WDITextInsert(pSysView->Window,
		  "Time executing process code: \t\t %s => %2.2f %% \n",
		  lTimeStr,
		  (float) 100 * (DBGetTimeInDouble(pProcess->TimeProcCode) / DBGetTimeInDouble(lTraceDuration)));
    DBFormatTimeInReadableString(lTimeStr,
				 pProcess->TimeRuning.tv_sec,
				 pProcess->TimeRuning.tv_usec);
    WDITextInsert(pSysView->Window,
		  "Time running: \t\t\t\t\t\t %s => %2.2f %% \n",
		  lTimeStr,
		  (float) 100 * (DBGetTimeInDouble(pProcess->TimeRuning) / DBGetTimeInDouble(lTraceDuration)));
    DBFormatTimeInReadableString(lTimeStr,
				 pProcess->TimeIO.tv_sec,
				 pProcess->TimeIO.tv_usec);
    WDITextInsert(pSysView->Window,
		  "Time waiting for I/O: \t\t\t\t %s => %2.2f %% \n\n",
		  lTimeStr,
		  (float) 100 * (DBGetTimeInDouble(pProcess->TimeIO) / DBGetTimeInDouble(lTraceDuration)));

    /* Show process-specific system call analysis */
    pSyscall = pProcess->Syscalls;
    }

  /* System call information header */
  if(pSyscall != NULL)
    {
    WDITextInsert(pSysView->Window,
		  "System call accounting (name, nb times called, total time spent in syscall) :\n");
    WDITextInsert(pSysView->Window,
		  "-----------------------------------------------------------------------------\n");
    }

  /* Display the system call analysis */
  for(; pSyscall != NULL; pSyscall = pSyscall->Next)
    {
    /* Compute tabbing according to syscall's name length */
    if(strlen(pSysView->EventDB->SyscallString(pSysView->EventDB, pSyscall->ID)) < 6)
      sprintf(lTabing, "\t\t");
    else if (strlen(pSysView->EventDB->SyscallString(pSysView->EventDB, pSyscall->ID)) < 14)
      sprintf(lTabing, "\t");
    else
      lTabing[0] = '\0';

    /* Insert the system call description */
    DBFormatTimeInReadableString(lTimeStr,
				 pSyscall->Time.tv_sec,
				 pSyscall->Time.tv_usec);
    WDITextInsert(pSysView->Window,
		  "%s: %s %6d \t %s \n",
		  pSysView->EventDB->SyscallString(pSysView->EventDB, pSyscall->ID),
		  lTabing,
		  pSyscall->Nb,
		  lTimeStr);
    }

#if 0
  /* Place view at the begining of the scroll area */ /* This is dirty, but I didn't find any other way. K.Y. */
  gtk_adjustment_set_value(GTK_RANGE(GTK_SCROLLED_WINDOW(pSysView->Window->PTScrolledText)->hscrollbar)->adjustment,
			   0);
  gtk_adjustment_set_value(GTK_RANGE(GTK_SCROLLED_WINDOW(pSysView->Window->PTScrolledText)->vscrollbar)->adjustment,
			   0);
#endif

  /* Thaw text area */
  gtk_text_thaw(GTK_TEXT(pTextArea));
}

/******************************************************************
 * Function :
 *    SHPTRTAITaskSelect()
 * Description :
 *    Handles the occurence of a selection of a RTAI task.
 * Parameters :
 *    pmWidget, The widget selected.
 *    pmData, Pointer to the RTAI task selected
 * Return values :
 *    NONE
 * History :
 *    14/06/2000 K.Y., Initial typing.
 * Note :
 ******************************************************************/
#if SUPP_RTAI
void SHPTRTAITaskSelect(GtkWidget* pmWidget, gpointer pmData)
{
  gchar          lTimeStr[TIME_STR_LEN];  /* Time string */
  RTAItask*      pTask;                   /* Task selected */
  RTAIsystem*    pRTAISystem;             /* RTAI system description */
  systemView*    pSysView = NULL;         /* System viewed */
  systemView*    pSysViewPtr;             /* System view pointer */
  GtkWidget*     pTextArea;               /* Text area where process information is to be printed */
  struct timeval lTraceDuration;          /* Duration of trace */

  /* Is there anything to be visualized */
  if((pTask = (RTAItask*) pmData) == NULL)
    return;

  /* Get the system to which this task belongs */
  for(pSysViewPtr = sMainSystemViewList; pSysViewPtr != NULL; pSysViewPtr = pSysViewPtr->Next)
    if(pSysViewPtr->System == pTask->System)
      pSysView = pSysViewPtr;

  /* Is there any such thing */
  if(pSysView == NULL)
    {
    /* Now I'm lost .... */
    g_print("Internal error: RTAI Task doesn't have valid parent system");
    exit(1);
    }

  /* Get the text area where information is to be displayed */
  pTextArea = pSysView->Window->PTProcessText;

  /* Freeze text area */
  gtk_text_freeze(GTK_TEXT(pTextArea));

  /* Erase current text content */
  gtk_text_backward_delete(GTK_TEXT(pTextArea), gtk_text_get_length(GTK_TEXT(pTextArea)));

  /*  Duration */
  DBTimeSub(lTraceDuration, pSysView->EventDB->EndTime, pSysView->EventDB->StartTime);

  /* Get the RTAI system description */
  pRTAISystem = RTAI_SYSTEM(pSysView->System->SystemSpec);

  /* Are we dealing with the linux task */
  if(pTask->TID == 0)
    {
    /* Main trace characteristics */
    WDITextInsert(pSysView->Window,
		  "Main trace characteristics :\n");
    WDITextInsert(pSysView->Window,
		  "----------------------------\n");
    /*  Start time*/
    DBFormatTimeInReadableString(lTimeStr,
				 pSysView->EventDB->StartTime.tv_sec,
				 pSysView->EventDB->StartTime.tv_usec);
    WDITextInsert(pSysView->Window,
		  "Trace start time: \t %s \n",
		  lTimeStr);

    /*  End time */
    DBFormatTimeInReadableString(lTimeStr,
				 pSysView->EventDB->EndTime.tv_sec,
				 pSysView->EventDB->EndTime.tv_usec);
    WDITextInsert(pSysView->Window,
		  "Trace end time: \t %s \n",
		  lTimeStr);

    /*  Duration */
    DBFormatTimeInReadableString(lTimeStr,
				 lTraceDuration.tv_sec,
				 lTraceDuration.tv_usec);
    WDITextInsert(pSysView->Window,
		  "Trace duration: \t %s \n\n",
		  lTimeStr);


    /*  Number of occurences of some events */
    WDITextInsert(pSysView->Window,
		  "Number of occurrences of some key events :\n");
    WDITextInsert(pSysView->Window,
		  "------------------------------------------\n");
    WDITextInsert(pSysView->Window,
		  "Events: \t\t\t %ld \n",
		  pSysView->EventDB->Nb);
    WDITextInsert(pSysView->Window,
		  "RT-Events: \t\t\t %ld (%2.2f %%) \n",
		  pRTAISystem->NbRTEvents,
		  100 * ((float)pRTAISystem->NbRTEvents) / ((float)pSysView->EventDB->Nb));
    WDITextInsert(pSysView->Window,
		  "RTAI mounts: \t\t\t %ld \n",
		  pRTAISystem->Mount);
    WDITextInsert(pSysView->Window,
		  "RTAI un-mounts: \t\t %ld \n",
		  pRTAISystem->UMount);
    WDITextInsert(pSysView->Window,
		  "Global IRQ entries: \t %ld \n",
		  pRTAISystem->GlobalIRQEntry);
    WDITextInsert(pSysView->Window,
		  "Global IRQ exits: \t\t %ld \n",
		  pRTAISystem->GlobalIRQExit);
    WDITextInsert(pSysView->Window,
		  "CPU-own IRQ entries: \t %ld \n",
		  pRTAISystem->CPUOwnIRQEntry);
    WDITextInsert(pSysView->Window,
		  "CPU-own IRQ exits: \t\t %ld \n",
		  pRTAISystem->CPUOwnIRQExit);
    WDITextInsert(pSysView->Window,
		  "Trap entries: \t\t\t %ld \n",
		  pRTAISystem->TrapEntry);
    WDITextInsert(pSysView->Window,
		  "Trap exits: \t\t\t %ld \n",
		  pRTAISystem->TrapExit);
    WDITextInsert(pSysView->Window,
		  "SRQ entries: \t\t\t %ld \n",
		  pRTAISystem->SRQEntry);
    WDITextInsert(pSysView->Window,
		  "SRQ exits: \t\t\t %ld \n",
		  pRTAISystem->SRQExit);
    WDITextInsert(pSysView->Window,
		  "Switches to Linux: \t\t %ld \n",
		  pRTAISystem->SwitchToLinux);
    WDITextInsert(pSysView->Window,
		  "Switches to RT: \t\t %ld \n",
		  pRTAISystem->SwitchToRT);
    WDITextInsert(pSysView->Window,
		  "RT-Scheduling changes: \t %ld \n",
		  pRTAISystem->SchedChange);
    WDITextInsert(pSysView->Window,
		  "LXRT-Scheduling changes: %ld \n",
		  pRTAISystem->LXRTSchedChange);
    }
  else
    {
    /* Task characteristics */
    WDITextInsert(pSysView->Window,
		  "Task characteristics :\n");
    WDITextInsert(pSysView->Window,
		  "----------------------\n");

    /* Is this task a Linux process buddy */
    if(pTask->IsProcessBuddy == TRUE)
      {
      WDITextInsert(pSysView->Window,
		    "RT buddy of Linux process: \t %s(%d) \n",
		    pTask->BuddyProcess->Command,
		    pTask->BuddyProcess->PID);
      }

    /* Is this a linux process shadow */
    if(pTask->IsProcessShadow == TRUE)
      {
      WDITextInsert(pSysView->Window,
		    "RT shadow of Linux process:  %s(%d) \n",
		    pTask->ShadowProcess->Command,
		    pTask->ShadowProcess->PID);
      }

    /* Task times */
    WDITextInsert(pSysView->Window,
		  "\nTask time info (usecs) :\n");
    WDITextInsert(pSysView->Window,
		  "--------------------------\n");
    DBFormatTimeInReadableString(lTimeStr,
				 pTask->TimeOfBirth.tv_sec,
				 pTask->TimeOfBirth.tv_usec);
    WDITextInsert(pSysView->Window,
		  "Time of birth: \t\t\t\t %s\n",
		  lTimeStr);
    DBFormatTimeInReadableString(lTimeStr,
				 pTask->TimeRunning.tv_sec,
				 pTask->TimeRunning.tv_usec);
    WDITextInsert(pSysView->Window,
		  "Total time running: \t\t %s => %2.2f %% \n",
		  lTimeStr,
		  (float) 100 * (DBGetTimeInDouble(pTask->TimeRunning) / DBGetTimeInDouble(lTraceDuration)));
    WDITextInsert(pSysView->Window,
		  "Number of times scheduled: \t %d \n",
		  pTask->NbTimesScheduled);
    WDITextInsert(pSysView->Window,
		  "Average time running: \t\t %0.2f \n",
		  (float) (DBGetTimeInDouble(pTask->TimeRunning) / (float) pTask->NbTimesScheduled));
    WDITextInsert(pSysView->Window,
		  "Average time between runs: \t %0.2f \n",
		  (float) (DBGetTimeInDouble(pTask->TimeBetweenRuns) / (float) pTask->NbTimesScheduled));

    /* Communication info */
    WDITextInsert(pSysView->Window,
		  "\nTask communication info :\n");
    WDITextInsert(pSysView->Window,
		  "-------------------------\n");
    WDITextInsert(pSysView->Window,
		  "Bytes written to FIFO (PUT): \t %d \n",
		  pTask->QFIFOPut);
    WDITextInsert(pSysView->Window,
		  "Bytes read from FIFO (GET): \t %d \n",
		  pTask->QFIFOGet);
    }

  /* Thaw text area */
  gtk_text_thaw(GTK_TEXT(pTextArea));
}
#endif /* SUPP_RTAI */

/******************************************************************
 * Function :
 *    SHRTEventSelect()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHRTEventSelect(GtkWidget*      pmCList,
		     gint            pmRow,
		     gint            pmColumn,
		     GdkEventButton* pmEvent,
		     gpointer        pmData)
{
  systemView*  pSysView;        /* The system being displayed */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    return;

  /* Store the selected event */
  pSysView->Window->LastSelectedEvent = *(event*) gtk_clist_get_row_data(GTK_CLIST(pmCList), pmRow);
  pSysView->Window->EventSelected = TRUE;
}

/******************************************************************
 * Function :
 *    SHRTEventButtonPress()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHRTEventButtonPress(GtkWidget*      pmCList,
			  GdkEventButton* pmEvent,
			  gpointer        pmData)
{
  systemView*  pSysView;        /* The system being displayed */
  gint         row, column;     /* The clicked row and column */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    return;

  /* if we have a right-click event */
  if(pmEvent->button == 3)
    /* If we clicked on an item, get its row and column values */
    if(gtk_clist_get_selection_info(GTK_CLIST(pmCList), pmEvent->x, pmEvent->y, &row, &column))
      {
      /* Highlight the selected row */
      gtk_clist_select_row(GTK_CLIST(pmCList), row, column);

      /* Store the selected event */
      pSysView->Window->LastSelectedEvent = *(event*) gtk_clist_get_row_data(GTK_CLIST(pmCList), row);
      pSysView->Window->EventSelected = TRUE;

      /* Display the popup menu */
      gtk_menu_popup(GTK_MENU(pSysView->Window->RawEventPopup),
		     NULL, NULL, NULL, NULL,
		     pmEvent->button, GDK_CURRENT_TIME);
      }
}

/******************************************************************
 * Function :
 *    SHRTVAdjustValueChanged()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHRTVAdjustValueChanged(GtkAdjustment*  pmVAdjust,
			     gpointer        pmData)
{
  event        lEvent;          /* Event used for searching */
  guint32      lPosition;       /* The position to scroll to */
  systemView*  pSysView;        /* The system being displayed */

  /* Do we have anything meaningfull */
  if((pSysView = (systemView*) pmData) == NULL)
    return;

  /* Is there an event database? */
  if(pSysView->EventDB == NULL)
    return;

  /* Set the pointer to the first event */
  if(pSysView->EventDB->TraceStart == NULL)
    return;

  /* Are we closer to the beginning? */
  if((pmVAdjust->value - (pmVAdjust->upper / 2)) < 0)
    {
    /* Set the navigation pointer to the beginning of the list */
    lEvent =  pSysView->EventDB->FirstEvent;

    /* Calculate distance from beginning */
    lPosition = (guint32) pmVAdjust->value;

    /* Find the event in the event database */
    while(lPosition > 0)
      {
      lPosition--;
      if(DBEventNext(pSysView->EventDB, &lEvent) != TRUE)
	break;
      }
    }
  else
    {
    /* Set the navigation pointer to the end of the list */
    lEvent = pSysView->EventDB->LastEvent;

    /* Calculate distance from end */
    lPosition = (guint32) (pmVAdjust->upper - pmVAdjust->value);

    /* Find the event in the event database */
    while(lPosition > 0)
      {
      lPosition--;
      if(DBEventPrev(pSysView->EventDB, &lEvent) != TRUE)
	break;
      }
    }

  /* Fill the event list according to what was found */
  WDFillEventList(pSysView->Window->RTCList,
		  pSysView->EventDB,
		  pSysView->System,
		  &lEvent,
		  &(pSysView->Window->LastSelectedEvent));
}

/******************************************************************
 * Function :
 *    SHGotoProcAnalysis()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHGotoProcAnalysis(GtkWidget* pmWidget, gpointer pmData)
{
  char         lTreeItemType[30]; /* String describing type of item to look for */
  void*        pDataToFind;       /* Generic pointer to data to be found */
  systemView*  pSysView;          /* The system view */
  GtkTreeItem* pTempTreeItem;     /* Temporary pointer to the TreeItem */
  
  if((pSysView = (systemView*) pmData) == NULL)
    {
    g_print("Proc analysis without valid SystemView pointer! \n");
    exit(1);
    }

  /* If an item has been selected by popup menu */
  if(pSysView->Window->EventSelected)
    {
    /* Get the event's ID */
    if(DBEventID(pSysView->EventDB, &(pSysView->Window->LastSelectedEvent)) <= TRACE_MAX)
      {
      /* Get the event's process */
      pDataToFind = (void*) DBEventProcess(pSysView->EventDB, &(pSysView->Window->LastSelectedEvent), pSysView->System, FALSE);

      /* We are looking for process data */
      strcpy(lTreeItemType, TREE_ITEM_DATA_PROC);
      }
    else
#if SUPP_RTAI
      {
      /* Get the event's task */
      pDataToFind = (void*) RTAIDBEventTask(pSysView->EventDB, &(pSysView->Window->LastSelectedEvent), pSysView->System, FALSE);

      /* We are looking for task data */
      strcpy(lTreeItemType, TREE_ITEM_DATA_RTAI_TASK);
      }
#else
      pDataToFind = NULL;
#endif /* SUPP_RTAI */
    
    /* Is there something to look for */
    if(pDataToFind == NULL)
      return;

    /* Search for the TreeItem */
    pTempTreeItem = WDISearchSubTree(GTK_TREE(pSysView->Window->PTProcessTree),
				     lTreeItemType,
				     pDataToFind);

    /* Was a tree item found? */
    if(pTempTreeItem)
      /* Is the TreeItem already selected? */
      if(GTK_WIDGET(pTempTreeItem)->state != GTK_STATE_SELECTED)
	/* Select the node */
	gtk_tree_select_child(GTK_TREE(pSysView->Window->PTProcessTree), GTK_WIDGET(pTempTreeItem));

    /* No event should be selected anymore */
    pSysView->Window->EventSelected = FALSE;
    }

  /* Select the process tree notebook page */
  gtk_notebook_set_page(GTK_NOTEBOOK(pSysView->Window->MNotebook), 1);
}

/******************************************************************
 * Function :
 *    SHViewEventInEG()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHViewEventInEG(GtkWidget* pmWidget, gpointer pmData)
{
  systemView*  pSysView;    /* The system view */
  
  if((pSysView = (systemView*) pmData) == NULL)
    {
    g_print("Proc analysis without valid SystemView pointer! \n");
    exit(1);
    }

  /* If an item has been selected by popup menu */
  if(pSysView->Window->EventSelected)
    /* Display that event */
    EGScrollToEvent(pSysView->Window->GTEventGraph, &(pSysView->Window->LastSelectedEvent));

  /* No event should be selected anymore */
  pSysView->Window->EventSelected = FALSE;

  /* Display the event graph notebook page */
  gtk_notebook_set_page(GTK_NOTEBOOK(pSysView->Window->MNotebook), 0);
}

/******************************************************************
 * Function :
 *    SHViewEventInRT()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void SHViewEventInRT(GtkWidget* pmWidget, gpointer pmData)
{
  systemView*  pSysView;  /* The system view */
  
  if((pSysView = (systemView*) pmData) == NULL)
    {
    g_print("SHViewEventInRT without valid SystemView pointer! \n");
    exit(1);
    }

  /* Display the raw events notebook page */
  gtk_notebook_set_page(GTK_NOTEBOOK(pSysView->Window->MNotebook), 2);

  /* If an item has been selected by popup menu */
  if(pSysView->Window->EventSelected)
    {
    /* Select the event found */
    WDISelectRTEvent(pSysView, &(pSysView->Window->LastSelectedEvent));

    /* No event should be selected anymore */
    pSysView->Window->EventSelected = FALSE;
    }
}

/**********************************************************************************/
/******************************* Windowing functions ******************************/
/**********************************************************************************/
/******************************************************************
 * Function :
 *    WDAddAccelerators()
 * Description :
 *    Adds accelerators keys to the application.
 * Parameters :
 *    pmSysView, System view for which signals have to be connected
 * Return values :
 *    NONE
 * History :
 ******************************************************************/
void WDAddAccelerators(systemView* pmSysView)
{
  /* Add acceletor for opening traces */
  gtk_widget_add_accelerator(pmSysView->Window->OpenTrace,
			     "activate",
			     pmSysView->Window->MAccelerator,
			     'O',
			     GDK_CONTROL_MASK,
			     GTK_ACCEL_VISIBLE);

  /* Add acceletor for closing traces */
  gtk_widget_add_accelerator(pmSysView->Window->CloseTrace,
			     "activate",
			     pmSysView->Window->MAccelerator,
			     'C',
			     GDK_CONTROL_MASK,
			     GTK_ACCEL_VISIBLE);

  /* Add acceletor for dumping to file */
  gtk_widget_add_accelerator(pmSysView->Window->DumpToFile,
			     "activate",
			     pmSysView->Window->MAccelerator,
			     'D',
			     GDK_CONTROL_MASK,
			     GTK_ACCEL_VISIBLE);

  /* Add acceletor for exiting the application */
  gtk_widget_add_accelerator(pmSysView->Window->Quit,
			     "activate",
			     pmSysView->Window->MAccelerator,
			     'X',
			     GDK_CONTROL_MASK,
			     GTK_ACCEL_VISIBLE);

  /* Add acceletor for zooming in */
  gtk_widget_add_accelerator(pmSysView->Window->ZoomIn,
			     "activate",
			     pmSysView->Window->MAccelerator,
			     GDK_Page_Up,
			     GDK_CONTROL_MASK,
			     GTK_ACCEL_VISIBLE);

  /* Add acceletor for zooming out */
  gtk_widget_add_accelerator(pmSysView->Window->ZoomOut,
			     "activate",
			     pmSysView->Window->MAccelerator,
			     GDK_Page_Down,
			     GDK_CONTROL_MASK,
			     GTK_ACCEL_VISIBLE);

  /* Add acceletor for showing the horizon */
  gtk_widget_add_accelerator(pmSysView->Window->ShowHorizon,
			     "activate",
			     pmSysView->Window->MAccelerator,
			     'Z',
			     GDK_CONTROL_MASK,
			     GTK_ACCEL_VISIBLE);

  /* Add acceletor for going to an event */
  gtk_widget_add_accelerator(pmSysView->Window->ToolGoToEvent,
			     "activate",
			     pmSysView->Window->MAccelerator,
			     'E',
			     GDK_CONTROL_MASK,
			     GTK_ACCEL_VISIBLE);

  /* Add acceletor for going to viewing a time-frame */
  gtk_widget_add_accelerator(pmSysView->Window->ToolViewTimeFrame,
			     "activate",
			     pmSysView->Window->MAccelerator,
			     'T',
			     GDK_CONTROL_MASK,
			     GTK_ACCEL_VISIBLE);
}

/******************************************************************
 * Function :
 *    WDConnectSignals()
 * Description :
 *    Attaches signal handlers to the window items.
 * Parameters :
 *    pmSysView, System view for which signals have to be connected
 * Return values :
 *    NONE
 * History :
 * Note :
 *    This function attaches a pointer to the main window during
 *    the connect. This means that the handlers will get a pointer
 *    to the window in the data argument.
 ******************************************************************/
void WDConnectSignals(systemView* pmSysView)
{
  /* Connect the main window signals */
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->MWindow),
		     "delete_event",
		     GTK_SIGNAL_FUNC(SHDeleteEvent),
		     pmSysView);
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->MWindow),
		     "destroy",
		     GTK_SIGNAL_FUNC(SHDestroy),
		     pmSysView);

  /* Connect the menu items */
  /*  File menu */
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->OpenTrace),
		     "activate",
		     GTK_SIGNAL_FUNC(SHOpenTrace),
		     pmSysView);
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->CloseTrace),
		     "activate",
		     GTK_SIGNAL_FUNC(SHCloseTrace),
		     pmSysView);
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->DumpToFile),
		     "activate",
		     GTK_SIGNAL_FUNC(SHDumpToFile),
		     pmSysView);
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->Quit),
		     "activate",
		     GTK_SIGNAL_FUNC(SHQuit),
		     pmSysView);
  /*  Tools menu */
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->ZoomIn),
		     "activate",
		     GTK_SIGNAL_FUNC(SHZoomIn),
		     pmSysView);
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->ZoomOut),
		     "activate",
		     GTK_SIGNAL_FUNC(SHZoomOut),
		     pmSysView);
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->ShowHorizon),
		     "activate",
		     GTK_SIGNAL_FUNC(SHShowHorizon),
		     pmSysView);
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->ToolGoToEvent),
		     "activate",
		     GTK_SIGNAL_FUNC(SHGotoEvent),
		     pmSysView);
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->ToolViewTimeFrame),
		     "activate",
		     GTK_SIGNAL_FUNC(SHViewTimeFrame),
		     pmSysView);
  /*  Edit menu */
#if 0
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->),
		     "activate",
		     GTK_SIGNAL_FUNC(),
		     pmSysView);
#endif
  /*  Options menu */
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->Colors),
		     "activate",
		     GTK_SIGNAL_FUNC(SHColorSelect),
		     pmSysView);
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->ConfigureDaemon),
		     "activate",
		     GTK_SIGNAL_FUNC(SHConfigureDaemon),
		     pmSysView);
  /*  Help menu */
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->Contents),
		     "activate",
		     GTK_SIGNAL_FUNC(SHContents),
		     pmSysView);
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->About),
		     "activate",
		     GTK_SIGNAL_FUNC(SHAbout),
		     pmSysView);

  /* Popup menus */

  /* Raw event Popup menu */
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->RawGotoProcess),
		     "activate",
		     GTK_SIGNAL_FUNC(SHGotoProcAnalysis),
		     pmSysView);
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->RawViewEvent),
		     "activate",
		     GTK_SIGNAL_FUNC(SHViewEventInEG),
		     pmSysView);

  /* Event graph Popup menu */
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->EventGotoProcess),
		     "activate",
		     GTK_SIGNAL_FUNC(SHGotoProcAnalysis),
		     pmSysView);
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->EventViewRawEvent),
		     "activate",
		     GTK_SIGNAL_FUNC(SHViewEventInRT),
		     pmSysView);

  /* FORCEFULLY disconnect event handlers from the notebook widget */
  /*  I didn't find any cleaner way to do this. K.Y. 9/5/2000 */
  GTK_SIGNAL_FUNC(GTK_WIDGET_CLASS(GTK_OBJECT(pmSysView->Window->MNotebook)->klass)->key_press_event) = NULL,
  GTK_SIGNAL_FUNC(GTK_WIDGET_CLASS(GTK_OBJECT(pmSysView->Window->MNotebook)->klass)->focus_in_event) = NULL,

  /* Connect the key press event */
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->MWindow),
		     "key_press_event",
		     GTK_SIGNAL_FUNC(SHKeyPressed),
		     pmSysView);

  /* Enable the key-release and key-press events to be emitted */
  gtk_widget_add_events(pmSysView->Window->MWindow,
			GDK_KEY_RELEASE_MASK);

  /* Connect the key released event */
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->MWindow),
		     "key_release_event",
		     GTK_SIGNAL_FUNC(SHKeyReleased),
		     pmSysView);

  /* Set signals for event graph */
  EGConnectSignals(pmSysView->Window->GTEventGraph);

  /* Set process tree callbacks */
#if 0 /* This is now done in WDFillTree */
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->PTProcessTree),
		     "select_child",
		     GTK_SIGNAL_FUNC(SHPTProcessSelect),
		     pmSysView);
#endif

  /* Set event list callbacks */
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->RTCList),
		     "select_row",
		     GTK_SIGNAL_FUNC(SHRTEventSelect),
		     pmSysView);
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->RTCList),
		     "button-press-event",
		     GTK_SIGNAL_FUNC(SHRTEventButtonPress),
		     pmSysView);
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->RTVAdjust),
		     "value-changed",
		     GTK_SIGNAL_FUNC(SHRTVAdjustValueChanged),
		     pmSysView);

  /* Set DrawArea Popup menu callback */
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->GTEventGraph->DrawArea),
		     "button-press-event",
		     GTK_SIGNAL_FUNC(SHEGIconButtonPress),
		     pmSysView->Window->GTEventGraph);

  /* Add the accelerator keys */
  WDAddAccelerators(pmSysView);

#if 0 /* For coding only */
  gtk_signal_connect(GTK_OBJECT(pmSysView->Window->),
		     ,
		     GTK_SIGNAL_FUNC(),
		     pmSysView);
#endif
}

/******************************************************************
 * Function :
 *    WDShowMainWindow()
 * Description :
 *    Displays the toolkit window.
 * Parameters :
 *    pmWindow, Window to be displayed.
 * Return values :
 *    NONE.
 * History :
 * Note :
 ******************************************************************/
void WDShowMainWindow(systemView* pmSysView)
{
  mainWindow* pmWindow = pmSysView->Window; /* pointer to the main window */

  /* Show all the widgets */
  /*  Main widgets */
  gtk_widget_show(pmWindow->MVBox);
  gtk_widget_show(pmWindow->MMenu);
  gtk_widget_show(pmWindow->MNotebook);
  gtk_widget_show(pmWindow->MStatusBarBox);
  gtk_widget_show(pmWindow->MToolBar);

  /*  Main menu items */
  gtk_widget_show(pmWindow->FileMenuTitle);
#if 0
  gtk_widget_show(pmWindow->EditMenuTitle);
#endif
  gtk_widget_show(pmWindow->ToolsMenuTitle);
  gtk_widget_show(pmWindow->OptionsMenuTitle);
#if 0
  gtk_widget_show(pmWindow->TraceMenuTitle);
#endif
  gtk_widget_show(pmWindow->HelpMenuTitle);

  /*  Submenus */

  /*  File menu items */
  gtk_widget_show(pmWindow->OpenTrace);
  gtk_widget_show(pmWindow->CloseTrace);
  gtk_widget_show(pmWindow->DumpToFile);
  gtk_widget_show(pmWindow->FileMenuSeparator1);
  gtk_widget_show(pmWindow->Quit);

  /* Tools menu items */
  gtk_widget_show(pmWindow->ZoomIn);
  gtk_widget_show(pmWindow->ZoomOut);
  gtk_widget_show(pmWindow->ToolMenuSeparator1);
  gtk_widget_show(pmWindow->ShowHorizon);
  gtk_widget_show(pmWindow->ToolMenuSeparator2);
  gtk_widget_show(pmWindow->ToolGoToEvent);
  gtk_widget_show(pmWindow->ToolViewTimeFrame);

  /*  Options menu items */
  gtk_widget_show(pmWindow->Colors);
#if 0
  gtk_widget_show(pmWindow->OptMenuSeparator1);
  gtk_widget_show(pmWindow->ConfigureDaemon);
#endif

  /*  Help menu items */
  gtk_widget_show(pmWindow->Contents);
  gtk_widget_show(pmWindow->HelpMenuSeparator1);
  gtk_widget_show(pmWindow->About);

  /* Popup menus */

  /* Raw event popup and items */
  gtk_widget_show(pmWindow->RawEventPopup);
  gtk_widget_show(pmWindow->RawViewEvent);
  gtk_widget_show(pmWindow->RawGotoProcess);

  /* Event graph popup and items */
  gtk_widget_show(pmWindow->EventGraphPopup);
  gtk_widget_show(pmWindow->EventGotoProcess);
  gtk_widget_show(pmWindow->EventViewRawEvent);

  /* Note: Toolbar Buttons are created at the same time Signals are connected down
     at WDToolBarPopulate */

  /*  The Notebook thumbnails */
  gtk_widget_show(pmWindow->Graph);
  gtk_widget_show(pmWindow->Process);
  gtk_widget_show(pmWindow->RawTrace);

  /*  Graph thumbnail */
  gtk_widget_show(pmWindow->GTHBox);

  /*  Process thumbnail */
  gtk_widget_show(pmWindow->PTHPanned);
  gtk_widget_show(pmWindow->PTScrolledTree);
  gtk_widget_show(pmWindow->PTProcessTree);
  gtk_widget_show(pmWindow->PTScrolledText);
  gtk_widget_show(pmWindow->PTProcessText);

  /*  Raw event trace */
  gtk_widget_show(pmWindow->RTHBox);
  gtk_widget_show(pmWindow->RTCList);
  gtk_widget_show(pmWindow->RTVScroll);

  /*  Status bar components */
  gtk_widget_show(pmWindow->MainSBar);
  gtk_widget_show(pmWindow->BegTimeSBar);
  gtk_widget_show(pmWindow->EndTimeSBar);

  /* Set main window title if it has not been set */
  if(!pmSysView->Options->InputFileName)
    gtk_window_set_title(GTK_WINDOW(pmWindow->MWindow), "Trace Visualizer");

  /* Place the window in the middle of the screen */
  gtk_window_set_position(GTK_WINDOW(pmWindow->MWindow), GTK_WIN_POS_CENTER);

  /* Set window size */
#if 1
  gtk_widget_set_usize(GTK_WIDGET(pmWindow->MWindow), 770, 400);
#else
  gtk_widget_set_usize(GTK_WIDGET(pmWindow->MWindow), 400, 200);
#endif

  /* Main window, ALWAYS DO THIS LAST */
  gtk_widget_show(pmWindow->MWindow);

  /* Populate the toolbar and attach its signal handlers.  If you do this
     before the previous two operations, each pixmap throws an error. */
  WDToolBarPopulate(pmSysView);

  /* Event graph */
  EGShowEventGraph(pmWindow->GTEventGraph);

  /* Set main window icon */
  WDISetWindowIcon(pmWindow->MWindow);

  /* Enable menu items if an InputFile is opened */
  WDSetMenusSensitivity(pmSysView, pmSysView->Options->InputFileName != NULL);
}

/******************************************************************
 * Function :
 *    WDCreateMainWindow()
 * Description :
 *    Creates a toolkit main window.
 * Parameters :
 *    pmSysView, The system view the window will display.
 * Return values :
 *    Pointer to the newly created window.
 * History :
 * Note :
 *    Exits if there's a memory allocation problem.
 ******************************************************************/
mainWindow* WDCreateMainWindow(systemView* pmSysView)
{
  gchar*         RTCListTitles[RTCLIST_NB_COLUMNS] = {"CPU-ID",
                                                      "Event",
						      "Time",
						      "PID",
						      "Entry Length",
						      "Event Description"};
  mainWindow*    pWindow;     /* The main window to be created */

  /* Create space for the new window */
  if((pWindow = (mainWindow*) g_malloc(sizeof(mainWindow))) == NULL)
    {
    printf("Memory allocation problem \n");
    exit(1);
    }

  /* Initialize the fields that don't need extensive treatment */
  pWindow->SystemView          = pmSysView;
  pWindow->tlbOpenTrace        = NULL;
  pWindow->tlbCloseTrace       = NULL;
  pWindow->tlbDumpFile         = NULL;
  pWindow->tlbZoomIn           = NULL;
  pWindow->tlbZoomOut          = NULL;
  pWindow->tlbGotoEvent        = NULL;
  pWindow->tlbShowHorizon      = NULL;
  pWindow->tlbHideSysCalls     = NULL;
  pWindow->tlbHideIconText     = NULL;
  pWindow->tlbHideIRQs         = NULL;
  pWindow->tlbHideTraps        = NULL;
  pWindow->tlbHideSoftIRQs     = NULL;
  pWindow->tlbHideSchedChange  = NULL;
  pWindow->tlbSlowH            = NULL;
  pWindow->tlbSlowV            = NULL;
  pWindow->tlbSlowI            = NULL;
  pWindow->OpenTraceWindow     = NULL;
  pWindow->ColorSelectWindow   = NULL;
  pWindow->ViewTimeFrameWindow = NULL;
  pWindow->GotoEventWindow     = NULL;
  pWindow->DumpToFileWindow    = NULL;
  pWindow->HelpContents        = NULL;
  pWindow->AboutBox            = NULL;

  /* Allocate the main window's ressources */
  pWindow->MWindow       = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  pWindow->MVBox         = gtk_vbox_new(FALSE, 0);
  pWindow->MMenu         = gtk_menu_bar_new();
  pWindow->MToolBar      = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_ICONS);
  pWindow->MNotebook     = gtk_notebook_new();
  pWindow->MStatusBarBox = gtk_hbox_new(FALSE, 0);
  pWindow->MAccelerator  = gtk_accel_group_new();

  /* Attach accelerator group to main window */
  gtk_accel_group_attach(pWindow->MAccelerator, GTK_OBJECT(pWindow->MWindow));

  /* Pack the main window widgets */
  gtk_container_add(GTK_CONTAINER(pWindow->MWindow), pWindow->MVBox);
  gtk_box_pack_start(GTK_BOX(pWindow->MVBox), pWindow->MMenu, FALSE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(pWindow->MVBox), pWindow->MToolBar, FALSE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(pWindow->MVBox), pWindow->MNotebook, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(pWindow->MVBox), pWindow->MStatusBarBox, FALSE, TRUE, 0);

  /* Create the menu titles */
  pWindow->FileMenuTitle    = gtk_menu_item_new_with_label("File");
  pWindow->EditMenuTitle    = gtk_menu_item_new_with_label("Edit");
  pWindow->ToolsMenuTitle   = gtk_menu_item_new_with_label("Tools");
  pWindow->OptionsMenuTitle = gtk_menu_item_new_with_label("Options");
  pWindow->TraceMenuTitle   = gtk_menu_item_new_with_label("Trace");
  pWindow->HelpMenuTitle    = gtk_menu_item_new_with_label("Help");

  /* Pack the menu titles */
  gtk_menu_bar_append(GTK_MENU_BAR(pWindow->MMenu), pWindow->FileMenuTitle);
#if 0
  gtk_menu_bar_append(GTK_MENU_BAR(pWindow->MMenu), pWindow->EditMenuTitle);
#endif
  gtk_menu_bar_append(GTK_MENU_BAR(pWindow->MMenu), pWindow->ToolsMenuTitle);
  gtk_menu_bar_append(GTK_MENU_BAR(pWindow->MMenu), pWindow->OptionsMenuTitle);
  gtk_menu_bar_append(GTK_MENU_BAR(pWindow->MMenu), pWindow->TraceMenuTitle);
  gtk_menu_bar_append(GTK_MENU_BAR(pWindow->MMenu), pWindow->HelpMenuTitle);

  /* Create the submenus */
  pWindow->FileMenu    = gtk_menu_new();
  pWindow->EditMenu    = gtk_menu_new();
  pWindow->ToolsMenu   = gtk_menu_new();
  pWindow->OptionsMenu = gtk_menu_new();
  pWindow->TraceMenu   = gtk_menu_new();
  pWindow->HelpMenu    = gtk_menu_new();

  /* Set the submenus as corresponding to their titles */
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(pWindow->FileMenuTitle), pWindow->FileMenu);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(pWindow->EditMenuTitle), pWindow->EditMenu);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(pWindow->ToolsMenuTitle), pWindow->ToolsMenu);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(pWindow->OptionsMenuTitle), pWindow->OptionsMenu);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(pWindow->TraceMenuTitle), pWindow->TraceMenu);
  gtk_menu_item_set_submenu(GTK_MENU_ITEM(pWindow->HelpMenuTitle), pWindow->HelpMenu);
  
  /* Create file menu items */
  pWindow->OpenTrace  = gtk_menu_item_new_with_label("Open Trace");
  pWindow->CloseTrace = gtk_menu_item_new_with_label("Close Trace");
  pWindow->DumpToFile = gtk_menu_item_new_with_label("Dump To File");
  pWindow->FileMenuSeparator1 = gtk_menu_item_new();
  pWindow->Quit       = gtk_menu_item_new_with_label("Exit");

  /* Fill the file menu */
  gtk_menu_append(GTK_MENU(pWindow->FileMenu), pWindow->OpenTrace);
  gtk_menu_append(GTK_MENU(pWindow->FileMenu), pWindow->CloseTrace);
  gtk_menu_append(GTK_MENU(pWindow->FileMenu), pWindow->DumpToFile);
  gtk_menu_append(GTK_MENU(pWindow->FileMenu), pWindow->FileMenuSeparator1);
  gtk_menu_append(GTK_MENU(pWindow->FileMenu), pWindow->Quit);

  /* Create the tools menu items */
  pWindow->ZoomIn             = gtk_menu_item_new_with_label("Zoom In");
  pWindow->ZoomOut            = gtk_menu_item_new_with_label("Zoom Out");
  pWindow->ToolMenuSeparator1 = gtk_menu_item_new();
  pWindow->ShowHorizon        = gtk_check_menu_item_new_with_label("Show Horizon");
  gtk_check_menu_item_set_show_toggle(GTK_CHECK_MENU_ITEM(pWindow->ShowHorizon),TRUE);
  pWindow->ToolMenuSeparator2 = gtk_menu_item_new();
  pWindow->ToolGoToEvent      = gtk_menu_item_new_with_label("Go to event...");
  pWindow->ToolViewTimeFrame  = gtk_menu_item_new_with_label("View Time Frame");

  /* Fill the tools menu */
  gtk_menu_append(GTK_MENU(pWindow->ToolsMenu), pWindow->ZoomIn);
  gtk_menu_append(GTK_MENU(pWindow->ToolsMenu), pWindow->ZoomOut);
  gtk_menu_append(GTK_MENU(pWindow->ToolsMenu), pWindow->ToolMenuSeparator1);
  gtk_menu_append(GTK_MENU(pWindow->ToolsMenu), pWindow->ShowHorizon);
  gtk_menu_append(GTK_MENU(pWindow->ToolsMenu), pWindow->ToolMenuSeparator2);
  gtk_menu_append(GTK_MENU(pWindow->ToolsMenu), pWindow->ToolGoToEvent);
  gtk_menu_append(GTK_MENU(pWindow->ToolsMenu), pWindow->ToolViewTimeFrame);

  /* Create options menu items */
  pWindow->Colors            = gtk_menu_item_new_with_label("Colors");
  pWindow->OptMenuSeparator1 = gtk_menu_item_new();
  pWindow->ConfigureDaemon   = gtk_menu_item_new_with_label("Configure Trace Daemon");

  /* Fill the options menu */
  gtk_menu_append(GTK_MENU(pWindow->OptionsMenu), pWindow->Colors);
  gtk_menu_append(GTK_MENU(pWindow->OptionsMenu), pWindow->OptMenuSeparator1);
  gtk_menu_append(GTK_MENU(pWindow->OptionsMenu), pWindow->ConfigureDaemon);

  /* Create help menu items */
  pWindow->Contents = gtk_menu_item_new_with_label("Contents");
  pWindow->HelpMenuSeparator1 = gtk_menu_item_new();
  pWindow->About    = gtk_menu_item_new_with_label("About");

  /* Fill the help menu */
  gtk_menu_append(GTK_MENU(pWindow->HelpMenu), pWindow->Contents);
  gtk_menu_append(GTK_MENU(pWindow->HelpMenu), pWindow->HelpMenuSeparator1);
  gtk_menu_append(GTK_MENU(pWindow->HelpMenu), pWindow->About);

  /* Create the Popup menus */

  /* Create and fill the Raw Event popup */
  pWindow->RawEventPopup = gtk_menu_new();
  pWindow->RawViewEvent  = gtk_menu_item_new_with_label("View event in graph");
  gtk_menu_append(GTK_MENU(pWindow->RawEventPopup), pWindow->RawViewEvent);
  pWindow->RawGotoProcess   = gtk_menu_item_new_with_label("Go to process analysis");
  gtk_menu_append(GTK_MENU(pWindow->RawEventPopup), pWindow->RawGotoProcess);

  /* Create and fill the Event graph popup */
  pWindow->EventGraphPopup   = gtk_menu_new();
  pWindow->EventViewRawEvent = gtk_menu_item_new_with_label("View raw event data");
  gtk_menu_append(GTK_MENU(pWindow->EventGraphPopup), pWindow->EventViewRawEvent);
  pWindow->EventGotoProcess  = gtk_menu_item_new_with_label("Go to process analysis");
  gtk_menu_append(GTK_MENU(pWindow->EventGraphPopup), pWindow->EventGotoProcess);

  /* Create thumbnail labels */
  pWindow->Graph    = gtk_label_new("Event Graph");
  pWindow->Process  = gtk_label_new("Process analysis");
  pWindow->RawTrace = gtk_label_new("Raw Trace");

  /* Create thumbnails' main content */
  pWindow->GTHBox     = gtk_hbox_new(FALSE, 0);
  pWindow->PTHPanned  = gtk_hpaned_new();
  pWindow->RTHBox     = gtk_hbox_new(FALSE, 0);
  gtk_container_set_border_width(GTK_CONTAINER(pWindow->PTHPanned), 5);
  gtk_container_set_border_width(GTK_CONTAINER(pWindow->RTHBox), 5);

  /* Create the notebook's pages */
  gtk_notebook_append_page(GTK_NOTEBOOK(pWindow->MNotebook), pWindow->GTHBox, pWindow->Graph);
  gtk_notebook_append_page(GTK_NOTEBOOK(pWindow->MNotebook), pWindow->PTHPanned, pWindow->Process);
  gtk_notebook_append_page(GTK_NOTEBOOK(pWindow->MNotebook), pWindow->RTHBox, pWindow->RawTrace);

  /* Create the event graph to be placed in the graph hbox */
  pWindow->GTEventGraph = EGCreateEventGraph(pWindow);

  /* Create window containing scrollable process tree */
  pWindow->PTProcessTree  = gtk_tree_new();
  pWindow->PTScrolledTree = gtk_scrolled_window_new(NULL, NULL);
  gtk_tree_set_selection_mode(GTK_TREE(pWindow->PTProcessTree), GTK_SELECTION_SINGLE);
  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(pWindow->PTScrolledTree),
				 GTK_POLICY_AUTOMATIC,
				 GTK_POLICY_AUTOMATIC);
  gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(pWindow->PTScrolledTree),
					pWindow->PTProcessTree);
  gtk_paned_add1(GTK_PANED(pWindow->PTHPanned), pWindow->PTScrolledTree);
  gtk_widget_set_usize(GTK_WIDGET(pWindow->PTScrolledTree), 175, 0);

  /* Create process text space */
  pWindow->PTScrolledText = gtk_scrolled_window_new(NULL, NULL);
  pWindow->PTProcessText  = gtk_text_new(NULL, NULL);
#if 0 /* This should be configurable through a font menu ... */
  pWindow->PTTextFont     = gdk_font_load("-*-courier-medium-r-*-*-12-*-*-*-m-*-*-*");
#else
  pWindow->PTTextFont     = gdk_font_load("-misc-fixed-medium-r-normal--10-100-75-75-c-60-iso8859-1");
#if 0
  pWindow->PTTextFont     = gdk_font_load("-misc-fixed-bold-r-normal--12-120-75-75-c-80-iso8859-1");
#endif
#endif
  gtk_text_set_editable(GTK_TEXT(pWindow->PTProcessText), FALSE);
  gtk_container_add(GTK_CONTAINER(pWindow->PTScrolledText),
		    pWindow->PTProcessText);
  gtk_paned_add2(GTK_PANED(pWindow->PTHPanned), pWindow->PTScrolledText);

  /* Create raw trace list and pack it */
  pWindow->RTCList  = gtk_clist_new_with_titles(RTCLIST_NB_COLUMNS, RTCListTitles);
  gtk_clist_set_selection_mode(GTK_CLIST(pWindow->RTCList), GTK_SELECTION_SINGLE);
  gtk_box_pack_start(GTK_BOX(pWindow->RTHBox), pWindow->RTCList, TRUE, TRUE, 0);

  /* Create vertical scrollbar and pack it */
  pWindow->RTVScroll  = gtk_vscrollbar_new(NULL);
  gtk_box_pack_start(GTK_BOX(pWindow->RTHBox), pWindow->RTVScroll, FALSE, TRUE, 0);

  /* Get the vertical scrollbar's adjustment */
  pWindow->RTVAdjust = gtk_range_get_adjustment(GTK_RANGE(pWindow->RTVScroll));

  /* Configure the columns of the list */
  gtk_clist_set_column_justification(GTK_CLIST(pWindow->RTCList), 0, GTK_JUSTIFY_LEFT);
  gtk_clist_set_column_justification(GTK_CLIST(pWindow->RTCList), 1, GTK_JUSTIFY_LEFT);
  gtk_clist_set_column_justification(GTK_CLIST(pWindow->RTCList), 2, GTK_JUSTIFY_RIGHT);
  gtk_clist_set_column_justification(GTK_CLIST(pWindow->RTCList), 3, GTK_JUSTIFY_RIGHT);
  gtk_clist_set_column_justification(GTK_CLIST(pWindow->RTCList), 4, GTK_JUSTIFY_RIGHT);
  gtk_clist_set_column_justification(GTK_CLIST(pWindow->RTCList), 5, GTK_JUSTIFY_LEFT);
  gtk_clist_set_column_width(GTK_CLIST(pWindow->RTCList), 0, 45);
  gtk_clist_set_column_width(GTK_CLIST(pWindow->RTCList), 1, 120);
  gtk_clist_set_column_width(GTK_CLIST(pWindow->RTCList), 2, 120);
  gtk_clist_set_column_width(GTK_CLIST(pWindow->RTCList), 3, 45);
  gtk_clist_set_column_width(GTK_CLIST(pWindow->RTCList), 4, 60);

  /* Allocate the status bar components */
  pWindow->MainSBar    = gtk_statusbar_new();
  pWindow->BegTimeSBar = gtk_statusbar_new();
  pWindow->EndTimeSBar = gtk_statusbar_new();

  /* Set the size of the status bar components */
  gtk_widget_set_usize(GTK_WIDGET(pWindow->BegTimeSBar), 160, 0);
  gtk_widget_set_usize(GTK_WIDGET(pWindow->EndTimeSBar), 160, 0);

  /* Get the status bar contexts */
  pWindow->MainSBarContextID =
    gtk_statusbar_get_context_id(GTK_STATUSBAR(pWindow->MainSBar),
				 "Main Status Bar");
  pWindow->BegTimeSBarContextID =
    gtk_statusbar_get_context_id(GTK_STATUSBAR(pWindow->MainSBar),
				 "Begining time Status Bar");
  pWindow->EndTimeSBarContextID =
    gtk_statusbar_get_context_id(GTK_STATUSBAR(pWindow->MainSBar),
				 "End time Status Bar");

  /* Pack the status bars into the status bar hbox */
  gtk_box_pack_start(GTK_BOX(pWindow->MStatusBarBox), pWindow->MainSBar, TRUE, TRUE, 0);
  gtk_box_pack_start(GTK_BOX(pWindow->MStatusBarBox), pWindow->BegTimeSBar, FALSE, TRUE, 5);
  gtk_box_pack_start(GTK_BOX(pWindow->MStatusBarBox), pWindow->EndTimeSBar, FALSE, TRUE, 0);

  /* No events have been selected */
  pWindow->EventSelected = FALSE;

  /* Give the caller the newly created window */
  return pWindow;
}

/******************************************************************
 * Function :
 *    WDDestroySystemView()
 * Description :
 *    Destroys a toolkit main window.
 * Parameters :
 *    pmSysView, pointer to the systemview to be destroyed
 * Return values :
 *    NONE
 * History :
 * Note :
 *    Event structures must be freed first. see WDIFreeTraceStructures().
 ******************************************************************/
void WDDestroySystemView(systemView* pmSystemView)
{
  systemView* Navigator; /* Temporary System View pointer */

  /* free the system elements */
  WDIFreeTraceStructures(pmSystemView);
  if(pmSystemView->Window)
    {
    /* Free the Event Graph structures */
    EGDestroyEventGraph(&pmSystemView->Window->GTEventGraph);

    /* Free the window itself */
    g_free(pmSystemView->Window);
    }

  /* Dequeue this system view from the main system view list */

  /* Is this SystemView the first one in the list? */
  if(sMainSystemViewList == pmSystemView) 
    /* Update the main list pointer */
    sMainSystemViewList = pmSystemView->Next;
  else
    {
    /* Find the previous item in the list */
    for(Navigator = sMainSystemViewList; Navigator->Next != pmSystemView; Navigator = Navigator->Next);

    /* Update the list pointer */
    Navigator->Next = pmSystemView->Next;
    }

  /* Free that SystemView */
  g_free(pmSystemView);
}

/******************************************************************
 * Function :
 *    WDFillTree()
 * Description :
 *    Fills a GTK tree with the content of the tree of processes in
 *    the system.
 * Parameters :
 *    pmGTKTree,
 *    pmTree, 
 * Return values :
 *    NONE.
 * History :
 *    K.Y., 17/06/99, Initial typing.
 * Note :
 ******************************************************************/
void WDFillTree(GtkWidget* pmGTKTree, process* pmTree)
{
  char       lLabel[256]; /* Maximum length of label*/
  process*   pProc;       /* Generic process pointer */
  GtkWidget* pTreeItem;   /* An item in the process tree */
  GtkWidget* pSubTree;    /* Subtree for children */

  /* For all the children of the same level */
  for(pProc = pmTree; pProc != NULL; pProc = pProc->NextChild)
    {
    /* Does this process have a name */
    if(pProc->Command != NULL)
      sprintf(lLabel, "%s (%d)", pProc->Command, pProc->PID);
    else if(pProc->PID == 0)
      sprintf(lLabel, "The All Mighty (0)");
    else
      sprintf(lLabel, "%d", pProc->PID);

    /* Create a new tree item */
    pTreeItem = gtk_tree_item_new_with_label(lLabel);
 
    /* Store Process pointer in the row data */
    gtk_object_set_data(GTK_OBJECT(pTreeItem),
			TREE_ITEM_DATA_PROC,
			(gpointer) pProc);

    /* Connect a signal to this item */
    gtk_signal_connect(GTK_OBJECT(pTreeItem),
		       "select",
		       GTK_SIGNAL_FUNC(SHPTProcessSelect),
		       pProc);

    /* Append this to the tree */
    gtk_tree_prepend (GTK_TREE(pmGTKTree), pTreeItem);

    /* Show it to the public */
    gtk_widget_show(pTreeItem);

    /* Does this process have any children */
    if(pProc->Children != NULL)
      {
      /* Create a subtree */
      pSubTree = gtk_tree_new();
      gtk_tree_set_selection_mode (GTK_TREE(pSubTree), GTK_SELECTION_SINGLE);
      gtk_tree_set_view_mode (GTK_TREE(pSubTree), GTK_TREE_VIEW_ITEM);
      gtk_tree_item_set_subtree (GTK_TREE_ITEM(pTreeItem), pSubTree);

      /* Fill the subtree */
      WDFillTree(pSubTree, pProc->Children);
      }
    }  
}

/******************************************************************
 * Function :
 *    WDFillRTAITaskTree()
 * Description :
 *    Fills a GTK tree with the content of the tree of tasks in
 *    the RTAI system.
 * Parameters :
 *    pmGTKTree, The GTK tree where tasks are to be inserted.
 *    pmTree, The task tree to be used to fill the GTK tree.
 * Return values :
 *    NONE.
 * History :
 *    K.Y., 14/06/2000, This is largely inspired by WDFillTree.
 * Note :
 ******************************************************************/
#if SUPP_RTAI
void WDFillRTAITaskTree(GtkWidget* pmGTKTree, RTAItask* pmTree)
{
  char       lLabel[256]; /* Maximum length of label*/
  RTAItask*  pTask;       /* Generic task pointer */
  GtkWidget* pTreeItem;   /* An item in the task tree */
  GtkWidget* pSubTree;    /* Subtree for children */

  /* For all the children of the same level */
  for(pTask = pmTree; pTask != NULL; pTask = pTask->NextChild)
    {
    /* Print the task ID */
    if(pTask->TID != 0)
      sprintf(lLabel, "%d", pTask->TID);
    else
      sprintf(lLabel, "RTAI Subsystem");

    /* Create a new tree item */
    pTreeItem = gtk_tree_item_new_with_label(lLabel);
 
    /* Store task pointer in the raw data */
    gtk_object_set_data(GTK_OBJECT(pTreeItem),
			TREE_ITEM_DATA_RTAI_TASK,
			(gpointer) pTask);

    /* Connect a signal to this item */
    gtk_signal_connect(GTK_OBJECT(pTreeItem),
		       "select",
		       GTK_SIGNAL_FUNC(SHPTRTAITaskSelect),
		       pTask);

    /* Append this to the tree */
    gtk_tree_prepend (GTK_TREE(pmGTKTree), pTreeItem);

    /* Show it to the public */
    gtk_widget_show(pTreeItem);

    /* Does this task have any children */
    if(pTask->Children != NULL)
      {
      /* Create a subtree */
      pSubTree = gtk_tree_new();
      gtk_tree_set_selection_mode (GTK_TREE(pSubTree), GTK_SELECTION_SINGLE);
      gtk_tree_set_view_mode (GTK_TREE(pSubTree), GTK_TREE_VIEW_ITEM);
      gtk_tree_item_set_subtree (GTK_TREE_ITEM(pTreeItem), pSubTree);

      /* Fill the subtree */
      WDFillRTAITaskTree(pSubTree, pTask->Children);
      }
    }  
}
#endif /* SUPP_RTAI */

/******************************************************************
 * Function :
 *    WDFillEventList()
 * Description :
 *    Fills the window's event list using the trace database.
 * Parameters :
 *    pmList, The list to be filled.
 *    pmTraceDB, The database of events.
 *    pmSystem, The system to which this list belongs.
 *    pmEvent, Event from which we start drawing.
 *    pmSelectedEvent, Event selected if any.
 * Return values :
 *    NONE.
 * History :
 *    K.Y., 18/06/99, Initial typing.
 * Note :
 ******************************************************************/
void WDFillEventList(GtkWidget*  pmList,
		     db*         pmTraceDB,
		     systemInfo* pmSystem,
		     event*      pmEvent,
		     event*      pmSelectedEvent)
{
  gint                i = 0;                              /* Generic index */
  event               lEvent;                             /* Generic event */
  gchar               lTimeStr[TIME_STR_LEN];             /* Time of event */
  static gchar*       lString[RTCLIST_NB_COLUMNS]={'\0'}; /* Strings describing event */
  process*            pProcess;                           /* Generic process pointer */
#if SUPP_RTAI
  RTAItask*           pTask = NULL;                       /* Generic task pointer */
#endif /* SUPP_RTAI */
  eventDescription    lEventDesc;                         /* Description of event */

  /* Did we allocate space for strings */
  if(lString[0] == NULL)
    /* Allocate space for strings */
    for (i = 0;  i < RTCLIST_NB_COLUMNS - 1; i++)
      lString[i] = (char*) g_malloc(80);

  /* Allocate space for description string */
  lString[RTCLIST_NB_COLUMNS - 1] = (char*) g_malloc(256);

  /* If no event was supplied, start at the beginning */
  if(pmEvent == NULL)
    lEvent = pmTraceDB->FirstEvent;
  else
    lEvent = *pmEvent;

  /* Freeze and clear clist */
  gtk_clist_freeze(GTK_CLIST(pmList));
  gtk_clist_clear(GTK_CLIST(pmList));

  /* Reset index */
  i = 0;

  /* Go through the event list */
  do
    {
    /* Get the event description */
    DBEventDescription(pmTraceDB, &lEvent, TRUE, &lEventDesc);

    /* Get the event's process */
    pProcess = DBEventProcess(pmTraceDB, &lEvent, pmSystem, FALSE);

#if SUPP_RTAI
    /* Does this trace contain RTAI information */
    if(pmTraceDB->SystemType == TRACE_SYS_TYPE_RTAI_LINUX)
      /* Get the RTAI task to which this event belongs */
      pTask = RTAIDBEventTask(pmTraceDB, &lEvent, pmSystem, FALSE);
#endif /* SUPP_RTAI */

    /* Set the event's entry in the list of raw events displayed */
    sRawEventsDisplayed[i] = lEvent;

    /* Add text describing the event */
    /*  The CPU ID */
    if(pmTraceDB->LogCPUID == TRUE)
      sprintf(lString[0], "%d", lEventDesc.CPUID);
    else
      sprintf(lString[0], "0");

    /*  The event ID */
    sprintf(lString[1], "%s", pmTraceDB->EventString(pmTraceDB, lEventDesc.ID, &lEvent));

    /*  The event's time of occurence */
    DBFormatTimeInReadableString(lTimeStr,
				 lEventDesc.Time.tv_sec,
				 lEventDesc.Time.tv_usec);    
    sprintf(lString[2], "%s", lTimeStr);

    /* Is this an RT event */
    if(lEventDesc.ID <= TRACE_MAX)
      {
      /*  The PID of the process to which the event belongs */
      if(pProcess != NULL)
	sprintf(lString[3], "%d", pProcess->PID);
      else
	sprintf(lString[3], "N/A");
      }
#if SUPP_RTAI
    else
      {
      /*  The TID of the task to which the event belongs */
      if(pTask != NULL)
	sprintf(lString[3], "RT:%d", pTask->TID);
      else
	sprintf(lString[3], "RT:N/A");
      }
#endif /* SUPP_RTAI */

    /*  The size of the entry */
    sprintf(lString[4], "%d", lEventDesc.Size);

    /*  The string describing the event */
    sprintf(lString[5], "%s", lEventDesc.String);

    /* Insert the entry into the list */
    gtk_clist_append(GTK_CLIST(pmList), lString);

    /* Set the row's data to point to the current event */
    WDI_gtk_clist_set_last_row_data_full(GTK_CLIST(pmList), (gpointer) &(sRawEventsDisplayed[i]), NULL);

    /* Was this the last selected event */
    if(DBEventsEqual(lEvent, (*pmSelectedEvent)))
      gtk_clist_select_row(GTK_CLIST(pmList), i, 0);

    /* Go to next row */
    i++;
    } while((DBEventNext(pmTraceDB, &lEvent) == TRUE) && (i < RTCLIST_NB_ROWS));

  /* Resize the list's length */
  gtk_widget_queue_resize(pmList);

  /* Thaw the clist */
  gtk_clist_thaw(GTK_CLIST(pmList));
}

/******************************************************************
 * Function :
 *    WDDisplayTrace()
 * Description :
 *    Displays a trace in a given window.
 * Parameters :
 *    pmSysView, System view for which trace is to be displayed
 * Return values :
 *    NONE.
 * History :
 *    K.Y., 17/06/99, Initial typing.
 * Note :
 ******************************************************************/
void WDDisplayTrace(systemView* pmSysView)
{
  gchar         lString[256];    /* Temporary string to build window title */

  /* Display the event graph */
  EGDisplayEventTrace(pmSysView->Window->GTEventGraph,
		      pmSysView->System,
		      pmSysView->EventDB);

  /* Fill the process tree */
  WDFillTree(pmSysView->Window->PTProcessTree,
	     pmSysView->System->ProcTree);

#if SUPP_RTAI
  /* Does this trace contain RTAI information */
  if(pmSysView->EventDB->SystemType == TRACE_SYS_TYPE_RTAI_LINUX)
    WDFillRTAITaskTree(pmSysView->Window->PTProcessTree,
		       RTAI_SYSTEM(pmSysView->System->SystemSpec)->TaskTree);
#endif /* SUPP_RTAI */

  /* Fix a mysterious GTK+ bug... */
  if(!GTK_TREE(pmSysView->Window->PTProcessTree)->root_tree)
    GTK_TREE(pmSysView->Window->PTProcessTree)->root_tree = GTK_TREE(pmSysView->Window->PTProcessTree);

  /* Set the CList's extents */
  pmSysView->Window->RTVAdjust->lower          = 0;
  pmSysView->Window->RTVAdjust->upper          = (gfloat) pmSysView->EventDB->Nb;
  pmSysView->Window->RTVAdjust->step_increment = 1;
  pmSysView->Window->RTVAdjust->page_increment = RTCLIST_NB_COLUMNS;
  pmSysView->Window->RTVAdjust->page_size      = RTCLIST_NB_COLUMNS;
  gtk_adjustment_changed(GTK_ADJUSTMENT(pmSysView->Window->RTVAdjust));
  gtk_adjustment_set_value(GTK_ADJUSTMENT(pmSysView->Window->RTVAdjust), 0);

  /* Enable items requiring an event DB to be functionnal */
  WDSetMenusSensitivity(pmSysView, TRUE);

  /* Fail-safe method for building main window title */
  if(pmSysView->Options->InputFileName)
    sprintf(lString, "Trace Visualizer - %s", pmSysView->Options->InputFileName);
  else
    sprintf(lString, "Trace Visualizer");

  /* Set main window title */
  gtk_window_set_title(GTK_WINDOW(pmSysView->Window->MWindow), lString);
}

/******************************************************************
 * Function :
 *    WDCreateSystemView()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
systemView* WDCreateSystemView(systemInfo* pmSystem, db* pmTraceDB, options* pmOptions)
{
  systemView*  pSystemView;   /* The system to be displayed */

  /* Create a new system view */
  pSystemView = (systemView*) g_malloc(sizeof(systemView));

  /* Set the system elements */
  pSystemView->EventDB = pmTraceDB;
  pSystemView->System  = pmSystem;
  pSystemView->Options = pmOptions;
  pSystemView->Window  = WDCreateMainWindow(pSystemView);

  /* Enqueue this system view to the main system view list */
  pSystemView->Next   = sMainSystemViewList;
  sMainSystemViewList = pSystemView;

  /* Connect the signal handlers to this system view */
  WDConnectSignals(pSystemView);

  /* Give the completed system view to the caller */
  return pSystemView;
}

/******************************************************************
 * Function :
 *    WDStatusBarDisplay()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void WDStatusBarDisplay(gpointer pmMainWindow, gchar* pmString)
{
  mainWindow*   pMainWindow = (mainWindow*) pmMainWindow;  /* Main window pointer */

  /* Pop the last message off the status bar */
  gtk_statusbar_pop(GTK_STATUSBAR(pMainWindow->MainSBar),
		     pMainWindow->MainSBarContextID);		    

  /* Push the message down to the status bar */
  gtk_statusbar_push(GTK_STATUSBAR(pMainWindow->MainSBar),
		     pMainWindow->MainSBarContextID,
		     pmString);
}

/******************************************************************
 * Function :
 *    WDTimeSBarDisplay()
 * Description :
 * Parameters :
 * Return values :
 * History :
 * Note :
 ******************************************************************/
void WDTimeSBarDisplay(gpointer pmMainWindow, gdouble pmStartTime, gdouble pmEndTime)
{
  char          lTimeString[TIME_STR_LEN];                 /* Time string */
  char          lSBarString[TIME_STR_LEN + 10];            /* Status bar string */
  mainWindow*   pMainWindow = (mainWindow*) pmMainWindow;  /* Main window pointer */

  /* Pop the last message off the main status bar */
  /*  This makes "visual sense" when used */
  gtk_statusbar_pop(GTK_STATUSBAR(pMainWindow->MainSBar),
		     pMainWindow->MainSBarContextID);		    

  /* Pop the last message off the status bars */
  gtk_statusbar_pop(GTK_STATUSBAR(pMainWindow->BegTimeSBar),
		     pMainWindow->BegTimeSBarContextID);
  gtk_statusbar_pop(GTK_STATUSBAR(pMainWindow->EndTimeSBar),
		     pMainWindow->EndTimeSBarContextID);

  /* Push the message down the status bars */
  WDIFormatTimeInReadableString(lTimeString, pmStartTime);
  sprintf(lSBarString, " Start: %s", lTimeString);
  gtk_statusbar_push(GTK_STATUSBAR(pMainWindow->BegTimeSBar),
		     pMainWindow->BegTimeSBarContextID,
		     lSBarString);
#if 0 /* Display the time of the end of the period drawn */
  WDIFormatTimeInReadableString(lTimeString, pmEndTime);
  sprintf(lSBarString, " End: %s", lTimeString);
#else /* Display the span of time displayed */
  WDIFormatTimeInReadableString(lTimeString, pMainWindow->GTEventGraph->Interval);
  sprintf(lSBarString, " Span: %s", lTimeString);
#endif
  gtk_statusbar_push(GTK_STATUSBAR(pMainWindow->EndTimeSBar),
		     pMainWindow->EndTimeSBarContextID,
		     lSBarString);
}

/******************************************************************
 * Function :
 *    WDSetMenusSensitivity()
 * Description : Sets the sensitivity of all relevant menu items
 * Parameters : 
 *    pmSysView, System view describing the current window
 *    pmSensitivityValue, 
 * Return values :
 *    NONE
 * History :
 *    JH.D., 13/09/99, First draft
 * Note :
 ******************************************************************/
void WDSetMenusSensitivity(systemView* pmSysView, gboolean pmSensitivityValue)
{
  /* File menu items */
  /* Close current trace trace */
  gtk_widget_set_sensitive(pmSysView->Window->CloseTrace, pmSensitivityValue);
  /* Dump trace to file */
  gtk_widget_set_sensitive(pmSysView->Window->DumpToFile, pmSensitivityValue);

  /* Edit menu items */

  /* Tools menu items */
  /* Zoom in */
  gtk_widget_set_sensitive(pmSysView->Window->ZoomIn, pmSensitivityValue);
  /* Zoom out */
  gtk_widget_set_sensitive(pmSysView->Window->ZoomOut, pmSensitivityValue);
  /* Show horizon */
  gtk_widget_set_sensitive(pmSysView->Window->ShowHorizon, pmSensitivityValue);
  /* View time frame */
  gtk_widget_set_sensitive(pmSysView->Window->ToolGoToEvent, pmSensitivityValue);
  /* View time frame */
  gtk_widget_set_sensitive(pmSysView->Window->ToolViewTimeFrame, pmSensitivityValue);

  /* Options menu items */
  /* Display colors */
  gtk_widget_set_sensitive(pmSysView->Window->Colors, pmSensitivityValue);

  /* Toolbar items, if they are created */
  /* Close trace */
  if(pmSysView->Window->tlbCloseTrace)
    gtk_widget_set_sensitive(pmSysView->Window->tlbCloseTrace, pmSensitivityValue);

  /* Dump to file */
  if(pmSysView->Window->tlbDumpFile)
    gtk_widget_set_sensitive(pmSysView->Window->tlbDumpFile, pmSensitivityValue);

  /* Zoom in */
  if(pmSysView->Window->tlbZoomIn)
    gtk_widget_set_sensitive(pmSysView->Window->tlbZoomIn, pmSensitivityValue);

  /* Zoom out */
  if(pmSysView->Window->tlbZoomOut)
    gtk_widget_set_sensitive(pmSysView->Window->tlbZoomOut, pmSensitivityValue);

  /* Go to event */
  if(pmSysView->Window->tlbGotoEvent)
    gtk_widget_set_sensitive(pmSysView->Window->tlbGotoEvent, pmSensitivityValue);

  /* Show Horizon */
  if(pmSysView->Window->tlbShowHorizon)
    gtk_widget_set_sensitive(pmSysView->Window->tlbShowHorizon, pmSensitivityValue);

  /* Hide icon text */
  if(pmSysView->Window->tlbHideIconText)
    gtk_widget_set_sensitive(pmSysView->Window->tlbHideIconText, pmSensitivityValue);

  /* Hide system call details */
  if(pmSysView->Window->tlbHideSysCalls)
    gtk_widget_set_sensitive(pmSysView->Window->tlbHideSysCalls, pmSensitivityValue);

  /* Hide IRQs */
  if(pmSysView->Window->tlbHideIRQs)
    gtk_widget_set_sensitive(pmSysView->Window->tlbHideIRQs, pmSensitivityValue);

  /* Hide traps */
  if(pmSysView->Window->tlbHideTraps)
    gtk_widget_set_sensitive(pmSysView->Window->tlbHideTraps, pmSensitivityValue);

  /* Hide soft IRQs */
  if(pmSysView->Window->tlbHideSoftIRQs)
    gtk_widget_set_sensitive(pmSysView->Window->tlbHideSoftIRQs, pmSensitivityValue);

  /* Hide scheduling changes */
  if(pmSysView->Window->tlbHideSchedChange)
    gtk_widget_set_sensitive(pmSysView->Window->tlbHideSchedChange, pmSensitivityValue);

  /* Hide kernel timer */
  if(pmSysView->Window->tlbHideKernelTimer)
    gtk_widget_set_sensitive(pmSysView->Window->tlbHideKernelTimer, pmSensitivityValue);

  /* Draw horizontal lines slow */
  if(pmSysView->Window->tlbSlowH)
    gtk_widget_set_sensitive(pmSysView->Window->tlbSlowH, pmSensitivityValue);

  /* Draw vertical lines slow */
  if(pmSysView->Window->tlbSlowV)
    gtk_widget_set_sensitive(pmSysView->Window->tlbSlowV, pmSensitivityValue);

  /* Draw icons slow */
  if(pmSysView->Window->tlbSlowI)
    gtk_widget_set_sensitive(pmSysView->Window->tlbSlowI, pmSensitivityValue);
}

/******************************************************************
 * Function :
 *    WDToolBarPopulate()
 * Description : Inserts all required buttons in the toolbar
 * Parameters : 
 *    pmSysView, System view describing the current window
 * Return values :
 *    NONE
 * History :
 *    JH.D., 07/08/99, First draft
 * Note :
 *    This function creates the buttons that will appear in the toolbar
 *    and attaches the same signals as their menu counterparts
 *    New "hide icon" toggles also share a single callback.  This
 *    function is called exactly once.
 ******************************************************************/
void WDToolBarPopulate(systemView* pmSysView)
{
  /* Insert the Toolbar Buttons and connect Signals*/
  /*  Open a trace */
  pmSysView->Window->tlbOpenTrace =
    gtk_toolbar_append_element(GTK_TOOLBAR (pmSysView->Window->MToolBar), 
			       GTK_TOOLBAR_CHILD_BUTTON, NULL,
			       "Open", "Open a new trace", NULL,
			       CreateWidgetFromXpm(pmSysView->Window->MWindow, 
						   (char **) xpm_open),
			       GTK_SIGNAL_FUNC(SHOpenTrace), pmSysView);       

  /*  Close the trace */
  pmSysView->Window->tlbCloseTrace =
    gtk_toolbar_append_element(GTK_TOOLBAR (pmSysView->Window->MToolBar), 
			       GTK_TOOLBAR_CHILD_BUTTON, NULL,
			       "Close", "Close this trace", NULL,
			       CreateWidgetFromXpm(pmSysView->Window->MWindow, 
						   (char **) xpm_close),
			       GTK_SIGNAL_FUNC(SHCloseTrace), pmSysView);

  /*  Insert a separator */
  gtk_toolbar_append_space(GTK_TOOLBAR (pmSysView->Window->MToolBar));         

  /*  Dump to file */
  pmSysView->Window->tlbDumpFile =
    gtk_toolbar_append_element(GTK_TOOLBAR (pmSysView->Window->MToolBar), 
			       GTK_TOOLBAR_CHILD_BUTTON, NULL,
			       "Dump", "Dump to file", NULL,
			       CreateWidgetFromXpm(pmSysView->Window->MWindow, 
						   (char **) xpm_dump),
			       GTK_SIGNAL_FUNC(SHDumpToFile), pmSysView);

  /*  Insert a separator */
  gtk_toolbar_append_space(GTK_TOOLBAR (pmSysView->Window->MToolBar));         

  /*  Zoom in */
  pmSysView->Window->tlbZoomIn =
    gtk_toolbar_append_element(GTK_TOOLBAR (pmSysView->Window->MToolBar), 
			       GTK_TOOLBAR_CHILD_BUTTON, NULL,
			       "Zoom in", "Zoom in on graph", NULL,
			       CreateWidgetFromXpm(pmSysView->Window->MWindow,
						   (char **) xpm_zoom_in),
			       GTK_SIGNAL_FUNC(SHZoomIn), pmSysView);          

  /*  Zoom out */
  pmSysView->Window->tlbZoomOut =
    gtk_toolbar_append_element(GTK_TOOLBAR (pmSysView->Window->MToolBar), 
			       GTK_TOOLBAR_CHILD_BUTTON, NULL,
			       "Zoom out", "Zoom out from graph", NULL,
			       CreateWidgetFromXpm(pmSysView->Window->MWindow,
						   (char **) xpm_zoom_out),
			       GTK_SIGNAL_FUNC(SHZoomOut), pmSysView);         
 
  /*  Insert a separator*/
  gtk_toolbar_append_space(GTK_TOOLBAR (pmSysView->Window->MToolBar));

  /*  Go to event */
  pmSysView->Window->tlbGotoEvent =
    gtk_toolbar_append_element(GTK_TOOLBAR (pmSysView->Window->MToolBar), 
			       GTK_TOOLBAR_CHILD_BUTTON, NULL,
			       "Go to Event", "Find event in event list", NULL,
			       CreateWidgetFromXpm(pmSysView->Window->MWindow,
						   (char **) xpm_find),
			       GTK_SIGNAL_FUNC(SHGotoEvent), pmSysView);

  /*  Insert a separator*/
  gtk_toolbar_append_space(GTK_TOOLBAR (pmSysView->Window->MToolBar));         

  /*  Show horizon */
  pmSysView->Window->tlbShowHorizon =
    gtk_toolbar_append_element(GTK_TOOLBAR (pmSysView->Window->MToolBar), 
			       GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
			       "Horizon", "Toggle Horizon", NULL,
			       CreateWidgetFromXpm(pmSysView->Window->MWindow,
						   (char **) xpm_horizon),
			       GTK_SIGNAL_FUNC(SHShowHorizon), pmSysView);     

  /*  Insert a separator*/
  gtk_toolbar_append_space(GTK_TOOLBAR (pmSysView->Window->MToolBar));         

  /* "Hide icon" toggle buttons.  The callback just performs a redraw as
      EGI*Draw* routines now read the active state of the button. */

  /* Hide icon text */
  pmSysView->Window->tlbHideIconText =
    gtk_toolbar_append_element(GTK_TOOLBAR (pmSysView->Window->MToolBar), 
			       GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
			       "Icons", "Hide Icon Text", NULL,
			       CreateWidgetFromXpm(pmSysView->Window->MWindow,
						   (char **) xpm_icon_textOFF),
			       GTK_SIGNAL_FUNC(SHToggleTBIcon), pmSysView);

  /* Hide system calls */
  pmSysView->Window->tlbHideSysCalls =
    gtk_toolbar_append_element(GTK_TOOLBAR (pmSysView->Window->MToolBar), 
			       GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
			       "Syscalls", "Hide system calls", NULL,
			       CreateWidgetFromXpm(pmSysView->Window->MWindow,
						   (char **) xpm_SysCallsOFF),
			       GTK_SIGNAL_FUNC(SHToggleTBIcon), pmSysView);

  /* Hide hard IRQs */
  pmSysView->Window->tlbHideIRQs =
    gtk_toolbar_append_element(GTK_TOOLBAR (pmSysView->Window->MToolBar), 
			       GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
			       "IRQs", "Hide Hard IRQs", NULL,
			       CreateWidgetFromXpm(pmSysView->Window->MWindow,
						   (char **) xpm_IRQsOFF),
			       GTK_SIGNAL_FUNC(SHToggleTBIcon), pmSysView);

  /* Hide traps */
  pmSysView->Window->tlbHideTraps =
    gtk_toolbar_append_element(GTK_TOOLBAR (pmSysView->Window->MToolBar), 
			       GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
			       "Traps", "Hide Traps", NULL,
			       CreateWidgetFromXpm(pmSysView->Window->MWindow,
						   (char **) xpm_trapsOFF),
			       GTK_SIGNAL_FUNC(SHToggleTBIcon), pmSysView);

  /* Hide soft IRQs */
  pmSysView->Window->tlbHideSoftIRQs =
    gtk_toolbar_append_element(GTK_TOOLBAR (pmSysView->Window->MToolBar), 
			       GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
			       "IRQs", "Hide Soft IRQs", NULL,
			       CreateWidgetFromXpm(pmSysView->Window->MWindow,
						   (char **) xpm_bottom_halfOFF),
			       GTK_SIGNAL_FUNC(SHToggleTBIcon), pmSysView);

  /* Hide scheduling changes */
  pmSysView->Window->tlbHideSchedChange =
    gtk_toolbar_append_element(GTK_TOOLBAR (pmSysView->Window->MToolBar), 
			       GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
			       "IRQs", "Hide Schedule Changes", NULL,
			       CreateWidgetFromXpm(pmSysView->Window->MWindow,
						   (char **) xpm_sched_changeOFF),
			       GTK_SIGNAL_FUNC(SHToggleTBIcon), pmSysView);

  /* Toggle kernel timers. */
  pmSysView->Window->tlbHideKernelTimer =
    gtk_toolbar_append_element(GTK_TOOLBAR (pmSysView->Window->MToolBar), 
			       GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
			       "Timer", "Hide Kernel Timer", NULL,
			       CreateWidgetFromXpm(pmSysView->Window->MWindow,
						   (char **) xpm_kernel_timerOFF),
			       GTK_SIGNAL_FUNC(SHToggleTBIcon), pmSysView);

  /*  Insert a separator*/
  gtk_toolbar_append_space(GTK_TOOLBAR (pmSysView->Window->MToolBar));

  /* Slow drawing (draw everything, even if it overlaps) */
  /* Draw slow horizon lines */
  pmSysView->Window->tlbSlowH =
    gtk_toolbar_append_element(GTK_TOOLBAR (pmSysView->Window->MToolBar), 
			       GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
			       "Speed", "Slow HLines", NULL,
			       CreateWidgetFromXpm(pmSysView->Window->MWindow,
						   (char **) xpm_SlowH),
			       GTK_SIGNAL_FUNC(SHToggleTBIcon), pmSysView);
  /* Draw slow vertical lines */
  pmSysView->Window->tlbSlowV =
    gtk_toolbar_append_element(GTK_TOOLBAR (pmSysView->Window->MToolBar), 
			       GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
			       "Speed", "Slow VLines", NULL,
			       CreateWidgetFromXpm(pmSysView->Window->MWindow,
						   (char **) xpm_SlowV),
			       GTK_SIGNAL_FUNC(SHToggleTBIcon), pmSysView);
  /* Draw slow icons */
  pmSysView->Window->tlbSlowI =
    gtk_toolbar_append_element(GTK_TOOLBAR (pmSysView->Window->MToolBar), 
			       GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
			       "Speed", "Slow Icons", NULL,
			       CreateWidgetFromXpm(pmSysView->Window->MWindow,
						   (char **) xpm_SlowI),
			       GTK_SIGNAL_FUNC(SHToggleTBIcon), pmSysView);
}