This file is indexed.

/usr/share/tcltk/iwidgets4.1.0/scripts/menubar.itk is in iwidgets4 4.1.0-1.

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

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
#
# Menubar widget
# ----------------------------------------------------------------------
# The Menubar command creates a new window (given by the pathName 
# argument) and makes it into a Pull down menu widget. Additional 
# options, described above may be specified on the command line or 
# in the option database to configure aspects of the Menubar such 
# as its colors and font. The Menubar command returns its pathName 
# argument. At the time this command is invoked, there must not exist 
# a window named pathName, but pathName's parent must exist.
# 
# A Menubar is a widget that simplifies the task of creating 
# menu hierarchies. It encapsulates a frame widget, as well 
# as menubuttons, menus, and menu entries. The Menubar allows 
# menus to be specified and refer enced in a more consistent 
# manner than using Tk to build menus directly. First, Menubar
# allows a menu tree to be expressed in a hierachical "language". 
# The Menubar accepts a menuButtons option that allows a list of 
# menubuttons to be added to the Menubar. In turn, each menubutton
# accepts a menu option that spec ifies a list of menu entries 
# to be added to the menubutton's menu (as well as an option 
# set for the menu).   Cascade entries in turn, accept a menu 
# option that specifies a list of menu entries to be added to 
# the cascade's menu (as well as an option set for the menu). In 
# this manner, a complete menu grammar can be expressed to the 
# Menubar. Additionally, the Menubar allows each component of 
# the Menubar system to be referenced by a simple componentPathName 
# syntax. Finally, the Menubar extends the option set of menu 
# entries to include the helpStr option used to implement status 
# bar help.
#
# WISH LIST:
#   This section lists possible future enhancements.
#
# ----------------------------------------------------------------------
#  AUTHOR: Bill W. Scott
#
#  CURRENT MAINTAINER: Chad Smith --> csmith@adc.com or itclguy@yahoo.com
#
#  @(#) $Id: menubar.itk,v 1.8 2001/08/15 18:33:13 smithc Exp $
# ----------------------------------------------------------------------
#            Copyright (c) 1995 DSC Technologies Corporation
# ======================================================================
# Permission to use, copy, modify, distribute and license this software 
# and its documentation for any purpose, and without fee or written 
# agreement with DSC, is hereby granted, provided that the above copyright 
# notice appears in all copies and that both the copyright notice and 
# warranty disclaimer below appear in supporting documentation, and that 
# the names of DSC Technologies Corporation or DSC Communications 
# Corporation not be used in advertising or publicity pertaining to the 
# software without specific, written prior permission.
# 
# DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-
# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE
# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, 
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL 
# DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 
# SOFTWARE.
# ======================================================================


#
# Usual options.
#
itk::usual Menubar {
    keep -activebackground -activeborderwidth -activeforeground \
	    -anchor -background -borderwidth -cursor -disabledforeground \
	    -font -foreground -highlightbackground -highlightthickness \
	    -highlightcolor -justify -padx -pady -wraplength
}

itcl::class iwidgets::Menubar {
    inherit itk::Widget

    constructor { args } {}

    itk_option define -foreground foreground Foreground Black
    itk_option define -activebackground activeBackground Foreground "#ececec"
    itk_option define -activeborderwidth activeBorderWidth BorderWidth 2 
    itk_option define -activeforeground activeForeground Background black
    itk_option define -anchor anchor Anchor center
    itk_option define -borderwidth borderWidth BorderWidth 2
    itk_option define \
	    -disabledforeground disabledForeground DisabledForeground #a3a3a3 
    itk_option define \
	    -font font Font "-Adobe-Helvetica-Bold-R-Normal--*-120-*-*-*-*-*-*"
    itk_option define \
	    -highlightbackground highlightBackground HighlightBackground #d9d9d9
    itk_option define -highlightcolor highlightColor HighlightColor Black
    itk_option define \
	    -highlightthickness highlightThickness HighlightThickness 0
    itk_option define -justify justify Justify center
    itk_option define -padx padX Pad 4p
    itk_option define -pady padY Pad 3p
    itk_option define -wraplength wrapLength WrapLength 0
    itk_option define -menubuttons menuButtons MenuButtons {}
    itk_option define -helpvariable helpVariable HelpVariable {}

    public {
	method add { type path args } { }
	method delete { args } { }
	method index { path } { }
	method insert { beforeComponent type name args }
	method invoke { entryPath } { }
	method menucget { args } { }
	method menuconfigure { path args } { }
	method path { args } { }
	method type { path } { }
	method yposition { entryPath } { }
    }

    private {
	method menubutton { menuName args } { }
	method options { args } { }
	method command { cmdName args } { }
	method checkbutton { chkName args } { }
	method radiobutton { radName args } { }
	method separator { sepName args } { }
	method cascade { casName args } { }
	method _helpHandler { menuPath } { }
	method _addMenuButton { buttonName args} { }
	method _insertMenuButton { beforeMenuPath buttonName args} { }
	method _makeMenuButton {buttonName args} { }
	method _makeMenu \
	    { componentName widgetName menuPath menuEvalStr } { }
	method _substEvalStr { evalStr } { }
	method _deleteMenu { menuPath {menuPath2 {}} } { }
	method _deleteAMenu { path } { }
	method _addEntry { type path args } { }
	method _addCascade { tkMenuPath path args } { }
	method _insertEntry { beforeEntryPath type name args } { }
	method _insertCascade { bfIndex tkMenuPath path args } { }
	method _deleteEntry { entryPath {entryPath2 {}} } { }
	method _configureMenu { path tkPath {option {}} args } { }
	method _configureMenuOption { type path args } { }
	method _configureMenuEntry { path index {option {}} args } { }
	method _unsetPaths { parent } { }
	method _entryPathToTkMenuPath {entryPath} { }
	method _getTkIndex { tkMenuPath tkIndex} { }
	method _getPdIndex { tkMenuPath tkIndex } { }
	method _getMenuList { } { }
	method _getEntryList { menu } { }
	method _parsePath { path } { }
	method _getSymbolicPath { parent segment } { }
	method _getCallerLevel { }

	variable _parseLevel 0        ;# The parse level depth
	variable _callerLevel #0      ;# abs level of caller
	variable _pathMap             ;# Array indexed by Menubar's path
                                      ;# naming, yields tk menu path
	variable _entryIndex -1       ;# current entry help is displayed
                                      ;# for during help <motion> events

	variable _tkMenuPath          ;# last tk menu being added to
	variable _ourMenuPath         ;# our last valid path constructed.

	variable _menuOption          ;# The -menu option
	variable _helpString          ;# The -helpstr optio
    }
}

#
# Use option database to override default resources.
#
option add *Menubar*Menu*tearOff         false        widgetDefault
option add *Menubar*Menubutton*relief    flat         widgetDefault
option add *Menubar*Menu*relief          raised       widgetDefault

#
# Provide a lowercase access method for the menubar class
#
proc ::iwidgets::menubar { args } {
    uplevel ::iwidgets::Menubar $args
}

# ------------------------------------------------------------------
#                           CONSTRUCTOR
# ------------------------------------------------------------------
itcl::body iwidgets::Menubar::constructor { args } {
    component hull configure -borderwidth 0

    #
    # Create the Menubar Frame that will hold the menus.
    #
    # might want to make -relief and -bd options with defaults
    itk_component add menubar {
	frame $itk_interior.menubar -relief raised -bd 2
    } {
	keep -cursor -background -width -height
    }
    pack $itk_component(menubar) -fill both -expand yes

    # Map our pathname to class to the actual menubar frame
    set _pathMap(.) $itk_component(menubar)

    eval itk_initialize $args

    #
    # HACK HACK HACK
    # Tk expects some variables to be defined and due to some
    # unknown reason we confuse its normal ordering. So, if
    # the user creates a menubutton with no menu it will fail
    # when clicked on with a "Error: can't read $tkPriv(oldGrab):
    # no such element in array". So by setting it to null we
    # avoid this error.
    uplevel #0 "set tkPriv(oldGrab) {}"

}

# ------------------------------------------------------------------
#                           OPTIONS
# ------------------------------------------------------------------
# This first set of options are for configuring menus and/or menubuttons
# at the menu level.
#
# ------------------------------------------------------------------
# OPTION -foreground
#
# menu
# menubutton
# ------------------------------------------------------------------
itcl::configbody iwidgets::Menubar::foreground {
}

# ------------------------------------------------------------------
# OPTION -activebackground
#
# menu
# menubutton
# ------------------------------------------------------------------
itcl::configbody iwidgets::Menubar::activebackground {
}

# ------------------------------------------------------------------
# OPTION -activeborderwidth
#
# menu
# ------------------------------------------------------------------
itcl::configbody iwidgets::Menubar::activeborderwidth {
}

# ------------------------------------------------------------------
# OPTION -activeforeground
#
# menu
# menubutton
# ------------------------------------------------------------------
itcl::configbody iwidgets::Menubar::activeforeground {
}

# ------------------------------------------------------------------
# OPTION -anchor
#
# menubutton
# ------------------------------------------------------------------
itcl::configbody iwidgets::Menubar::anchor {
}

# ------------------------------------------------------------------
# OPTION -borderwidth
#
# menu
# menubutton
# ------------------------------------------------------------------
itcl::configbody iwidgets::Menubar::borderwidth {
}

# ------------------------------------------------------------------
# OPTION -disabledforeground
#
# menu
# menubutton
# ------------------------------------------------------------------
itcl::configbody iwidgets::Menubar::disabledforeground {
}

# ------------------------------------------------------------------
# OPTION -font
#
# menu
# menubutton
# ------------------------------------------------------------------
itcl::configbody iwidgets::Menubar::font {
}

# ------------------------------------------------------------------
# OPTION -highlightbackground
#
# menubutton
# ------------------------------------------------------------------
itcl::configbody iwidgets::Menubar::highlightbackground {
}

# ------------------------------------------------------------------
# OPTION -highlightcolor
#
# menubutton
# ------------------------------------------------------------------
itcl::configbody iwidgets::Menubar::highlightcolor {
}

# ------------------------------------------------------------------
# OPTION -highlightthickness
#
# menubutton
# ------------------------------------------------------------------
itcl::configbody iwidgets::Menubar::highlightthickness {
}

# ------------------------------------------------------------------
# OPTION -justify
#
# menubutton
# ------------------------------------------------------------------
itcl::configbody iwidgets::Menubar::justify {
}

# ------------------------------------------------------------------
# OPTION -padx
#
# menubutton
# ------------------------------------------------------------------
itcl::configbody iwidgets::Menubar::padx {
}

# ------------------------------------------------------------------
# OPTION -pady
#
# menubutton
# ------------------------------------------------------------------
itcl::configbody iwidgets::Menubar::pady {
}

# ------------------------------------------------------------------
# OPTION -wraplength
#
# menubutton
# ------------------------------------------------------------------
itcl::configbody iwidgets::Menubar::wraplength {
}

# ------------------------------------------------------------------
# OPTION -menubuttons
#
# The menuButton option is a string which specifies the arrangement 
# of menubuttons on the Menubar frame. Each menubutton entry is 
# delimited by the newline character. Each entry is treated as 
# an add command to the Menubar. 
#
# ------------------------------------------------------------------
itcl::configbody iwidgets::Menubar::menubuttons {
    if { $itk_option(-menubuttons) != {} } {

	# IF one exists already, delete the old one and create
	# a new one
	if { ! [catch {_parsePath .0}] } {
	    delete .0 .last
	} 

	#
	# Determine the context level to evaluate the option string at
	#
	set _callerLevel [_getCallerLevel]

	#
	# Parse the option string in their scope, then execute it in
	# our scope.
	#
	incr _parseLevel
	_substEvalStr itk_option(-menubuttons)
	eval $itk_option(-menubuttons)

	# reset so that we know we aren't parsing in a scope currently.
	incr _parseLevel -1
    }
}

# ------------------------------------------------------------------
# OPTION -helpvariable
#
# Specifies the global variable to update whenever the mouse is in 
# motion over a menu entry. This global variable is updated with the 
# current value of the active menu entry's helpStr. Other widgets 
# can "watch" this variable with the trace command, or as is the 
# case with entry or label widgets, they can set their textVariable 
# to the same global variable. This allows for a simple implementation 
# of a help status bar. Whenever the mouse leaves a menu entry, 
# the helpVariable is set to the empty string {}.
# ------------------------------------------------------------------
itcl::configbody iwidgets::Menubar::helpvariable {
    if {"" != $itk_option(-helpvariable) &&
	![string match ::* $itk_option(-helpvariable)] &&
        ![string match @itcl* $itk_option(-helpvariable)]} {
        set itk_option(-helpvariable) "::$itk_option(-helpvariable)"
    }
}


# -------------------------------------------------------------
#
# METHOD: add type path args
#
# Adds either a menu to the menu bar or a menu entry to a
# menu pane.
#
# If the type is one of  cascade,  checkbutton,  command,
# radiobutton,  or separator it adds a new entry to the bottom
# of the menu denoted by the menuPath prefix of componentPath-
# Name.  The  new entry's type is given by type. If additional
# arguments are present, they  specify  options  available  to
# component  type  Entry. See the man pages for menu(n) in the
# section on Entries. In addition all entries accept an  added
# option, helpStr:
#
#     -helpstr value
#
# Specifes the string to associate with  the  entry.
# When the mouse moves over the associated entry, the variable
# denoted by helpVariable is set. Another widget can  bind  to
# the helpVariable and thus display status help.
#
# If the type is menubutton, it adds a new  menubut-
# ton  to  the  menu bar. If additional arguments are present,
# they specify options available to component type MenuButton.
#
# If the type is menubutton  or  cascade,  the  menu
# option  is  available  in  addition to normal Tk options for
# these to types.
#
#      -menu menuSpec
#
# This is only valid for componentPathNames of  type
# menubutton  or  cascade. Specifes an option set and/or a set
# of entries to place on a menu and associate with  the  menu-
# button or cascade. The option keyword allows the menu widget
# to be configured. Each item in the menuSpec  is  treated  as
# add  commands  (each  with  the  possibility of having other
# -menu options). In this way a menu can be recursively built.
#
# The last segment of  componentPathName  cannot  be
# one  of  the  keywords last, menu, end. Additionally, it may
# not be a number. However the componentPathName may be refer-
# enced  in  this  manner  (see  discussion  of Component Path
# Names).
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::add { type path args } {
    if ![regexp \
            {^(menubutton|command|cascade|separator|radiobutton|checkbutton)$} \
            $type] {
        error "bad type \"$type\": must be one of the following:\
            \"command\", \"checkbutton\", \"radiobutton\",\
            \"separator\", \"cascade\", or \"menubutton\""
    }
    regexp {[^.]+$} $path segName
    if [regexp {^(menu|last|end|[0-9]+)$} $segName] {
        error "bad name \"$segName\": user created component \
                path names may not end with \
		\"end\", \"last\", \"menu\", \
                or be an integer"
    }

    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # OK, either add a menu
    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
    if { $type == "menubutton" } {
	# grab the last component name (the menu name)
	eval _addMenuButton $segName $args
	# ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
	# Or add an entry
	# '''''''''''''''''''''''''''''''''''''''''''''''''''''
    } else {
	eval _addEntry $type $path $args
    }
}


# -------------------------------------------------------------
#
# METHOD: delete entryPath ?entryPath2?
#
# If componentPathName is of component type MenuButton or
# Menu,  delete  operates  on menus. If componentPathName is of
# component type Entry, delete operates on menu entries.
#
# This  command  deletes  all  components  between   com-
# ponentPathName  and  componentPathName2  inclusive.  If com-
# ponentPathName2  is  omitted  then  it  defaults   to   com-
# ponentPathName. Returns an empty string.
#
# If componentPathName is of type Menubar, then all menus
# and  the menu bar frame will be destroyed. In this case com-
# ponentPathName2 is ignored.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::delete { args } {

    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Handle out of bounds in arg lengths
    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
    if { [llength $args] > 0 && [llength $args] <=2 } {

	# Path Conversions
	# '''''''''''''''''''''''''''''''''''''''''''''''''''''
	set path [_parsePath [lindex $args 0]]

	set pathOrIndex $_pathMap($path)

	# Menu Entry
	# '''''''''''''''''''''''''''''''''''''''''''''''''''''
	if { [regexp {^[0-9]+$} $pathOrIndex] } {
	    eval "_deleteEntry $args"

	    # Menu
	    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
	} else {
	    eval "_deleteMenu $args"
	}
    } else {
	error "wrong # args: should be \
		\"$itk_component(hull) delete pathName ?pathName2?\""
    }
    return ""
}

# -------------------------------------------------------------
#
# METHOD: index path
#
# If componentPathName is of type menubutton or menu,  it
# returns  the  position of the menu/menubutton on the Menubar
# frame.
#
# If componentPathName is  of  type  command,  separator,
# radiobutton,  checkbutton,  or  cascade, it returns the menu
# widget's numerical index for the entry corresponding to com-
# ponentPathName. If path is not found or the Menubar frame is
# passed in, -1 is returned.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::index { path } {

    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Path conversions
    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
    if { [catch {set fullPath [_parsePath $path]} ] } {
	return -1
    }
    if { [catch {set tkPathOrIndex $_pathMap($fullPath)} ] } {
	return -1
    }

    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # If integer, return the value, otherwise look up the menu position
    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
    if { [regexp {^[0-9]+$} $tkPathOrIndex] } {
	set index $tkPathOrIndex
    } else {
	set index [lsearch [_getMenuList] $fullPath]
    }

    return $index
}

# -------------------------------------------------------------
#
# METHOD: insert beforeComponent type name ?option value?
#
# Insert a new component named name before the  component
# specified by componentPathName.
#
# If componentPathName is of type MenuButton or Menu, the
# new  component  inserted  is of type Menu and given the name
# name. In this  case  valid  option  value  pairs  are  those
# accepted by menubuttons.
#
# If componentPathName is of type  Entry,  the  new  com-
# ponent inserted is of type Entry and given the name name. In
# this case valid option value pairs  are  those  accepted  by
# menu entries.
#
# name cannot be one of the  keywords  last,  menu,  end.
# dditionally,  it  may  not  be  a  number. However the com-
# ponentPathName may be referenced in this manner (see discus-
# sion of Component Path Names).
#
# Returns -1 if the menubar frame is passed in.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::insert { beforeComponent type name args } {
     if ![regexp \
            {^(menubutton|command|cascade|separator|radiobutton|checkbutton)$} \
            $type] {
        error "bad type \"$type\": must be one of the following:\
 		\"command\", \"checkbutton\", \"radiobutton\",\
 		\"separator\", \"cascade\", or \"menubutton\""
    }
    regexp {[^.]+$} $name segName
    if [regexp {^(menu|last|end|[0-9]+)$} $segName] {
	error "bad name \"$name\": user created component \
		path names may not end with \
		\"end\", \"last\", \"menu\", \
		or be an integer"
    }

    set beforeComponent [_parsePath $beforeComponent]

    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Choose menu insertion or entry insertion
    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
    if { $type == "menubutton" } {
	eval _insertMenuButton $beforeComponent $name $args
    } else {
	eval _insertEntry $beforeComponent $type $name $args
    }
}


# -------------------------------------------------------------
#
# METHOD: invoke entryPath
#
# Invoke  the  action  of  the  menu  entry  denoted   by
# entryComponentPathName.  See  the sections on the individual
# entries in the menu(n) man pages. If the menu entry is  dis-
# abled  then  nothing  happens.  If  the  entry has a command
# associated with it  then  the  result  of  that  command  is
# returned  as the result of the invoke widget command. Other-
# wise the result is an empty string.
#
# If componentPathName is not a menu entry, an  error  is
# issued.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::invoke { entryPath } {

    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Path Conversions
    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
    set entryPath [_parsePath $entryPath]
    set index $_pathMap($entryPath)

    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Error Processing
    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
    # first verify that beforeEntryPath is actually a path to
    # an entry and not to menu, menubutton, etc.
    if { ! [regexp {^[0-9]+$} $index] } {
	error "bad entry path: beforeEntryPath is not an entry"
    }

    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Call invoke command
    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
    # get the tk menu path to call
    set tkMenuPath [_entryPathToTkMenuPath $entryPath]

    # call the menu's invoke command, adjusting index based on tearoff
    $tkMenuPath invoke [_getTkIndex $tkMenuPath $index]
}

# -------------------------------------------------------------
#
# METHOD: menucget componentPath option
#
# Returns the current value of the  configuration  option
# given  by  option.  The  component type of componentPathName
# determines the valid available options.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::menucget { path opt } {
    return [lindex [menuconfigure $path $opt] 4]
}

# -------------------------------------------------------------
#
# METHOD: menuconfigure componentPath ?option? ?value option value...?
#
# Query or modify the configuration options of  the  sub-
# component  of the Menubar specified by componentPathName. If
# no option is specified, returns a list describing all of the
# available     options     for     componentPathName     (see
# Tk_ConfigureInfo for  information  on  the  format  of  this
# list).  If  option is specified with no value, then the com-
# mand returns a list describing the one  named  option  (this
# list  will  be identical to the corresponding sublist of the
# value returned if no option is specified). If  one  or  more
# option-value  pairs are specified, then the command modifies
# the given widget option(s) to have the  given  value(s);  in
# this case the command returns an empty string. The component
# type of componentPathName  determines  the  valid  available
# options.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::menuconfigure { path args } {

    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Path Conversions
    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
    set path [_parsePath $path]
    set tkPathOrIndex $_pathMap($path)

    # Case: Menu entry being configured
    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
    if { [regexp {^[0-9]+$} $tkPathOrIndex] } {
	eval "_configureMenuEntry $path $tkPathOrIndex $args"

	# Case: Menu (button and pane) being configured.
	# '''''''''''''''''''''''''''''''''''''''''''''''''''''
    } else {
	eval _configureMenu $path $tkPathOrIndex $args
    }
}

# -------------------------------------------------------------
#
# METHOD: path
#
# SYNOPIS: path ?<mode>? <pattern>
#
# Returns a fully formed component path that matches pat-
# tern.  If no match is found it returns -1. The mode argument
# indicates how the search is to be  matched  against  pattern
# and it must have one of the following values:
#
#     -glob     Pattern is a glob-style pattern which is
#       matched  against each component path using the same rules as
#       the string match command.
#
#     -regexp   Pattern is treated as a regular  expression  
#       and matched against each component path using the same
#       rules as the regexp command.
#
# The default mode is -glob.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::path { args } {

    set len [llength $args]
    if { $len < 1 || $len > 2 } {
	error "wrong # args: should be \
		\"$itk_component(hull) path ?mode?> <pattern>\""
    }

    set pathList [array names _pathMap]

    set len [llength $args]
    switch -- $len {
	1 {
	    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
	    # Case: no search modes given
	    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
	    set pattern [lindex $args 0]
	    set found [lindex $pathList [lsearch -glob $pathList $pattern]]
	} 
	2 {
	    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
	    # Case: search modes present (-glob, -regexp)
	    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
	    set options [lindex $args 0]
	    set pattern [lindex $args 1]
	    set found \
		    [lindex $pathList [lsearch $options $pathList $pattern]]
	}
	default {
	    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
	    # Case: wrong # arguments
	    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
	    error "wrong # args: \
		    should be \"$itk_component(hull) path ?-glob? ?-regexp? pattern\""
	}
    }

    return $found
}

# -------------------------------------------------------------
#
# METHOD: type path
#
# Returns the type of the component  given  by  entryCom-
# ponentPathName.  For menu entries, this is the type argument
# passed to the add/insert widget command when the  entry  was
# created, such as command or separator. Othewise it is either
# a menubutton or a menu.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::type { path } {

    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Path Conversions
    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
    set path [_parsePath $path]

    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Error Handling: does the path exist?
    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
    if { [catch {set index $_pathMap($path)} ] } {
	error "bad path \"$path\""
    }

    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # ENTRY, Ask TK for type
    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
    if { [regexp {^[0-9]+$} $index] } {
	# get the menu path from the entry path name
	set tkMenuPath [_entryPathToTkMenuPath $path]

	# call the menu's type command, adjusting index based on tearoff
	set type [$tkMenuPath type [_getTkIndex $tkMenuPath $index]]
	# ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
	# MENUBUTTON, MENU, or FRAME
	# '''''''''''''''''''''''''''''''''''''''''''''''''''''
    } else {
	# should not happen, but have a path that is not a valid window.
	if { [catch {set className [winfo class $_pathMap($path)]}] } {
	    error "serious error: \"$path\" is not a valid window"
	}
	# get the classname, look it up, get index, us it to look up type
	set type [ lindex \
		{frame menubutton menu} \
		[lsearch { Frame Menubutton Menu } $className] \
		]
    }
    return $type
}

# -------------------------------------------------------------
#
# METHOD: yposition entryPath
#
# Returns a decimal string giving the y-coordinate within
# the  menu window of the topmost pixel in the entry specified
# by componentPathName. If the  componentPathName  is  not  an
# entry, an error is issued.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::yposition { entryPath } {

    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Path Conversions
    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
    set entryPath [_parsePath $entryPath]
    set index $_pathMap($entryPath)

    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Error Handling
    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
    # first verify that entryPath is actually a path to
    # an entry and not to menu, menubutton, etc.
    if { ! [regexp {^[0-9]+$} $index] } {
	error "bad value: entryPath is not an entry"
    }

    # ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Call yposition command
    # '''''''''''''''''''''''''''''''''''''''''''''''''''''
    # get the menu path from the entry path name
    set tkMenuPath [_entryPathToTkMenuPath $entryPath]

    # call the menu's yposition command, adjusting index based on tearoff
    return [$tkMenuPath yposition [_getTkIndex $tkMenuPath $index]]

}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# PARSING METHODS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# -------------------------------------------------------------
#
# PARSING METHOD: menubutton
#
# This method is invoked via an evaluation of the -menubuttons
# option for the Menubar.
#
# It adds a new menubutton and processes any -menu options
# for creating entries on the menu pane associated with the 
# menubutton
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::menubutton { menuName args } {
    eval "add menubutton .$menuName $args"
}

# -------------------------------------------------------------
#
# PARSING METHOD: options
#
# This method is invoked via an evaluation of the -menu
# option for menubutton commands.
#
# It configures the current menu ($_ourMenuPath) with the options
# that follow (args)
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::options { args } {
    eval "$_tkMenuPath configure $args"
}


# -------------------------------------------------------------
#
# PARSING METHOD: command
#
# This method is invoked via an evaluation of the -menu
# option for menubutton commands.
#
# It adds a new command entry to the current menu, $_ourMenuPath
# naming it $cmdName. Since this is the most common case when
# creating menus, streamline it by duplicating some code from
# the add{} method.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::command { cmdName args } {
    set path $_ourMenuPath.$cmdName

    # error checking
    regsub {.*[.]} $path "" segName
    if [regexp {^(menu|last|end|[0-9]+)$} $segName] {
 	error "bad name \"$segName\": user created component \
 		path names may not end with \
 		\"end\", \"last\", \"menu\", \
 		or be an integer"
    }

    eval _addEntry command $path $args
}

# -------------------------------------------------------------
#
# PARSING METHOD: checkbutton
#
# This method is invoked via an evaluation of the -menu
# option for menubutton/cascade commands.
#
# It adds a new checkbutton entry to the current menu, $_ourMenuPath
# naming it $chkName.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::checkbutton { chkName args } {
    eval "add checkbutton $_ourMenuPath.$chkName $args"
}

# -------------------------------------------------------------
#
# PARSING METHOD: radiobutton
#
# This method is invoked via an evaluation of the -menu
# option for menubutton/cascade commands.
#
# It adds a new radiobutton entry to the current menu, $_ourMenuPath
# naming it $radName.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::radiobutton { radName args } {
    eval "add radiobutton $_ourMenuPath.$radName $args"
}

# -------------------------------------------------------------
#
# PARSING METHOD: separator
#
# This method is invoked via an evaluation of the -menu
# option for menubutton/cascade commands.
#
# It adds a new separator entry to the current menu, $_ourMenuPath
# naming it $sepName.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::separator { sepName args } {
    eval $_tkMenuPath add separator
    set _pathMap($_ourMenuPath.$sepName) [_getPdIndex $_tkMenuPath end]
}

# -------------------------------------------------------------
#
# PARSING METHOD: cascade
#
# This method is invoked via an evaluation of the -menu
# option for menubutton/cascade commands.
#
# It adds a new cascade entry to the current menu, $_ourMenuPath
# naming it $casName. It processes the -menu option if present,
# adding a new menu pane and its associated entries found.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::cascade { casName args } {
    
    # Save the current menu we are adding to, cascade can change
    # the current menu through -menu options.
    set saveOMP $_ourMenuPath
    set saveTKP $_tkMenuPath

    eval "add cascade $_ourMenuPath.$casName $args"

    # Restore the saved menu states so that the next entries of
    # the -menu/-menubuttons we are processing will be at correct level.
    set _ourMenuPath $saveOMP
    set _tkMenuPath $saveTKP
}

# ... A P I   S U P P O R T   M E T H O D S...

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# MENU ADD, INSERT, DELETE
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# -------------------------------------------------------------
#
# PRIVATE METHOD: _addMenuButton
#
# Makes a new menubutton & associated -menu, pack appended
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_addMenuButton { buttonName args} {

    eval "_makeMenuButton $buttonName $args"

    #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Pack at end, adjust for help buttonName
    # ''''''''''''''''''''''''''''''''''
    if { $buttonName == "help" } {
	pack $itk_component($buttonName) -side right
    } else {
	pack $itk_component($buttonName) -side left
    }

    return $itk_component($buttonName)
}

# -------------------------------------------------------------
#
# PRIVATE METHOD: _insertMenuButton
#
# inserts a menubutton named $buttonName on a menu bar before 
# another menubutton specified by $beforeMenuPath
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_insertMenuButton { beforeMenuPath buttonName args} {

    eval "_makeMenuButton $buttonName $args"

    #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Pack before the $beforeMenuPath
    # ''''''''''''''''''''''''''''''''
    set beforeTkMenu $_pathMap($beforeMenuPath)
    regsub {[.]menu$} $beforeTkMenu "" beforeTkMenu
    pack $itk_component(menubar).$buttonName \
	    -side left \
	    -before $beforeTkMenu

    return $itk_component($buttonName)
}

# -------------------------------------------------------------
#
# PRIVATE METHOD: _makeMenuButton
#
# creates a menubutton named buttonName on the menubar with args.
# The -menu option if present will trigger attaching a menu pane.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_makeMenuButton {buttonName args} {

    #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Capture the -menu option if present
    # '''''''''''''''''''''''''''''''''''
    array set temp $args
    if { [::info exists temp(-menu)] } {
	# We only keep this in case of menuconfigure or menucget
	set _menuOption(.$buttonName) $temp(-menu)
	set menuEvalStr $temp(-menu)
    } else {
	set menuEvalStr {}
    }

    # attach the actual menu widget to the menubutton's arg list
    set temp(-menu) $itk_component(menubar).$buttonName.menu
    set args [array get temp]

    #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Create menubutton component
    # ''''''''''''''''''''''''''''''''
    itk_component add $buttonName {
        eval ::menubutton \
                $itk_component(menubar).$buttonName \
                $args 
    } {
        keep \
                -activebackground \
                -activeforeground \
                -anchor \
                -background \
                -borderwidth \
                -cursor \
                -disabledforeground \
                -font \
                -foreground \
                -highlightbackground \
                -highlightcolor \
                -highlightthickness \
                -justify \
                -padx \
                -pady \
                -wraplength
    }
    
    set _pathMap(.$buttonName) $itk_component($buttonName)

    _makeMenu \
	    $buttonName-menu \
	    $itk_component($buttonName).menu \
	    .$buttonName \
	    $menuEvalStr

    return $itk_component($buttonName)
    
}

# -------------------------------------------------------------
#
# PRIVATE METHOD: _makeMenu
#
# Creates a menu.
# It then evaluates the $menuEvalStr to create entries on the menu.
#
# Assumes the existence of $itk_component($buttonName)
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_makeMenu \
	{ componentName widgetName menuPath menuEvalStr } {

    #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Create menu component
    # ''''''''''''''''''''''''''''''''
    itk_component add $componentName {
	::menu $widgetName
    } {
	keep \
		-activebackground \
		-activeborderwidth \
		-activeforeground \
		-background \
		-borderwidth \
		-cursor \
		-disabledforeground \
		-font \
		-foreground 
    }

    set _pathMap($menuPath.menu) $itk_component($componentName)

    #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Attach help handler to this menu
    # ''''''''''''''''''''''''''''''''
    bind $itk_component($componentName) <<MenuSelect>> \
	    [itcl::code $this _helpHandler $menuPath.menu]

    #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Handle -menu
    #'''''''''''''''''''''''''''''''''
    set _ourMenuPath $menuPath
    set _tkMenuPath $itk_component($componentName)

    #
    # A zero parseLevel says we are at the top of the parse tree,
    # so get the context scope level and do a subst for the menuEvalStr.
    #
    if { $_parseLevel == 0 } {
        set _callerLevel [_getCallerLevel]
    }

    #
    # bump up the parse level, so if we get called via the 'eval $menuEvalStr'
    # we know to skip the above steps...
    #
    incr _parseLevel
    eval $menuEvalStr

    #
    # leaving, so done with this parse level, so bump it back down 
    #
    incr _parseLevel -1
}

# -------------------------------------------------------------
#
# PRIVATE METHOD: _substEvalStr
#
# This performs the substitution and evaluation of $ [], \ found
# in the -menubutton/-menus options
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_substEvalStr { evalStr } {
    upvar $evalStr evalStrRef
    set evalStrRef [uplevel $_callerLevel [list subst $evalStrRef]]
}


# -------------------------------------------------------------
#
# PRIVATE METHOD: _deleteMenu
#
# _deleteMenu menuPath ?menuPath2?
#
# deletes menuPath or from menuPath to menuPath2
#
# Menu paths may be formed in one of two ways
#	.MENUBAR.menuName  where menuName is the name of the menu
#	.MENUBAR.menuName.menu  where menuName is the name of the menu
#
# The basic rule is '.menu' is not needed.
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_deleteMenu { menuPath {menuPath2 {}} } {

    if { $menuPath2 == "" } {
	# get a corrected path (subst for number, last, end)
	set path [_parsePath $menuPath]

	_deleteAMenu $path

    } else {
	# gets the list of menus in interface order
	set menuList [_getMenuList]

	# ... get the start menu and the last menu ...

	# get a corrected path (subst for number, last, end)
	set menuStartPath [_parsePath $menuPath]

	regsub {[.]menu$} $menuStartPath "" menuStartPath

	set menuEndPath [_parsePath $menuPath2]

	regsub {[.]menu$} $menuEndPath "" menuEndPath
	
	# get the menu position (0 based) of the start and end menus.
	set start [lsearch -exact $menuList $menuStartPath]
	if { $start == -1 } {
	    error "bad menu path \"$menuStartPath\": \
		    should be one of $menuList"
	}
	set end [lsearch -exact $menuList $menuEndPath]
	if { $end == -1 } {
	    error "bad menu path \"$menuEndPath\": \
		    should be one of $menuList"
	}

	# now create the list from this range of menus
	set delList [lrange $menuList $start $end]

	# walk thru them deleting each menu.
	# this list has no .menu on the end.
	foreach m $delList {
	    _deleteAMenu $m.menu
	}
    }
}

# -------------------------------------------------------------
#
# PRIVATE METHOD: _deleteAMenu
#
# _deleteMenu menuPath 
#
# deletes a single Menu (menubutton and menu pane with entries)
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_deleteAMenu { path } {

    # We will normalize the path to not include the '.menu' if
    # it is on the path already.

    regsub {[.]menu$} $path "" menuButtonPath
    regsub {.*[.]} $menuButtonPath "" buttonName

    # Loop through and destroy any cascades, etc on menu.
    set entryList [_getEntryList $menuButtonPath]
    foreach entry $entryList {
	_deleteEntry $entry
    }

    # Delete the menubutton and menu components...
    destroy $itk_component($buttonName-menu)
    destroy $itk_component($buttonName)

    # This is because of some itcl bug that doesn't delete
    # the component on the destroy in some cases...
    catch {itk_component delete $buttonName-menu}
    catch {itk_component delete $buttonName}
    
    # unset our paths
    _unsetPaths $menuButtonPath

}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ENTRY ADD, INSERT, DELETE
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# -------------------------------------------------------------
#
# PRIVATE METHOD: _addEntry
#
# Adds an entry to menu.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_addEntry { type path args } {

    # Error Checking
    # ''''''''''''''
    # the path should not end with '.menu'
    # Not needed -- already checked by add{}
    # if { [regexp {[.]menu$} $path] } {
    #  error "bad entry path: \"$path\". \
    #    	The name \"menu\" is reserved for menu panes"
    # }

    # get the tkMenuPath
    set tkMenuPath [_entryPathToTkMenuPath $path]
    if { $tkMenuPath == "" } {
	error "bad entry path: \"$path\". The menu path prefix is not valid"
    }

    # get the -helpstr option if present
    array set temp $args
    if { [::info exists temp(-helpstr)] } {
	set helpStr $temp(-helpstr)
	unset temp(-helpstr)
    } else {
	set helpStr {}
    }
    set args [array get temp]

    # Handle CASCADE
    # ''''''''''''''
    # if this is a cascade go ahead and add in the menu...
    if { $type == "cascade" } {
	eval [list _addCascade $tkMenuPath $path] $args
	# Handle Non-CASCADE
	# ''''''''''''''''''
    } else {
	# add the entry if one doesn't already exist with the same
	# command name
	if [::info exists _pathMap($path)] {
	  set cmdname [lindex [split $path .] end]
	  error "Cannot add $type \"$cmdname\". A menu item already\
	    exists with this name."
	}
	eval [list $tkMenuPath add $type] $args
	set _pathMap($path) [_getPdIndex $tkMenuPath end]
    }

    # Remember the help string
    set _helpString($path) $helpStr

    return $_pathMap($path)
}

# -------------------------------------------------------------
#
# PRIVATE METHOD: _addCascade
#
# Creates a cascade button.  Handles the -menu option
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_addCascade { tkMenuPath path args } {

    # get the cascade name from our path
    regsub {.*[.]} $path "" cascadeName

    #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Capture the -menu option if present
    # '''''''''''''''''''''''''''''''''''
    array set temp $args
    if { [::info exists temp(-menu)] } {
	set menuEvalStr $temp(-menu)
    } else {
	set menuEvalStr {}
    }

    # attach the menu pane
    set temp(-menu) $tkMenuPath.$cascadeName
    set args [array get temp]

    # Create the cascade entry
    eval $tkMenuPath add cascade $args
    
    # Keep the -menu string in case of menuconfigure or menucget
    if { $menuEvalStr != "" } {
	set _menuOption($path) $menuEvalStr
    }

    # update our pathmap
    set _pathMap($path) [_getPdIndex $tkMenuPath end]

    _makeMenu \
	    $cascadeName-menu \
	    $tkMenuPath.$cascadeName \
	    $path \
	    $menuEvalStr

    #return $itk_component($cascadeName)

}

# -------------------------------------------------------------
#
# PRIVATE METHOD: _insertEntry
#
# inserts an entry on a menu before entry given by beforeEntryPath.
# The added entry is of type TYPE and its name is NAME. ARGS are
# passed for customization of the entry.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_insertEntry { beforeEntryPath type name args } {

    # convert entryPath to an index value
    set bfIndex $_pathMap($beforeEntryPath)

    # first verify that beforeEntryPath is actually a path to
    # an entry and not to menu, menubutton, etc.
    if { ! [regexp {^[0-9]+$} $bfIndex] } {
	error "bad entry path: $beforeEntryPath is not an entry"
    }

    # get the menu path from the entry path name
    regsub {[.][^.]*$} $beforeEntryPath "" menuPathPrefix
    set tkMenuPath $_pathMap($menuPathPrefix.menu)

    # If this entry already exists in the path map, throw an error.
    if [::info exists _pathMap($menuPathPrefix.$name)] {
      error "Cannot insert $type \"$name\". A menu item already\
	exists with this name."
    }

    # INDEX is zero based at this point.

    # ENTRIES is a zero based list...
    set entries [_getEntryList $menuPathPrefix]

    # 
    # Adjust the entries after the inserted item, to have
    # the correct index numbers. Note, we stay zero based 
    # even though tk flips back and forth depending on tearoffs.
    #
    for {set i $bfIndex} {$i < [llength $entries]} {incr i} {
	# path==entry path in numerical order
	set path [lindex $entries $i]

	# add one to each entry after the inserted one.
	set _pathMap($path) [expr {$i + 1}]
    }

    # get the -helpstr option if present
    array set temp $args
    if { [::info exists temp(-helpstr)] } {
	set helpStr $temp(-helpstr)
	unset temp(-helpstr)
    } else {
	set helpStr {}
    }
    set args [array get temp]

    set path $menuPathPrefix.$name

    # Handle CASCADE
    # ''''''''''''''
    # if this is a cascade go ahead and add in the menu...
    if { [string match cascade $type] } {

	if { [ catch {eval "_insertCascade \
		$bfIndex $tkMenuPath $path $args"} errMsg ]} {
	    for {set i $bfIndex} {$i < [llength $entries]} {incr i} {
		# path==entry path in numerical order
		set path [lindex $entries $i]

		# sub the one we added earlier.
		set _pathMap($path) [expr {$_pathMap($path) - 1}]
		# @@ delete $hs
	    }
	    error $errMsg
	}

	# Handle Entry
	# ''''''''''''''
    } else {

	# give us a zero or 1-based index based on tear-off menu status
	# invoke the menu's insert command
	if { [catch {eval "$tkMenuPath insert \
		[_getTkIndex $tkMenuPath $bfIndex] $type $args"} errMsg]} {
	    for {set i $bfIndex} {$i < [llength $entries]} {incr i} {
		# path==entry path in numerical order
		set path [lindex $entries $i]

		# sub the one we added earlier.
		set _pathMap($path) [expr {$_pathMap($path) - 1}]
		# @@ delete $hs
	    }
	    error $errMsg
	}
	

	# add the helpstr option to our options list (attach to entry)
	set _helpString($path) $helpStr

	# Insert the new entry path into pathmap giving it an index value
	set _pathMap($menuPathPrefix.$name) $bfIndex
	
    }

    return [_getTkIndex $tkMenuPath $bfIndex]
}

# -------------------------------------------------------------
#
# PRIVATE METHOD: _insertCascade
#
# Creates a cascade button.  Handles the -menu option
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_insertCascade { bfIndex tkMenuPath path args } {

    # get the cascade name from our path
    regsub {.*[.]} $path "" cascadeName

    #,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    # Capture the -menu option if present
    # '''''''''''''''''''''''''''''''''''
    array set temp $args
    if { [::info exists temp(-menu)] } {
	# Keep the -menu string in case of menuconfigure or menucget
	set _menuOption($path) $temp(-menu)
	set menuEvalStr $temp(-menu)
    } else {
	set menuEvalStr {}
    }

    # attach the menu pane
    set temp(-menu) $tkMenuPath.$cascadeName
    set args [array get temp]

    # give us a zero or 1-based index based on tear-off menu status
    # invoke the menu's insert command
    eval "$tkMenuPath insert \
	    [_getTkIndex $tkMenuPath $bfIndex] cascade $args"
    
    # Insert the new entry path into pathmap giving it an index value
    set _pathMap($path) $bfIndex
    _makeMenu \
	    $cascadeName-menu \
	    $tkMenuPath.$cascadeName \
	    $path \
	    $menuEvalStr

    #return $itk_component($cascadeName)
}

# -------------------------------------------------------------
#
# PRIVATE METHOD: _deleteEntry
#
# _deleteEntry entryPath ?entryPath2?
#
#   either
# deletes the entry entryPath
#   or
# deletes the entries from entryPath to entryPath2 
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_deleteEntry { entryPath {entryPath2 {}} } {

    if { $entryPath2 == "" } {
	# get a corrected path (subst for number, last, end)
	set path [_parsePath $entryPath]

	set entryIndex $_pathMap($path)
	if { $entryIndex == -1 } {
	    error "bad value for pathName: \
		    $entryPath in call to delet"
	}

	# get the type, if cascade, we will want to delete menu
	set type [type $path]

	# ... munge up the menu name ...

	# the tkMenuPath is looked up with the .menu added to lookup
	# strip off the entry component
	regsub {[.][^.]*$} $path "" menuPath
	set tkMenuPath $_pathMap($menuPath.menu)

	# get the ordered entry list
	set entries [_getEntryList $menuPath]

	# ... Fix up path entry indices ...

	# delete the path from the map
	unset _pathMap([lindex $entries $entryIndex])

	# Subtract off 1 for each entry below the deleted one.
	for {set i [expr {$entryIndex + 1}]} \
		{$i < [llength $entries]} \
		{incr i} {
	    set epath [lindex $entries $i]
	    incr _pathMap($epath) -1
	}

	# ... Delete the menu entry widget ...

	# delete the menu entry, ajusting index for TK
	$tkMenuPath delete [_getTkIndex $tkMenuPath $entryIndex]

	if { $type == "cascade" } {
	    regsub {.*[.]} $path "" cascadeName
	    destroy $itk_component($cascadeName-menu)

	    # This is because of some itcl bug that doesn't delete
	    # the component on the destroy in some cases...
	    catch {itk_component delete $cascadeName-menu}

	    _unsetPaths $path
	}

    } else { 
	# get a corrected path (subst for number, last, end)
	set path1 [_parsePath $entryPath]
	set path2 [_parsePath $entryPath2]

	set fromEntryIndex $_pathMap($path1)
	if { $fromEntryIndex == -1 } {
	    error "bad value for entryPath1: \
		    $entryPath in call to delet"
	}
	set toEntryIndex $_pathMap($path2)
	if { $toEntryIndex == -1 } {
	    error "bad value for entryPath2: \
		    $entryPath2 in call to delet"
	}
	# ... munge up the menu name ...

	# the tkMenuPath is looked up with the .menu added to lookup
	# strip off the entry component
	regsub {[.][^.]*$} $path1 "" menuPath
	set tkMenuPath $_pathMap($menuPath.menu)

	# get the ordered entry list
	set entries [_getEntryList $menuPath]

	# ... Fix up path entry indices ...

	# delete the range from the pathMap list
	for {set i $fromEntryIndex} {$i <= $toEntryIndex} {incr i} {
	    unset _pathMap([lindex $entries $i])
	}

	# Subtract off 1 for each entry below the deleted range.
	# Loop from one below the bottom delete entry to end list
	for {set i [expr {$toEntryIndex + 1}]} \
		{$i < [llength $entries]} \
		{incr i} {
	    # take this path and sets its index back by size of
	    # deleted range.
	    set path [lindex $entries $i]
	    set _pathMap($path) \
		    [expr {$_pathMap($path) - \
		    (($toEntryIndex - $fromEntryIndex) + 1)}]
	}

	# ... Delete the menu entry widget ...

	# delete the menu entry, ajusting index for TK
	$tkMenuPath delete \
		[_getTkIndex $tkMenuPath $fromEntryIndex] \
		[_getTkIndex $tkMenuPath $toEntryIndex]

    }
}

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# CONFIGURATION SUPPORT
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# -------------------------------------------------------------
#
# PRIVATE METHOD: _configureMenu
#
# This configures a menu. A menu is a true tk widget, thus we
# pass the tkPath variable. This path may point to either a 
# menu button (does not end with the name 'menu', or a menu
# which ends with the name 'menu'
#
# path : our Menubar path name to this menu button or menu pane.
#        if we end with the name '.menu' then it is a menu pane.
# tkPath : the path to the corresponding Tk menubutton or menu.
# args   : the args for configuration
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_configureMenu { path tkPath {option {}} args } {

    set class [winfo class $tkPath]

    if { $option == "" } {
	# No arguments: return all options
	set configList [$tkPath configure]

	if { [info exists _menuOption($path)] } {
	    lappend configList [list -menu menu Menu {} $_menuOption($path)]
	} else {
	    lappend configList [list -menu menu Menu {} {}]
	}
	if { [info exists _helpString($path)] } {
	    lappend configList [list -helpstr helpStr HelpStr {} \
		    $_helpString($path)]
	} else {
	    lappend configList [list -helpstr helpStr HelpStr {} {}]
	}
	return $configList

    } elseif {$args == "" } {
	if { $option == "-menu" } {
	    if { [info exists _menuOption($path)] } {
		return [list -menu menu Menu {} $_menuOption($path)]
	    } else {
		return [list -menu menu Menu {} {}]
	    }
	} elseif { $option == "-helpstr" } {
	    if { [info exists _helpString($path)] } {
		return [list -helpstr helpStr HelpStr {} $_helpString($path)]
	    } else {
		return [list -helpstr helpStr HelpStr {} {}]
	    }
	} else {
	    # ... OTHERWISE, let Tk get it.
	    return [$tkPath configure $option]
	}
    } else {
	set args [concat $option $args]

	# If this is a menubutton, and has -menu option, process it
	if { $class == "Menubutton" && [regexp -- {-menu} $args] } {
	    eval _configureMenuOption menubutton $path $args
	} else {
	    eval $tkPath configure $args
	}
	return ""
    }
}

# -------------------------------------------------------------
#
# PRIVATE METHOD: _configureMenuOption
#
# Allows for configuration of the -menu option on
# menubuttons and cascades
#
# find out if we are the last menu, or are before one.
# delete the old menu.
# if we are the last, then add us back at the end
# if we are before another menu, get the beforePath
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_configureMenuOption { type path args } {

    regsub {[.][^.]*$} $path "" pathPrefix

    if { $type == "menubutton" } {
	set menuList [_getMenuList]
	set pos [lsearch $menuList $path]
	if { $pos == ([llength $menuList] - 1) } {
	    set insert false
	} else {
	    set insert true
	}
    } elseif { $type == "cascade" } {
	set lastEntryPath [_parsePath $pathPrefix.last]
	if { $lastEntryPath == $path } {
	    set insert false
	} else {
	    set insert true
	}
	set pos [index $path]

    }


    eval "delete $pathPrefix.$pos"
    if { $insert } {
	# get name from path...
	regsub {.*[.]} $path "" name

	eval insert $pathPrefix.$pos $type \
		$name $args
    } else {
	eval add $type $path $args
    }
}

# -------------------------------------------------------------
#
# PRIVATE METHOD: _configureMenuEntry
#
# This configures a menu entry. A menu entry is either a command,
# radiobutton, separator, checkbutton, or a cascade. These have
# a corresponding Tk index value for the corresponding tk menu
# path.
#
# path   : our Menubar path name to this menu entry.
# index  : the t
# args   : the args for configuration
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_configureMenuEntry { path index {option {}} args } {

    set type [type $path]

    # set len [llength $args]

    # get the menu path from the entry path name
    set tkMenuPath [_entryPathToTkMenuPath $path]

    if { $option == "" } {
	set configList [$tkMenuPath entryconfigure \
		[_getTkIndex $tkMenuPath $index]]

	if { $type == "cascade" } {
	    if { [info exists _menuOption($path)] } {
		lappend configList [list -menu menu Menu {} \
			$_menuOption($path)]
	    } else {
		lappend configList [list -menu menu Menu {} {}]
	    }
	}
	if { [info exists _helpString($path)] } {
	    lappend configList [list -helpstr helpStr HelpStr {} \
		    $_helpString($path)]
	} else {
	    lappend configList [list -helpstr helpStr HelpStr {} {}]
	}
	return $configList

    } elseif { $args == "" } {
	if { $option == "-menu" } {
	    if { [info exists _menuOption($path)] } {
		return [list -menu menu Menu {} $_menuOption($path)]
	    } else {
		return [list -menu menu Menu {} {}]
	    }
	} elseif { $option == "-helpstr" } {
	    if { [info exists _helpString($path)] } {
		return [list -helpstr helpStr HelpStr {} \
			$_helpString($path)]
	    } else {
		return [list -helpstr helpStr HelpStr {} {}]
	    }
	} else {
	    # ... OTHERWISE, let Tk get it.
	    return [$tkMenuPath entryconfigure \
		    [_getTkIndex $tkMenuPath $index] $option]
	}
    } else {
	array set temp [concat $option $args]

	# ... Store -helpstr val,strip out -helpstr val from args
	if { [::info exists temp(-helpstr)] } {
	    set _helpString($path) $temp(-helpstr)
	    unset temp(-helpstr)
	}

	set args [array get temp]
	if { $type == "cascade" && [::info exists temp(-menu)] } {
	    eval "_configureMenuOption cascade $path $args"
	} else {
	    # invoke the menu's entryconfigure command
	    # being careful to ajust the INDEX to be 0 or 1 based 
	    # depending on the tearoff status
	    # if the stripping process brought us down to no options
	    # to set, then forget the configure of widget.
	    if { [llength $args] != 0 } {
		eval $tkMenuPath entryconfigure \
			[_getTkIndex $tkMenuPath $index] $args
	    }
	}
	return ""
    }
}

# -------------------------------------------------------------
#
# PRIVATE METHOD: _unsetPaths
#
# comment
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_unsetPaths { parent } {

    # first get the complete list of all menu paths
    set pathList [array names _pathMap]

    # for each path that matches parent prefix, unset it.
    foreach path $pathList {
	if { [regexp [subst -nocommands {^$parent}] $path] } {
	    unset _pathMap($path)
	}
    }
}

# -------------------------------------------------------------
#
# PRIVATE METHOD: _entryPathToTkMenuPath
#
# Takes an entry path like .mbar.file.new and changes it to
# .mbar.file.menu and performs a lookup in the pathMap to
# get the corresponding menu widget name for tk
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_entryPathToTkMenuPath {entryPath} {

    # get the menu path from the entry path name
    # by stripping off the entry component of the path
    regsub {[.][^.]*$} $entryPath "" menuPath

    # the tkMenuPath is looked up with the .menu added to lookup
    if { [catch {set tkMenuPath $_pathMap($menuPath.menu)}] } {
	return ""
    } else {
	return $_pathMap($menuPath.menu)
    }
}


# -------------------------------------------------------------
#
# These two methods address the issue of menu entry indices being
# zero-based when the menu is not a tearoff menu and 1-based when
# it is a tearoff menu. Our strategy is to hide this difference.
# 
# _getTkIndex returns the index as tk likes it: 0 based for non-tearoff
# and 1 based for tearoff menus.
# 
# _getPdIndex (get pulldown index) always returns it as 0 based.
# 
# -------------------------------------------------------------

# -------------------------------------------------------------
# 
# PRIVATE METHOD: _getTkIndex
#
# give us a zero or 1-based answer depending on the tearoff
# status of the menu. If the menu denoted by tkMenuPath is a
# tearoff menu it returns a 1-based result, otherwise a 
# zero-based result.
# 
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_getTkIndex { tkMenuPath tkIndex} {

    # if there is a tear off make it 1-based index
    if { [$tkMenuPath cget -tearoff] } {
	incr tkIndex
    }

    return $tkIndex
}

# -------------------------------------------------------------
# 
# PRIVATE METHOD: _getPdIndex
#
# Take a tk index and give me a zero based numerical index
#
# Ask the menu widget for the index of the entry denoted by
# 'tkIndex'. Then if the menu is a tearoff adjust the value
# to be zero based.
#
# This method returns the index as if tearoffs did not exist.
# Always returns a zero-based index.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_getPdIndex { tkMenuPath tkIndex } {

    # get the index from the tk menu
    # this 0 based for non-tearoff and 1-based for tearoffs
    set pdIndex [$tkMenuPath index $tkIndex]

    # if there is a tear off make it 0-based index
    if { [$tkMenuPath cget -tearoff] } {
	incr pdIndex -1
    }

    return $pdIndex
}

# -------------------------------------------------------------
# 
# PRIVATE METHOD: _getMenuList
#
# Returns the list of menus in the order they are on the interface
# returned list is a list of our menu paths
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_getMenuList { } {
    # get the menus that are packed
    set tkPathList [pack slaves $itk_component(menubar)]

    regsub -- {[.]} $itk_component(hull) "" mbName
    regsub -all -- "\[.\]$mbName\[.\]menubar\[.\]" $tkPathList "." menuPathList

    return $menuPathList
}

# -------------------------------------------------------------
# 
# PRIVATE METHOD: _getEntryList
#
#
# This method looks at a menupath and gets all the entries and
# returns a list of all the entry path names in numerical order
# based on their index values.
#
# MENU is the path to a menu, like .mbar.file.menu or .mbar.file
# we will calculate a menuPath from this: .mbar.file
# then we will build a list of entries in this menu excluding the
# path .mbar.file.menu
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_getEntryList { menu } {

    # if it ends with menu, clip it off
    regsub {[.]menu$} $menu "" menuPath

    # first get the complete list of all menu paths
    set pathList [array names _pathMap]

    set numEntries 0
    # iterate over the pathList and put on menuPathList those
    # that match the menuPattern
    foreach path $pathList {
	# if this path is on the menuPath's branch
	if { [regexp [subst -nocommands {$menuPath[.][^.]*$}] $path] } {
	    # if not a menu itself
	    if { ! [regexp {[.]menu$} $path] } {
		set orderedList($_pathMap($path)) $path
		incr numEntries
	    }
	}
    }
    set entryList {}

    for {set i 0} {$i < $numEntries} {incr i} {
	lappend entryList $orderedList($i)
    }

    return $entryList

}

# -------------------------------------------------------------
# 
# PRIVATE METHOD: _parsePath
#
# given path, PATH, _parsePath splits the path name into its
# component segments. It then puts the name back together one
# segment at a time and calls _getSymbolicPath to replace the
# keywords 'last' and 'end' as well as numeric digits.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_parsePath { path } {
    set segments [split [string trimleft $path .] .]

    set concatPath ""
    foreach seg $segments {

	set concatPath [_getSymbolicPath $concatPath $seg]

	if { [catch {set _pathMap($concatPath)} ] } {
	    error "bad path: \"$path\" does not exist. \"$seg\" not valid"
	}
    }
    return $concatPath
}

# -------------------------------------------------------------
# 
# PRIVATE METHOD: _getSymbolicPath
#
# Given a PATH, _getSymbolicPath looks for the last segment of
# PATH to contain: a number, the keywords last or end. If one
# of these it figures out how to get us the actual pathname
# to the searched widget
#
# Implementor's notes:
#	Surely there is a shorter way to do this. The only diff
#	for non-numeric is getting the llength of the correct list
#	It is hard to know this upfront so it seems harder to generalize.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_getSymbolicPath { parent segment } {

    # if the segment is a number, then look it up positionally
    # MATCH numeric index
    if { [regexp {^[0-9]+$} $segment] } {

	# if we have no parent, then we area menubutton
	if { $parent == {} } {
	    set returnPath [lindex [_getMenuList] $segment]
	} else {
	    set returnPath [lindex [_getEntryList $parent.menu] $segment]
	}

	# MATCH 'end' or 'last' keywords.
    } elseif { $segment == "end" || $segment == "last" } {

	# if we have no parent, then we are a menubutton
	if { $parent == {} } {
	    set returnPath [lindex [_getMenuList] end]
	} else {
	    set returnPath [lindex [_getEntryList $parent.menu] end]
	}
    } else {
	set returnPath $parent.$segment
    }

    return $returnPath
}

# -------------------------------------------------------------
# 
# PRIVATE METHOD: _helpHandler
#
# Bound to the <Motion> event on a menu pane. This puts the
# help string associated with the menu entry into the 
# status widget help area. If no help exists for the current
# entry, the status widget is cleared.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_helpHandler { menuPath } {

    if { $itk_option(-helpvariable) == {} } {
	return
    }

    set tkMenuWidget $_pathMap($menuPath)

    set entryIndex [$tkMenuWidget index active]

    # already on this item?
    if { $entryIndex == $_entryIndex } {
	return
    }

    set _entryIndex $entryIndex

    if {"none" != $entryIndex} {
        set entries [_getEntryList $menuPath]

        set menuEntryHit \
	    [lindex $entries [_getPdIndex $tkMenuWidget $entryIndex]]

        # blank out the old one
        set $itk_option(-helpvariable) {}

        # if there is a help string for this entry
        if { [::info exists _helpString($menuEntryHit)] } {
	    set $itk_option(-helpvariable) $_helpString($menuEntryHit)
        }
    } else {
	set $itk_option(-helpvariable) {}
	set _entryIndex -1
    }
}

# -------------------------------------------------------------
#
# PRIVATE METHOD: _getCallerLevel
#
# Starts at stack frame #0 and works down till we either hit
# a ::Menubar stack frame or an ::itk::Archetype stack frame 
# (the latter happens when a configure is called via the 'component'
# method
#
# Returns the level of the actual caller of the menubar command
# in the form of #num where num is the level number caller stack frame.
#
# -------------------------------------------------------------
itcl::body iwidgets::Menubar::_getCallerLevel { } {

    set levelName {}
    set levelsAreValid true
    set level 0
    set callerLevel #$level

    while { $levelsAreValid } {
	# Hit the end of the stack frame
	if [catch {uplevel #$level {namespace current}}] {
	    set levelsAreValid false
	    set callerLevel #[expr {$level - 1}]
	    # still going
	} else {
	    set newLevelName [uplevel #$level {namespace current}]
	    # See if we have run into the first ::Menubar level
	    if { $newLevelName == "::itk::Archetype" || \
		    $newLevelName == "::iwidgets::Menubar" } {
		# If so, we are done-- set the callerLevel
		set levelsAreValid false
		set callerLevel #[expr {$level - 1}]
	    } else {
		set levelName $newLevelName
	    }
	}
	incr level
    }
    return $callerLevel
}


#
# The default tkMenuFind proc in menu.tcl only looks for menubuttons
# in frames.  Since our menubuttons are within the Menubar class, the
# default proc won't find them during menu traversal.  This proc
# redefines the default proc to remedy the problem.
#-----------------------------------------------------------
# BUG FIX: csmith (Chad Smith: csmith@adc.com), 3/30/99
#-----------------------------------------------------------
# The line, "set qchild ..." below had a typo.  It should be
# "info command $child" instead of "winfo command $child".
#-----------------------------------------------------------
proc tkMenuFind {w char} {
    global tkPriv
    set char [string tolower $char]

    # Added by csmith, 5/10/01, to fix a bug reported on the itcl mailing list.
    if {$w == "."} {
      foreach child [winfo child $w] {
        set match [tkMenuFind $child $char]
	if {$match != ""} {
	  return $match
	}
      }
      return {}
    }

    foreach child [winfo child $w] {
	switch [winfo class $child] {
	    Menubutton {
		set qchild [info command $child]
		set char2 [string index [$qchild cget -text] \
			[$qchild cget -underline]]
		if {([string compare $char [string tolower $char2]] == 0)
		|| ($char == "")} {
		    if {[$qchild cget -state] != "disabled"} {
			return $child
		    }
		}
	    }
	    Frame -
	    Menubar {
		set match [tkMenuFind $child $char]
		if {$match != ""} {
		    return $match
		}
	    }
	}
    }
    return {}
}