aboutsummaryrefslogtreecommitdiff
path: root/vendor/x11iraf/guidemo/table.gui
blob: 68d71df9acde624c2980e410146a0c179d7e1995 (plain) (blame)
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
# TABDEMO.GUI -- Test the Table widget.

reset-server
appInitialize tabdemo Tabdemo {

    *demoObjects:\
    	toplevel		Layout		panel \
    	panel			Frame		panelMenuFrame \
	panelMenuFrame		Layout		panelMenuBar \
	panelMenuBar		Command		newCol \
	panelMenuBar		Command		newRow \
	panelMenuBar		Command		newTable \
	panelMenuBar		Command		tclShell \
	panelMenuBar		Command		quitButton


	Tabdemo*background:			grey
	*Tabdemo.geometry:			+0+0

	*Group.shrinkToFit:                 	True
	*Command.height:			28
	*Command.shadowWidth:			1
	*Frame.frameWidth:			1
	*Frame.innerOffset:			4
	*Frame.highlightThickness:		0
	*borderWidth:				0
	*Scrollbar2.location:			0 0 17 17
	*Scrollbar.beNiceToColormap:		False

	*panel.width:				600
	*panel.height:				350
	*panel.layout: vertical { \
	    panelMenuFrame < +inf -inf * > \
	    5 < +inf > horizontal { 5 < +inf > }\
	}

	*panelMenuBar.layout: horizontal { \
	    2 newRow 1 newCol 1 newTable 1 tclShell 2 < +inf > quitButton 2 \
	}
	*newCol.label:				New Col
	*newRow.label:				New Row
	*newTable.label:			New Table
	*tclShell.label:			TclShell
	*quitButton.label:			Quit

} ; createObjects demoObjects

send quitButton addCallback "send client gkey q ; deactivate unmap"

# Utility procedure to test True/False strings in resources.
proc true {v} {expr {$v == "true" || $v == "True" || $v == "TRUE"}}

# Utility functions.
proc min {a b} { expr {($a < $b) ? $a : $b} }
proc max {a b} { expr {($a > $b) ? $a : $b} }

# Create the Table objects in the OBM.

set tabnumber	0				;# initialize table counter

proc doTable args {
    global  tabnumber

    set tab  [ format "tab%d" $tabnumber ] 
    set objs [ tableBuildObjects panel $tab ]

#   tableSetOption $tab DefLabels  no
#   tableSetOption $tab RowLabels  no
#   tableSetOption $tab ColLabels  no
#   tableSetOption $tab Tracking   no
#   tableSetOption $tab RowScroll  no
#   tableSetOption $tab ColScroll  no
#   tableSetOption $tab DefaultTranslations  no
    tableSetOption $tab RowMultiSelect  no
    tableSetOption $tab ColMultiSelect  no
#   tableSetOption $tab RowLabelCols 2
#   tableSetOption $tab ColLabelRows 2
    tableSetOption $tab Background  bisque3

    # Now create the new objects.
    appExtend $objs
    createObjects ${tab}Objects

    # Now construct a layout for the new object.
    set new ""
    set panStart "vertical \{ panelMenuFrame < +inf -inf * > 5 < -5 >"
    for {set i 0} {$i <= $tabnumber} {incr i} {

	# Send the existing table a small height so they'll ajust to 
	# fit the new table.
	if {$i < $tabnumber} { send tab${i}TableFrame set height 10 }

	# Append a layout spec for the table.
	set new \
	    [format "%s tab%dTableFrame < +inf -inf * +inf -inf > 5 < -5 >" \
	        $new $i]
    }
    set panEnd   "\}"
    set panelLayout [format "%s %s %s" $panStart $new $panEnd]

    # Send the panel the new layout incorporating the newly created Table.
    send panel set layout $panelLayout

    # Now create the table itself, it should appear as if by magic.
    tableCreate $tab 12 30 { }

    # Apply some default test callbacks for selection/edit events.
    tableAddSelectCallback $tab Row demoSelCB
    tableAddSelectCallback $tab Col demoSelCB
    tableAddSelectCallback $tab Cell demoSelCB
    tableAddUnSelectCallback $tab Row demoUnSelCB
    tableAddUnSelectCallback $tab Col demoUnSelCB
    tableAddUnSelectCallback $tab Cell demoUnSelCB
    tableAddEditCallback $tab demoEditCB

    # Increment the global table counter.
    incr tabnumber

} ; send newTable addCallback doTable

proc demoSelCB { name row col x y args } {
    print "demoSelCB:  name=$name r=$row c=$col x=$x y=$y args='$args'"
}

proc demoUnSelCB { name row col x y args } {
    print "demoUnSelCB:  name=$name r=$row c=$col x=$x y=$y args='$args'"
}

proc demoEditCB { name row col str args } {
    print "demoEditCB:  name=$name row=$row col=$col str='$str' args='$args'"
}


################################################################################

################################################################################
#
#  TABLE WIDGET PROCEDURES -- This interface provides simple access to a
#  named instance of a Table "meta-widget".  The "widget" is actually a
#  number of widgets (Table, Scrollbars, etc) in a common layout to provide
#  row/col headings, scrollable data tables, and callbacks for [gs]etting
#  attributes.  The meta-widget is created on-the-fly with a given named
#  and parent object, it is the callers responsibility to adjust the layout
#  of the parent to incorporate the new objects.
#
#	The Table widget itself has various quirks and non-standard implem-
#  entations so features such as editing cells or access to certain callbacks
#  are not fully implemented in the OBM and hidden here.  Most of what's
#  needed can be handled by these procedures, however these routines may be
#  used to manage multiple named tables in a GUI.
#
#
#	           tableBuildObjects  parent tab
#	              tableSetOption  tab option value
#             tableAddSelectCallback  tab type cbname
#               tableAddEditCallback  tab cbname
#	         tableDestroyObjects  tab
#
#		         tableCreate  tab nrows ncols data
#	                tableSetData  tab data
#	        tableSetColumnLabels  tab labels
#	           tableSetRowLabels  tab labels
#
#                     tableSelectRow  tab [ rownum | "all" ]
#                   tableUnSelectRow  tab [ rownum | "all" ]
#                     tableSelectCol  tab [ colnum | "all" ]
#                   tableUnSelectCol  tab [ colnum | "all" ]
#                    tableSelectCell  tab x y
#                  tableUnSelectCell  tab x y
#            list = tableGetSelected  tab type
#
#              tableSetRowLabelsAttr  tab attr value
#      value = tableGetRowLabelsAttr  tab attr
#              tableSetColLabelsAttr  tab attr value
#      value = tableGetColLabelsAttr  tab attr
#               tableSetRowLabelAttr  tab row attr value
#       value = tableGetRowLabelAttr  tab row attr
#               tableSetColLabelAttr  tab col attr value
#       value = tableGetColLabelAttr  tab col attr
#
#           attr = tableGetCelllAttr  tab row col attr
#                  tableSetCelllAttr  tab row col attr value
#            value = tableGetRowAttr  tab row attr
#                    tableSetRowAttr  tab row attr value
#            value = tableGetColAttr  tab col attr
#                    tableSetColAttr  tab col attr value
#
#                     tableDeleteCol  tab col 
#                     tableDeleteRow  tab row 
#                        tableAddCol  tab col width [where]
#                        tableAddRow  tab row [where]
#
#              nrows = tableGetNrows  tab
#              ncols = tableGetNcols  tab
#            height = tableGetHeight  tab
#              width = tableGetWidth  tab
#
#      See obm$widget.c for a complete list of the OBM commands available
#  for this widget, and procedure header comments for details about the 
#  interface here.
#
################################################################################

set tabNrows(name) 			0
set tabNcols(name) 			0
set tabData(name) 			0
set tabColLabs(name)			0
set tabRowHeights(name,j)		0
set tabColWidths(name,i) 		0

set tabHeight(name)			0
set tabWidth(name)			0
set tabScrollSize(name,type)		0
set tabScrollPos(name,type)		0

# Meta-widget options, should be set before the tableCreate call.
set tabOption(name,RowLabels)		yes
set tabOption(name,ColLabels)		yes
set tabOption(name,DefLabels)		yes
set tabOption(name,Tracking)		yes
set tabOption(name,RowScroll)		yes
set tabOption(name,ColScroll)		yes
set tabOption(name,Editable)		yes
set tabOption(name,RowSelect)		yes
set tabOption(name,ColSelect)		no
set tabOption(name,CellSelect)		no
set tabOption(name,DefaultTranslations)	yes
set tabOption(name,Background)		grey
set tabOption(name,Foreground)		black
set tabOption(name,HighlightColor)	grey90
set tabOption(name,RowLabelCols)	1
set tabOption(name,ColLabelRows)	1

# Selection lists.
set tabSelected(name,Row)		{}
set tabSelected(name,Col)		{}
set tabSelected(name,Cell)		{}
set tabSelectionCB(name,Row)		{}
set tabSelectionCB(name,Col)		{}
set tabSelectionCB(name,Cell)		{}
set tabUnSelectionCB(name,Row)		{}
set tabUnSelectionCB(name,Col)		{}
set tabUnSelectionCB(name,Cell)		{}
set tabEditCB(name)			{}


# TABLEBUILDOBJECTS -- Utility routine to build the object list for the meta-
# widget.
#
#  Usage:	
#	    tableBuildObjects  <parent> <tab>

proc tableBuildObjects { parent tab } {

    set objDef {
	*TABObjects: \
	    PARENT           Frame       	TABTableFrame	\
            TABTableFrame    Layout      	TABFrameLayout	\
            TABFrameLayout   Layout      	TABTableLayout	\
            TABTableLayout   Viewport    	TABTabView	\
            TABTabView       Table       	TABTab		\
            TABTableLayout   Label       	TABSpacer1      \
            TABTableLayout   Viewport    	TABRowTabView	\
            TABRowTabView    Table       	TABRowTab	\
            TABTableLayout   Viewport    	TABColTabView	\
            TABColTabView    Table       	TABColTab	\
            TABFrameLayout   Label       	TABLabel       	\
            TABFrameLayout   Label       	TABSpacer2      \
            TABFrameLayout   Scrollbar   	TABColScroll   	\
            TABFrameLayout   Scrollbar   	TABRowScroll	\
\
	    toplevel         TopLevelShell   	TABEditShell	\
	    TABEditShell     Layout          	TABEditLayout	\
	    TABEditLayout    Frame           	TABEditMenuFrame\
	    TABEditMenuFrame Layout          	TABEditMenuBar	\
	    TABEditMenuBar   Command         	TABEditApply	\
	    TABEditMenuBar   Command         	TABEditClear	\
	    TABEditMenuBar   Command         	TABEditCancel	\
	    TABEditLayout    Frame           	TABEditFrame	\
	    TABEditFrame     AsciiText       	TABEditText	\




        ! Global Table widget resources.
        *Table.literalWidth:                    	20
        *Table.rowHeight:                       	18
        *Table.shadowWidth:                     	2
        *Table.labelShadowWidth:                	1
        *Table.tableMargin:                     	0
        *Table.columnMargin:                     	0
        *Table.rowMargin:                     		0
        *Table.internalHeight:                  	0
        *Table.internalWidth:                   	0
        *Table*font:					7x13bold

        *TABTableFrame*Group.shrinkToFit:               True
        *TABTableFrame*Command.height:                  28
        *TABTableFrame*Command.shadowWidth:             1
        *TABTableFrame*Frame.frameWidth:                1
        *TABTableFrame*Frame.innerOffset:               4
        *TABTableFrame*Frame.highlightThickness:        0
        *TABTableFrame*Frame.borderWidth:               0
        *TABTableFrame*Frame.shrinkToFit:               True
        *TABTableFrame*Table.borderWidth:               1
        *TABTableFrame*Scrollbar.beNiceToColormap:      False

	*TABTableFrame.height:					10
	*TABTableFrame.width:					10
	*TABTableFrame*Layout.height:				10
	*TABTableFrame*Layout.width:				10
	*TABTableFrame*Label.height:				12
	*TABTableFrame*Label.label:
	*TABTableFrame*Label.font:				6x12

	*TABFrameLayout.TABTableLayout.height:			10
	*TABFrameLayout.TABTableLayout.width:			10
	*TABFrameLayout.TABTableLayout*Layout.height:		10
	*TABFrameLayout.TABTableLayout*Layout.width:		10
	*TABFrameLayout.TABTableLayout*Viewport.height:		20
	*TABFrameLayout.TABTableLayout*Viewport.width:		20
        *TABFrameLayout.TABTableLayout*Table.height:		20
        *TABFrameLayout.TABTableLayout*Table.width:		20


        ! The following resources enable the scrollbars on the Viewport
        ! widget but effectively hide them from display.  This allows us
        ! to control the viewport manually from the Table code, e.g. to
        ! scroll both the column headings and data table.
        *TABFrameLayout.TABTableLayout*Viewport.allowVert:      True
        *TABFrameLayout.TABTableLayout*Viewport.allowHoriz:     True
        *TABFrameLayout.TABTableLayout*Viewport.forceBars:      True
        *TABFrameLayout.TABTableLayout*Viewport.useBottom:      True
        *TABFrameLayout.TABTableLayout*Viewport.useRight:       True
        *TABFrameLayout.TABTableLayout*Viewport.borderWidth:    1

        *TABTableLayout*TABRowTabView*vertical.thickness:   	1
        *TABTableLayout*TABRowTabView*horizontal.thickness: 	1
        *TABTableLayout*TABColTabView*vertical.thickness:   	1
        *TABTableLayout*TABColTabView*horizontal.thickness: 	1
        *TABTableLayout*TABTabView*vertical.thickness:   	1
        *TABTableLayout*TABTabView*horizontal.thickness: 	1

        *TABTableFrame.TABFrameLayout.TABRowScroll.thickness:   12
        *TABTableFrame.TABFrameLayout.TABRowScroll.width:       12
        *TABTableFrame.TABFrameLayout.TABRowScroll.height:      12
        *TABTableFrame.TABFrameLayout.TABRowScroll.orientation: Vertical

        *TABTableFrame.TABFrameLayout.TABColScroll.thickness:   12
        *TABTableFrame.TABFrameLayout.TABColScroll.width:       12
        *TABTableFrame.TABFrameLayout.TABColScroll.height:      12
        *TABTableFrame.TABFrameLayout.TABColScroll.orientation: Horizontal

        *TABFrameLayout.layout: horizontal { \
	    vertical { \
		2 < -2 > \
                TABTableLayout < +inf -inf * +inf -inf > \
		2 < -2 > \
	        horizontal { \
		    TABLabel 1 < -1 > TABColScroll < +inf -inf * > \
	        } \
	    } \
	    vertical { \
		TABSpacer2 1 < -1 > TABRowScroll < * +inf -inf >  22 < -22 > \
	    } \
	}
	*TABTableFrame.TABFrameLayout.TABLabel.label: 		(  0,  0)
        *TABTableFrame.TABFrameLayout.TABLabel.font:            6x12
        *TABTableFrame.TABFrameLayout.TABLabel.width:           80
        *TABTableFrame.TABFrameLayout.TABLabel.height:          12
        *TABTableFrame.TABFrameLayout*TABColScroll.height:      12
        *TABTableFrame.TABFrameLayout.TABSpacer2.height:        27
        *TABTableFrame.TABFrameLayout.TABSpacer2.shadowWidth:   0

        *TABTableLayout.layout: horizontal { \
            vertical { \
                TABSpacer1 1 < -1 > TABRowTabView < * +inf -inf > \
            } \
            3 < -3 > \
            vertical { \
                TABColTabView < +inf -inf * > \
                3 < -3 > \
                TABTabView < +inf -inf * +inf -inf > \
            } \
            3 < -3 > \
        }	
	*TABTableLayout.TABSpacer1.height:	  		27
	*TABTableLayout.TABSpacer1.shadowWidth:	  		0

    !---------------------------+
    ! Set the editor resources. |
    !---------------------------+
    *TABEditShell.title:                          Table Value Editor
    *TABEditShell.width:                          275
    *TABEditShell.height:                         80
    *TABEditLayout*borderWidth:                   0
    *TABEditLayout.layout:  vertical { \
        TABEditFrame < +inf -inf * +inf -inf > \
        -2 \
        TABEditMenuFrame < +inf -inf * > \
        -2 \
    }

    *TABEditMenuBar.layout: horizontal { \
	TABEditApply 5 \
	10 < +inf -inf > \
	TABEditClear 5 \
	10 < +inf -inf > \
	TABEditCancel 5 \
    }
    *TABEditMenuFrame.height:                       80
    *TABEditMenuFrame.outerOffset:                  0
    *TABEditMenuFrame.innerOffset:                  5
    *TABEditMenuFrame.frameType:                    chiseled
    *TABEditMenuFrame.frameWidth:                   2
    *TABEditFrame.frameType:                        sunken
    *TABEditFrame.frameWidth:                       2
    *TABEditFrame.outerOffset:                      5
    *TABEditText*scrollVertical:                    never
    *TABEditText*scrollHorizontal:                  whenNeeded
    *TABEditText*font:                              7x13
    *TABEditText*editType:                          edit
    *TABEditApply.label:                            Apply
    *TABEditApply.width:                            150
    *TABEditClear.label:                            Clear
    *TABEditClear.width:                            150
    *TABEditCancel.label:                           Cancel
    *TABEditCancel.width:                           150

    }

    regsub -all TAB $objDef $tab tmp1
    regsub -all PARENT $tmp1 $parent objs
    set objs [format "{ %s }" $objs]

    return $objs
} 


# TABLEDESTROYOBJECTS -- Destroy the specified table and all it's objects.
#
#  Usage:	
#	    tableDestroyObjects  <tab>

proc tableDestroyObjects { tab } {
    destroyObject ${tab}TableFrame 
}


# TABESETOPTION -- Set an option for the Table meta-widget.
#
# Usage:
#		tableSetOption <tab> <option> [yes|no]
#
# where <tab> is the table name given when the meta-widget was created, and
# <option> is one of:
#
#
#    Option Name	    Type     Default	Description
#    -----------	    ----     -------	-----------
#    RowLabels		    bool     yes	display a row label table
#    ColLabels		    bool     yes	display a column label table
#    DefLabels		    bool     yes	do default labels of rows/cols
#    Tracking		    bool     yes	do coord tracking in data table
#    RowScroll		    bool     yes	display row scrollbar
#    ColScroll		    bool     yes	display column scrollbar
#    Editable		    bool     yes	table is editable
#    RowSelect		    bool     yes	rows are selectable
#    ColSelect		    bool     yes	cols are selectable
#    CellSelect		    bool     yes	cells are selectable
#    RowMultiSelect	    bool     yes	multiple rows may be selected
#    ColMultiSelect	    bool     yes	multiple cols may be selected
#    CellMultiSelect	    bool     yes	multiple cells may be selected
#    DefaultTranslations    bool     yes	use default table translations
#    Foreground		    color    black	meta-widget foreground color
#    Background		    color    grey	meta-widget background color
#    HighlightColor	    color    grey90	selected item highlight color
#    RowLabelCols	    int	     1		number of columns in row labels
#    ColLabelRows	    int	     1		number of rows in column labels
#

proc tableSetOption { tab option value } {
    global tabOption
    set tabOption(${tab},${option}) $value

    # Now handle the special cases where one option may disable some other.
}


# TABLEADDSELECTCALLBACK -- Add a user-defined callback to be executed
# when there is a row, column, or cell selection event occurs.
#
#  Usage:	
#	    tableAddSelectCallback  <tab> <type> <cbname>
#
# where <type> is "Row", "Col", or "Cell" and <cbname> specifies a procedure
# to be called whenever the specified <type> is selected.  Procedures are
# called as
#		<cbname> name row col x y
#
# where 'name' is the table name, 'row' and 'col' are the coordinates of the
# selection and 'x' and 'y' are the raw event coordinates.  Registered proc-
# edures are required to declare all these arguments but do not need to use
# them.

proc tableAddSelectCallback { tab type cbname } {
    global tabSelectionCB
    lappend tabSelectionCB(${tab},${type}) $cbname
}


# TABLEADDUNSELECTCALLBACK -- Add a user-defined callback to be executed
# when there is a row, column, or cell un-selection event occurs.
#
#  Usage:	
#	    tableAddUnSelectCallback  <tab> <type> <cbname>
#
# where <type> is "Row", "Col", or "Cell" and <cbname> specifies a procedure
# to be called whenever the specified <type> is selected.  Procedures are
# called as
#		<cbname> name row col x y state
#
# where 'name' is the table name, 'row' and 'col' are the coordinates of the
# selection and 'x' and 'y' are the raw event coordinates.  Registered proc-
# edures are required to declare all these arguments but do not need to use
# them.

proc tableAddUnSelectCallback { tab type cbname } {
    global tabUnSelectionCB
    lappend tabUnSelectionCB(${tab},${type}) $cbname
}



# TABLEADDEDITCALLBACK -- Add a user-defined callback to be executed
# when there is an edit event.
#
#  Usage:	
#	    tableAddEditCallback <tab> <cbname>
#
# <cbname> specifies a procedure to be called whenever the table editor 
# Apply button has been pressed.  Procedures are called as
#
#		<cbname> name row col new_string
#
# where 'name' is the table name, 'row' and 'col' are the coordinates of the
# edited cell and 'new_string' is the new value inserted in the table.  Reg-
# istered procedures are required to declare all these arguments but do not
# need to use them.

proc tableAddEditCallback { tab cbname } {
    global tabEditCB
    lappend tabEditCB(${tab}) $cbname
}


# TABLECREATE -- Create a named instance of the Table meta-widget.  The
# individual objects in the meta-widget are created dynamically and the
# entire thing is created as a child of the named parent object.  The
# standard callbacks are assigned and the table is initialized, however
# it is the callers responsibility to adjust the parent's layout to make
# the meta-widget visible and assign any constraint callbacks.
#
#  Usage:	
#	    tableCreate  <tab> <nrows> <ncols> <data>
#
# The <data> is specified as a Tcl list of the form:
#
#      { {r1c1 r1c2 ... r1cN}
#        {r2c1 r2c2 ... r2cN}
#              :
#        {rNc1 rNc2 ... rNcN} }
#
# String values must be quoted, rows/cols will be truncated or cleared if
# the specified table size does not agree with the size of the data table
# being loaded.

set tabBGWidgets { \
    TABTab TABRowTab TABColTab TABLabel TABColScroll \
    TABRowScroll TABEditApply TABEditClear TABEditCancel \
    TABEditApply TABEditClear TABEditCancel TABEditText \
    TABEditFrame TABEditMenuBar TABEditMenuFrame \
}
set tabFGWidgets { \
    TABTab TABRowTab TABColTab TABLabel TABColScroll \
    TABRowScroll TABEditApply TABEditClear TABEditCancel \
    TABEditApply TABEditClear TABEditCancel TABEditText \
}

proc tableCreate { tab nrows ncols data } {
    global tabNrows tabNcols tabRowHeights tabColWidths
    global tabHeight tabWidth tabDebug tabOption 
    global tabEditCB tabSelectionCB tabUnSelectionCB 
    global tabSelected tabBGWidgets tabFGWidgets

    set err ""
    catch {
        if { ![info exists tabOption(${tab},RowLabelCols)] } {
            set tabOption(${tab},RowLabelCols) $tabOption(name,RowLabelCols)
        }
    } err
    if {$err != ""} {
        set tabOption(${tab},RowLabelCols) $tabOption(name,RowLabelCols)
    }
    set err ""
    catch {
        if { ![info exists tabOption(${tab},ColLabelRows)] } {
            set tabOption(${tab},ColLabelRows) $tabOption(name,ColLabelRows)
        }
    } err
    if {$err != ""} {
        set tabOption(${tab},ColLabelRows) $tabOption(name,ColLabelRows)
    }

           
    set tabNrows(${tab},data)	$nrows
    set tabNcols(${tab},data) 	$ncols
    set tabNrows(${tab},rows) 	$nrows
    set tabNcols(${tab},rows) 	$tabOption(${tab},RowLabelCols)
    set tabNrows(${tab},cols) 	$tabOption(${tab},ColLabelRows)
    set tabNcols(${tab},cols) 	$ncols
    set tabData($tab)  		$data

    # Initialize with a default row height.
    set rh [send ${tab}Tab get rowHeight]
    set tabRowHeights($tab,default) $rh
    for {set i 1} {$i <= $nrows} {incr i} { 
	set tabRowHeights($tab,$i) $rh 
    }

    # Initialize with a default column width.
    set cw [send ${tab}Tab get defaultWidth]
    for {set i 1} {$i <= $ncols} {incr i} { 
	set tabColWidths($tab,$i) $cw 
    }

    # Initialize the table.
    send ${tab}Tab setTable $nrows $ncols $data

    # Initialize the labels.
    tableSetDefaultLabels $tab

    # Save the table dimensions.
    set tabHeight($tab) [ tableGetHeight $tab ]
    set tabWidth($tab)  [ tableGetWidth  $tab ]

    # Set the default table translations.
    tableSetDefaultTranslations $tab

    # Attach the default-callbacks to the new Table.
    tableAddCallbacks $tab

    # Set Default Scrollbars for the table.
    tableSetDefaultScrollbars $tab yes

    # Default the colors.
    set err ""
    catch { 
      if { ![info exists tabOption(${tab},HighlightColor)] != 0 } {
        set tabOption(${tab},HighlightColor) $tabOption(name,HighlightColor)
      }
    } err 
    if {$err != ""} {
        set tabOption(${tab},HighlightColor) $tabOption(name,HighlightColor)
    }
    set err ""
    catch { 
      if { ![info exists tabOption(${tab},Background)] != 0 } {
        set tabOption(${tab},Background)     $tabOption(name,Background)
      }
    } err 
    if {$err != ""} {
        set tabOption(${tab},Background)     $tabOption(name,Background)
    }
    set err ""
    catch { 
      if { ![info exists tabOption(${tab},Foreground)] != 0 } {
        set tabOption(${tab},Foreground)     $tabOption(name,Foreground)
      }
    } err
    if {$err != ""} {
        set tabOption(${tab},Foreground)     $tabOption(name,Foreground)
    }

    regsub -all TAB $tabBGWidgets $tab bgwidgets
    foreach w $bgwidgets { 
	send $w set background $tabOption(${tab},Background) 
    }
    regsub -all TAB $tabFGWidgets $tab fgwidgets
    foreach w $fgwidgets { 
	send $w set foreground $tabOption(${tab},Foreground)
    }

    # Default selections.
    set tabSelected(${tab},Row)		{}
    set tabSelected(${tab},Col)		{}
    set tabSelected(${tab},Cell)	{}

    set tabSelectionCB(${tab},Row) 	{}
    set tabSelectionCB(${tab},Col) 	{}
    set tabSelectionCB(${tab},Cell) 	{}
    set tabUnSelectionCB(${tab},Row) 	{}
    set tabUnSelectionCB(${tab},Col) 	{}
    set tabUnSelectionCB(${tab},Cell) 	{}
    set tabEditCB(${tab}) 		{}
}


# TABLESETDATA -- Set the data elements of a table meta-widget.
#
# Usage:
#		tableSetData  <tab> <data>
#
# where <tab> is the table name given when the meta-widget was created, and
# <data> is of the form:
#
#      { {r1c1 r1c2 ... r1cN}
#        {r2c1 r2c2 ... r2cN}
#              :
#        {rNc1 rNc2 ... rNcN} }

proc tableSetData { tab data } {
    global tabNrows tabNcols

    send ${tab}Tab setTable $tabNrows(${tab},data) $tabNcols(${tab},data) $data

#   send ${tab}Tab setTable \
#	[expr ($tabNrows(${tab},data) + 20)] \
#	[expr ($tabNcols(${tab},data) + 20)] \
#	$data
}


# TABLESETSIZE -- Set the size of a table meta-widget.
#
# Usage:
#               tableSetSize  <tab> <nrows> <ncols>
#

proc tableSetSize { tab nrows ncols } {
    global tabNrows tabNcols tabOption 
    global tabHeight tabWidth tabRowHeights

    set tabNrows(${tab},data)   $nrows
    set tabNcols(${tab},data)   $ncols

    set tabNrows(${tab},rows)   $nrows
    set tabNcols(${tab},rows)   $tabOption(${tab},RowLabelCols)
    set tabNrows(${tab},cols)   $tabOption(${tab},ColLabelRows)
    set tabNcols(${tab},cols)   $ncols

    send ${tab}Tab    setTableSize $nrows $ncols
    send ${tab}RowTab setTableSize $tabNrows(${tab},rows) $tabNcols(${tab},rows)
    send ${tab}ColTab setTableSize $tabNrows(${tab},cols) $tabNcols(${tab},cols)

    set rh [send ${tab}Tab get rowHeight]
    set tabRowHeights($tab,default) $rh
    for {set i 1} {$i <= $nrows} {incr i} { 
	set tabRowHeights($tab,$i) $rh 
    }

    # Save the table dimensions.
    set tabHeight($tab) [ tableGetHeight $tab ]
    set tabWidth($tab)  [ tableGetWidth  $tab ]

    #tableSetDefaultScrollbars $tab yes
}


# TABLESETCOLUMNLABELS -- Set the column header labels for a table.
# meta-widget.
#
# Usage:
#		tableSetColumnLabels  <tab> <column_labs>
#
# where <tab> is the table name given when the meta-widget was created, and
# <data> is of the form:
#
#      { { r1c1 } { r1c2 } ... { r1cN } }

proc tableSetColumnLabels { tab col_labs } {
    global tabNrows tabNcols
    send ${tab}ColTab \
	setTable $tabNrows(${tab},cols) $tabNcols(${tab},cols) $col_labs
}


# TABLESETROWLABELS -- Set the row header labels for a table.
# meta-widget.
#
# Usage:
#		tableSetColumnLabels  <tab> <row_labs>
#
# where <tab> is the table name given when the meta-widget was created, and
# <data> is of the form:
#
#      { {r1c1 r1c2 ... r1cN} }

proc tableSetRowLabels { tab row_labs } {
    global tabNrows tabNcols
    send ${tab}RowTab \
	setTable $tabNrows(${tab},rows) $tabNcols(${tab},rows) $row_labs
}


# TABLESETCOLLABELSATTR -- Set the column header labels for a table
# meta-widget.
#
# Usage:
#		tableSetColumnLabels  <tab> <attr> <value> [<row>]
#
# where <attr> is one of
#
#      background              background color
#      foreground              foreground color
#      width                   column width
#      justify		       label justification

proc tableSetColLabelsAttr { tab attr value args } {
    if {$args != ""} {
        send ${tab}ColTab setRowAttr $args $attr $value
    } else {
        send ${tab}ColTab setRowAttr 1 $attr $value
    }
}


# TABLESETROWLABELSATTR -- Set the row header labels for a table meta-widget.
#
# Usage:
#		tableSetRowLabelsAttr  <tab> <attr> <value> [<col>]
#
# where <attr> is one of
#
#      background              background color
#      foreground              foreground color
#      width	               column width
#      justify	               label justification

proc tableSetRowLabelsAttr { tab attr value args } {
    if {$args != ""} {
        send ${tab}RowTab setColAttr $args $attr $value
    } else {
        send ${tab}RowTab setColAttr 1 $attr $value
    }
}


# TABLEGETROWLABELSATTR -- Get the row header labels for a table meta-widget.
#
# Usage:
#		value = tableGetRowLabelsAttr  <tab> <attr> [<col>]
#
# where <attr> is one of
#
#      background              background color
#      foreground              foreground color
#      width	               column width
#      justify	               label justification

proc tableGetRowLabelsAttr { tab attr args } {
    if {$args != ""} {
        return [ send ${tab}RowTab getColAttr $args $attr ]
    } else {
        return [ send ${tab}RowTab getColAttr 1 $attr ]
    }
}


# TABLEGETCOLLABELSATTR -- Get the column header labels for a table.
# meta-widget.
#
# Usage:
#		value = tableGetColLabelsAttr  <tab> <attr> [<row>]
#
# where <attr> is one of
#
#      background              background color
#      foreground              foreground color
#      width                   column width
#      justify		       label justification

proc tableGetColLabelsAttr { tab attr args } {
    if {$args != ""} {
        return [ send ${tab}ColTab getRowAttr $args $attr ]
    } else {
        return [ send ${tab}ColTab getRowAttr 1 $attr ]
    }
}


# TABLESETROWLABELATTR -- Set the specified attribute for the row label table.
#
# Usage:
#         tableSetRowLabelAttr  <tab> <row> <attr> <value> [<row>]
#
# The cell position is given as a 1-indexed array element where the UL
# of the table is cell (1,1).  Allowed attributes for a cell include:
#
#              label                   label text (string)
#              background              background color (string)
#              foreground              foreground color (string)

proc tableSetRowLabelAttr { tab row attr value args } {
    if {$args != ""} {
        send ${tab}RowTab setCellAttr $row $args $attr $value
    } else {
        send ${tab}RowTab setCellAttr $row 1 $attr $value
    }
}


# TABLESETCOLLABELATTR -- Get the specified attribute for the col label table.
#
# Usage:
#        value = tableSetColLabelAttr  <tab> <col> <attr> <value> [<row>]
#
# The cell position is given as a 1-indexed array element where the UL
# of the table is cell (1,1).  Allowed attributes for a cell include:
#
#              label                   label text (string)
#              background              background color (string)
#              foreground              foreground color (string)

proc tableSetColLabelAttr { tab col attr value args } {
    if {$args != ""} {
        send ${tab}ColTab setCellAttr $args $col $attr $value
    } else {
        send ${tab}ColTab setCellAttr 1 $col $attr $value
    }
}


# TABLEGETCELLATTR -- Get the specified attribute for the cell.
#
# Usage:
#		value = tableGetCellAttr  <tab> <row> <col> <attr>
#
# The cell position is given as a 1-indexed array element where the UL
# of the table is cell (1,1).  Allowed attributes for a cell include:
#
#              label                   label text (string)
#              background              background color (string)
#              foreground              foreground color (string)

proc tableGetCellAttr { tab row col attr } {
    return [ send ${tab}Tab getCellAttr $row $col $attr ]
}


# TABLESETCELLATTR -- Set the specified attribute for the cell.
#
# Usage:
#		tableSetCellAttr  <tab> <row> <col> <attr> <value>
#
# The cell position is given as a 1-indexed array element where the UL
# of the table is cell (1,1).  Allowed attributes for a cell include:
#
#              label                   label text (string)
#              background              background color (string)
#              foreground              foreground color (string)

proc tableSetCellAttr { tab row col attr value } {
    send ${tab}Tab setCellAttr $row $col $attr $value
}


# TABLEGETROWATTR -- Get the specified attribute for the row.
#
# Usage:
#		value = tableGetCellAttr  <tab> <row> <attr>
#
# The row position is given as a 1-indexed array element where the UL
# of the table is cell (1,1).  Allowed attributes for a row include:
#
#      background              background color
#      foreground              foreground color

proc tableGetRowAttr { tab row attr } {
    return [ send ${tab}Tab getRowAttr $row $attr ]
}


# TABLESETROWATTR -- Set the specified attribute for the row.
#
# Usage:
#		tableSetRowAttr  <tab> <row> <attr> <value>
#
# The row position is given as a 1-indexed array element where the UL
# of the table is cell (1,1).  Allowed attributes for a row include:
#
#      background              background color
#      foreground              foreground color

proc tableSetRowAttr { tab row attr value } {
    send ${tab}Tab setRowAttr $row $attr $value
}


# TABLEGETCOLATTR -- Get the specified attribute for the column.
#
# Usage:
#		value = tableGetColAttr  <tab> <col> <attr>
#
# The column position is given as a 1-indexed array element where the UL
# of the table is cell (1,1).  Allowed attributes for a column include:
#
#              width                   column width (pixels)
#              background              background color (string)
#              foreground              foreground color (string)
#              justify                 text justification (string)

proc tableGetColAttr { tab col attr } {
    return [ send ${tab}Tab getColAttr $col $attr ]
}


# TABLESETCOLATTR -- Set the specified attribute for the column.
#
# Usage:
#		tableSetColAttr  <tab> <col> <attr> <value>
#
# The column position is given as a 1-indexed array element where the UL
# of the table is cell (1,1).  Allowed attributes for a column include:
#
#              width                   column width (pixels)
#              background              background color (string)
#              foreground              foreground color (string)
#              justify                 text justification (string)

proc tableSetColAttr { tab col attr value } {
    global tabColWidths tabNcols

    send ${tab}Tab setColAttr $col $attr $value
    if {$attr == "width"} { 
	set tabColWidths(${tab},$col) $value 
    }
}


# TABLEDELETECOL -- Delete the specified column from the named table.
#
# Usage:
#		tableDeleteCol  <tab> <col>

proc tableDeleteCol { tab col } {
    global tabColWidths tabNcols

    send ${tab}Tab    deleteCol $col
    send ${tab}ColTab deleteCol $col
    incr tabNcols(${tab},data) -1
    catch { unset tabColWidths(${tab},$col) } err
}


# TABLEDELETEROW -- Delete the specified row from the named table.
#
# Usage:
#		tableDeleteRow  <tab> <row>

proc tableDeleteRow { tab row } {
    global tabRowHeights tabNrows 

    send ${tab}Tab    deleteRow $row
    send ${tab}RowTab deleteRow $row
    incr tabNrows(${tab},data) -1
    catch { unset tabRowHeights(${tab},$row) } err
}


# TABLEDADDCOL -- Add a column to the named table at the specified position.
#
# Usage:
#		tableAddCol  <tab> <col> <width>

proc tableAddCol { tab col width args} {
    global tabColWidths tabNcols

    send ${tab}Tab    addCol $col $width $args
    send ${tab}ColTab addCol $col $width $args
    incr tabNcols(${tab},data)

    set ncols $tabNcols(${tab},data)
    if {$col == "first"} {
	set colnum 1
    } elseif {$col == "last"} {
	set colnum $tabNcols(${tab},data)
    } else {
	set colnum $col
    }

    # Update the column widths.
    for {set c $ncols} {$c > $colnum} {incr c -1} {
        set tabColWidths(${tab},$c) $tabColWidths(${tab},[expr ($c - 1)])
    }
    set tabColWidths(${tab},$colnum) $width
}


# TABLEADDROW -- Add a rows to the named table at the specified position.
#
# Usage:
#		tableAddRow  <tab> <row>

proc tableAddRow { tab row args } {
    global tabRowHeights tabNrows 

    send ${tab}Tab    addRow $row $args
    send ${tab}RowTab addRow $row $args
    incr tabNrows(${tab},data)
    set tabRowHeights(${tab},$row) $tabRowHeights(${tab},default)
}


# TABLEGETNROWS -- Return the number of rows in a named table.
#
# Usage:
#		nrows = tableGetNrows  <tab>

proc tableGetNrows { tab } { 
    global tabNrows
    return $tabNrows(${tab},data)
}


# TABLEGETNCOLS -- Return the number of columns in a named table.
#
# Usage:
#		ncols = tableGetNcols  <tab>

proc tableGetNcols { tab }  { 
    global tabNcols
    return $tabNcols(${tab},data)
}


# TABLEGETHEIGHT -- Compute the height of the table given varying row heights.
#
# Usage:
#		height = tableGetHeight  <tab>

proc tableGetHeight { tab } { 
    return  [ send ${tab}Tab get height ]
}


# TABLEGETWIDTH -- Compute the width of the table given varying column widths.
#
# Usage:
#		width = tableGetWidth  <tab>

proc tableGetWidth { tab }  { 
    return  [ send ${tab}Tab get width ]
}


# TABLEGETSELECTED -- Return a list of the selected items.
#
# Usage:	list = tableGetSelected  tab type
#
# where <type> is 'Row', 'Col', or 'Cell'.

proc tableGetSelected { tab type } {
    global tabSelected
    return $tabSelected(${tab},${type})
}



# TABLESELECTROW -- User-selectable row procedure.  Row may be the string
# "all" in which case we select all rows in the table, otherwise may sure
# selection is unique.

proc tableSelectRow { tab row } {
    global tabSelected tabOption tabNrows

    set color $tabOption(${tab},HighlightColor)
    if {$row == "all"} {
	for {set i 0} {$i < $tabNrows(${tab},data)} {incr i} {
            set index [lsearch $tabSelected(${tab},Row) $row ]
	    if {$index < 0} {
	        lappend tabSelected(${tab},Row) $i
	        tableSetRowAttr ${tab} $i background $color
	        tableSetRowAttr ${tab}Row $i background $color
	    }
	}
    } else {
        set index [lsearch $tabSelected(${tab},Row) $row ]
	if {$index < 0} {
	    lappend tabSelected(${tab},Row) $row
	    tableSetRowAttr ${tab} $row background $color
	    tableSetRowAttr ${tab}Row $row background $color
	}
    }
}


# TABLESELECTCOL -- User-selectable column procedure.  Col may be the string
# "all" in which case we select all cols in the table, otherwise may sure
# selection is unique.

proc tableSelectCol { tab col } {
    global tabSelected tabOption tabNcols

    set color $tabOption(${tab},HighlightColor)
    if {$col == "all"} {
	for {set i 0} {$i < $tabNcols(${tab},data)} {incr i} {
            set index [lsearch $tabSelected(${tab},Col) $col ]
	    if {$index < 0} {
	        lappend tabSelected(${tab},Col) $i
	        tableSetColAttr ${tab} $i background $color
	        tableSetColAttr ${tab}Col $i background $color
	    }
	}
    } else {
        set index [lsearch $tabSelected(${tab},Col) $col ]
	if {$index < 0} {
	    lappend tabSelected(${tab},Col) $col
	    tableSetRowAttr ${tab} $col background $color
	    tableSetRowAttr ${tab}Col $col background $color
	}
    }
}


# TABLESELECTCELL -- User-callable cell selection procedure

proc tableSelectCell { tab col row } {
    global tabSelected tabOption

    set color $tabOption(${tab},HighlightColor)
    set index [lsearch $tabSelected(${tab},Col) [list $row $col] ]
    if {$index < 0} {
        lappend tabSelected(${tab},Cell) [list $row $col]
        tableSetCellAttr ${tab} $row $col background $color
    }
}


# TABLEUNSELECTROW -- Deselect the specified row.

proc tableUnSelectRow { tab row } {
    global tabSelected tabOption tabNrows

    set color $tabOption(${tab},Background)
    if {$row == "all"} {
	for {set i 0} {$i < $tabNrows(${tab},data)} {incr i} {
            set index [lsearch $tabSelected(${tab},Row) $i ]
	    if {$index >= 0} {
                set tabSelected(${tab},Row) \
                    [ lreplace $tabSelected(${tab},Row) $index $index ]
	        tableSetRowAttr ${tab} $i background $color
	        tableSetRowAttr ${tab}Row $i background $color
	    }
	}
    } else {
        # Delete it from the list.
        set index [lsearch $tabSelected(${tab},Row) $row ]
	if {$index >= 0} {
            set tabSelected(${tab},Row) \
                [ lreplace $tabSelected(${tab},Row) $index $index ]
            tableSetRowAttr ${tab} $row background $color
            tableSetRowAttr ${tab}Row $row background $color
	}
    }
}


# TABLEUNSELECTCOL -- Deselect the specified col.

proc tableUnSelectCol { tab col } {
    global tabSelected tabOption tabNrows

    set color $tabOption(${tab},Background)
    if {$col == "all"} {
	for {set i 0} {$i < $tabNcols(${tab},data)} {incr i} {
            set index [lsearch $tabSelected(${tab},Col) $i ]
	    if {$index >= 0} {
                set tabSelected(${tab},Col) \
                    [ lreplace $tabSelected(${tab},Col) $index $index ]
	        tableSetColAttr ${tab} $i background $color
	        tableSetColAttr ${tab}Col $i background $color
	    }
	}
    } else {
        # Delete it from the list.
        set index [lsearch $tabSelected(${tab},Col) $col ]
	if {$index >= 0} {
            set tabSelected(${tab},Col) \
                [ lreplace $tabSelected(${tab},Col) $index $index ]
            tableSetColAttr ${tab} $col background $color
            tableSetColAttr ${tab}Col $col background $color
	}
    }
}


# TABLEUNSELECTCELL -- Deselect the specified cell.

proc tableUnSelectCell { tab col row } {
    global tabSelected tabOption

    set val   [list $row $col]
    set index [lsearch $tabSelected(${tab},Cell) $val ]
    set color $tabOption(${tab},Background)

    # Delete it from the list.
    if {$index >= 0} {
        set tabSelected(${tab},Cell) \
            [ lreplace $tabSelected(${tab},Cell) $index $index ]
        tableSetCellAttr ${tab} $row $col background $color
    }
}



#==============================================================================
# TABLEDIT -- Enable the cell editor
#==============================================================================

set tabEditRow		0
set tabEditCol		0
set tabEditValue	""

set tableEditorUp	0

proc tableEdit { name x y } {
    global tabEditValue tabEditRow tabEditCol tableEditCB, tableEditorUp

    regsub Tab $name "" tab

    set ry [tablePos2CellY $tab $y]
    set rx [tablePos2CellX $tab $x]

    if {$rx < 0 || $ry < 0} \
	return
	
    set newcell 0
    if {$tabEditRow != $rx || $tabEditCol != $ry} {
	set newcell 1
    }

    set tabEditCol   [tablePos2CellX $tab $x]
    set tabEditRow   [tablePos2CellY $tab $y]
    set tabEditValue [tableGetCellAttr $tab $tabEditRow $tabEditCol label]

    if {$tableEditorUp == 0 || $newcell == 1} {
        send ${tab}EditApply  addCallback tableEditApply
        send ${tab}EditCancel addCallback tableEditCancel
        send ${tab}EditClear  addCallback tableEditClear
        send ${tab}EditText   addCallback tableEditLoad
        send ${tab}EditText set string $tabEditValue
        send ${tab}EditShell move $x [expr ($y + 50)]
        send ${tab}EditShell map
	set tableEditorUp 1
    } else {
        send ${tab}EditApply  deleteCallback tableEditApply
        send ${tab}EditCancel deleteCallback tableEditCancel
        send ${tab}EditClear  deleteCallback tableEditClear
        send ${tab}EditText   deleteCallback tableEditLoad
        send ${tab}EditShell  unmap
	set tableEditorUp 0
    }
}

proc tableEditApply { button args } {
    global tabEditValue tabEditRow tabEditCol tabEditCB tabEditorUp
    regsub EditApply $button "" tab

    set str [send ${tab}EditText get string]

    tableSetCellAttr $tab $tabEditRow $tabEditCol label $str
    set tabEditValue $str

    # Now do the user-defined selection callbacks.
    if { [llength $tabEditCB(${tab})] > 0} {
        foreach cb $tabEditCB(${tab}) {$cb $tab $tabEditRow $tabEditCol "$str"}
    }

    # Close the window.
    send ${tab}EditApply  deleteCallback tableEditApply
    send ${tab}EditCancel deleteCallback tableEditCancel
    send ${tab}EditClear  deleteCallback tableEditClear
    send ${tab}EditText   deleteCallback tableEditLoad
    send ${tab}EditShell  unmap
    set tableEditorUp 0
}

proc tableEditLoad { widget mode pattern args } {
    regsub EditText $widget "" tab
    tableEditApply ${tab}EditApply
}

proc tableEditClear { button args } { 
    global tabEditValue

    regsub EditClear $button "" tab
    send ${tab}EditText set string ""
}

proc tableEditCancel { button args } { 
    global tableEditValue tableEditorUp

    regsub EditCancel $button "" tab
    send ${tab}EditShell unmap
    send ${tab}EditApply  deleteCallback tableEditApply
    send ${tab}EditCancel deleteCallback tableEditCancel
    send ${tab}EditClear  deleteCallback tableEditClear
    send ${tab}EditText   deleteCallback tableEditLoad
    set tableEditorUp 0
}


###############################################################################
#
# Private Procedures
#
###############################################################################


# TABLEADDCALLBACKS -- Add the default widget callbacks. 

proc tableAddCallbacks { tab } {

    # Attach the scrollbars actions.
    if {[ tableOption $tab RowScroll] == "yes"} {
        send ${tab}RowScroll addCallback tableJumpScroll
    } else {
        send ${tab}RowScroll "unmap ; set width 0"
    }

    if {[ tableOption $tab ColScroll] == "yes"} {
        send ${tab}ColScroll addCallback tableJumpScroll
    } else {
        send ${tab}Label set height 0
        send ${tab}ColScroll "unmap ; set height 0"
    }

    if {[tableOption $tab Tracking] == "no"} {
	send ${tab}Label set label ""
	send ${tab}Label set width 50
    }

    # Setup a resize handler that will adjust the scrollbars/viewports.
    send ${tab}TableFrame addEventHandler tableResizeHandler structureNotifyMask
}


# TABLERESIZEHANDLER -- Resize callbacks, called as an eventHandler when
# the parent window or the table meta-widget changes size.  All we need to
# do here is reset the scrollbars to reflect the new size.

proc tableResizeHandler { table args } { 
    regsub TableFrame $table "" tab
    #tableSetDefaultScrollbars $tab no
    tableSetDefaultScrollbars $tab yes
}


# TABLETRACK -- Track the motion in the table.

proc tableTrack { name x y } {
    regsub Tab $name "" tab
    if {[ tableOption $tab Tracking] == "no"} {
	return
    }

    set nr  [tableGetNrows $tab]
    set nc  [tableGetNcols $tab]
    set col [tablePos2CellX $tab $x]
    set row [tablePos2CellY $tab $y]
    if {$col < 0 || $row < 0} {
        send ${tab}Label set label "         "
    } else {
        send ${tab}Label set label [ format "(%3d,%3d)" $row $col ]
    } 
}


# TABLESELECT -- Do the default selection callback which applies to rows,
# columns and cells.

proc tableSelect { name type x y } {
    global tabOption tabSelected tabSelectionCB tabUnSelectionCB


    regsub Row $name  "" rc
    regsub Col $name  "" cc

    if {$type == "Row"} {
        if {$rc == $name || [ tableOption $name RowSelect ] == "no"} \
	    return
        regsub ${type}Tab $name "" tab
        set col [tablePos2CellX $tab $x]
        set row [tablePos2CellY $tab $y]
        set val $row
    } elseif {$type == "Col"} {
        if {$cc == $name || [ tableOption $name ColSelect ] == "no"} \
	    return
        regsub ${type}Tab $name "" tab
        set col [tablePos2CellX $tab $x]
        set row [tablePos2CellY $tab $y]
        set val $col
    } elseif {$type == "Cell"} {
        if {$rc != $name && $cc != $name} \
	    return
        if {[ tableOption $name CellSelect ] == "no"} \
	    return
        regsub Tab $name "" tab
        set col [tablePos2CellX $tab $x]
        set row [tablePos2CellY $tab $y]
        set val [list $row $col]
    }
    
    if {$col < 0 || $row < 0} \
	return

    set index [ lsearch $tabSelected(${tab},${type}) $val ]
    set color $tabOption(${tab},HighlightColor)
	
    # If we're doing a radio selection, turn off anything already selected.
    
    if {[ tableOption $tab ${type}MultiSelect] == "no"} {
	if { [llength $tabSelected(${tab},${type})] == 1} {
            tableSet${type}Attr ${tab} \
		[lindex $tabSelected(${tab},${type}) 0] \
	        background $tabOption(${tab},Background)
            tableSet${type}Attr ${tab}${type} \
		[lindex $tabSelected(${tab},${type}) 0] \
	        background $tabOption(${tab},Background)

	    # Now do the user-defined un-selection callbacks.
	    if { [llength $tabUnSelectionCB(${tab},${type})] > 0} {
	        foreach cb $tabUnSelectionCB(${tab},${type}) { 
		    $cb $tab $row $col $x $y 0
		}
	    }

	    set tabSelected(${tab},${type}) [list $val ]

	    if {$type == "Row"} {
		foreach c $tabSelected(${tab},Col) {
                    tableSetColAttr ${tab} $c background $color
		}
	    } elseif {$type == "Col"} {
		foreach c $tabSelected(${tab},Row) {
                    tableSetRowAttr ${tab} $c background $color
		}
	    }
	} else {
            lappend tabSelected(${tab},${type}) $val
	}
    } else {
        if { $index < 0} {
            lappend tabSelected(${tab},${type}) $val
	}
    }

    # If this has already been selected, toggle it.
    if { $index >= 0} {
	if {$type != "Cell"} {
            tableSet${type}Attr ${tab} \
	        [lindex $tabSelected(${tab},${type}) $index] \
	        background $tabOption(${tab},Background)
            tableSet${type}Attr ${tab}${type} \
	        [lindex $tabSelected(${tab},${type}) $index] \
	        background $tabOption(${tab},Background)

	    # Now do the user-defined un-selection callbacks.
	    if { [llength $tabUnSelectionCB(${tab},${type})] > 0} {
	        foreach cb $tabUnSelectionCB(${tab},${type}) { 
		    $cb $tab $row $col $x $y 0
		}
	    }

	} else {
            tableSet${type}Attr ${tab} \
	        $row $col background $tabOption(${tab},Background)

	    # Now do the user-defined selection callbacks.
	    if { [llength $tabUnSelectionCB(${tab},${type})] > 0} {
	        foreach cb $tabUnSelectionCB(${tab},${type}) { 
		    $cb $tab $row $col $x $y 0
		}
	    }
	}

	# Delete it from the list
	set tabSelected(${tab},${type}) \
	    [ lreplace $tabSelected(${tab},${type}) $index $index ]

	# Go back and re-select the row/col intersection but don't 
	# generate an event for it, purely cosmetic.
	if {$type == "Row"} {
	    foreach c $tabSelected(${tab},Col) {
                tableSetColAttr ${tab} $c background $color
	    }
	} elseif {$type == "Col"} {
	    foreach c $tabSelected(${tab},Row) {
                tableSetRowAttr ${tab} $c background $color
	    }
	}

    } else {

        # Highlight the selected item.
	if {$type != "Cell"} {
            tableSet${type}Attr ${tab} $val background $color
            tableSet${type}Attr ${tab}${type} $val background $color
	} else {
            tableSet${type}Attr ${tab} $row $col background $color
	}

        # Now do the user-defined selection callbacks.
        if { [llength $tabSelectionCB(${tab},${type})] > 0} {
            foreach cb $tabSelectionCB(${tab},${type}) { 
	        $cb $tab $row $col $x $y 1
	    }
        }
    }
}


# TABLESETDEFAULTLABELS -- Set the default labels for the table, i.e. letters
# for columns headings and numbers for the row labels.
#
#  Usage:	
#	    tableSetDefaultLabels  <tab>

proc tableSetDefaultLabels { tab } {
    # Set the default Row labels, i.e numbers
    tableSetDefaultRowLabels $tab

    # Now set the default Column Labels, i.e. letters
    tableSetDefaultColLabels $tab
}
    

# TABLESETDEFAULTTRANSLATIONS -- Set the default translations for the widget.

proc tableSetDefaultTranslations { tab } {

    if {[ tableOption $tab DefaultTranslations ] == "no"} {
	return
    }

    # Set the coord tracking translations.
    set trans1 ""
    if {[ tableOption $tab Tracking ] == "yes"} {
	set trans1 { \
	    <Motion>:call(tableTrack,$name,$x,$y)
	}
    }
		
    set trans2 ""
    if {[ tableOption $tab CellSelect ] == "yes"} {
	set trans2 { \
	    <Btn1Down>:call(tableSelect,$name,Cell,$x,$y)
	}
    }
		
    set trans3 ""
    if {[ tableOption $tab Editable ] == "yes"} {
	set trans3 { \
	    <Btn3Down>:call(tableEdit,$name,$x,$y)
	}
    }
    set trans "$trans1 $trans2 $trans3"
    send ${tab}Tab set translations $trans


    # Set the row-selectable translations.
    if {[ tableOption $tab RowSelect ] == "yes"} {
        send ${tab}RowTab set translations \
	    "<Btn1Down>: call(tableSelect,\$name,Row,\$x,\$y)"
    }

    # Set the col-selectable translations.
    if {[ tableOption $tab ColSelect ] == "yes"} {
        send ${tab}ColTab set translations \
	    "<Btn1Down>: call(tableSelect,\$name,Col,\$x,\$y)"
    }
}


# TABLESETDEFAULTSCROLLBARS -- Set the default scrollbar position and size
# in the meta-widget.

proc tableSetDefaultScrollbars { tab init } {
    global tabHeight tabWidth tabScrollSize tabScrollPos tabDebug
    global tabNcols tabNrows tabColWidths


    set visW [ send ${tab}TabView get width]
    set visH [ send ${tab}TabView get height]
    set rh   [ send ${tab}Tab get rowHeight]
    set sw   [ send ${tab}Tab get shadowWidth]
    set th   [expr ($tabNrows(${tab},data) * ($rh + (2 * $sw)) )]
    set tw    0
    for {set i 1} {$i <= $tabNcols(${tab},data)} {incr i} {
	set  w $tabColWidths(${tab},$i)
	set tw [ expr ($tw + $w + (2 * $sw)) ]
    }
    set rowS [max 0.0 [min 1.0 [expr (double($visH)/double($th)) ]]]
    set colS [max 0.0 [min 1.0 [expr (double($visW)/double($tw)) ]]]
#print "defScroll: data visW=$visW  visH=$visH  th=$th  tw=$tw"
#print "defScroll: ($tab,$init)  rowS = $rowS   colS = $colS"
			
    set tabScrollSize($tab,row) $rowS
    set tabScrollSize($tab,col) $colS
    set tabScrollPos($tab,row)  0.0
    set tabScrollPos($tab,col)  0.0

    if {[ tableOption $tab RowScroll] == "yes"} {
        send ${tab}RowScroll setScrollbar 0.0 $tabScrollSize($tab,row)
    }
    if {[ tableOption $tab ColScroll] == "yes"} {
        send ${tab}ColScroll setScrollbar 0.0 $tabScrollSize($tab,col)
    }

    if {$init == "yes"} {
	send ${tab}TabView    setLocation 0.0 0.0
	send ${tab}ColTabView setLocation 0.0 0.0
	send ${tab}RowTabView setLocation 0.0 0.0
    }
}


# TABLEJUMPSCROLL -- Scroll the specified table.  This scrolls both the
# data and row/column label tables.

proc tableJumpScroll { widget cbtype pos } {
    global scrollHeight tabWidth tabHeight tabDebug
    global tabScrollSize tabScrollPos tabDebug

    if {$pos < 0.01} { 
	set pos 0.0 
    }

    if { [string match *ColScroll $widget] } {
	regsub ColScroll $widget "" tab
	set y $tabScrollPos($tab,row)
        send ${tab}TabView    setLocation $pos $y
        send ${tab}ColTabView setLocation $pos 0.0
	set tabScrollPos($tab,col) $pos

    } elseif { [string match *RowScroll $widget] } {
	regsub RowScroll $widget "" tab
	set x $tabScrollPos($tab,col)
        send ${tab}TabView    setLocation $x  $pos
        send ${tab}RowTabView setLocation 0.0 $pos
	set tabScrollPos($tab,row) $pos
    }
}


# TABLEOPTION -- Return any defined table option.

proc tableOption { tab option } {
    global tabOption

    set val yes
    catch { 
	if {[info exists tabOption(${tab},${option}) ]} { 
	    if { $tabOption(${tab},${option}) } { 
		set val yes 
	    } else {
		set val no 
	    }
	} 
    } err 

    return $val
}


# TABLEPOS2CELLX -- Convert a widget position to a cell column number.

proc tablePos2CellX { tab x } {
    global tabColWidths tabNcols 

    set nc [ tableGetNcols $tab ]
    set cellX 1
    for {set w 0} {$w < $x && $cellX <= $nc} {incr cellX} {
	set w [ expr ($w + $tabColWidths($tab,$cellX) + 3) ]
    }
    if {$x > $w} {
	return -1
    } else {
        return [ min [incr cellX -1] $tabNcols(${tab},data) ]
    }
}

# TABLEPOS2CELLY -- Convert a widget position to a cell row number.

proc tablePos2CellY { tab y } {
    global tabRowHeights tabNrows 

    set nr [ tableGetNrows $tab ]
    set cellY 1
    for {set h 0} {$h < $y && $cellY <= $nr} {incr cellY} {
	set h [ expr ($h + $tabRowHeights($tab,$cellY)) + 2 ]
    }
    if {$y > $h} {
	return -1
    } else {
        return [ min [incr cellY -1] $tabNrows(${tab},data) ]
    }
}


# TABLESETDEFAULTROWLABELS  -- Utility to set the default row labels.

proc tableSetDefaultRowLabels { tab args } {
    global tabNrows tabOption

    # Set the default Row labels, i.e numbers
    set rowlabs {}
    for {set i 1} {$i <= $tabNrows(${tab},data)} {incr i} {
	if {[ tableOption $tab DefLabels ] == "yes"} {
	    lappend rowlabs $i
        } else {
	    lappend rowlabs {}
        }
    }
    if {[ tableOption $tab RowLabels ] == "yes"} {
    	send ${tab}RowTab setTable $tabNrows(${tab},data) \
            $tabOption(${tab},RowLabelCols) $rowlabs
	set cw [send ${tab}RowTab get defaultWidth]
	send ${tab}RowTabView set width \
	    [expr ($tabOption(${tab},RowLabelCols) * $cw)]
    } else {
    	send ${tab}RowTab set width 0
    }
}


# TABLESETDEFAULTCOLLABELS -- Utility to set the default columns labels.

proc tableSetDefaultColLabels { tab args } {
    global tabNcols tabOption

    # Now set the default Column Labels, i.e. letters
    set collabs ""
    set j 65
    for {set i 1} {$i <= $tabNcols(${tab},data)} {incr i} {
	if {[ tableOption $tab DefLabels ] == "yes"} {
	    if {$j > 90} {
		set j 97
		set collabs [ format "%s { %c } " $collabs $j ]
	    } elseif {$j > 122} {
		set j 1
		set collabs [ format "%s { %d } " $collabs $j ]
	    } else {
		set collabs [ format "%s { %c } " $collabs $j ]
	    }
	    incr j
        } else {
	    lappend collabs {}
        }
    }
    if {[ tableOption $tab ColLabels ] == "yes"} {
        send ${tab}ColTab setTable $tabOption(${tab},ColLabelRows) \
	    $tabNcols(${tab},data) [ list $collabs ]
	send ${tab}ColTabView set height \
	    [expr ($tabOption(${tab},ColLabelRows) * 21)]
	send ${tab}Spacer1 set height \
	    [expr ($tabOption(${tab},ColLabelRows) * 24)]
	send ${tab}Spacer2 set height \
	    [expr ($tabOption(${tab},ColLabelRows) * 24)]
    } else {
        send ${tab}ColTab set height 0
    }
}


################################################################################


################################################################################



activate


appExtend {
    *tclObjects:\
	toplevel	TopLevelShell   tcl_panel\
	tcl_panel  	Layout		tclLayout\
	tclLayout  	Group		tclCmdGroup\
	tclCmdGroup  	Layout	 	tclCmd\
	tclCmd	 	Command	 	tclClear\
	tclCmd	 	Command	 	tclExecute\
	tclCmd	 	Command	 	tclDismiss\
	tclLayout  	Frame	 	tclFrame\
	tclFrame	AsciiText  	tclEntry


    !--------------------------------
    ! Define a debug Tcl shell.
    !--------------------------------
    *tcl_panel.width:                           550
    *tcl_panel.height:                          180
    *tcl_panel.title:                           Debug TCL Command Entry
    *tclLayout*borderWidth:                     0
    *tclLayout*shrinkToFit:			True
    *tclLayout*Frame.frameType:                 sunken
    *tclLayout*Frame.frameWidth:                2
    *tclLayout.layout:  vertical { \
        tclCmdGroup < +inf -inf * > \
        tclFrame < +inf -inf * +inf -inf> \
    }
    *tclEntry*foreground:                       black
    *tclEntry*editType:                         edit
    *tclEntry*type:                             string
    *tclEntry*font:				7x13
    *tclEntry*scrollVertical:                   Always
    *tclEntry*scrollHorizontal:                 whenNeeded

    *tclCmdGroup.label:         
    *tclCmdGroup.outerOffset:                   0
    *tclCmdGroup.innerOffset:                   0
    *tclCmd.layout: vertical { \
        5 \
        horizontal { 5 tclClear 3 tclExecute 10 < +inf -10> tclDismiss 5 } \
        5 \
    }
    *tclClear.label:                            Clear
    *tclExecute.label:                          Execute
    *tclDismiss.label:                          Dismiss

} ; createObjects tclObjects



################################################
# Define some TCL debug procedures.
################################################

proc tclCommandClear {widget args} {
    send tclEntry set string ""
} ; send tclClear addCallback tclCommandClear

proc tclCommandExecute {widget args} {
    send server [send tclEntry {get string}]
} ; send tclExecute addCallback tclCommandExecute

proc tclCommand {widget mode command args} {
    send server $command
} ; send tclEntry   addCallback tclCommand

proc tclClose {widget args} {
    send tcl_panel unmap
} ; send tclDismiss addCallback tclClose

send tclShell addCallback "send tcl_panel map"