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
|
<!DOCTYPE html>
<html>
<head>
<title>Scrollutil Programmer's Guide</title>
<meta name="Author" content="Csaba Nemethi">
<meta name="Keywords" content=
"scrollarea, scrollsync, mouse wheel event, binding, event handling, scrolling, scrollable widget container, focus">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<div align="center">
<h1>Scrollutil Programmer's Guide</h1>
<h2>For Scrollutil Version 1.7</h2>
<h3>by</h3>
<h2>Csaba Nemethi</h2>
<address>
<a href="mailto:csaba.nemethi@t-online.de">csaba.nemethi@t-online.de</a>
</address>
</div>
<hr>
<h2 id="contents">Contents</h2>
<h4><a href="#overview">Overview</a></h4>
<ul>
<li><a href="#ov_what">What Is Scrollutil?</a></li>
<li><a href="#ov_get">How to Get It?</a></li>
<li><a href="#ov_install">How to Install It?</a></li>
<li><a href="#ov_use">How to Use It?</a></li>
<li><a href="#ov_scaling">More on
<code>scrollutil::scalingpct</code></a></li>
</ul>
<h4><a href="#examples">Examples</a></h4>
<ul>
<li><a href="#ex_styleUtil">The Helper Script
<code>styleUtil.tcl</code></a></li>
<li><a href="#ex_ScrolledTablelist">A Scrolled tablelist Widget</a></li>
<li><a href="#ex_ScrolledText">A Scrolled text Widget</a></li>
<li><a href="#ex_SyncListboxes">Synchronizing Two listbox Widgets</a></li>
<li><a href="#ex_SyncTablelists">Synchronizing Three tablelist
Widgets</a></li>
<li><a href="#ex_SuScrollableFrameDemo1">A Script Using a
scrollutil::scrollableframe Widget</a></li>
<li><a href="#ex_BwScrollableFrameDemo1">A Script Using a BWidget
ScrollableFrame Widget</a></li>
<li><a href="#ex_ScrolledFrameDemo1">A Script Using an
iwidgets::scrolledframe Widget</a></li>
<li><a href="#ex_SuScrollableFrameDemo2">A Script Using Two
scrollutil::scrollableframe Widgets</a></li>
<li><a href="#ex_BwScrollableFrameDemo2">A Script Using Two BWidget
ScrollableFrame Widgets</a></li>
<li><a href="#ex_ScrolledFrameDemo2">A Script Using Two
iwidgets::scrolledframe Widgets</a></li>
</ul>
<div align="center">
<p><a href="index.html">Start page</a></p>
</div>
<hr>
<h2 id="overview">Overview</h2>
<h3 id="ov_what">What Is Scrollutil?</h3>
<p>Scrollutil is a library package for Tcl/Tk versions 8.0 or higher, written
in pure Tcl/Tk code. It contains:</p>
<ul>
<li>the implementation of the <a href=
"scrollarea.html"><b>scrollarea</b></a>, <a href=
"scrollsync.html"><b>scrollsync</b></a>, and <a href=
"scrollableframe.html"><b>scrollableframe</b></a> mega-widgets, including a
general utility module for mega-widgets;</li>
<li>the command <code><b><a href=
"wheelEvent.html#add">scrollutil::addMouseWheelSupport</a></b></code>,
which creates mouse wheel event bindings for a given binding tag.
This command requires Tcl/Tk 8.4 or later;</li>
<li>commands for <i>user-friendly</i> mouse wheel event handling in
<b>scrollable widget containers</b> like scrollutil::scrollableframe,
BWidget ScrollableFrame, and iwidgets::scrolledframe. These commands
require Tcl/Tk versions 8.4 or higher on X11 and Mac OS X and Tk 8.6b2 or
later on Windows;</li>
<li>demo scripts illustrating the use of the Scrollutil package in
connection with various scrollable widgets and the above-mentioned
scrollable widget containers;</li>
<li>this tutorial;</li>
<li>reference pages in HTML format.</li>
</ul>
<p><b>The scrollutil::scrollarea mega-widget</b> greatly simplifies the
creation of arbitrary scrolled widgets. It consists of a scrollable
widget and two scrollbars connected with that widget. The display mode
of each scrollbar can be <code>static</code>, <code>dynamic</code>, or
<code>none</code>. This scrolled window implementation also supports
the widgets that are scrollable in one direction only (e.g., entry and
ttk::entry) and respects the header component and title columns of <a href=
"https://www.nemethi.de/tablelist/">tablelist</a> widgets (this is freely
configurable).</p>
<p>The scrollutil::scrollarea widget is similar to BWidget ScrolledWindow and
its snit-based equivalent widget::scrolledwindow, contributed by Jeffrey
Hobbs and contained in tklib. The snit-based <a href=
"http://web.tiscali.it/irrational/tcl/scrodget-2.1/">scrodget</a> package by
Aldo Buratti and its TclOO-based equivalent <a href=
"https://wiki.tcl-lang.org/page/A+Scrolled+Widget+implemented+with+TclOO">scrolledwidget</a>
contributed by Johann Oberdorfer are further scrolled window implementations.
However, <i>full</i> tablelist support is only provided by the scrollarea
widget, which is free from external dependencies like BWidget, snit, or (for
Tcl 8.5) TclOO. It is also free from the <a href=
"https://wiki.tcl-lang.org/page/Scroll+bars+that+appear+only+when+needed">shimmering
problem in connection with text widgets</a>, which the above-mentioned
scrolled window implementations either share with the autoscroll package
(contained in tklib) or circumvent in a suboptimal way.</p>
<p><b>The scrollutil::scrollsync mega-widget</b> is designed for scrolling
several widgets simultaneously. Whenever the horizontal/vertical
position of the view in the window of one of its widgets changes, the view in
the windows of all the other widgets is automatically adjusted accordingly,
thus making sure that the view's position in these windows is kept in
sync. This mega-widget is horizontally and vertically scrollable, hence
it can be embedded into a scrollutil::scrollarea widget via the latter's
<code>setwidget</code> subcommand.</p>
<p><b>The scrollutil::scrollableframe mega-widget</b> is a scrollable widget
container. It contains a content frame, whose dimensions are typically
larger than those of the widget itself. Arbitrary regions of this frame
can be brought into view by scrolling, and the widget also provides a command
for making individual widgets contained in the content frame visible in the
scrollableframe window.</p>
<p>The scrollutil::scrollableframe widget is similar to BWidget
ScrollableFrame and iwidgets::scrolledframe. However, unlike these
widgets, which use a canvas for scrolling the content frame, it adjusts the
view with the aid of the <code><b>place</b></code> geometry manager, just
like the <code>scrolledframe::scrolledframe</code> command of the
Scrolledframe package by Maurice Bredelet (ulis) and its optimized and
enhanced version contributed by Keith Nash. For details on these
commands see the wiki page</p>
<blockquote>
<address>
<a href=
"https://wiki.tcl-lang.org/page/A+scrolled+frame">https://wiki.tcl-lang.org/page/A+scrolled+frame</a>
</address>
</blockquote>
<p>Scrollutil's canvas-free approach is more lightweight and integrates
better in applications that use tile widgets.</p>
<p>From the point of view of <b>the commands related to mouse wheel event
handling</b> provided by the Scrollutil package, the scrollability of a
widget or widget container window means that the associated Tcl command
supports the <code>xview scroll <i>number</i> units</code>
and <code>yview scroll <i>number</i> units</code>
subcommands. The reason for requiring at least Tk version 8.6b2 on
Windows for the commands related to scrollable widget containers is that in
earlier Tk versions on this platform the mouse wheel events were sent to the
widget having the focus rather than to the one under the pointer.</p>
<p>To make use of the user-friendly mouse wheel event handling via the
Scrollutil package, follow the steps below:</p>
<ul>
<li>Create mouse wheel event bindings for the binding tag
<code>"all"</code> or for the toplevel widgets (including <code>"."</code>)
having scrollable widget containers, by invoking the <code><a href=
"wheelEvent.html#create">scrollutil::createWheelEventBindings</a></code>
command. In addition, register your scrollable widget containers for
scrolling via these bindings with the aid of the <code><a href=
"wheelEvent.html#enable">scrollutil::enableScrollingByWheel</a></code>
command. Note that for the scrollutil::scrollableframe widget this
command is automatically invoked at creation time. The
above-mentioned bindings handle the mouse wheel events by scrolling the
(innermost) registered scrollable widget container that is an ascendant of
the widget under the pointer and is contained in the latter's
toplevel.</li>
<li class="tm">Invoke the <code><a href=
"wheelEvent.html#adapt">scrollutil::adaptWheelEventHandling</a></code>
command for those widgets contained in registered scrollable widget
containers that have mouse wheel event (class) bindings. This step
eliminates the annoying and often dangerous double-handling effect, by
modifying the mouse wheel event handling as follows: If the focus is
on the widget under the pointer then the mouse wheel events will be handled
by the (class bindings of the) widget only, otherwise by the bindings
created with the <code>scrollutil::createWheelEventBindings</code>
command. Without this step the mouse wheel events would scroll both
the listbox, text, ttk::treeview, or tablelist widget under the pointer
<i>and</i> the widget container to whose descendants the latter belongs, or
they would select the next/previous value in the ttk::combobox or
ttk::spinbox under the pointer <i>in addition to</i> scrolling the widget
container.</li>
<li class="tm">For some widgets it can be desirable to make the focus check
within this modified event handling less restrictive. For example, if
the widget under the pointer is an entry component of a <a href=
"https://www.nemethi.de/mentry/">mentry</a> of type <code>"Date"</code>,
<code>"Time"</code>, <code>"DateTime"</code>, <code>"IPAddr"</code>, or
<code>"IPv6Addr"</code> and the focus is on any of its siblings, then the
mouse wheel events sent to this entry should be handled by the entry widget
itself rather than scrolling the widget container that is an ascendant of
the mentry. The <code><a href=
"wheelEvent.html#setFocusCkWin">scrollutil::setFocusCheckWindow</a></code>
command covers exactly cases like this.</li>
</ul>
<p>The mouse wheel event handling with the aid of the Scrollutil package was
also tested to work with the <code>scrolledframe::scrolledframe</code>
command of the Scrolledframe package by Maurice Bredelet (ulis) and its
optimized and enhanced version contributed by Keith Nash, as well as with the
<code>sframe</code> command implemented by Paul Walton. For details on
these commands (which provide further implementations of scrollable widget
containers) see the above-mentioned wiki page.</p>
<h3 id="ov_get">How to Get It?</h3>
<p>Scrollutil is available for free download from the Web page</p>
<blockquote>
<address>
<a href="https://www.nemethi.de">https://www.nemethi.de</a>
</address>
</blockquote>
<p>The distribution file is <code>scrollutil1.7.tar.gz</code> for UNIX and
<code>scrollutil1_7.zip</code> for Windows. These files contain the
same information, except for the additional carriage return character
preceding the linefeed at the end of each line in the text files for
Windows.</p>
<p>Scrollutil is also included in tklib, which has the address</p>
<blockquote>
<address>
<a href="https://core.tcl.tk/tklib">https://core.tcl.tk/tklib</a>
</address>
</blockquote>
<h3 id="ov_install">How to Install It?</h3>
<p>Install the package as a subdirectory of one of the directories given by
the <code>auto_path</code> variable. For example, you can install it as
a directory at the same level as the Tcl and Tk script libraries. The
locations of these library directories are given by the
<code>tcl_library</code> and <code>tk_library</code> variables,
respectively.</p>
<p>To install Scrollutil <i>on UNIX</i>, <code>cd</code> to the desired
directory and unpack the distribution file
<code>scrollutil1.7.tar.gz</code>:</p>
<blockquote>
<pre>
gunzip -c scrollutil1.7.tar.gz | tar -xf -
</pre>
</blockquote>
<p>On most UNIX systems this can be replaced with</p>
<blockquote>
<pre>
tar -zxf scrollutil1.7.tar.gz
</pre>
</blockquote>
<p>Both commands will create a directory named <code>scrollutil1.7</code>,
with the subdirectories <code>demos</code>, <code>doc</code>, and
<code>scripts</code>.</p>
<p><i>On Windows</i>, use WinZip or some other program capable of unpacking
the distribution file <code>scrollutil1_7.zip</code> into the directory
<code>scrollutil1.7</code>, with the subdirectories <code>demos</code>,
<code>doc</code>, and <code>scripts</code>.</p>
<p>Notice that in tklib the Scrollutil <code>demos</code> directory is
replaced with the subdirectory <code>scrollutil</code> of the
<code>examples</code> directory. Please take this into account when
reading the <a href="#examples">examples</a> below.</p>
<h3 id="ov_use">How to Use It?</h3>
<p>The Scrollutil distribution provides two packages, called
<b>Scrollutil</b> and <b>Scrollutil_tile</b>. The main difference
between the two is that Scrollutil_tile enables the tile-based,
theme-specific appearance of scrollarea, scrollsync, and scrollableframe
widgets; this package requires Tcl/Tk 8.4 or higher and tile 0.6 or
higher. It is not possible to use both packages in one and the same
application, because both are implemented in the same <code>scrollutil</code>
namespace and provide identical commands.</p>
<p>To be able to access the commands and variables defined in the package
Scrollutil, your scripts must contain one of the lines</p>
<blockquote>
<pre>
package require scrollutil ?<i>version</i>?
package require Scrollutil ?<i>version</i>?
</pre>
</blockquote>
<p>You can use either one of the two statements above because the file
<code>scrollutil.tcl</code> contains both lines</p>
<blockquote>
<pre>
package provide scrollutil ...
package provide Scrollutil ...
</pre>
</blockquote>
<p>Likewise, to be able to access the commands and variables defined in the
package Scrollutil_tile, your scripts must contain one of the lines</p>
<blockquote>
<pre>
package require scrollutil_tile ?<i>version</i>?
package require Scrollutil_tile ?<i>version</i>?
</pre>
</blockquote>
<p>Again, you can use either one of the two statements above because the file
<code>scrollutil_tile.tcl</code> contains both lines</p>
<blockquote>
<pre>
package provide scrollutil_tile ...
package provide Scrollutil_tile ...
</pre>
</blockquote>
<p>You are free to remove one of these two lines from
<code>scrollutil.tcl</code> and <code>scrollutil_tile.tcl</code>,
respectively, if you want to prevent the corresponding packages from making
themselves known under two different names each. Of course, by doing so
you restrict the argument of <code>package require</code> to a
single name.</p>
<p>Since the packages Scrollutil and Scrollutil_tile are implemented in the
<code>scrollutil</code> namespace, you must either invoke the</p>
<blockquote>
<pre>
namespace import scrollutil::<i>pattern</i> ?scrollutil::<i>pattern ...</i>?
</pre>
</blockquote>
<p>command to import the <i>procedures</i> you need, or use qualified names
like <code>scrollutil::scrollarea</code>. In the <a href=
"#examples">examples</a> below we have chosen the latter approach.</p>
<p>To access Scrollutil <i>variables</i>, you <i>must</i> use qualified
names. There are only four Scrollutil variables that are designed to
be accessed outside the namespace <code>scrollutil</code>:</p>
<ul>
<li>The variable <code>scrollutil::version</code> holds the current version
number of the Scrollutil package.</li>
<li>The variable <code>scrollutil::library</code> holds the location of the
Scrollutil installation directory.</li>
<li>The read-only variable <code>scrollutil::scalingpct</code> is set at
application start time to the scaling percentage corresponding to the
display's DPI scaling level. Scrollutil adapts, among others, the
default width of the Tk core scrollbars on X11 and that of the
ttk::scrollbar widget for the built-in themes <code>alt</code>,
<code>clam</code>, <code>classic</code>, and <code>default</code> to the
value of this variable. The currently supported values are
<code>100</code>, <code>125</code>, <code>150</code>, <code>175</code>, and
<code>200</code>. You can use this variable, e.g., if you want to
create images of different sizes, depending on the DPI scaling level.
For example, if your application uses images of size 16 x 16 on an unscaled
display and <code>scrollutil::scalingpct</code> has the value
<code>150</code>, then the image size for this display should be
24 x 24.</li>
<li>The read-only variable <code>scrollutil::usingTile</code> has the value
<code>0</code> in the package Scrollutil and the value <code>1</code> in
Scrollutil_tile.</li>
</ul>
<p>The Scrollutil_tile package checks whether the required Tk and tile
versions are present, by executing the commands</p>
<blockquote>
<pre>
package require Tk 8.4
if {$::tk_version < 8.5 || [regexp {^8\.5a[1-5]$} $::tk_patchLevel]} {
package require tile 0.6
}
</pre>
</blockquote>
<p>The second command above reflects the fact that, beginning with Tk 8.5a6,
tile is integrated into the Tk core and therefore it should only be loaded
explicitly when using an earlier Tk version.</p>
<h3 id="ov_scaling">More on <code>scrollutil::scalingpct</code></h3>
<p>The way Scrollutil initializes the variable
<code>scrollutil::scalingpct</code> depends on the windowing system:</p>
<p><i>On Windows and Mac OS X Aqua</i> the scaling percentage is computed
from <code>[tk scaling]</code>. Note that on Mac OS X the result
is always <code>100</code>, regardless of the display's scaling level.
On this system the desktop engine automatically scales everything as
needed.</p>
<p><i>On X11</i>, computing the scaling percentage from <code>[tk
scaling]</code> is done as fallback method only, because the
implementation of display scaling is highly dependent on the desktop
environment and it mostly manipulates system resources that are resident
outside of Xlib, which Tk is based on. (Traditional X applications like
<code>bitmap</code> and <code>xmag</code> are also affected by this.)
With the exception of Xfce and MATE, Scrollutil computes the scaling
percentage from the value of the X resource <code>Xft.dpi</code>, by
executing the <code>xrdb</code> application. On GNOME-based systems
where <code>xrdb</code> is not installed per default (e.g., Solus GNOME and
Solus Budgie), it uses the <code>xrandr</code> application and the file
<code>~/.config/monitors.xml</code> instead.</p>
<ul>
<li class="tm">On <i>Xfce and MATE</i> the display scaling mode can be
either unscaled (1x, normal) or scaled (2x, HiDPI), and the variable
<code>scrollutil::scalingpct</code> will be set accordingly to
<code>100</code> or <code>200</code>.</li>
<li class="tm">In case of <i>GNOME on Xorg, Budgie, and Cinnamon versions
earlier than 4.6</i>, the display scaling can be either 100 % or 200 %, and
Scrollutil sets the variable <code>scrollutil::scalingpct</code>
accordingly to <code>100</code> or <code>200</code>. In newer GNOME
and Budgie versions on Ubuntu one can enable the
<code>x11-randr-fractional-scaling</code> as experimental feature, which
adds 125 %, 150 %, and 175 % to the list of supported scaling
percentages. Note that, due to the way this fractional scaling is
implemented, if the display scaling was set to one of these intermediate
levels, the value of <code>scrollutil::scalingpct</code> will be
<code>200</code>. The same is valid for the fractional scaling
support on Cinnamon, introduced in version 4.6.</li>
<li class="tm"><i>GNOME on Wayland</i> traditionally supports the display
scaling values 100 % and 200 %, and the variable
<code>scrollutil::scalingpct</code> will be set accordingly to
<code>100</code> or <code>200</code>. In newer GNOME versions one can
enable the experimental feature <code>scale-monitor-framebuffer</code>,
which adds 125 %, 150 %, and 175 % to the list of supported scaling
percentages. With this feature enabled, the value of
<code>scrollutil::scalingpct</code> will be <code>100</code> for all
scaling levels 100 %, 125 %, ..., 200 %. This is due to the fact that
in this case, instead of window contents, monitor framebuffers will be
scaled in a logical pixel coordinate space.</li>
<li class="tm"><i>KDE Plasma on Xorg</i> provides fractional scaling
support. On this desktop, Scrollutil will set the variable
<code>scrollutil::scalingpct</code> to <code>100</code>, <code>125</code>,
<code>150</code>, <code>175</code>, or <code>200</code>, depending on the
display's scaling level.</li>
<li class="tm"><i>KDE Plasma on Wayland</i> supports fractional scaling,
too. In this case, the value of the variable
<code>scrollutil::scalingpct</code> will always be <code>100</code>,
regardless of the display's scaling level.</li>
</ul>
<p>After getting the scaling percentage on X11, Scrollutil sets the scaling
factor to be used by Tk to convert between physical units and pixels, by
passing the scaling factor corresponding to the scaling percentage to
the <code>tk scaling</code> command.</p>
<p>When initializing the variable <code>scrollutil::scalingpct</code> on X11,
Scrollutil also corrects the sizes of the standard fonts if needed.
These fonts (<code>TkDefaultFont</code>, <code>TkTextFont</code>, etc.) are
defined in the file <code>$tk_library/ttk/fonts.tcl</code>. For quite a
long time, the font sizes for X11 given in this file were sizes in pixels,
which was not suitable for use on HiDPI displays. This caused several
Linux distributions to bundle patched versions of this file, in which the
sizes in pixels are replaced with sizes in points. The same fix was
committed in February 2020 into the Tk core repository. To make sure
that, regardless of the Tk version, the font sizes will suit the display's
scaling level, Scrollutil examines this library file and, if the latter
contains sizes in pixels, then it sets the <code>-size</code> option of the
standard fonts to corresponding sizes in points (without altering the
file). In addition, for the HiDPI mode on Xfce and MATE, Scrollutil
doubles the sizes (in points) of the standard fonts (the way display scaling
works on these desktops makes this necessary).</p>
<p>Independently of the windowing system, the code responsible for the
initialization of the variable <code>scrollutil::scalingpct</code> also
scales:</p>
<ul>
<li>the default width of the Tk core scrollbars on X11;</li>
<li>for the built-in themes <code>alt</code>, <code>clam</code>,
<code>classic</code>, and <code>default</code>, the default width of the
ttk::scrollbar widget, as well as the arrows of the ttk::combobox and
ttk::spinbox widgets;</li>
<li>for the <code>alt</code> and <code>clam</code> themes, the arrow of
the ttk::menubutton widget;</li>
<li>for the <code>clam</code>, <code>classic</code>, and
<code>default</code> themes, the indicators of the ttk::checkbutton and
ttk::radiobutton widgets.</li>
</ul>
<p>In addition, the above-mentioned variable initialization code makes sure
that in the <code>vista</code> and <code>xpnative</code> themes the
indicators of the ttk::checkbutton and ttk::radiobutton widgets will appear
properly scaled, regardless of the Tk release being used. (A
long-standing bug in the implementation of these widgets was fixed in May
2020, but Scrollutil provides a workaround for the Tk versions that are still
affected by this bug.)</p>
<div align="center">
<p><a href="#contents">Contents</a> <a href=
"index.html">Start page</a></p>
</div>
<hr>
<h2 id="examples">Examples</h2>
<h3 id="ex_styleUtil">The Helper Script <code>styleUtil.tcl</code></h3>
<p>All the examples in the <code>demos</code> directory use tile (ttk)
widgets and contain the lines</p>
<blockquote>
<pre>
set dir [file dirname [info script]]
source [file join $dir styleUtil.tcl]
</pre>
</blockquote>
<p>The script <code>styleUtil.tcl</code> starts with a comment related to the
<code><a href=
"scrollarea.html#autohidescrollbars">-autohidescrollbars</a></code>
scrollarea configuration option:</p>
<blockquote>
<pre>
<span class="cmt">#
# To set the "-autohidescrollbars" option of all scrollarea
# widgets in all demo scripts to true, uncomment the line below:
#
# option add *Scrollarea.autoHideScrollbars 1</span>
</pre>
</blockquote>
<p>You are free to follow this hint or to run the demo scripts with the
default <code>-autohidescrollbars 0</code> scrollarea
setting.</p>
<p>On X11, the script sets the theme to a slightly patched variant of the
<code>clam</code> theme (having smaller ttk::button widgets as well as
ttk::treeview and tablelist headers). Next, it patches a few ttk widget
styles and defines the style <code>Small.Toolbutton</code>.</p>
<p>The patch for the style <code>TCombobox</code> makes sure that the
(readonly) ttk::combobox widgets of the themes <code>alt</code>,
<code>clam</code>, and <code>default</code> will show whether they have the
focus. This basic requirement, which makes the keyboard navigation more
user-friendly, is already fulfilled by the themes <code>vista</code>,
<code>xpnative</code>, and <code>aqua</code>.</p>
<p>The ttk::button widgets of the style <code>Small.Toolbutton</code> created
by the procedure <code>createToolbutton</code>, implemented in this helper
script, will appear raised when they have the focus. Again, this makes
the keyboard navigation more user-friendly.</p>
<h3 id="ex_ScrolledTablelist">A Scrolled tablelist Widget</h3>
<p>This example shows how you can greatly simplify the creation of a scrolled
tablelist by using a <a href="scrollarea.html">scrollarea</a> widget.</p>
<p>The file <code>ScrolledTablelist1.tcl</code> in the <code>demos</code>
directory creates a horizontally and vertically scrolled tablelist widget
having two header rows and one title column, and manages the two scrollbars
in such a way that the vertical scrollbar appears below the tablelist's
header and the horizontal one starts to the right of the widget's title
column area:</p>
<blockquote>
<img src="ScrolledTablelist.png" alt="ScrolledTablelist" width="478"
height="334">
</blockquote>
<p>The script achieves these requirements using traditional scrollbar
management, which is shown below in <span class="red">red</span> color:</p>
<blockquote>
<pre>
package require Tk 8.5
package require tablelist_tile 6.3
set dir [file dirname [info script]]
source [file join $dir styleUtil.tcl]
wm title . "Scrolled Tablelist"
<span class="cmt">#
# Create the tablelist and the scrollbars as children
# of a frame having -borderwidth 1 and -relief sunken
#</span>
set f [ttk::frame .f]
set frm [ttk::frame $f.frm <span class="red">-borderwidth 1 -relief sunken</span>]
set tbl $frm.tbl
<span class="red">set vsb $frm.vsb
set hsb $frm.hsb</span>
tablelist::tablelist $tbl ... <span class="red">-borderwidth 0</span> \
<span class="red"> -xscrollcommand [list $hsb set] -yscrollcommand [list $vsb set]</span>
. . .
<span class="red">ttk::scrollbar $vsb -orient vertical -command [list $tbl yview]
ttk::scrollbar $hsb -orient horizontal -command [list $tbl xview]</span>
. . .
<span class="cmt">#
# Manage the widgets within the frame
#</span>
<span class="red">grid $tbl -row 0 -rowspan 2 -column 0 -columnspan 2 -sticky news
if {[tk windowingsystem] eq "win32"} {
grid $vsb -row 0 -rowspan 2 -column 2 -sticky ns
} else {
grid [$tbl cornerpath] -row 0 -column 2 -sticky ew
grid $vsb -row 1 -column 2 -sticky ns
}
grid [$tbl cornerpath -sw] -row 2 -column 0 -sticky ns
grid $hsb -row 2 -column 1 -sticky ew
grid rowconfigure $frm 1 -weight 1
grid columnconfigure $frm 1 -weight 1</span>
. . .
<span class="cmt">#
# Manage the frame
#</span>
pack $frm -expand yes -fill both -padx 7p -pady 7p
pack $f -expand yes -fill both
</pre>
</blockquote>
<p>The file <code>ScrolledTablelist2.tcl</code> in the <code>demos</code>
directory replaces the rather technical code above with just a few lines
(shown below in <span class="red">red</span> color), by embedding the
tablelist into a scrollarea widget. It requires Tablelist version 6.5,
which is needed so the <code><a href=
"scrollarea.html#respectheader">-respectheader</a></code> and <code><a href=
"scrollarea.html#respecttitlecolumns">-respecttitlecolumns</a></code>
scrollarea options can work as expected (for earlier Tablelist versions these
options are silently ignored). As a further benefit, the scrollbars
created with this method will have the default display mode
<code>dynamic</code>.</p>
<blockquote>
<pre>
package require Tk 8.5
package require tablelist_tile 6.5
<span class="red">package require scrollutil_tile</span>
set dir [file dirname [info script]]
source [file join $dir styleUtil.tcl]
wm title . "Scrolled Tablelist"
<span class="cmt">#
# Create the tablelist within a scrollarea
#</span>
set f [ttk::frame .f]
<span class="red">set sa [scrollutil::scrollarea $f.sa]</span>
set tbl $sa.tbl
tablelist::tablelist $tbl ...
. . .
<span class="red">$sa setwidget $tbl</span>
. . .
<span class="cmt">#
# Manage the scrollarea
#</span>
pack $sa -expand yes -fill both -padx 7p -pady 7p
pack $f -expand yes -fill both
</pre>
</blockquote>
<h3 id="ex_ScrolledText">A Scrolled text Widget</h3>
<p>The file <code>ScrolledText.tcl</code> in the <code>demos</code> directory
shows how the <a href="scrollarea.html">scrollarea</a> widget circumvents the
potential shimmering effect in connection with text widgets.</p>
<blockquote>
<img src="ScrolledText.png" alt="ScrolledText" width="399" height="335">
</blockquote>
<p>Here is the relevant code, in which the lines related to the scrollarea
widget are shown in <span class="red">red</span> color:</p>
<blockquote>
<pre>
<span class="red">package require scrollutil_tile</span>
set dir [file dirname [info script]]
source [file join $dir styleUtil.tcl]
wm title . "Scrolled Text"
<span class="cmt">#
# Create a text widget within a scrollarea
#</span>
set f [ttk::frame .f]
<span class="red">set sa [scrollutil::scrollarea $f.sa -lockinterval 10]</span>
set txt [text $sa.txt -font TkFixedFont -width 49 -height 12 \
-spacing1 1.5p -spacing3 1.5p -wrap none]
<span class="red">$sa setwidget $txt</span>
<span class="cmt">#
# Populate the text widget and set the background color of line #25 to red
#</span>
for {set i 1} {$i <= 30} {incr i} {
set j [expr {2*$i}]
$txt insert end [string repeat x $j]\n
}
$txt delete 30.end
$txt tag configure bgRed -background red
$txt tag add bgRed 25.0 25.end
. . .
<span class="cmt">#
# Manage the scrollarea
#</span>
pack $sa -expand yes -fill both -padx 7p -pady 7p
pack $f -expand yes -fill both
<span class="cmt">#
# Adjust the vertical view in the text window
# so that line #25 becomes the bottom line
#</span>
tkwait visibility $txt
after 100 [list $txt yview 14.0]
</pre>
</blockquote>
<p>The script creates a text widget <code>$txt</code> embedded into a
scrollarea, populates it with 30 lines, and adjusts the vertical view in the
text window so that line #25 becomes the bottom line. This line has 50
characters, hence it doesn't fit completely into the window, whose width is
49 characters. Consequently, the command <code>$txt
xview</code> will return the list <code>{0.0 0.98}</code>,
hence the scrollarea's horizontal scrollbar will be mapped and will obscure
most part of the bottom line. Since this line has <code>red</code>
background, it is easy to see how much of it sticks out above the upper edge
of the scrollbar.</p>
<p>Let's analyze what happens if the text widget's height is decreased by
dragging the main window's upper or lower edge, just until the red pixels get
obscured by the horizontal scrollbar. After performing this action,
line #25 is completely out of view and the new bottom line is line #24, which
has 48 characters, hence the command <code>$txt xview</code> will
return <code>{0.0 1.0}</code>. Normally, this would cause the
horizontal scrollbar to be unmapped. However, that would make line #25
to the bottom line, thus causing the horizontal scrollbar to be mapped
again. This time the scrollbar would completely obscure this line,
which would result in line #24 to become the bottom line, which would cause
the scrollbar to be unmapped again, and so on. In other words, the
horizontal scrollbar would get mapped and unmapped in an endless loop, giving
rise to an annoying flickering effect. The built-in locking mechanism
of the scrollarea widget guards against such potential endless loops.
To make sure that the locking will work as expected, we have set the
<code><a href="scrollarea.html#lockinterval">-lockinterval</a></code>
scrollarea option to <code>10</code> (recall that the default value is
<code>1</code>).</p>
<h3 id="ex_SyncListboxes">Synchronizing Two listbox Widgets</h3>
<p>The file <code>SyncListboxes.tcl</code> in the <code>demos</code>
directory creates two listboxes within a <a href=
"scrollsync.html">scrollsync</a> widget, which in turn is embedded into a
<a href="scrollarea.html">scrollarea</a>.</p>
<blockquote>
<img src="SyncListboxes.png" alt="SyncListboxes" width="318" height="302">
</blockquote>
<p>Here is the relevant code, in which the lines related to the scrollarea
and scrollsync widgets are shown in <span class="red">red</span> color:</p>
<blockquote>
<pre>
<span class="red">package require scrollutil_tile</span>
set dir [file dirname [info script]]
source [file join $dir styleUtil.tcl]
wm title . "European Countries"
. . .
set f [ttk::frame .f]
. . .
<span class="cmt">#
# Create a scrollsync widget within a scrollarea
#</span>
<span class="red">set sa [scrollutil::scrollarea $f.sa]
set ss [scrollutil::scrollsync $sa.ss]
$sa setwidget $ss</span>
<span class="cmt">#
# Populate the scrollsync widget with two listboxes
#</span>
. . .
set lb1 [listbox $ss.lb1 -activestyle none -highlightthickness 0 -width 16]
set lb2 [listbox $ss.lb2 -activestyle none -highlightthickness 0 -width 16]
<span class="red">$ss setwidgets [list $lb1 $lb2]</span>
. . .
grid $lb1 $lb2 -sticky news -padx {0 1.5p}
grid rowconfigure $ss 0 -weight 1
grid columnconfigure $ss 0 -weight 1
grid columnconfigure $ss 1 -weight 1
. . .
pack $sa -side top -expand yes -fill both -padx 7p -pady {1.5p 7p}
pack $f -expand yes -fill both
. . .
</pre>
</blockquote>
<h3 id="ex_SyncTablelists">Synchronizing Three tablelist Widgets</h3>
<p>The file <code>SyncTablelists.tcl</code> in the <code>demos</code>
directory creates three tablelists within a <a href=
"scrollsync.html">scrollsync</a> widget, which in turn is embedded into a
<a href="scrollarea.html">scrollarea</a>.</p>
<blockquote>
<img src="SyncTablelists.png" alt="SyncTablelists" width="546" height=
"323">
</blockquote>
<p>The relevant code is similar to the one shown in the <a href=
"#ex_SyncListboxes">previous example</a>:</p>
<blockquote>
<pre>
package require tablelist_tile
<span class="red">package require scrollutil_tile</span>
set dir [file dirname [info script]]
source [file join $dir styleUtil.tcl]
wm title . "Synchronized Tablelists"
. . .
set f [ttk::frame .f]
. . .
<span class="cmt">#
# Create a scrollsync widget within a scrollarea
#</span>
<span class="red">set sa [scrollutil::scrollarea $f.sa]
set ss [scrollutil::scrollsync $sa.ss]
$sa setwidget $ss</span>
<span class="cmt">#
# Populate the scrollsync widget with three tablelists
#</span>
if {$ttk::currentTheme ne "aqua"} {
option add *Tablelist.background white
option add *Tablelist.stripeBackground #f0f0f0
}
for {set n 1; set colWidth 40} {$n <= 3} {incr n; incr colWidth 20} {
set tbl [tablelist::tablelist $ss.tbl$n \
-columns [list 0 "Column 0" left $colWidth "Column 1" left]]
set tbl$n $tbl
for {set i 0} {$i < 40} {incr i} {
$tbl insert end [list "cell $i,0" "cell $i,1"]
}
}
<span class="red">$ss setwidgets [list $tbl1 $tbl2 $tbl3]</span>
grid $tbl1 $tbl2 $tbl3 -sticky news -padx {0 1.5p}
grid rowconfigure $ss 0 -weight 1
grid columnconfigure $ss 0 -weight 1
grid columnconfigure $ss 1 -weight 1
grid columnconfigure $ss 2 -weight 1
. . .
pack $sa -side top -expand yes -fill both -padx 7p -pady {1.5p 7p}
pack $f -expand yes -fill both
. . .
</pre>
</blockquote>
<p>The option database settings above for the <code>-background</code> and
<code>-stripebackground</code> tablelist configuration options are not
present in case of the <code>aqua</code> theme, because for this theme the
default values of these options are not only <code>aqua</code>-specific, but
in addition on Mac OS 10.14 (Mojave) and later they also depend on the
current system appearance (Light Mode or Dark Mode).</p>
<p>Notice that column #1 of the three tablelist widgets is 40, 60, and 80
characters wide, respectively. For this reason, when scrolling
horizontally to the right, the left table's view will reach its horizontal
end position first, then that of the midde table, and as last one the view of
the right table.</p>
<h3 id="ex_SuScrollableFrameDemo1">A Script Using a
scrollutil::scrollableframe Widget</h3>
<p>The file <code>SuScrollableFrmDemo1.tcl</code> in the <code>demos</code>
directory creates a <a href=
"scrollableframe.html">scrollutil::scrollableframe</a> widget embedded into a
<a href="scrollarea.html">scrollarea</a> and creates mouse wheel event
bindings for the binding tag <code>"all"</code> with the aid of the
<code><a href=
"wheelEvent.html#create">scrollutil::createWheelEventBindings</a></code>
command. Recall that the scrollableframe was automatically registered
for scrolling by these bindings at creation time, hence there is no need to
invoke the <code><a href=
"wheelEvent.html#enable">scrollutil::enableScrollingByWheel</a></code>
command for it again. After that, the script populates the content
frame of the scrollableframe with ttk::label widgets displaying the names of
the European countries, ttk::combobox widgets for selecting the corresponding
capital cities, and ttk::button widgets of the style
<code>Small.Toolbutton</code> (created by using the procedure
<code>createToolbutton</code>, implemented in the file
<code><a href="#ex_styleUtil">styleUtil.tcl</a></code>) for the less patient
users, displaying the text "Resolve".</p>
<blockquote>
<img src="ScrollableFrmDemo1.png" alt="ScrollableFrmDemo1" width="403"
height="370">
</blockquote>
<p>Here is the relevant code:</p>
<blockquote>
<pre>
<span class="red">package require scrollutil_tile</span>
set dir [file dirname [info script]]
source [file join $dir styleUtil.tcl]
wm title . "European Capitals Quiz"
<span class="cmt">#
# Create a scrollableframe within a scrollarea
#</span>
set f [ttk::frame .f]
<span class="red">set sa [scrollutil::scrollarea $f.sa]
set sf [scrollutil::scrollableframe $sa.sf]
$sa setwidget $sf</span>
<span class="cmt">#
# Create mouse wheel event bindings for the binding tag "all"
#</span>
<span class="red">scrollutil::createWheelEventBindings all</span>
<span class="cmt">#
# Get the content frame and populate it
#</span>
<span class="red">set cf [$sf contentframe]</span>
set countryList {
Albania Andorra Austria Belarus Belgium "Bosnia and Herzegovina" Bulgaria
. . .
}
set capitalList {
Tirana "Andorra la Vella" Vienna Minsk Brussels Sarajevo Sofia
. . .
}
. . .
set capitalList [lsort $capitalList]
. . .
set row 0
foreach country $countryList {
. . .
set w [ttk::combobox $cf.cb$row -state readonly -width 14 \
-values $capitalList]
. . .
<span class="cmt">#
# Make the keyboard navigation more user-friendly
#</span>
bind $w <<TraverseIn>> [list <span class="red">$sf see %W</span>]
<span class="cmt">#
# Adapt the handling of the mouse wheel events for the ttk::combobox widget
#</span>
<span class="red">scrollutil::adaptWheelEventHandling $w</span>
. . .
incr row
}
. . .
</pre>
</blockquote>
<p>We make the keyboard navigation more user-friendly with the aid of the
<code><a href="scrollableframe.html#see">see</a></code> subcommand of the
scrollableframe widget when handling the
<code><<TraverseIn>></code> virtual event for the ttk::combobox
and (not shown above) ttk::button widgets. In addition, we invoke the
<code><a href=
"wheelEvent.html#adapt">scrollutil::adaptWheelEventHandling</a></code>
command for every ttk::combobox widget, which is needed for a user-friendly
event handling, being that this widget has built-in bindings for the mouse
wheel events. Due to this command, the mouse wheel events over one of
the ttk::combobox widgets will only select the next/previous capital city if
the widget has the focus, otherwise they will scroll the scrollableframe.</p>
<p>With this script you can also test the scanning in the
scrollableframe: If you press mouse button 1 over a free space of the
scrollableframe window then the cursor will take on the shape of a pointing
hand, and by draggging the mouse, the content frame will drag at high speed
through the window, in the direction the mouse moves.</p>
<h3 id="ex_BwScrollableFrameDemo1">A Script Using a BWidget ScrollableFrame
Widget</h3>
<p>The file <code>BwScrollableFrmDemo1.tcl</code> in the <code>demos</code>
directory creates a BWidget ScrollableFrame embedded into a <a href=
"scrollarea.html">scrollarea</a> widget, creates mouse wheel event bindings
for the binding tag <code>"all"</code> with the aid of the <code><a href=
"wheelEvent.html#create">scrollutil::createWheelEventBindings</a></code>
command, and invokes the <code><a href=
"wheelEvent.html#enable">scrollutil::enableScrollingByWheel</a></code>
command for this ScrollableFrame, thus registering the latter for scrolling
by these bindings. After that it populates the content frame of the
ScrollableFrame with the same widgets as
<code>SuScrollableFrmDemo1.tcl</code> in the <a href=
"#ex_SuScrollableFrameDemo1">previous example</a>.</p>
<p>Here is the relevant code:</p>
<blockquote>
<pre>
package require BWidget
Widget::theme yes
<span class="red">package require scrollutil_tile</span>
set dir [file dirname [info script]]
source [file join $dir styleUtil.tcl]
wm title . "European Capitals Quiz"
<span class="cmt">#
# Create a ScrollableFrame within a scrollarea
#</span>
set f [ttk::frame .f]
<span class="red">set sa [scrollutil::scrollarea $f.sa]</span>
set sf [ScrollableFrame $sa.sf]
<span class="red">$sa setwidget $sf</span>
. . .
<span class="cmt">#
# Create mouse wheel event bindings for the binding tag "all" and
# register the ScrollableFrame for scrolling by these bindings
#</span>
<span class="red">scrollutil::createWheelEventBindings all
scrollutil::enableScrollingByWheel $sf</span>
<span class="cmt">#
# Get the content frame and populate it
#</span>
set cf [$sf getframe]
set countryList {
Albania Andorra Austria Belarus Belgium "Bosnia and Herzegovina" Bulgaria
. . .
}
set capitalList {
Tirana "Andorra la Vella" Vienna Minsk Brussels Sarajevo Sofia
. . .
}
. . .
set capitalList [lsort $capitalList]
. . .
set row 0
foreach country $countryList {
. . .
set w [ttk::combobox $cf.cb$row -state readonly -width 14 \
-values $capitalList]
. . .
<span class="cmt">#
# Make the keyboard navigation more user-friendly
#</span>
bind $w <<TraverseIn>> [list $sf see %W]
<span class="cmt">#
# Adapt the handling of the mouse wheel events for the ttk::combobox widget
#</span>
<span class="red">scrollutil::adaptWheelEventHandling $w</span>
. . .
incr row
}
. . .
</pre>
</blockquote>
<h3 id="ex_ScrolledFrameDemo1">A Script Using an iwidgets::scrolledframe
Widget</h3>
<p>The file <code>ScrolledFrmDemo1.tcl</code> in the <code>demos</code>
directory creates an iwidgets::scrolledframe widget, creates mouse wheel
event bindings for the binding tag <code>"all"</code> with the aid of the
<code><a href=
"wheelEvent.html#create">scrollutil::createWheelEventBindings</a></code>
command, and invokes the <code><a href=
"wheelEvent.html#enable">scrollutil::enableScrollingByWheel</a></code>
command for this scrolledframe, thus registering the latter for scrolling by
these bindings. After that it populates the content frame of the
scrolledframe with the same widgets as <code>SuScrollableFrmDemo1.tcl</code>
and <code>BwScrollableFrmDemo1.tcl</code> in the two previous examples.</p>
<p>Here is the relevant code:</p>
<blockquote>
<pre>
if {[catch {package require iwidgets} result1] != 0 &&
[catch {package require Iwidgets} result2] != 0} {
error "$result1; $result2"
}
set dir [file dirname [info script]]
source [file join $dir scrolledwidgetPatch.itk] ;<span class=
"cmt"># adds ttk::scrollbar widgets</span>
<span class="red">package require scrollutil_tile</span>
source [file join $dir styleUtil.tcl]
wm title . "European Capitals Quiz"
. . .
<span class="cmt">#
# Create a scrolledframe
#</span>
set f [ttk::frame .f]
set sf [iwidgets::scrolledframe $f.sf -borderwidth 1 -relief sunken \
-scrollmargin 0]
. . .
<span class="cmt">#
# Create mouse wheel event bindings for the binding tag "all"
# and register the scrolledframe for scrolling by these bindings
#</span>
<span class="red">scrollutil::createWheelEventBindings all
scrollutil::enableScrollingByWheel $sf</span>
<span class="cmt">#
# Get the content frame and populate it
#</span>
set cf [$sf childsite]
. . .
<i><exactly as in the two previous examples, except the stuff related to keyboard navigation></i>
. . .
</pre>
</blockquote>
<p>The code related to keyboard navigation is not present in this example,
because the iwidgets::scrolledframe widget doesn't provide a <code>see</code>
subcommand.</p>
<h3 id="ex_SuScrollableFrameDemo2">A Script Using Two
scrollutil::scrollableframe Widgets</h3>
<p>The script <code>SuScrollableFrmDemo2.tcl</code> in the <code>demos</code>
directory creates a <a href=
"scrollableframe.html">scrollutil::scrollableframe</a> widget embedded into a
<a href="scrollarea.html">scrollarea</a> and then <code>source</code>s the
script <code>SuScrollableFrmContent.tcl</code>, which populates the content
frame of the scrollableframe with the following widgets:</p>
<ul>
<li>a series of ttk::label widgets;</li>
<li>a scrolled text widget <code>$txt</code> within a scrollarea;</li>
<li>a scrolled listbox widget <code>$lb</code> within a scrollarea;</li>
<li>a ttk::combobox widget <code>$cb</code>;</li>
<li>a ttk::spinbox widget <code>$sb</code>;</li>
<li>a ttk::entry widget <code>$e</code>;</li>
<li>a ttk::separator widget;</li>
<li>a mentry widget <code>$me</code> of type <code>"Date"</code>;</li>
<li>a scrolled tablelist widget <code>$tbl</code> within a scrollarea;</li>
<li>a scrolled ttk::treeview widget <code>$tv</code> within a
scrollarea.</li>
</ul>
<p>With the exception of ttk::label, ttk::entry, and ttk::separator, all
these widgets have bult-in mouse wheel event bindings.</p>
<blockquote>
<img src="ScrollableFrmDemo2.png" alt="ScrollableFrmDemo2" width="601"
height="511">
</blockquote>
<p>Here is the relevant code:</p>
<blockquote>
<pre>
package require Tk 8.5.9 ;<span class=
"cmt"># for ttk::spinbox</span>
package require mentry_tile 3.2 ;<span class=
"cmt"># for mouse wheel support</span>
package require tablelist_tile 6.5 ;<span class=
"cmt"># for -(x|y)mousewheelwindow</span>
;<span class=
"cmt"># and scrollutil::scrollarea</span>
<span class="red">package require scrollutil_tile</span>
set dir [file dirname [info script]]
source [file join $dir styleUtil.tcl]
wm title . "Scrollutil Demo"
<span class="cmt">#
# Create a scrollableframe within a scrollarea
#</span>
set tf [ttk::frame .tf]
<span class="red">set sa [scrollutil::scrollarea $tf.sa]
set sf [scrollutil::scrollableframe $sa.sf]
$sa setwidget $sf</span>
<span class="cmt">#
# Get the content frame and populate it
#</span>
<span class="red">set cf [$sf contentframe]</span>
source [file join $dir SuScrollableFrmContent.tcl]
<span class="cmt">#
# Make the keyboard navigation more user-friendly
#</span>
foreach w [list $cb $sb $e $me] {
bind $w <<TraverseIn>> [list <span class="red">$sf see %W</span>]
}
foreach w [list $txt $lb $tbl $tv] {
bind $w <<TraverseIn>> [list seeScrollarea $sf %W]
}
proc seeScrollarea {sf w} { <span class="red">$sf see [scrollutil::getscrollarea $w]</span> }
</pre>
</blockquote>
<p>Whenever the <code><<TraverseIn>></code> virtual event is sent
to one of the four widgets created within scrollareas, we query the path name
of the corresponding scrollarea via <code><a href=
"scrollarea.html#getscrollarea">scrollutil::getscrollarea</a></code> and
bring that scrollarea (including the scrollbars and the border) into view
rather than just the widget in question. While <i>in this script</i> we
could have used <code>[winfo parent]</code> instead, the command
<code>scrollutil::getscrollarea</code> is the recommended one, being that it
works also for widgets that are no children of the corresponding
scrollareas.</p>
<p>Here is the additional stuff related to the mouse wheel events, using the
Scrollutil commands described in the <a href="#ov_what">What Is
Scrollutil?</a> section:</p>
<blockquote>
<pre>
<span class="cmt">#
# Create mouse wheel event bindings for the binding tag "all"
#</span>
<span class="red">scrollutil::createWheelEventBindings all</span>
<span class="cmt">#
# Adapt the handling of the mouse wheel events for the text, listbox,
# ttk::combobox, ttk::spinbox, tablelist, and ttk::treeview widgets, as
# well as for the entry components of the mentry widget of type "Date"
#</span>
set entryList [$me entries]
<span class="red">scrollutil::adaptWheelEventHandling $txt $lb $cb $sb $tbl $tv {*}$entryList</span>
<span class="cmt">#
# For the entry components of the mentry widget
# set the "focus check window" to the mentry
#</span>
<span class="red">scrollutil::setFocusCheckWindow {*}$entryList $me</span>
</pre>
</blockquote>
<p>Notice that we have passed, among others, the tablelist widget to the
<code><a href=
"wheelEvent.html#adapt">scrollutil::adaptWheelEventHandling</a></code>
command. This will only work for Tablelist versions 6.4 and later,
because the command handles tablelist widgets by setting their
<code>-xmousewheelwindow</code> and <code>-ymousewheelwindow</code> options
to the path name of the containing toplevel window, and these options were
introduced in Tablelist version 6.4. (For earlier Tablelist versions
the command silently ignores any tablelist widget passed to it as
argument.)</p>
<p>As already mentioned, in the file <code>SuScrollableFrmContent.tcl</code>
the scrolled text, listbox, tablelist, and ttk::treeview widgets are created
within <a href="scrollarea.html">scrollarea</a> widgets:</p>
<blockquote>
<pre>
<span class="red">set _sa [scrollutil::scrollarea ...]</span>
set txt [text $_sa.txt -font TkFixedFont -width 73]
<span class="red">scrollutil::addMouseWheelSupport $txt
$_sa setwidget $txt</span>
grid $_sa ...
. . .
<span class="red">set _sa [scrollutil::scrollarea ...]</span>
set lb [listbox $_sa.lb -width 0]
<span class="red">$_sa setwidget $lb</span>
grid $_sa ...
. . .
<span class="red">set _sa [scrollutil::scrollarea ...]</span>
set tbl [tablelist::tablelist $_sa.tbl ...]
. . .
<span class="red">$_sa setwidget $tbl</span>
grid $_sa ...
. . .
<span class="red">set _sa [scrollutil::scrollarea ... -borderwidth 0]</span>
set tv [ttk::treeview $_sa.tv ...]
. . .
<span class="red">$_sa setwidget $tv</span>
grid $_sa ...
</pre>
</blockquote>
<p>In the case of the text, listbox, and tablelist widgets we use scrollarea
widgets with their default <code>-borderwidth 1 -relief
sunken</code> settings, which will cause the <code><a href=
"scrollarea.html#setwidget">setwidget</a></code> subcommand of the associated
Tcl commands to set the <code>-borderwidth</code> option of the text,
listbox, and tablelist widgets to <code>0</code>. On the other hand,
for the ttk::treeview we use a scrollarea widget with
<code>-borderwidth 0</code>, because the ttk::treeview has a border of
width <code>1</code> and doesn't support the <code>-borderwidth</code>
configuration option.</p>
<p>For our text widget we prefer a mouse wheel event handling that scrolls
the widget by lines rather than pixels, as done by the <code>Text</code>
class bindings in Tk 8.5 and later; we achieve this by passing the path name
<code>$txt</code> to the <code><a href=
"wheelEvent.html#add">scrollutil::addMouseWeelSupport</a></code> command.</p>
<p>The file <code>SuScrollableFrmContent.tcl</code> implements just a minimal
interaction between four of the already mentioned widgets within the content
frame: By selecting a Tablelist release from the ttk::combobox
<code>$cb</code>, the ttk::spinbox <code>$sb</code> is set to the
corresponding number of changes, the comment associated with that release is
inserted into the ttk::entry <code>$e</code>, and the corresponding item of
the tablelist <code>$tbl</code> is selected and brought into view within the
tablelist widget.</p>
<p>The file <code>SuScrollableFrmContent.tcl</code> contains also the
implementation of the procedure <code>configTablelist</code>, associated with
the "Configure Tablelist Widget" button as the value of its
<code>-command</code> option. This procedure opens a toplevel window
that contains a <a href=
"scrollableframe.html">scrollutil::scrollableframe</a> widget created
with the <code><a href=
"scrollableframe.html#fitcontentwidth">-fitcontentwidth</a> yes</code>
setting within a <a href="scrollarea.html">scrollarea</a>. After that
it populates the content frame of the scrollableframe with ttk::label,
ttk::combobox, ttk::spinbox, ttk::entry, and ttk::checkbutton widgets used to
display and edit the configuration options of the tablelist widget. The
procedure handles the <code><<TraverseIn>></code> virtual event
sent to one of these widgets with the aid of the scrollableframe's
<code><a href="scrollableframe.html#see">see</a></code> subcommand.
Whenever a ttk::combobox or ttk::spinbox is created, the <code><a href=
"wheelEvent.html#adapt">scrollutil::adaptWheelEventHandling</a></code>
command is invoked for it, being that these widgets have built-in bindings
for the mouse wheel events.</p>
<p>The widgets populating the content frame are managed using
<code>grid</code>. In case of the ttk::entry widgets we invoke
<code>grid</code> with <code>-sticky we</code>. Due to this and
the <code>-fitcontentwidth yes</code> scrollableframe setting,
the ttk::entry widgets will stretch or shrink whenever the width of the
scrollableframe changes as a result of resizing the toplevel window.</p>
<blockquote>
<img src="TablelistConfig.png" alt="TablelistConfig" width="380"
height="400">
</blockquote>
<h3 id="ex_BwScrollableFrameDemo2">A Script Using Two BWidget ScrollableFrame
Widgets</h3>
<p>The script <code>BwScrollableFrmDemo2.tcl</code> in the <code>demos</code>
directory creates a BWidget ScrollableFrame embedded into a <a href=
"scrollarea.html">scrollarea</a> widget and then <code>source</code>s the
script <code>BwScrollableFrmContent.tcl</code>, which populates the content
frame of the ScrollableFrame with the same widgets as
<code>SuScrollableFrmContent.tcl</code> in the <a href=
"#ex_SuScrollableFrameDemo2">previous example</a>.</p>
<p>Here is the relevant code:</p>
<blockquote>
<pre>
package require Tk 8.5.9 ;<span class=
"cmt"># for ttk::spinbox</span>
package require BWidget
Widget::theme yes
package require mentry_tile 3.2 ;<span class=
"cmt"># for mouse wheel support</span>
package require tablelist_tile 6.5 ;<span class=
"cmt"># for -(x|y)mousewheelwindow</span>
;<span class=
"cmt"># and scrollutil::scrollarea</span>
<span class="red">package require scrollutil_tile</span>
set dir [file dirname [info script]]
source [file join $dir styleUtil.tcl]
wm title . "Scrollutil Demo"
<span class="cmt">#
# Create a ScrollableFrame within a scrollarea
#</span>
set tf [ttk::frame .tf]
<span class="red">set sa [scrollutil::scrollarea $tf.sa]</span>
set sf [ScrollableFrame $sa.sf]
<span class="red">$sa setwidget $sf</span>
. . .
<span class="cmt">#
# Get the content frame and populate it
#</span>
set cf [$sf getframe]
source [file join $dir BwScrollableFrmContent.tcl]
<span class="cmt">#
# Make the keyboard navigation more user-friendly
#</span>
foreach w [list $cb $sb $e $me] {
bind $w <<TraverseIn>> [list $sf see %W]
}
foreach w [list $txt $lb $tbl $tv] {
bind $w <<TraverseIn>> [list seeScrollarea $sf %W]
}
proc seeScrollarea {sf w} { $sf see [<span class="red">scrollutil::getscrollarea $w</span>] }
</pre>
</blockquote>
<p>The additional stuff related to the mouse wheel events contains the same
Scrollutil command invocations as the one in the previous example, except
that in addition it registers the ScrollableFrame for scrolling with the
mouse wheel:</p>
<blockquote>
<pre>
<span class="cmt">#
# Create mouse wheel event bindings for the binding tag "all" and
# register the ScrollableFrame for scrolling by these bindings
#</span>
<span class="red">scrollutil::createWheelEventBindings all
scrollutil::enableScrollingByWheel $sf</span>
. . .
</pre>
</blockquote>
<p>The file <code>BwScrollableFrmContent.tcl</code> contains also the
implementation of the procedure <code>configTablelist</code>, associated with
the "Configure Tablelist Widget" button as the value of its
<code>-command</code> option. This procedure opens a toplevel window
that contains a BWidget ScrollableFrame created with the
<code>-constrainedwidth yes</code> setting within a <a href=
"scrollarea.html">scrollarea</a> widget and invokes the <code><a href=
"wheelEvent.html#enable">scrollutil::enableScrollingByWheel</a></code>
command for this ScrollableFrame, thus registering the latter for scrolling
by the already created mouse wheel event bindings for the binding tag
<code>"all"</code>. After that it populates the content frame of the
ScrollableFrame with ttk::label, ttk::combobox, ttk::spinbox, ttk::entry, and
ttk::checkbutton widgets used to display and edit the configuration options
of the tablelist widget. The procedure handles the
<code><<TraverseIn>></code> virtual event sent to one of these
widgets with the aid of the ScrollableFrame's <code>see</code>
subcommand. Whenever a ttk::combobox or ttk::spinbox is created, the
<code><a href=
"wheelEvent.html#adapt">scrollutil::adaptWheelEventHandling</a></code>
command is invoked for it, being that these widgets have built-in bindings
for the mouse wheel events.</p>
<p>Again, all this is nearly identical to what we did in the previous
example.</p>
<h3 id="ex_ScrolledFrameDemo2">A Script Using Two iwidgets::scrolledframe
Widgets</h3>
<p>The script <code>ScrolledFrmDemo2.tcl</code> in the <code>demos</code>
directory creates an iwidgets::scrolledframe widget and then
<code>source</code>s the file <code>ScrolledFrmContent.tcl</code>, which
populates the content frame of the scrolledframe with the same widgets as
<code>SuScrollableFrmContent.tcl</code> and
<code>BwScrollableFrmContent.tcl</code> in the two previous examples.</p>
<p>Here is the relevant code:</p>
<blockquote>
<pre>
package require Tk 8.5.9 ;<span class=
"cmt"># for ttk::spinbox</span>
if {[catch {package require iwidgets} result1] != 0 &&
[catch {package require Iwidgets} result2] != 0} {
error "$result1; $result2"
}
set dir [file dirname [info script]]
source [file join $dir scrolledwidgetPatch.itk] ;<span class=
"cmt"># adds ttk::scrollbar widgets</span>
package require mentry_tile 3.2 ;<span class=
"cmt"># for mouse wheel support</span>
package require tablelist_tile 6.5 ;<span class=
"cmt"># for -(x|y)mousewheelwindow</span>
;<span class=
"cmt"># and scrollutil::scrollarea</span>
<span class="red">package require scrollutil_tile</span>
source [file join $dir styleUtil.tcl]
wm title . "Scrollutil Demo"
. . .
<span class="cmt">#
# Create a scrolledframe
#</span>
set tf [ttk::frame .tf]
set sf [iwidgets::scrolledframe $tf.sf -borderwidth 1 -relief sunken \
-scrollmargin 0]
. . .
<span class="cmt">#
# Get the content frame and populate it
#</span>
set cf [$sf childsite]
. . .
source [file join $dir ScrolledFrmContent.tcl]
</pre>
</blockquote>
<p>The additional stuff related to the mouse wheel events contains the same
Scrollutil command invocations as the one in the previous example.</p>
<p>The file <code>ScrolledFrmContent.tcl</code> contains also the
implementation of the procedure <code>configTablelist</code>, associated with
the "Configure Tablelist Widget" button as the value of its
<code>-command</code> option. This procedure opens a toplevel window
that contains an iwidgets::scrolledframe widget with a manually implemented
equivalent of the <code><a href=
"scrollableframe.html#fitcontentwidth">-fitcontentwidth</a> yes</code>
<a href="scrollableframe.html">scrollutil::scrollableframe</a> and
<code>-constrainedwidth yes</code> BWidget ScrollableFrame settings and
invokes the <code><a href=
"wheelEvent.html#enable">scrollutil::enableScrollingByWheel</a></code>
command for this scrolledframe, thus registering the latter for scrolling by
the already created mouse wheel event bindings for the binding tag
<code>"all"</code>. After that it populates the content frame of the
scrolledframe with ttk::label, ttk::combobox, ttk::spinbox, ttk::entry, and
ttk::checkbutton widgets used to display and edit the configuration options
of the tablelist widget. Whenever a ttk::combobox or ttk::spinbox is
created, the <code><a href=
"wheelEvent.html#adapt">scrollutil::adaptWheelEventHandling</a></code>
command is invoked for it, being that these widgets have built-in bindings
for the mouse wheel events.</p>
<p>Again, all this is nearly identical to what we did in the two previous
examples.</p>
<div align="center">
<p><a href="#contents">Contents</a> <a href=
"index.html">Start page</a></p>
</div>
</body>
</html>
|