1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412
|
#==============================================================================
# Contains the implementation of the multi-entry widget.
#
# Structure of the module:
# - Namespace initialization
# - Private procedure creating the default bindings
# - Public procedure creating a new mentry widget
# - Private configuration procedures
# - Private procedures implementing the mentry widget command
# - Private callback procedure
# - Private procedures used in bindings
# - Private utility procedures
#
# Copyright (c) 1999-2024 Csaba Nemethi (E-mail: csaba.nemethi@t-online.de)
#==============================================================================
#
# Namespace initialization
# ========================
#
namespace eval mentry {
#
# Get the windowing system ("x11", "win32", or "aqua")
#
variable winSys [tk windowingsystem]
#
# Create aliases for a few tile commands if not yet present
#
proc createTileAliases {} {
if {[interp alias {} ::mentry::style] ne ""} {
return ""
}
if {[llength [info commands ::ttk::style]] == 0} {
interp alias {} ::mentry::style {} ::style
if {[string compare $::tile::version "0.7"] >= 0} {
interp alias {} ::mentry::styleConfig {} ::style configure
} else {
interp alias {} ::mentry::styleConfig {} ::style default
}
interp alias {} ::mentry::getThemes {} ::tile::availableThemes
interp alias {} ::mentry::setTheme {} ::tile::setTheme
interp alias {} ::mentry::tileqt_kdeStyleChangeNotification \
{} ::tile::theme::tileqt::kdeStyleChangeNotification
interp alias {} ::mentry::tileqt_currentThemeName \
{} ::tile::theme::tileqt::currentThemeName
interp alias {} ::mentry::tileqt_currentThemeColour \
{} ::tile::theme::tileqt::currentThemeColour
} else {
interp alias {} ::mentry::style {} ::ttk::style
interp alias {} ::mentry::styleConfig {} ::ttk::style configure
interp alias {} ::mentry::getThemes {} ::ttk::themes
interp alias {} ::mentry::setTheme {} ::ttk::setTheme
interp alias {} ::mentry::tileqt_kdeStyleChangeNotification \
{} ::ttk::theme::tileqt::kdeStyleChangeNotification
interp alias {} ::mentry::tileqt_currentThemeName \
{} ::ttk::theme::tileqt::currentThemeName
interp alias {} ::mentry::tileqt_currentThemeColour \
{} ::ttk::theme::tileqt::currentThemeColour
}
interp alias {} ::mentry::getCurrentTheme {} ::mwutil::currentTheme
}
variable currentTheme [::mwutil::currentTheme]
if {$currentTheme ne ""} {
createTileAliases
}
variable widgetStyle ""
variable colorScheme ""
if {$currentTheme eq "tileqt"} {
set widgetStyle [tileqt_currentThemeName]
if {[info exists ::env(KDE_SESSION_VERSION)] &&
$::env(KDE_SESSION_VERSION) ne ""} {
set colorScheme [getKdeConfigVal "General" "ColorScheme"]
} else {
set colorScheme [getKdeConfigVal "KDE" "colorScheme"]
}
}
variable newAquaSupport [expr {
($::tk_version == 8.6 &&
[package vcompare $::tk_patchLevel "8.6.10"] >= 0) ||
($::tk_version >= 8.7 &&
[package vcompare $::tk_patchLevel "8.7a3"] >= 0)}]
variable extendedAquaSupport [expr {
[lsearch -exact [image types] "nsimage"] >= 0}]
variable uniformWheelSupport [expr {$::tk_version >= 8.7 &&
[package vcompare $::tk_patchLevel "8.7a4"] >= 0}]
variable touchpadScrollSupport [expr {
[llength [info commands ::tk::PreciseScrollDeltas]] != 0}]
#
# The array configSpecs is used to handle configuration options. The
# names of its elements are the configuration options for the Mentry widget
# class. The value of an array element is either an alias name or a list
# containing the database name and class as well as an indicator specifying
# the widgets to which the option applies: c stands for all children
# (entries and labels), e for the entries only, h for the hull, and w for
# the widget itself.
#
# Command-Line Name {Database Name Database Class W}
# -----------------------------------------------------------------------
#
variable configSpecs
array set configSpecs {
-background {background Background e}
-bg -background
-body {body Body w}
-borderwidth {borderWidth BorderWidth h}
-bd -borderwidth
-cursor {cursor Cursor c}
-disabledbackground {disabledBackground DisabledBackground e}
-disabledforeground {disabledForeground DisabledForeground c}
-exportselection {exportSelection ExportSelection e}
-font {font Font c}
-foreground {foreground Foreground c}
-fg -foreground
-highlightbackground {highlightBackground HighlightBackground h}
-highlightcolor {highlightColor HighlightColor h}
-highlightthickness {highlightThickness HighlightThickness h}
-insertbackground {insertBackground Foreground e}
-insertborderwidth {insertBorderWidth BorderWidth e}
-insertofftime {insertOffTime OffTime e}
-insertontime {insertOnTime OnTime e}
-insertwidth {insertWidth InsertWidth e}
-invalidcommand {invalidCommand InvalidCommand e}
-invcmd -invalidcommand
-justify {justify Justify e}
-readonlybackground {readonlyBackground ReadonlyBackground e}
-relief {relief Relief h}
-selectbackground {selectBackground Foreground e}
-selectborderwidth {selectBorderWidth BorderWidth e}
-selectforeground {selectForeground Background e}
-show {show Show e}
-state {state State e}
-takefocus {takeFocus TakeFocus h}
-textvariable {textVariable Variable e}
-validate {validate Validate e}
-validatecommand {validateCommand ValidateCommand e}
-vcmd -validatecommand
}
#
# Extend the elements of the array configSpecs
#
proc extendConfigSpecs {} {
variable helpEntry
variable usingTile
variable configSpecs
#
# Append the default values of the configuration options
# of an invisible entry widget to the values of the
# corresponding elements of the array configSpecs
#
set helpEntry .__helpEntry
for {set n 0} {[winfo exists $helpEntry]} {incr n} {
set helpEntry .__helpEntry$n
}
if {$usingTile} {
foreach opt {-borderwidth -bd -disabledbackground
-disabledforeground -highlightbackground
-highlightcolor -highlightthickness -insertbackground
-insertborderwidth -insertofftime -insertontime
-insertwidth -readonlybackground -relief
-selectbackground -selectborderwidth
-selectforeground} {
unset configSpecs($opt)
}
#
# Append theme-specific values to some
# elements of the array configSpecs
#
variable currentTheme
if {$currentTheme eq "aqua"} {
variable newAquaSupport
##nagelfar ignore
scan $::tcl_platform(osVersion) "%d" majorOSVersion
if {$newAquaSupport && $majorOSVersion >= 18} { ;# OS X 10.14+
update idletasks ;# needed for the isdark query
}
} elseif {$currentTheme eq "tileqt"} {
tileqt_kdeStyleChangeNotification
}
setThemeDefaults
#
# Append theme-independent values to some
# other elements of the array configSpecs
#
lappend configSpecs(-takefocus) {}
catch {lappend configSpecs(-cursor) [ttk::cursor text]}
ttk::entry $helpEntry -takefocus 0
} else {
tk::entry $helpEntry -takefocus 0
}
foreach configSet [$helpEntry configure] {
if {[llength $configSet] != 2} {
set opt [lindex $configSet 0]
if {[info exists configSpecs($opt)] &&
[llength $configSpecs($opt)] == 3} {
lappend configSpecs($opt) [lindex $configSet 3]
} elseif {$opt eq "-width"} {
lappend configSpecs(-body) [lindex $configSet 3]
}
}
}
}
extendConfigSpecs
variable configOpts [lsort [array names configSpecs]]
#
# Use a list to facilitate the handling of the command options
#
variable cmdOpts [list \
adjustentry attrib cget clear configure entries entrycount entrylimit \
entrypath getarray getlist getstring hasattrib isempty isfull \
labelcount labelpath labels put setentryextrawidth setentryfont \
setentrywidth unsetattrib]
}
#
# Private procedure creating the default bindings
# ===============================================
#
#------------------------------------------------------------------------------
# mentry::createBindings
#
# Creates the default bindings for the binding tags Mentry, MentryMain,
# MentryKeyNav, MentryEntry, and MentryLabel.
#------------------------------------------------------------------------------
proc mentry::createBindings {} {
#
# Define some Mentry class bindings
#
bind Mentry <KeyPress> continue
bind Mentry <FocusIn> {
if {[focus -lastfor %W] eq "%W"} {
catch {mentry::tabToEntry [mentry::firstNormal %W]}
}
}
bind Mentry <Destroy> {
namespace delete ::mentry::ns%W
catch {rename ::%W ""}
}
variable usingTile
if {$usingTile} {
bind Mentry <Activate> {
after idle [list mentry::updateLabelForegrounds %W 1]
}
bind Mentry <Deactivate> {
after idle [list mentry::updateLabelForegrounds %W 0]
}
}
bind Mentry <<TkWorldChanged>> {
if {"%d" eq "FontChanged"} {
mentry::updateFonts %W
}
}
#
# Define some bindings for the binding tag MentryMain
#
bindtags . [linsert [bindtags .] 1 MentryMain]
bind MentryMain <<ThemeChanged>> {
after idle mentry::handleThemeChangedEvent
}
variable winSys
variable newAquaSupport
if {$usingTile && $winSys eq "aqua" && $newAquaSupport} {
foreach event {<<LightAqua>> <<DarkAqua>>} {
bind MentryMain $event {
if {![info exists mentry::appearanceId]} {
set mentry::appearanceId \
[after 0 mentry::handleAppearanceEvent]
}
}
}
}
#
# Define the binding tag MentryKeyNav
#
mwutil::defineKeyNav Mentry
#
# Define some bindings for the binding tag MentryEntry
#
variable entryClicked 0
bind MentryEntry <Button-1> { set mentry::entryClicked 1 }
bind MentryEntry <ButtonRelease-1> { set mentry::entryClicked 0 }
bind MentryEntry <Left> { mentry::condGoToPrev %W }
bind MentryEntry <Right> { mentry::condGoToNext %W }
bind MentryEntry <Control-Left> { mentry::tabToPrev %W }
bind MentryEntry <Control-Right> { mentry::tabToNext %W }
bind MentryEntry <Home> { mentry::goToHome %W }
bind MentryEntry <End> { mentry::goToEnd %W }
bind MentryEntry <Shift-Home> { mentry::selectToHome %W }
bind MentryEntry <Shift-End> { mentry::selectToEnd %W }
bind MentryEntry <BackSpace> { mentry::backSpace %W }
bind MentryEntry <KeyPress> { mentry::procLabelChars %W %A }
if {$usingTile} {
#
# Define some bindings for the binding tag
# MentryEntry, needed for the aqua theme
#
bind MentryEntry <FocusIn> {
mentry::[winfo parent [winfo parent %W]] state focus
}
bind MentryEntry <FocusOut> {
mentry::[winfo parent [winfo parent %W]] state !focus
}
}
#
# Define some emacs-like key bindings for the binding tag MentryEntry
#
bind MentryEntry <Control-b> {
if {!$tk_strictMotif} {
mentry::condGoToPrev %W
}
}
bind MentryEntry <Control-f> {
if {!$tk_strictMotif} {
mentry::condGoToNext %W
}
}
bind MentryEntry <Meta-b> {
if {!$tk_strictMotif} {
mentry::tabToPrev %W
}
}
bind MentryEntry <Meta-f> {
if {!$tk_strictMotif} {
mentry::tabToNext %W
}
}
bind MentryEntry <Control-a> {
if {!$tk_strictMotif} {
mentry::goToHome %W
}
}
bind MentryEntry <Control-e> {
if {!$tk_strictMotif} {
mentry::goToEnd %W
}
}
bind MentryEntry <Control-h> {
if {!$tk_strictMotif} {
mentry::backSpace %W
}
}
bind MentryEntry <Meta-d> {
if {!$tk_strictMotif} {
%W delete insert end
break
}
}
bind MentryEntry <Meta-BackSpace> {
if {!$tk_strictMotif} {
mentry::delToLeft %W
}
}
bind MentryEntry <Meta-Delete> {
if {!$tk_strictMotif} {
mentry::delToLeft %W
}
}
#
# Define some bindings for the binding tag MentryLabel
#
bind MentryLabel <Button-1> { mentry::labelButton1 %W }
}
#
# Public procedure creating a new mentry widget
# =============================================
#
#------------------------------------------------------------------------------
# mentry::mentry
#
# Creates a new multi-entry widget whose name is specified as the first command-
# line argument, and configures it according to the options and their values
# given on the command line. Returns the name of the newly created widget.
#------------------------------------------------------------------------------
proc mentry::mentry args {
variable usingTile
variable configSpecs
variable configOpts
if {[llength $args] == 0} {
mwutil::wrongNumArgs "mentry pathName ?options?"
}
#
# Create a hull (a frame or tile entry) of the class Mentry
#
set win [lindex $args 0]
if {[catch {
if {$usingTile} {
ttk::entry $win -style Hull$win.TEntry -class Mentry
} else {
tk::frame $win -class Mentry -container 0 -height 0 -width 0
catch {$win configure -padx 0 -pady 0}
}
} result] != 0} {
return -code error $result
}
#
# Create a namespace within the current one to hold the data of the widget
#
namespace eval ns$win {
#
# The folowing array holds various data for this widget
#
variable data
array set data {
entryCount 0
labelCount 0
maxEntryIdx -1
maxLabelIdx -1
inActiveWin 1
}
#
# The following array is used to hold arbitrary
# attributes and their values for this widget
#
variable attribs
}
#
# Initialize some further components of data
#
upvar ::mentry::ns${win}::data data
foreach opt $configOpts {
set data($opt) [lindex $configSpecs($opt) 3]
}
if {$usingTile} {
variable themeDefaults
set data(themeDefaults) [array get themeDefaults]
foreach opt {-disabledbackground -readonlybackground} {
set data($opt) $themeDefaults($opt)
}
}
#
# Take into account that some scripts start by
# destroying all children of the root window
#
variable helpEntry
if {![winfo exists $helpEntry]} {
if {$usingTile} {
ttk::entry $helpEntry -takefocus 0
} else {
tk::entry $helpEntry -takefocus 0
}
}
#
# Configure the widget according to the command-line
# arguments and to the available database options
#
if {[catch {
mwutil::configureWidget $win configSpecs mentry::doConfig \
mentry::doCget [lrange $args 1 end] 1
} result] != 0} {
destroy $win
return -code error $result
}
#
# Move the original widget command into the current namespace
# and build a new widget procedure in the global one
#
rename ::$win $win
interp alias {} ::$win {} mentry::mentryWidgetCmd $win
return $win
}
#
# Private configuration procedures
# ================================
#
#------------------------------------------------------------------------------
# mentry::doConfig
#
# Applies the value val of the configuration option opt to the mentry widget
# win.
#------------------------------------------------------------------------------
proc mentry::doConfig {win opt val} {
variable usingTile
variable helpEntry
variable configSpecs
upvar ::mentry::ns${win}::data data
#
# Apply the value to the widget(s) corresponding to the given option
#
switch [lindex $configSpecs($opt) 2] {
c {
#
# Save the properly formatted value of val
# in data($opt) and apply it to all children
#
$helpEntry configure $opt $val
set val [$helpEntry cget $opt]
set data($opt) $val
foreach w [entries $win] {
configEntry $w $opt $val
}
foreach w [labels $win] {
$w configure $opt $val
}
#
# Some options need special handling
#
variable themeDefaults
if {$opt eq "-font"} {
if {$usingTile} {
adjustChildren $win
}
foreach name [array names data ?*-chars] {
set index [lindex [split $name "-"] 0]
foreach {chars1 chars2} $data($name) {}
adjustentrySubCmd $win $index $chars1 $chars2
}
foreach name [array names data ?*-width] {
set index [lindex [split $name "-"] 0]
setentrywidthSubCmd $win $index $data($name)
}
} elseif {$opt eq "-foreground" && $usingTile &&
!$data(inActiveWin) && $val eq $themeDefaults($opt)} {
foreach w [labels $win] {
$w configure $opt $themeDefaults(-foreground,background)
}
}
}
e {
if {$opt eq "-textvariable" && $val ne ""} {
#
# The text variable must be an array
#
global $val
if {[info exists $val] && ![array exists $val]} {
return -code error "variable \"$val\" isn't array"
}
#
# For each entry child, set the -textvariable configuration
# option of the entry to the corresponding array element
#
for {set n 0} {$n < $data(entryCount)} {incr n} {
[entryPath $win $n] configure $opt ${val}($n)
}
set data($opt) $val
} else {
if {$opt eq "-state"} {
set val [mwutil::fullOpt "state" $val \
{disabled normal readonly}]
}
#
# Save the properly formatted value of val in
# data($opt) and apply it to all entry children
#
$helpEntry configure $opt $val
set val [$helpEntry cget $opt]
set oldVal $data($opt)
set data($opt) $val
if {$opt eq "-background" && $usingTile} {
#
# Take into account that some themes attempt to
# change several widget colors by invoking
# tk_setPalette before the theme change is finished
# (e.g., breeze and breeze-dark) or immediately
# after it (e.g., sun-valley-light|dark), still
# before the variable currentTheme is updated at
# idle time by the procedure handleThemeChangedEvent
#
set theme [::mwutil::currentTheme]
variable currentTheme
if {$theme ne $currentTheme} {
set data($opt) $oldVal ;# restore the old value
return ""
}
#
# Most themes support the -fieldbackground option for
# the style element Entry.field. In Tk versions earlier
# than 8.6.10, the aqua theme supported the -background
# option instead. Some themes (like Arc, plastik, tileqt,
# vista, and xpnative) don't support either of them.
#
variable newAquaSupport
if {$currentTheme eq "aqua" && !$newAquaSupport} {
styleConfig $win.TEntry -background $val
} else {
styleConfig $win.TEntry -fieldbackground $val
}
} else {
foreach w [entries $win] {
configEntry $w $opt $val
}
}
#
# Some options need special handling
#
if {$opt eq "-background"} {
switch $data(-state) {
normal {
set labelBg $val
}
disabled {
set labelBg $data(-disabledbackground)
}
readonly {
set labelBg $data(-readonlybackground)
}
}
if {$labelBg eq ""} {
set labelBg $val
}
foreach w [labels $win] {
$w configure $opt $labelBg
}
#
# Set also the hull's background, because
# of the shadow colors of its 3-D border
#
if {$usingTile} {
if {$currentTheme eq "aqua" && !$newAquaSupport} {
styleConfig Hull$win.TEntry -background $labelBg
} else {
styleConfig Hull$win.TEntry \
-fieldbackground $labelBg
}
if {$currentTheme eq "aqua" && [winfo viewable $win]} {
update idletasks ;# to avoid some artifacts on aqua
}
} else {
$win configure $opt $labelBg
}
} elseif {[regexp \
{^-(disabledbackground|readonlybackground|state)$} \
$opt]} {
switch $data(-state) {
normal {
set labelBg $data(-background)
set labelState normal
}
disabled {
set labelBg $data(-disabledbackground)
set labelState disabled
}
readonly {
set labelBg $data(-readonlybackground)
set labelState normal
}
}
if {$labelBg eq ""} {
set labelBg $data(-background)
}
foreach w [labels $win] {
$w configure -background $labelBg -state $labelState
}
if {$usingTile} {
$win configure -state $data(-state)
} else {
$win configure -background $labelBg
}
}
}
}
h {
#
# Apply the value to the hull and save the
# properly formatted value of val in data($opt)
#
$win configure $opt $val
set data($opt) [$win cget $opt]
}
w {
if {$opt eq "-body"} {
createChildren $win $val
}
}
}
}
#------------------------------------------------------------------------------
# mentry::doCget
#
# Returns the value of the configuration option opt for the mentry widget win.
#------------------------------------------------------------------------------
proc mentry::doCget {win opt} {
upvar ::mentry::ns${win}::data data
return $data($opt)
}
#------------------------------------------------------------------------------
# mentry::createChildren
#
# For each <width, text> pair given in the list body, the procedure creates an
# entry of the given width and a label displaying the given text, and defines
# some callbacks as well as bindings for the entry just created.
#------------------------------------------------------------------------------
proc mentry::createChildren {win body} {
variable winSys
variable usingTile
variable newAquaSupport
variable themeDefaults
variable configSpecs
variable configOpts
upvar ::mentry::ns${win}::data data
#
# Check the syntax of body before performing any changes
#
set argCount [llength $body]
if {$argCount == 0} {
return -code error "expected at least one entry child width"
}
foreach {width text} $body {
##nagelfar ignore
if {[catch {format "%d" $width}] != 0 || $width <= 0} {
return -code error "expected positive integer but got \"$width\""
}
}
#
# Destroy any existing children of the hull
#
foreach w [winfo children $win] {
if {[regexp {^(Frame|Entry|Label)$} [winfo class $w]]} {
destroy $w
}
}
set data(entryCount) [expr {($argCount + 1) / 2}]
set data(labelCount) [expr {$argCount / 2}]
set data(maxEntryIdx) [expr {$data(entryCount) - 1}]
set data(maxLabelIdx) [expr {$data(labelCount) - 1}]
if {$usingTile} {
foreach {bd bd2 x deltaWidth} [geomParams] {}
}
foreach name [array names data ?*-chars] {
unset data($name)
}
foreach name [array names data ?*-font] {
unset data($name)
}
foreach name [array names data ?*-width] {
unset data($name)
}
set data(-body) {}
set n 0
foreach {width text} $body {
#
# Append the properly formatted value
# of width to the list data(-body)
#
##nagelfar ignore
lappend data(-body) [format "%d" $width]
#
# Create an entry of the given width
# within (a frame child of) the hull win
#
if {$usingTile} {
set f [framePath $win $n]
tk::frame $f -borderwidth 0 -container 0 -highlightthickness 0 \
-relief flat -takefocus 0
catch {$f configure -padx 0 -pady 0}
set w $f.e
ttk::entry $w -style $win.TEntry -takefocus 0 -textvariable "" \
-width $width
} else {
set w [entryPath $win $n]
tk::entry $w -borderwidth 0 -highlightthickness 0 \
-takefocus 0 -textvariable "" -width $width
}
#
# Apply to it the current configuration options
#
foreach opt $configOpts {
if {$opt eq "-textvariable" && $data($opt) ne ""} {
upvar data($opt) val
$w configure $opt ${val}($n)
} elseif {[regexp {[ec]} [lindex $configSpecs($opt) 2]]} {
configEntry $w $opt $data($opt)
}
}
#
# Manage the entry
#
if {$usingTile} {
set frameWidth [expr {[reqEntryWidth $w] - $deltaWidth}]
set frameHeight [expr {[winfo reqheight $w] - $bd2}]
$f configure -width $frameWidth -height $frameHeight
place $w -x -$x -relwidth 1.0 -width $deltaWidth \
-y -$bd -relheight 1.0 -height $bd2
pack $f -side left -expand 1 -fill both -pady $bd
if {$n == 0} {
pack configure $f -padx [list $bd 0]
}
} else {
pack $w -side left -expand 1 -fill both
}
#
# Define some callbacks for the entry just created
#
wcb::callback $w before insert [list wcb::checkEntryLen $width]
wcb::callback $w after insert \
[list mentry::condTabToNext $width $win $n]
#
# Modify the list of binding tags of the entry
#
bindtags $w [list $w MentryEntry [winfo class $w] [winfo toplevel $w] \
MentryKeyNav all]
if {$n == $data(labelCount)} {
if {$usingTile} {
set w $f
}
break
}
#
# Append the value of text to the list data(-body)
#
lappend data(-body) $text
#
# Create a label displaying the given text within the hull win
#
set w [labelPath $win $n]
tk::label $w -anchor center -bitmap "" -borderwidth 0 -height 0 \
-highlightthickness 0 -image "" -padx 0 -pady 0 \
-takefocus 0 -text $text -textvariable "" -width 0 \
-wraplength 0
set defVal [lindex [$w configure -underline] 3]
$w configure -underline $defVal ;# -1 or "" (see TIP #577)
if {$usingTile} {
set padY $themeDefaults(-labelpady)
} elseif {$winSys eq "aqua" && $newAquaSupport} {
set padY {0 0}
} else {
set padY {1 0}
}
pack $w -side left -expand 1 -fill y -pady $padY
#
# Apply to it the current configuration options
#
foreach opt $configOpts {
if {[lindex $configSpecs($opt) 2] eq "c" &&
[info exists data($opt)]} {
$w configure $opt $data($opt)
}
}
switch $data(-state) {
normal {
set labelBg $data(-background)
set labelState normal
}
disabled {
set labelBg $data(-disabledbackground)
set labelState disabled
}
readonly {
set labelBg $data(-readonlybackground)
set labelState normal
}
}
if {$labelBg eq ""} {
set labelBg $data(-background)
}
$w configure -background $labelBg -state $labelState
if {$usingTile} {
$w configure -disabledforeground $themeDefaults(-disabledforeground)
}
#
# Replace the binding tag Label with MentryLabel
# in the list of binding tags of the label
#
bindtags $w [lreplace [bindtags $w] 1 1 MentryLabel]
incr n
}
#
# Adjust the last child's geometry
#
if {$usingTile} {
if {$argCount == 1} {
pack configure $w -padx [list $bd $bd]
} elseif {[winfo class $w] eq "Label"} {
pack configure $w -padx [list 0 [expr {$bd + 1}]]
} else {
pack configure $w -padx [list 0 $bd]
}
} elseif {[winfo class $w] eq "Label"} {
pack configure $w -padx [list 0 1]
}
}
#
# Private procedures implementing the mentry widget command
# =========================================================
#
#------------------------------------------------------------------------------
# mentry::mentryWidgetCmd
#
# This procedure is invoked to process the Tcl command corresponding to a
# multi-entry widget.
#------------------------------------------------------------------------------
proc mentry::mentryWidgetCmd {win args} {
set argCount [llength $args]
if {$argCount == 0} {
mwutil::wrongNumArgs "$win option ?arg arg ...?"
}
upvar ::mentry::ns${win}::data data
variable cmdOpts
set cmd [mwutil::fullOpt "option" [lindex $args 0] $cmdOpts]
switch $cmd {
adjustentry {
if {$argCount < 3 || $argCount > 4} {
mwutil::wrongNumArgs "$win $cmd index string1 ?string2?"
}
set n [childIndex [lindex $args 1] $data(maxEntryIdx)]
set chars1 [lindex $args 2]
set chars2 [expr {$argCount == 4 ? [lindex $args 3] : ""}]
return [adjustentrySubCmd $win $n $chars1 $chars2]
}
attrib {
return [mwutil::attribSubCmd $win "widget" [lrange $args 1 end]]
}
cget {
if {$argCount != 2} {
mwutil::wrongNumArgs "$win $cmd option"
}
#
# Return the value of the specified configuration option
#
variable configSpecs
set opt [mwutil::fullConfigOpt [lindex $args 1] configSpecs]
return $data($opt)
}
clear {
if {$argCount < 2 || $argCount > 3} {
mwutil::wrongNumArgs "$win $cmd firstIndex ?lastIndex?"
}
set firstIdx [childIndex [lindex $args 1] $data(maxEntryIdx)]
if {$argCount == 3} {
set lastIdx [childIndex [lindex $args 2] $data(maxEntryIdx)]
} else {
set lastIdx $firstIdx
}
for {set n $firstIdx} {$n <= $lastIdx} {incr n} {
_[entryPath $win $n] delete 0 end
}
return ""
}
configure {
variable configSpecs
return [mwutil::configureSubCmd $win configSpecs mentry::doConfig \
mentry::doCget [lrange $args 1 end]]
}
entries {
if {$argCount != 1} {
mwutil::wrongNumArgs "$win $cmd"
}
return [entries $win]
}
entrycount {
if {$argCount != 1} {
mwutil::wrongNumArgs "$win $cmd"
}
return $data(entryCount)
}
entrylimit {
if {$argCount != 2} {
mwutil::wrongNumArgs "$win $cmd index"
}
set n [childIndex [lindex $args 1] $data(maxEntryIdx)]
return [lindex $data(-body) [expr {$n * 2}]]
}
entrypath {
if {$argCount != 2} {
mwutil::wrongNumArgs "$win $cmd index"
}
set n [childIndex [lindex $args 1] $data(maxEntryIdx)]
return [entryPath $win $n]
}
getarray {
if {$argCount != 2} {
mwutil::wrongNumArgs "$win $cmd array"
}
#
# The last argument must be an array
#
set varName [lindex $args 1]
set _varName [list $varName]
if {[uplevel info exists $_varName] &&
![uplevel array exists $_varName]} {
return -code error "variable \"$varName\" isn't array"
}
upvar $varName arr
for {set n 0} {$n < $data(entryCount)} {incr n} {
set arr($n) [[entryPath $win $n] get]
}
return ""
}
getlist {
if {$argCount != 1} {
mwutil::wrongNumArgs "$win $cmd"
}
set result {}
foreach w [entries $win] {
lappend result [$w get]
}
return $result
}
getstring {
if {$argCount != 1} {
mwutil::wrongNumArgs "$win $cmd"
}
set result ""
foreach w [winfo children $win] {
switch [winfo class $w] {
Frame { append result [$w.e get] }
Entry { append result [$w get] }
Label { append result [$w cget -text] }
}
}
return $result
}
hasattrib {
if {$argCount != 2} {
mwutil::wrongNumArgs "$win $cmd name"
}
return [mwutil::hasattribSubCmd $win "widget" [lindex $args 1]]
}
isempty {
switch $argCount {
1 {
foreach w [entries $win] {
if {[$w get] ne ""} {
return 0
}
}
return 1
}
2 {
set n [childIndex [lindex $args 1] $data(maxEntryIdx)]
set w [entryPath $win $n]
return [expr {[$w get] eq ""}]
}
default {
mwutil::wrongNumArgs "$win $cmd ?index?"
}
}
}
isfull {
switch $argCount {
1 {
for {set n 0} {$n < $data(entryCount)} {incr n} {
set w [entryPath $win $n]
set limit [lindex $data(-body) [expr {$n * 2}]]
if {[string length [$w get]] != $limit} {
return 0
}
}
return 1
}
2 {
set n [childIndex [lindex $args 1] $data(maxEntryIdx)]
set w [entryPath $win $n]
set limit [lindex $data(-body) [expr {$n * 2}]]
return [expr {[string length [$w get]] == $limit}]
}
default {
mwutil::wrongNumArgs "$win $cmd ?index?"
}
}
}
labelcount {
if {$argCount != 1} {
mwutil::wrongNumArgs "$win $cmd"
}
return $data(labelCount)
}
labelpath {
if {$argCount != 2} {
mwutil::wrongNumArgs "$win $cmd index"
}
set n [childIndex [lindex $args 1] $data(maxLabelIdx)]
return [labelPath $win $n]
}
labels {
if {$argCount != 1} {
mwutil::wrongNumArgs "$win $cmd"
}
return [labels $win]
}
put {
if {$argCount < 2} {
mwutil::wrongNumArgs "$win $cmd startIndex\
?string string ...?"
}
set startIdx [childIndex [lindex $args 1] $data(maxEntryIdx)]
return [putSubCmd $win $startIdx [lrange $args 2 end]]
}
setentryextrawidth {
if {$argCount != 3} {
mwutil::wrongNumArgs "$win $cmd index amount"
}
set n [childIndex [lindex $args 1] $data(maxEntryIdx)]
return [setentryextrawidthSubCmd $win $n [lindex $args 2]]
}
setentryfont {
if {$argCount != 3} {
mwutil::wrongNumArgs "$win $cmd index font"
}
set n [childIndex [lindex $args 1] $data(maxEntryIdx)]
return [setentryfontSubCmd $win $n [lindex $args 2]]
}
setentrywidth {
if {$argCount != 3} {
mwutil::wrongNumArgs "$win $cmd index characters"
}
set n [childIndex [lindex $args 1] $data(maxEntryIdx)]
return [setentrywidthSubCmd $win $n [lindex $args 2]]
}
unsetattrib {
if {$argCount != 2} {
mwutil::wrongNumArgs "$win $cmd name"
}
return [mwutil::unsetattribSubCmd $win "widget" [lindex $args 1]]
}
}
}
#------------------------------------------------------------------------------
# mentry::adjustentrySubCmd
#
# This procedure is invoked to process the mentry adjustentry subcommand.
#------------------------------------------------------------------------------
proc mentry::adjustentrySubCmd {win index chars1 chars2} {
upvar ::mentry::ns${win}::data data
set data($index-chars) [list $chars1 $chars2]
set w [entryPath $win $index]
set font [$w cget -font]
#
# Get the max. widths maxWidth1 and maxWidth2
# of the characters in chars1 and chars2
#
set len [string length $chars1]
set maxWidth1 0
for {set n 0} {$n < $len} {incr n} {
set width [font measure $font -displayof $w [string index $chars1 $n]]
if {$width > $maxWidth1} {
set maxWidth1 $width
}
}
set len [string length $chars2]
set maxWidth2 0
for {set n 0} {$n < $len} {incr n} {
set width [font measure $font -displayof $w [string index $chars2 $n]]
if {$width > $maxWidth2} {
set maxWidth2 $width
}
}
set count [lindex $data(-body) [expr {$index * 2}]]
#
# Get the requested width in case all count characters are from chars1
#
set reqWidth1 [expr {$maxWidth1 * $count}]
#
# Get the requested width in case count - 1 characters
# are from chars1 and one character is from chars2
#
set lessCount [expr {$count - 1}]
set reqWidth2 [expr {$maxWidth1*$lessCount + $maxWidth2}]
#
# Set the requested width to the maximum of the two
#
set reqWidth [expr {$reqWidth1 < $reqWidth2 ? $reqWidth2 : $reqWidth1}]
set zeroWidth [font measure $font -displayof $w "0"]
set availWidth [expr {$zeroWidth * $count}]
if {$reqWidth < $availWidth} {
return ""
}
variable usingTile
set iPadX [expr {($reqWidth - $availWidth + 1) / 2}]
if {$usingTile} {
pack configure [winfo parent $w] -ipadx $iPadX
} else {
pack configure $w -ipadx $iPadX
}
return ""
}
#------------------------------------------------------------------------------
# mentry::putSubCmd
#
# This procedure is invoked to process the mentry put subcommand.
#------------------------------------------------------------------------------
proc mentry::putSubCmd {win startIdx strList} {
upvar ::mentry::ns${win}::data data
#
# Attempt to replace the texts of the entry children whose indices are
# >= startIdx with the given strings, until either the entries or the
# strings are consumed, by using the delete and insert operations; abort
# the loop if one of these subcommands is canceled by some before-callback
#
set undo 0
set n $startIdx
set oldStrings {}
set oldPositions {}
foreach str $strList {
if {$n == $data(entryCount)} {
break
}
set w [entryPath $win $n]
lappend oldStrings [$w get]
lappend oldPositions [$w index insert]
$w delete 0 end
if {[wcb::canceled $w delete]} {
set undo 1
break
}
if {[set focus [focus -displayof $w]] eq $w} {
#
# Temporarily remove the procedure mentry::condTabToNext from
# the list of after-insert callbacks of this entry, because
# it might move the focus to the next enabled entry child
#
set callbackList [wcb::callback $w after insert]
set idx [lsearch -glob $callbackList "mentry::condTabToNext *"]
set callbackList2 [lreplace $callbackList $idx $idx ""]
eval wcb::callback [list $w] after insert $callbackList2
}
$w insert 0 $str
if {$focus eq $w} {
#
# Restore the after-insert callbacks of this entry
#
eval wcb::callback [list $w] after insert $callbackList
}
if {[wcb::canceled $w insert]} {
set undo 1
break
}
incr n
}
#
# Restore the original contents of the entry children if necessary, and
# in any case restore the position of the insertion cursor in each entry
#
set n $startIdx
foreach oldStr $oldStrings oldPos $oldPositions {
set w [entryPath $win $n]
if {$undo} {
$w delete 0 end
$w insert 0 $oldStr
}
$w icursor $oldPos
incr n
}
return [expr {!$undo}]
}
#------------------------------------------------------------------------------
# mentry::setentryextrawidthSubCmd
#
# This procedure is invoked to process the mentry setentryextrawidth subcommand.
#------------------------------------------------------------------------------
proc mentry::setentryextrawidthSubCmd {win index amount} {
set w [entryPath $win $index]
set pixels [winfo pixels $w $amount]
if {$pixels < 0} {
set pixels 0
}
set iPadX [expr {($pixels + 1) / 2}]
variable usingTile
if {$usingTile} {
pack configure [winfo parent $w] -ipadx $iPadX
} else {
pack configure $w -ipadx $iPadX
}
return ""
}
#------------------------------------------------------------------------------
# mentry::setentryfontSubCmd
#
# This procedure is invoked to process the mentry setentryfont subcommand.
#------------------------------------------------------------------------------
proc mentry::setentryfontSubCmd {win index font} {
set w [entryPath $win $index]
$w configure -font $font
upvar ::mentry::ns${win}::data data
set data($index-font) $font
if {[info exists data($index-chars)]} {
foreach {chars1 chars2} $data($index-chars) {}
adjustentrySubCmd $win $index $chars1 $chars2
}
if {[info exists data($index-width)]} {
setentrywidthSubCmd $win $index $data($index-width)
}
variable usingTile
if {!$usingTile} {
return ""
}
foreach {bd bd2 x deltaWidth} [geomParams] {}
set frameWidth [expr {[reqEntryWidth $w] - $deltaWidth}]
set frameHeight [expr {[winfo reqheight $w] - $bd2}]
[winfo parent $w] configure -width $frameWidth -height $frameHeight
place configure $w -x -$x -relwidth 1.0 -width $deltaWidth \
-y -$bd -relheight 1.0 -height $bd2
return ""
}
#------------------------------------------------------------------------------
# mentry::setentrywidthSubCmd
#
# This procedure is invoked to process the mentry setentrywidth subcommand.
#------------------------------------------------------------------------------
proc mentry::setentrywidthSubCmd {win index width} {
set w [entryPath $win $index]
$w configure -width $width
upvar ::mentry::ns${win}::data data
set data($index-width) $width
variable usingTile
if {!$usingTile} {
return ""
}
foreach {bd bd2 x deltaWidth} [geomParams] {}
set frameWidth [expr {[reqEntryWidth $w] - $deltaWidth}]
[winfo parent $w] configure -width $frameWidth
place configure $w -x -$x -relwidth 1.0 -width $deltaWidth
return ""
}
#------------------------------------------------------------------------------
# mentry::childIndex
#
# Checks the index n, rounds it to the nearest value between 0 and max, and
# returns either the rounded value or an error.
#------------------------------------------------------------------------------
proc mentry::childIndex {n max} {
if {[string first $n "end"] == 0} {
return $max
##nagelfar ignore
} elseif {[catch {format "%d" $n} index] != 0} {
return -code error \
"bad index \"$n\": must be end or a number"
} elseif {$index < 0} {
return 0
} elseif {$index > $max} {
return $max
} else {
return $index
}
}
#
# Private callback procedure
# ==========================
#
#------------------------------------------------------------------------------
# mentry::condTabToNext
#
# This after-insert callback checks whether the insertion cursor in the n'th
# entry child of the mentry widget win is just behind the character having the
# index width and the focus is on that entry; if this is the case, it moves the
# focus to the next enabled entry child, selects the content of that widget,
# and sets the insertion cursor to its end.
#------------------------------------------------------------------------------
proc mentry::condTabToNext {width win n w idx str} {
if {[$w index insert] == $width &&
[focus -displayof $win] eq [entryPath $win $n] &&
[set next [nextNormal $win $n]] ne ""} {
tabToEntry $next
}
}
#
# Private procedures used in bindings
# ===================================
#
#------------------------------------------------------------------------------
# mentry::updateLabelForegrounds
#
# This procedure handles the events <Activate> and <Deactivate> by updating the
# -foreground option of the labels of the mentry widget win.
#------------------------------------------------------------------------------
proc mentry::updateLabelForegrounds {win inActiveWin} {
#
# This is an "after idle" callback; check whether the window exists
#
if {![array exists ::mentry::ns${win}::data]} {
return ""
}
upvar ::mentry::ns${win}::data data
variable themeDefaults
set data(inActiveWin) $inActiveWin
if {!$data(inActiveWin) && \
$data(-foreground) eq $themeDefaults(-foreground)} {
set labelFg $themeDefaults(-foreground,background)
} else {
set labelFg $data(-foreground)
}
foreach w [labels $win] {
$w configure -foreground $labelFg
}
}
#------------------------------------------------------------------------------
# mentry::updateFonts
#
# This procedure handles the virtual event <<TkWorldChanged>> if the latter's
# %d field equals "FontChanged".
#------------------------------------------------------------------------------
proc mentry::updateFonts win {
upvar ::mentry::ns${win}::data data
doConfig $win -font $data(-font)
foreach name [array names data ?*-font] {
set index [lindex [split $name "-"] 0]
setentryfontSubCmd $win $index $data($name)
}
}
#------------------------------------------------------------------------------
# mentry::handleThemeChangedEvent
#
# This procedure handles the virtual event <<ThemeChanged>>.
#------------------------------------------------------------------------------
proc mentry::handleThemeChangedEvent {} {
variable currentTheme
variable widgetStyle
variable colorScheme
set newTheme [::mwutil::currentTheme]
if {$newTheme eq $currentTheme} {
if {$newTheme eq "tileqt"} {
set newWidgetStyle [tileqt_currentThemeName]
if {[info exists ::env(KDE_SESSION_VERSION)] &&
$::env(KDE_SESSION_VERSION) ne ""} {
set newColorScheme [getKdeConfigVal "General" "ColorScheme"]
} else {
set newColorScheme [getKdeConfigVal "KDE" "colorScheme"]
}
if {$newWidgetStyle eq $widgetStyle &&
$newColorScheme eq $colorScheme} {
return ""
}
} else {
return ""
}
}
set currentTheme $newTheme
if {$newTheme eq "tileqt"} {
set widgetStyle $newWidgetStyle
set colorScheme $newColorScheme
} else {
set widgetStyle ""
set colorScheme ""
}
variable usingTile
if {$usingTile} {
#
# Populate the array themeDefaults with
# values corresponding to the new theme
#
setThemeDefaults
event generate . <<MentryThemeDefaultsChanged>>
}
#
# Level-order traversal like in the Tk library procedue ::ttk::ThemeChanged
#
set lst1 {.}
while {[llength $lst1] != 0} {
set lst2 {}
foreach w $lst1 {
if {[winfo class $w] eq "Mentry"} {
updateConfiguration $w
}
foreach child [winfo children $w] {
lappend lst2 $child
}
}
set lst1 $lst2
}
}
#------------------------------------------------------------------------------
# mentry::updateConfiguration
#
# Updates the theme-specific default values of some mentry configuration
# options.
#------------------------------------------------------------------------------
proc mentry::updateConfiguration win {
upvar ::mentry::ns${win}::data data
variable usingTile
if {$usingTile} {
#
# Populate the array tmp with values corresponding to the old theme
#
array set tmp $data(themeDefaults)
#
# Set those configuration options whose values equal the old
# theme-specific defaults to the new theme-specific ones
#
variable themeDefaults
foreach opt {-disabledbackground -readonlybackground} {
set data($opt) $themeDefaults($opt)
}
foreach opt {-background -foreground -font} {
if {$data($opt) eq $tmp($opt)} {
doConfig $win $opt $themeDefaults($opt)
}
}
adjustChildren $win
#
# Most themes support the -fieldbackground option for the style element
# Entry.field. In Tk versions earlier than 8.6.10, the aqua theme
# supported the -background option instead. Some themes (like Arc,
# plastik, tileqt, vista, and xpnative) don't support either of them.
#
variable currentTheme
variable newAquaSupport
foreach style [list $win.TEntry Hull$win.TEntry] {
if {$currentTheme eq "aqua" && !$newAquaSupport} {
styleConfig $style -background $data(-background)
} else {
styleConfig $style -fieldbackground $data(-background)
}
if {[winfo viewable $win]} {
update idletasks ;# to avoid some artifacts on aqua
}
}
#
# Set the foreground color of the label children
#
if {!$data(inActiveWin) && \
$data(-foreground) eq $themeDefaults(-foreground)} {
set labelFg $themeDefaults(-foreground,background)
} else {
set labelFg $data(-foreground)
}
foreach w [labels $win] {
$w configure -foreground $labelFg \
-disabledforeground $themeDefaults(-disabledforeground)
}
set data(themeDefaults) [array get themeDefaults]
}
}
#------------------------------------------------------------------------------
# mentry::handleAppearanceEvent
#
# This procedure handles the virtual events <<LightAqua>> and <<DarkAqua>>.
#------------------------------------------------------------------------------
proc mentry::handleAppearanceEvent {} {
variable appearanceId
unset appearanceId
variable currentTheme
if {$currentTheme ne "aqua"} {
return ""
}
#
# Populate the array themeDefaults with
# values corresponding to the new appearance
#
setThemeDefaults
event generate . <<MentryThemeDefaultsChanged>>
#
# Level-order traversal like in the Tk library procedue ::ttk::ThemeChanged
#
set lst1 {.}
while {[llength $lst1] != 0} {
set lst2 {}
foreach w $lst1 {
if {[winfo class $w] eq "Mentry"} {
updateAppearance $w
}
foreach child [winfo children $w] {
lappend lst2 $child
}
}
set lst1 $lst2
}
}
#------------------------------------------------------------------------------
# mentry::updateAppearance
#
# Updates the appearance of the mentry widget win according to the virtual
# events <<LightAqua>> and <<DarkAqua>>.
#------------------------------------------------------------------------------
proc mentry::updateAppearance win {
upvar ::mentry::ns${win}::data data
#
# Populate the array tmp with values
# corresponding to the old appearance
#
array set tmp $data(themeDefaults)
#
# Set those configuration options whose values equal the old
# theme-specific defaults to the new theme-specific ones
#
variable themeDefaults
foreach opt {-disabledbackground -readonlybackground} {
set data($opt) $themeDefaults($opt)
}
foreach opt {-background -foreground} {
if {$data($opt) eq $tmp($opt)} {
doConfig $win $opt $themeDefaults($opt)
}
}
#
# Set the foreground color of the label children
#
if {!$data(inActiveWin) && \
$data(-foreground) eq $themeDefaults(-foreground)} {
set labelFg $themeDefaults(-foreground,background)
} else {
set labelFg $data(-foreground)
}
foreach w [labels $win] {
$w configure -foreground $labelFg \
-disabledforeground $themeDefaults(-disabledforeground)
}
set data(themeDefaults) [array get themeDefaults]
}
#------------------------------------------------------------------------------
# mentry::condGoToPrev
#
# This procedure handles <Left> events in the entry child w of a mentry widget.
# If the insertion cursor is at the beginning of the entry, the procedure
# clears the selection in the current entry, moves the focus to the previous
# enabled entry child, and sets the insertion cursor to the end of that widget.
#------------------------------------------------------------------------------
proc mentry::condGoToPrev w {
parseChildPath $w win n
if {[$w index insert] == 0 && [set prev [prevNormal $win $n]] ne ""} {
$w selection clear
focus $prev
entrySetCursor $prev end
return -code break ""
}
}
#------------------------------------------------------------------------------
# mentry::condGoToNext
#
# This procedure handles <Right> events in the entry child w of a mentry
# widget. If the insertion cursor is at the end of the entry's content, the
# procedure clears the selection in the current entry, moves the focus to the
# next enabled entry child, and sets the insertion cursor to the beginning of
# that widget.
#------------------------------------------------------------------------------
proc mentry::condGoToNext w {
parseChildPath $w win n
if {[$w index insert] == [$w index end] &&
[set next [nextNormal $win $n]] ne ""} {
$w selection clear
focus $next
entrySetCursor $next 0
return -code break ""
}
}
#------------------------------------------------------------------------------
# mentry::tabToPrev
#
# This procedure handles <Control-Left> events in the entry child w of a mentry
# widget. If possible, it moves the focus to the previous enabled entry child,
# selects the content of that widget, and sets the insertion cursor to its end;
# otherwise, it moves the insertion cursor to the beginning of the current
# entry and clears the selection in that widget.
#------------------------------------------------------------------------------
proc mentry::tabToPrev w {
parseChildPath $w win n
set prev [prevNormal $win $n]
if {$prev ne ""} {
tabToEntry $prev
} else {
entrySetCursor $w 0
}
return -code break ""
}
#------------------------------------------------------------------------------
# mentry::tabToNext
#
# This procedure handles <Control-Right> events in the entry child w of a
# mentry widget. If possible, it moves the focus to the next enabled entry
# child, selects the content of that widget, and sets the insertion cursor to
# its end; otherwise, it moves the insertion cursor to the end of the current
# entry and clears the selection in that widget.
#------------------------------------------------------------------------------
proc mentry::tabToNext w {
parseChildPath $w win n
set next [nextNormal $win $n]
if {$next ne ""} {
tabToEntry $next
} else {
entrySetCursor $w end
}
return -code break ""
}
#------------------------------------------------------------------------------
# mentry::goToHome
#
# This procedure handles <Home> events in the entry child w of a mentry widget.
# It clears the selection in the current entry, moves the focus to the first
# enabled entry child, and sets the insertion cursor to the beginning of that
# widget.
#------------------------------------------------------------------------------
proc mentry::goToHome w {
parseChildPath $w win n
set first [firstNormal $win]
$w selection clear
focus $first
catch {entrySetCursor $first 0}
return -code break ""
}
#------------------------------------------------------------------------------
# mentry::goToEnd
#
# This procedure handles <End> events in the entry child w of a mentry widget.
# It clears the selection in the current entry, moves the focus to the last
# enabled entry child, and sets the insertion cursor to the end of that widget.
#------------------------------------------------------------------------------
proc mentry::goToEnd w {
parseChildPath $w win n
set last [lastNormal $win]
$w selection clear
focus $last
catch {entrySetCursor $last end}
return -code break ""
}
#------------------------------------------------------------------------------
# mentry::selectToHome
#
# This procedure handles <Shift-Home> events in the entry child w of a mentry
# widget. It moves the focus to the first enabled entry child, sets the
# insertion cursor to the beginning of that widget, and either extends the
# selection to that position. or clears the selection in w and selects the
# contents of the new widget, depending upon whether the first enabled entry
# child equals w.
#------------------------------------------------------------------------------
proc mentry::selectToHome w {
parseChildPath $w win n
set first [firstNormal $win]
if {$first ne $w} {
$w selection clear
focus $first
catch {$first icursor end}
}
catch {
if {[$first selection present]} {
$first selection range 0 sel.last
} else {
$first selection range 0 insert
}
$first icursor 0
entryViewCursor $first
}
return -code break ""
}
#------------------------------------------------------------------------------
# mentry::selectToEnd
#
# This procedure handles <Shift-End> events in the entry child w of a mentry
# widget. It moves the focus to the last enabled entry child, sets the
# insertion cursor to the end of that widget, and either extends the
# selection to that position. or clears the selection in w and selects the
# contents of the new widget, depending upon whether the last enabled entry
# child equals w.
#------------------------------------------------------------------------------
proc mentry::selectToEnd w {
parseChildPath $w win n
set last [lastNormal $win]
if {$last ne $w} {
$w selection clear
focus $last
catch {$last icursor 0}
}
catch {
if {[$last selection present]} {
$last selection range sel.first end
} else {
$last selection range insert end
}
$last icursor end
entryViewCursor $last
}
return -code break ""
}
#------------------------------------------------------------------------------
# mentry::backSpace
#
# This procedure handles <BackSpace> events in the entry child w of a mentry
# widget. It deletes the selection if there is one in the entry. Otherwise,
# it deletes either the character to the left of the insertion cursor in the
# current entry, or the last character of the previous enabled entry child,
# depending upon the position of the insertion cursor. In the second case, it
# also moves the focus to the previous enabled entry child and sets the
# insertion cursor to its end.
#------------------------------------------------------------------------------
proc mentry::backSpace w {
parseChildPath $w win n
if {[$w selection present]} {
$w delete sel.first sel.last
} else {
if {[$w index insert] == 0 && [set prev [prevNormal $win $n]] ne ""} {
focus $prev
entrySetCursor $prev end
set w $prev
}
set x [expr {[$w index insert] - 1}]
if {$x >= 0} {
$w delete $x
}
if {[$w index insert] <= [$w index @0]} {
set range [$w xview]
set left [lindex $range 0]
set right [lindex $range 1]
$w xview moveto [expr {$left - ($right - $left)/2.0}]
}
}
return -code break ""
}
#------------------------------------------------------------------------------
# mentry::delToLeft
#
# This procedure handles <Meta-BackSpace> and <Meta-Delete> events in the entry
# child w of a mentry widget. It deletes either all characters to the left of
# the insertion cursor in the current entry, or the contents of the previous
# enabled entry child, depending upon the position of the insertion cursor. In
# the second case, it also clears the selection in the current entry widget and
# moves the focus to the previous enabled entry child.
#------------------------------------------------------------------------------
proc mentry::delToLeft w {
parseChildPath $w win n
if {[$w index insert] == 0 && [set prev [prevNormal $win $n]] ne ""} {
$w selection clear
focus $prev
$prev delete 0 end
} else {
$w delete 0 insert
}
return -code break ""
}
#------------------------------------------------------------------------------
# mentry::procLabelChars
#
# This procedure handles <KeyPress> events in the entry child w of a mentry
# widget. If this entry is non-empty and the character char corresponding to
# the event is contained in the text displayed in the label child following the
# entry (if any) then the procedure moves the focus to the next enabled entry
# child, selects the content of that widget, and sets the insertion cursor to
# its end.
#------------------------------------------------------------------------------
proc mentry::procLabelChars {w char} {
parseChildPath $w win n
set label [labelPath $win $n]
if {![winfo exists $label] ||
[string first $char [$label cget -text]] < 0} {
return ""
}
if {[$w get] eq ""} {
return -code break ""
}
set next [nextNormal $win $n]
if {$next ne ""} {
tabToEntry $next
}
return -code break ""
}
#------------------------------------------------------------------------------
# mentry::labelButton1
#
# This procedure handles <Button-1> events in the label child w of a mentry
# widget. It generates a <Button-1> event in the previous enabled entry child,
# after its last character.
#------------------------------------------------------------------------------
proc mentry::labelButton1 w {
parseChildPath $w win n
incr n
set entry [prevNormal $win $n]
if {$entry ne ""} {
set bbox [$entry bbox end]
set x [expr {[lindex $bbox 0] + [lindex $bbox 2]}]
event generate $entry <Button-1> -x $x
variable entryClicked
set entryClicked 0
}
}
#------------------------------------------------------------------------------
# mentry::parseChildPath
#
# Extracts the path name of the mentry widget as well as the child's index from
# the path name w of a child of a mentry widget.
#------------------------------------------------------------------------------
proc mentry::parseChildPath {w winName indexName} {
upvar $winName win $indexName index
return [regexp {^(.+)\.[fel]([0-9]+)(\.e)?$} $w dummy win index]
}
#
# Private utility procedures
# ==========================
#
#------------------------------------------------------------------------------
# mentry::framePath
#
# Returns the path name of the n'th frame child of the tile-based mentry widget
# win.
#------------------------------------------------------------------------------
proc mentry::framePath {win n} {
return $win.f$n
}
#------------------------------------------------------------------------------
# mentry::entryPath
#
# Returns the path name of the n'th entry (grand)child of the mentry widget win.
#------------------------------------------------------------------------------
proc mentry::entryPath {win n} {
variable usingTile
if {$usingTile} {
return $win.f$n.e
} else {
return $win.e$n
}
}
#------------------------------------------------------------------------------
# mentry::labelPath
#
# Returns the path name of the n'th label child of the mentry widget win.
#------------------------------------------------------------------------------
proc mentry::labelPath {win n} {
return $win.l$n
}
#------------------------------------------------------------------------------
# mentry::entries
#
# Returns a list containing the path names of the entry children of the widget
# win.
#------------------------------------------------------------------------------
proc mentry::entries win {
set lst {}
foreach w [winfo children $win] {
set class [winfo class $w]
if {$class eq "Entry"} {
lappend lst $w
} elseif {$class eq "Frame"} {
lappend lst $w.e
}
}
return $lst
}
#------------------------------------------------------------------------------
# mentry::labels
#
# Returns a list containing the path names of the label children of the widget
# win.
#------------------------------------------------------------------------------
proc mentry::labels win {
set lst {}
foreach w [winfo children $win] {
if {[winfo class $w] eq "Label"} {
lappend lst $w
}
}
return $lst
}
#------------------------------------------------------------------------------
# mentry::prevNormal
#
# Returns the path name of the rightmost enabled entry child to the left of the
# n'th entry of the mentry widget win.
#------------------------------------------------------------------------------
proc mentry::prevNormal {win n} {
for {incr n -1} {$n >= 0} {incr n -1} {
set w [entryPath $win $n]
if {[$w cget -state] eq "normal"} {
return $w
}
}
return ""
}
#------------------------------------------------------------------------------
# mentry::nextNormal
#
# Returns the path name of the leftmost enabled entry child to the right of the
# n'th entry of the mentry widget win.
#------------------------------------------------------------------------------
proc mentry::nextNormal {win n} {
upvar ::mentry::ns${win}::data data
for {incr n} {$n < $data(entryCount)} {incr n} {
set w [entryPath $win $n]
if {[$w cget -state] eq "normal"} {
return $w
}
}
return ""
}
#------------------------------------------------------------------------------
# mentry::firstNormal
#
# Returns the path name of the first enabled entry child of the mentry widget
# win.
#------------------------------------------------------------------------------
proc mentry::firstNormal win {
return [nextNormal $win -1]
}
#------------------------------------------------------------------------------
# mentry::lastNormal
#
# Returns the path name of the last enabled entry child of the mentry widget
# win.
#------------------------------------------------------------------------------
proc mentry::lastNormal win {
upvar ::mentry::ns${win}::data data
return [prevNormal $win $data(entryCount)]
}
#------------------------------------------------------------------------------
# mentry::adjustChildren
#
# Adjusts the geometry of the children of the tile-based mentry widget win.
#------------------------------------------------------------------------------
proc mentry::adjustChildren win {
set childList [winfo children $win]
set childCount [llength $childList]
if {$childCount == 0} {
return ""
}
foreach {bd bd2 x deltaWidth} [geomParams] {}
pack configure [framePath $win 0] -padx [list $bd 0]
variable themeDefaults
foreach w $childList {
if {[winfo class $w] eq "Frame"} {
set frameWidth [expr {[reqEntryWidth $w.e] - $deltaWidth}]
set frameHeight [expr {[winfo reqheight $w.e] - $bd2}]
$w configure -width $frameWidth -height $frameHeight
place configure $w.e -x -$x -relwidth 1.0 -width $deltaWidth \
-y -$bd -relheight 1.0 -height $bd2
pack configure $w -pady $bd
} else {
pack configure $w -pady $themeDefaults(-labelpady)
}
}
if {$childCount == 1} {
pack configure $w -padx [list $bd $bd]
} elseif {[winfo class $w] eq "Label"} {
pack configure $w -padx [list 0 [expr {$bd + 1}]]
} else {
pack configure $w -padx [list 0 $bd]
}
}
#------------------------------------------------------------------------------
# mentry::tabToEntry
#
# Moves the focus to the specified entry widget, selects its contents, and sets
# the insertion cursor to its end.
#------------------------------------------------------------------------------
proc mentry::tabToEntry w {
focus $w
$w selection range 0 end
$w icursor end
}
#------------------------------------------------------------------------------
# mentry::entrySetCursor
#
# Moves the insertion cursor to the specified position in the given entry
# widget, clears the selection, and makes sure that the insertion cursor is
# visible.
#------------------------------------------------------------------------------
proc mentry::entrySetCursor {w pos} {
$w icursor $pos
$w selection clear
entryViewCursor $w
}
#------------------------------------------------------------------------------
# mentry::entryViewCursor
#
# Makes sure that the insertion cursor in the specified entry is visible by
# adjusting the view if necessary.
#------------------------------------------------------------------------------
proc mentry::entryViewCursor w {
set c [$w index insert]
if {$c < [$w index @0] || $c > [$w index @[winfo width $w]]} {
$w xview $c
}
}
#------------------------------------------------------------------------------
# mentry::configEntry
#
# This procedure configures the entry widget w according to the options and
# their values given in args.
#------------------------------------------------------------------------------
proc mentry::configEntry {w args} {
foreach {opt val} $args {
switch -- $opt {
-background {
if {[winfo class $w] ne "TEntry"} {
$w configure $opt $val
}
}
-foreground {
if {[winfo class $w] eq "TEntry"} {
variable themeDefaults
if {[winfo rgb $w $val] eq \
[winfo rgb $w $themeDefaults(-foreground)]} {
set val "" ;# for automatic adaptation to the states
}
$w instate !disabled {
$w configure $opt $val
}
} else {
$w configure $opt $val
}
}
-state {
$w configure $opt $val
if {[winfo class $w] eq "TEntry"} {
variable themeDefaults
if {$val eq "disabled"} {
#
# Set the entry's foreground color to the theme-
# specific one (needed for current tile versions)
#
$w configure -foreground ""
} else {
#
# Restore the entry's foreground color
# (needed for current tile versions)
#
if {[parseChildPath $w win n]} {
upvar ::mentry::ns${win}::data data
configEntry $w -foreground $data(-foreground)
}
}
}
}
default {
$w configure $opt $val
}
}
}
}
#------------------------------------------------------------------------------
# mentry::reqEntryWidth
#
# Returns the requested width in pixels of the tile entry widget w.
#------------------------------------------------------------------------------
proc mentry::reqEntryWidth w {
variable currentTheme
variable isAwTheme
if {[string match "*clearlooks" $currentTheme] && $isAwTheme} {
#
# If the tile entry was created with -width 1 then in the awthemes
# "clearlooks" and "awclearlooks" themes its width will silently be
# changed to 2. For this reason, compute the widget's requested
# width based on its font rather than returning [winfo reqwidth $w].
#
set zeroWidth [font measure [$w cget -font] -displayof $w "0"]
return [expr {[$w cget -width] * $zeroWidth + 8}]
} elseif {$currentTheme eq "vista"} {
#
# If the tile entry was created with -width 1 or -width 2 then
# in the "vista" theme its width will silently be changed to 3.
# For this reason, compute the widget's requested width based
# on its font rather than returning [winfo reqwidth $w].
#
set zeroWidth [font measure [$w cget -font] -displayof $w "0"]
return [expr {[$w cget -width] * $zeroWidth + 6}]
} else {
return [winfo reqwidth $w]
}
}
#------------------------------------------------------------------------------
# mentry::geomParams
#
# Returns a few parameters needed for geometry management.
#------------------------------------------------------------------------------
proc mentry::geomParams {} {
variable themeDefaults
set bd $themeDefaults(-borderwidth)
set bd2 [expr {2*$bd}]
set x $bd
set deltaWidth $bd2
variable currentTheme
switch -- $currentTheme {
aqua {
variable newAquaSupport
if {$newAquaSupport} {
incr x 2
incr deltaWidth 4
}
}
Arc - arc - awarc {
incr x 2
incr deltaWidth 4
}
awdark - awlight {
incr x 4
incr deltaWidth 8
}
awblack - awtemplate {
incr x 2
incr deltaWidth 4
}
black - srivlg {
incr x
incr deltaWidth 2
}
Breeze - breeze - breeze-dark - awbreeze - awbreezedark {
incr x 3
incr deltaWidth 6
}
clearlooks - awclearlooks -
winxpblue - awwinxpblue {
variable isAwTheme
if {$isAwTheme} {
incr x
incr deltaWidth 2
}
}
sun-valley-light - sun-valley-dark {
incr x 9
incr deltaWidth 16
}
}
return [list $bd $bd2 $x $deltaWidth]
}
|