/usr/lib/perl5/Prima/Notebooks.pm is in libprima-perl 1.28-1.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 | #
# Copyright (c) 1997-2002 The Protein Laboratory, University of Copenhagen
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# Created by Dmitry Karasik <dk@plab.ku.dk>
#
# $Id: Notebooks.pm,v 1.32 2007/09/13 15:12:25 dk Exp $
use strict;
use Prima::Const;
use Prima::Classes;
use Prima::IntUtils;
package Prima::TabSet;
use vars qw(@ISA);
@ISA = qw(Prima::Widget Prima::MouseScroller);
{
my %RNT = (
%{Prima::Widget-> notification_types()},
DrawTab => nt::Action,
MeasureTab => nt::Action,
);
sub notification_types { return \%RNT; }
}
use constant DefGapX => 10;
use constant DefGapY => 5;
use constant DefLeftX => 5;
use constant DefArrowX => 25;
my @warpColors = (
0x50d8f8, 0x80d8a8, 0x8090f8, 0xd0b4a8, 0xf8fca8,
0xa890a8, 0xf89050, 0xf8d850, 0xf8b4a8, 0xf8d8a8,
);
sub profile_default
{
my $def = $_[ 0]-> SUPER::profile_default;
my $font = $_[ 0]-> get_default_font;
my %prf = (
colored => 1,
firstTab => 0,
focusedTab => 0,
height => $font-> { height} > 14 ? $font-> { height} * 2 : 28,
ownerBackColor => 1,
selectable => 1,
selectingButtons => 0,
tabStop => 1,
topMost => 1,
tabIndex => 0,
tabs => [],
);
@$def{keys %prf} = values %prf;
return $def;
}
sub init
{
my $self = shift;
$self-> {tabIndex} = -1;
for ( qw( colored firstTab focusedTab topMost lastTab arrows)) { $self-> {$_} = 0; }
$self-> {tabs} = [];
$self-> {widths} = [];
my %profile = $self-> SUPER::init(@_);
for ( qw( colored topMost tabs focusedTab firstTab tabIndex)) { $self-> $_( $profile{ $_}); }
$self-> recalc_widths;
$self-> reset;
return %profile;
}
sub reset
{
my $self = $_[0];
my @size = $self-> size;
my $w = DefLeftX * 2 + DefGapX;
for ( @{$self-> {widths}}) { $w += $_ + DefGapX; }
$self-> {arrows} = (( $w > $size[0]) and ( scalar( @{$self-> {widths}}) > 1));
if ( $self-> {arrows}) {
my $ft = $self-> {firstTab};
$w = DefLeftX * 2 + DefGapX;
$w += DefArrowX if $ft > 0;
my $w2 = $w;
my $la = $ft > 0;
my $i;
my $ra = 0;
my $ww = $self-> {widths};
for ( $i = $ft; $i < scalar @{$ww}; $i++) {
$w += DefGapX + $$ww[$i];
if ( $w + DefGapX + DefLeftX >= $size[0]) {
$ra = 1;
$i-- if
$i > $ft &&
$w - $$ww[$i] >= $size[0] - DefLeftX - DefArrowX - DefGapX;
last;
}
}
$i = scalar @{$self-> {widths}} - 1
if $i >= scalar @{$self-> {widths}};
$self-> {lastTab} = $i;
$self-> {arrows} = ( $la ? 1 : 0) | ( $ra ? 2 : 0);
} else {
$self-> {lastTab} = scalar @{$self-> {widths}} - 1;
}
}
sub recalc_widths
{
my $self = $_[0];
my @w;
my $i;
my ( $notifier, @notifyParms) = $self-> get_notify_sub(q(MeasureTab));
$self-> begin_paint_info;
$self-> push_event;
for ( $i = 0; $i < scalar @{$self-> {tabs}}; $i++) {
my $iw = 0;
$notifier-> ( @notifyParms, $i, \$iw);
push ( @w, $iw);
}
$self-> pop_event;
$self-> end_paint_info;
$self-> {widths} = [@w];
}
sub on_mousedown
{
my ( $self, $btn, $mod, $x, $y) = @_;
return if $self-> {mouseTransaction};
$self-> clear_event;
my ( $a, $ww, $ft, $lt) = (
$self-> {arrows}, $self-> {widths}, $self-> {firstTab}, $self-> {lastTab}
);
if (( $a & 1) and ( $x < DefLeftX + DefGapX * 2 + DefArrowX)) {
$self-> firstTab( $self-> firstTab - 1);
$self-> capture(1);
$self-> {mouseTransaction} = -1;
$self-> scroll_timer_start;
$self-> scroll_timer_semaphore(0);
return;
}
my @size = $self-> size;
if (( $a & 2) and ( $x >= $size[0] - DefLeftX - DefGapX * 2 - DefArrowX)) {
$self-> firstTab( $self-> firstTab + 1);
$self-> capture(1);
$self-> {mouseTransaction} = 1;
$self-> scroll_timer_start;
$self-> scroll_timer_semaphore(0);
return;
}
my $w = DefLeftX;
$w += DefGapX + DefArrowX if $a & 1;
my $i;
my $found = undef;
for ( $i = $ft; $i <= $lt; $i++) {
$found = $i, last if $x < $w + $$ww[$i] + DefGapX;
$w += $$ww[$i] + DefGapX;
}
return unless defined $found;
if ( $found == $self-> {tabIndex}) {
$self-> focusedTab( $found);
$self-> focus;
} else {
$self-> tabIndex( $found);
}
}
sub on_mousewheel
{
my ( $self, $mod, $x, $y, $z) = @_;
$self-> tabIndex( $self-> tabIndex + (( $z < 0) ? -1 : 1));
$self-> clear_event;
}
sub on_mouseup
{
my ( $self, $btn, $mod, $x, $y) = @_;
return unless $self-> {mouseTransaction};
$self-> capture(0);
$self-> scroll_timer_stop;
$self-> {mouseTransaction} = undef;
}
sub on_mousemove
{
my ( $self, $mod, $x, $y) = @_;
return unless $self-> {mouseTransaction};
return unless $self-> scroll_timer_semaphore;
$self-> scroll_timer_semaphore(0);
my $ft = $self-> firstTab;
$self-> firstTab( $ft + $self-> {mouseTransaction});
$self-> notify(q(MouseUp),1,0,0,0) if $ft == $self-> firstTab;
}
sub on_mouseclick
{
my $self = shift;
$self-> clear_event;
return unless pop;
$self-> clear_event unless $self-> notify( "MouseDown", @_);
}
sub on_keydown
{
my ( $self, $code, $key, $mod) = @_;
if ( $key == kb::Left || $key == kb::Right) {
$self-> focusedTab( $self-> focusedTab + (( $key == kb::Left) ? -1 : 1));
$self-> clear_event;
return;
}
if ( $key == kb::PgUp || $key == kb::PgDn) {
$self-> tabIndex( $self-> tabIndex + (( $key == kb::PgUp) ? -1 : 1));
$self-> clear_event;
return;
}
if ( $key == kb::Home || $key == kb::End) {
$self-> tabIndex(( $key == kb::Home) ? 0 : scalar @{$self-> {tabs}});
$self-> clear_event;
return;
}
if ( $key == kb::Space || $key == kb::Enter) {
$self-> tabIndex( $self-> focusedTab);
$self-> clear_event;
return;
}
}
sub on_paint
{
my ($self,$canvas) = @_;
my @clr = ( $self-> color, $self-> backColor);
@clr = ( $self-> disabledColor, $self-> disabledBackColor) if ( !$self-> enabled);
my @c3d = ( $self-> dark3DColor, $self-> light3DColor);
my @size = $canvas-> size;
$canvas-> color( $clr[1]);
$canvas-> bar( 0, 0, @size);
my ( $ft, $lt, $a, $ti, $ww, $tm) =
( $self-> {firstTab}, $self-> {lastTab}, $self-> {arrows}, $self-> {tabIndex},
$self-> {widths}, $self-> {topMost}
);
my $i;
my ( $notifier, @notifyParms) = $self-> get_notify_sub(q(DrawTab));
$self-> push_event;
my $atX = DefLeftX;
$atX += DefArrowX + DefGapX if $a & 1;
my $atXti = undef;
for ( $i = $ft; $i <= $lt; $i++) {
$atX += $$ww[$i] + DefGapX;
}
my @colorSet = ( @clr, @c3d);
$canvas-> clipRect( 0, 0, $size[0] - DefArrowX - DefGapX - DefLeftX, $size[1]) if $a & 2;
for ( $i = $lt; $i >= $ft; $i--) {
$atX -= $$ww[$i] + DefGapX;
$atXti = $atX, next if $i == $ti;
my @poly = (
$atX, DefGapY,
$atX + DefGapX, $size[1] - DefGapY - 1,
$atX + DefGapX + $$ww[$i], $size[1] - DefGapY - 1,
$atX + DefGapX * 2 + $$ww[$i], DefGapY
);
@poly[1,3,5,7] = @poly[3,1,7,5] unless $tm;
$notifier-> ( @notifyParms, $canvas, $i, \@colorSet, \@poly);
}
my $swapDraw = ( $ti == $lt) && ( $a & 2);
goto PaintSelTabBefore if $swapDraw;
PaintEarsThen:
$canvas-> clipRect( 0, 0, @size) if $a & 2;
if ( $a & 1) {
my $x = DefLeftX;
my @poly = (
$x, DefGapY,
$x + DefGapX, $size[1] - DefGapY - 1,
$x + DefGapX + DefArrowX, $size[1] - DefGapY - 1,
$x + DefGapX * 2 + DefArrowX, DefGapY
);
@poly[1,3,5,7] = @poly[3,1,7,5] unless $tm;
$notifier-> ( @notifyParms, $canvas, -1, \@colorSet, \@poly);
}
if ( $a & 2) {
my $x = $size[0] - DefLeftX - DefArrowX - DefGapX * 2;
my @poly = (
$x, DefGapY,
$x + DefGapX, $size[1] - DefGapY - 1,
$x + DefGapX + DefArrowX, $size[1] - DefGapY - 1,
$x + DefGapX * 2 + DefArrowX, DefGapY
);
@poly[1,3,5,7] = @poly[3,1,7,5] unless $tm;
$notifier-> ( @notifyParms, $canvas, -2, \@colorSet, \@poly);
}
$canvas-> color( $c3d[0]);
my @ld = $tm ? ( 0, DefGapY) : ( $size[1] - 0, $size[1] - DefGapY - 1);
$canvas-> line( $size[0] - 1, $ld[0], $size[0] - 1, $ld[1]);
if ($tm) {
$canvas-> color( $c3d[1]);
$canvas-> line( 0, $ld[1], $size[0] - 1, $ld[1]);
$canvas-> line( 0, $ld[0], 0, $ld[1]);
} else {
$canvas-> line( 0, $ld[1], $size[0] - 1, $ld[1]);
$canvas-> color( $c3d[1]);
$canvas-> line( 0, $ld[0], 0, $ld[1]);
}
$canvas-> color( $clr[0]);
goto EndOfSwappedPaint if $swapDraw;
PaintSelTabBefore:
if ( defined $atXti) {
my @poly = (
$atXti, DefGapY,
$atXti + DefGapX, $size[1] - DefGapY - 1,
$atXti + DefGapX + $$ww[$ti], $size[1] - DefGapY - 1,
$atXti + DefGapX * 2 + $$ww[$ti], DefGapY
);
@poly[1,3,5,7] = @poly[3,1,7,5] unless $tm;
my @poly2 = $tm ? (
$atXti, DefGapY,
$atXti + DefGapX * 2 + $$ww[$ti], DefGapY,
$atXti + DefGapX * 2 + $$ww[$ti] - 4, 0,
$atXti + 4, 0
) : (
$atXti, $size[1] - 1 - DefGapY,
$atXti + DefGapX * 2 + $$ww[$ti], $size[1] - 1 - DefGapY,
$atXti + DefGapX * 2 + $$ww[$ti] - 4, $size[1]-1,
$atXti + 4, $size[1]-1
);
$canvas-> clipRect(
0, 0,
$size[0] - DefArrowX - DefGapX - DefLeftX, $size[1]
) if $a & 2;
$notifier-> (
@notifyParms, $canvas, $ti, \@colorSet, \@poly,
$swapDraw ? undef : \@poly2
);
}
goto PaintEarsThen if $swapDraw;
EndOfSwappedPaint:
$self-> pop_event;
}
sub on_size
{
my ( $self, $ox, $oy, $x, $y) = @_;
if ( $x > $ox && (( $self-> {arrows} & 2) == 0)) {
my $w = DefLeftX * 2 + DefGapX;
my $ww = $self-> {widths};
$w += DefArrowX + DefGapX if $self-> {arrows} & 1;
my $i;
my $set = 0;
for ( $i = scalar @{$ww} - 1; $i >= 0; $i--) {
$w += $$ww[$i] + DefGapX;
$set = 1, $self-> firstTab( $i + 1), last if $w >= $x;
}
$self-> firstTab(0) unless $set;
}
$self-> reset;
}
sub on_fontchanged { $_[0]-> reset; $_[0]-> recalc_widths; }
sub on_enter { $_[0]-> repaint; }
sub on_leave { $_[0]-> repaint; }
sub on_measuretab
{
my ( $self, $index, $sref) = @_;
$$sref = $self-> get_text_width( $self-> {tabs}-> [$index]) + DefGapX * 4;
}
# see L<DrawTab> below for more info
sub on_drawtab
{
my ( $self, $canvas, $i, $clr, $poly, $poly2) = @_;
$canvas-> color(( $self-> {colored} && ( $i >= 0)) ?
( $warpColors[ $i % scalar @warpColors]) : $$clr[1]);
$canvas-> fillpoly( $poly);
$canvas-> fillpoly( $poly2) if $poly2;
$canvas-> color( $$clr[3]);
$canvas-> polyline( [@{$poly}[0..($self-> {topMost}?5:3)]]);
$canvas-> color( $$clr[2]);
$canvas-> polyline( [@{$poly}[($self-> {topMost}?4:2)..7]]);
$canvas-> line( $$poly[4]+1, $$poly[5], $$poly[6]+1, $$poly[7]);
$canvas-> color( $$clr[0]);
if ( $i >= 0) {
my @tx = (
$$poly[0] + ( $$poly[6] - $$poly[0] - $self-> {widths}-> [$i]) / 2 + DefGapX * 2,
$$poly[1] + ( $$poly[3] - $$poly[1] - $canvas-> font-> height) / 2
);
$canvas-> text_out( $self-> {tabs}-> [$i], @tx);
$canvas-> rect_focus( $tx[0] - 1, $tx[1] - 1,
$tx[0] + $self-> {widths}-> [$i] - DefGapX * 4 + 1, $tx[1] + $canvas-> font-> height + 1)
if ( $i == $self-> {focusedTab}) && $self-> focused;
} elsif ( $i == -1) {
$canvas-> fillpoly([
$$poly[0] + ( $$poly[6] - $$poly[0]) * 0.6,
$$poly[1] + ( $$poly[3] - $$poly[1]) * 0.2,
$$poly[0] + ( $$poly[6] - $$poly[0]) * 0.6,
$$poly[1] + ( $$poly[3] - $$poly[1]) * 0.6,
$$poly[0] + ( $$poly[6] - $$poly[0]) * 0.4,
$$poly[1] + ( $$poly[3] - $$poly[1]) * 0.4,
]);
} elsif ( $i == -2) {
$canvas-> fillpoly([
$$poly[0] + ( $$poly[6] - $$poly[0]) * 0.4,
$$poly[1] + ( $$poly[3] - $$poly[1]) * 0.2,
$$poly[0] + ( $$poly[6] - $$poly[0]) * 0.4,
$$poly[1] + ( $$poly[3] - $$poly[1]) * 0.6,
$$poly[0] + ( $$poly[6] - $$poly[0]) * 0.6,
$$poly[1] + ( $$poly[3] - $$poly[1]) * 0.4,
]);
}
}
sub get_item_width
{
return $_[0]-> {widths}-> [$_[1]];
}
sub tab2firstTab
{
my ( $self, $ti) = @_;
if (
( $ti >= $self-> {lastTab}) and
( $self-> {arrows} & 2) and
( $ti != $self-> {firstTab})
) {
my $w = DefLeftX;
$w += DefArrowX + DefGapX if $self-> {arrows} & 1;
my $i;
my $W = $self-> width;
my $ww = $self-> {widths};
my $moreThanOne = ( $ti - $self-> {firstTab}) > 0;
for ( $i = $self-> {firstTab}; $i <= $ti; $i++) {
$w += $$ww[$i] + DefGapX;
}
my $lim = $W - DefLeftX - DefArrowX - DefGapX * 2;
$lim -= DefGapX * 2 if $moreThanOne;
if ( $w >= $lim) {
my $leftw = DefLeftX * 2 + DefGapX + DefArrowX;
$leftw += DefArrowX + DefGapX if $self-> {arrows} & 1;
$leftw = $W - $leftw;
$leftw -= $$ww[$ti] if $moreThanOne;
$w = 0;
for ( $i = $ti; $i >= 0; $i--) {
$w += $$ww[$i] + DefGapX;
last if $w > $leftw;
}
return $i + 1;
}
} elsif ( $ti < $self-> {firstTab}) {
return $ti;
}
return undef;
}
sub set_tab_index
{
my ( $self, $ti) = @_;
$ti = 0 if $ti < 0;
my $mx = scalar @{$self-> {tabs}} - 1;
$ti = $mx if $ti > $mx;
return if $ti == $self-> {tabIndex};
$self-> {tabIndex} = $ti;
$self-> {focusedTab} = $ti;
my $newFirstTab = $self-> tab2firstTab( $ti);
defined $newFirstTab ?
$self-> firstTab( $newFirstTab) :
$self-> repaint;
$self-> notify(q(Change));
}
sub set_first_tab
{
my ( $self, $ft) = @_;
$ft = 0 if $ft < 0;
unless ( $self-> {arrows}) {
$ft = 0;
} else {
my $w = DefLeftX * 2 + DefGapX * 2;
$w += DefArrowX if $ft > 0;
my $haveRight = 0;
my $i;
my @size = $self-> size;
for ( $i = $ft; $i < scalar @{$self-> {widths}}; $i++) {
$w += DefGapX + $self-> {widths}-> [$i];
$haveRight = 1, last if $w >= $size[0];
}
unless ( $haveRight) {
$w += DefGapX;
for ( $i = $ft - 1; $i >= 0; $i--) {
$w += DefGapX + $self-> {widths}-> [$i];
if ( $w >= $size[0]) {
$i++;
$ft = $i if $ft > $i;
last;
}
}
}
}
return if $self-> {firstTab} == $ft;
$self-> {firstTab} = $ft;
$self-> reset;
$self-> repaint;
}
sub set_focused_tab
{
my ( $self, $ft) = @_;
$ft = 0 if $ft < 0;
my $mx = scalar @{$self-> {tabs}} - 1;
$ft = $mx if $ft > $mx;
$self-> {focusedTab} = $ft;
my $newFirstTab = $self-> tab2firstTab( $ft);
defined $newFirstTab ?
$self-> firstTab( $newFirstTab) :
( $self-> focused ? $self-> repaint : 0);
}
sub set_tabs
{
my $self = shift;
my @tabs = ( scalar @_ == 1 && ref( $_[0]) eq q(ARRAY)) ? @{$_[0]} : @_;
$self-> {tabs} = \@tabs;
$self-> recalc_widths;
$self-> reset;
$self-> lock;
$self-> firstTab( $self-> firstTab);
$self-> tabIndex( $self-> tabIndex);
$self-> unlock;
$self-> update_view;
}
sub set_top_most
{
my ( $self, $tm) = @_;
return if $tm == $self-> {topMost};
$self-> {topMost} = $tm;
$self-> repaint;
}
sub colored {($#_)?($_[0]-> {colored}=$_[1],$_[0]-> repaint) :return $_[0]-> {colored}}
sub focusedTab {($#_)?($_[0]-> set_focused_tab( $_[1])) :return $_[0]-> {focusedTab}}
sub firstTab {($#_)?($_[0]-> set_first_tab( $_[1])) :return $_[0]-> {firstTab}}
sub tabIndex {($#_)?($_[0]-> set_tab_index( $_[1])) :return $_[0]-> {tabIndex}}
sub topMost {($#_)?($_[0]-> set_top_most ( $_[1])) :return $_[0]-> {topMost}}
sub tabs {($#_)?(shift-> set_tabs ( @_ )) :return $_[0]-> {tabs}}
package Prima::Notebook;
use vars qw(@ISA);
@ISA = qw(Prima::Widget);
sub profile_default
{
my $def = $_[ 0]-> SUPER::profile_default;
my %prf = (
defaultInsertPage => undef,
pageCount => 0,
pageIndex => 0,
tabStop => 0,
ownerBackColor => 1,
);
@$def{keys %prf} = values %prf;
return $def;
}
sub init
{
my $self = shift;
$self-> {pageIndex} = -1;
$self-> {pageCount} = 0;
my %profile = $self-> SUPER::init(@_);
$self-> {pageCount} = $profile{pageCount};
$self-> {pageCount} = 0 if $self-> {pageCount} < 0;
my $j = $profile{pageCount};
push (@{$self-> {widgets}},[]) while $j--;
for ( qw( pageIndex defaultInsertPage)) { $self-> $_( $profile{ $_}); }
return %profile;
}
sub set_page_index
{
my ( $self, $pi) = @_;
$pi = 0 if $pi < 0;
$pi = $self-> {pageCount} - 1 if $pi > $self-> {pageCount} - 1;
my $sel = $self-> selected;
return if $pi == $self-> {pageIndex};
$self-> lock;
my $cp = $self-> {widgets}-> [$self-> {pageIndex}];
if ( defined $cp) {
for ( @$cp) {
$$_[1] = $$_[0]-> enabled;
$$_[2] = $$_[0]-> visible;
$$_[3] = $$_[0]-> current;
$$_[4] = $$_[0]-> geometry;
$$_[0]-> visible(0);
$$_[0]-> enabled(0);
$$_[0]-> geometry(gt::Default);
}
}
$cp = $self-> {widgets}-> [$pi];
if ( defined $cp) {
my $hasSel;
for ( @$cp) {
$$_[0]-> geometry($$_[4]);
$$_[0]-> enabled($$_[1]);
$$_[0]-> visible($$_[2]);
if ( !defined $hasSel && $$_[3]) {
$hasSel = 1;
$$_[0]-> select if $sel;
}
$$_[0]-> current($$_[3]);
}
}
my $i = $self-> {pageIndex};
$self-> {pageIndex} = $pi;
$self-> notify(q(Change), $i, $pi);
$self-> unlock;
$self-> update_view;
}
sub insert_page
{
my ( $self, $at) = @_;
$at = -1 unless defined $at;
$at = $self-> {pageCount} if $at < 0 || $at > $self-> {pageCount};
splice( @{$self-> {widgets}}, $at, 0, []);
$self-> {pageCount}++;
$self-> pageIndex(0) if $self-> {pageCount} == 1;
}
sub delete_page
{
my ( $self, $at, $removeChildren) = @_;
$removeChildren = 1 unless defined $removeChildren;
$at = -1 unless defined $at;
$at = $self-> {pageCount} - 1 if $at < 0 || $at >= $self-> {pageCount};
my @r = splice( @{$self-> {widgets}}, $at, 1);
$self-> {pageCount}--;
$self-> pageIndex( $self-> pageIndex);
if ( $removeChildren) {
$$_[0]-> destroy for @{$r[0]};
}
}
sub attach_to_page
{
my $self = shift;
my $page = shift;
$self-> insert_page if $self-> {pageCount} == 0;
$page = $self-> {pageCount} - 1 if $page > $self-> {pageCount} - 1 || $page < 0;
my $cp = $self-> {widgets}-> [$page];
for ( @_) {
next unless $_-> isa('Prima::Widget');
# $_->add_notification( Enable => \&_enable => $self);
# $_->add_notification( Disable => \&_disable => $self);
# $_->add_notification( Show => \&_show => $self);
# $_->add_notification( Hide => \&_hide => $self);
my @rec = ( $_, $_-> enabled, $_-> visible, $_-> current, $_-> geometry);
push( @{$cp}, [@rec]);
next if $page == $self-> {pageIndex};
$_-> visible(0);
$_-> autoEnableChildren(0);
$_-> enabled(0);
$_-> geometry(gt::Default);
}
}
sub insert
{
my $self = shift;
my $page = defined $self-> {defaultInsertPage} ?
$self-> {defaultInsertPage} :
$self-> pageIndex;
return $self-> insert_to_page( $page, @_);
}
sub insert_to_page
{
my $self = shift;
my $page = shift;
my $sel = $self-> selected;
$page = $self-> {pageCount} - 1 if $page > $self-> {pageCount} - 1 || $page < 0;
$self-> lock;
my @ctrls = $self-> SUPER::insert( @_);
$self-> attach_to_page( $page, @ctrls);
$ctrls[0]-> select if $sel && scalar @ctrls && $page == $self-> {pageIndex} &&
$ctrls[0]-> isa('Prima::Widget');
$self-> unlock;
return wantarray ? @ctrls : $ctrls[0];
}
sub insert_transparent
{
shift-> SUPER::insert( @_);
}
sub contains_widget
{
my ( $self, $ctrl) = @_;
my $i;
my $j;
my $cptr = $self-> {widgets};
for ( $i = 0; $i < $self-> {pageCount}; $i++) {
my $cp = $$cptr[$i];
my $j = 0;
for ( @$cp) {
return ( $i, $j) if $$_[0] == $ctrl;
$j++;
}
}
return;
}
sub widgets_from_page
{
my ( $self, $page) = @_;
return if $page < 0 or $page >= $self-> {pageCount};
my @r;
push( @r, $$_[0]) for @{$self-> {widgets}-> [$page]};
return @r;
}
sub on_childleave
{
my ( $self, $widget) = @_;
$self-> detach_from_page( $widget);
}
sub detach_from_page
{
my ( $self, $ctrl) = @_;
my ( $page, $number) = $self-> contains_widget( $ctrl);
return unless defined $page;
splice( @{$self-> {widgets}-> [$page]}, $number, 1);
}
sub delete_widget
{
my ( $self, $ctrl) = @_;
my ( $page, $number) = $self-> contains_widget( $ctrl);
return unless defined $page;
$ctrl-> destroy;
}
sub move_widget
{
my ( $self, $widget, $newPage) = @_;
my ( $page, $number) = $self-> contains_widget( $widget);
return unless defined $page;
@{$self-> {widgets}-> [$newPage]} = splice( @{$self-> {widgets}-> [$page]}, $number, 1);
$self-> repaint if $self-> {pageIndex} == $page || $self-> {pageIndex} == $newPage;
}
sub set_page_count
{
my ( $self, $pageCount) = @_;
$pageCount = 0 if $pageCount < 0;
return if $pageCount == $self-> {pageCount};
if ( $pageCount < $self-> {pageCount}) {
splice(@{$self-> {widgets}}, $pageCount);
$self-> {pageCount} = $pageCount;
$self-> pageIndex($pageCount - 1) if $self-> {pageIndex} < $pageCount - 1;
} else {
my $i = $pageCount - $self-> {pageCount};
push (@{$self-> {widgets}},[]) while $i--;
$self-> {pageCount} = $pageCount;
$self-> pageIndex(0) if $self-> {pageIndex} < 0;
}
}
my %virtual_properties = (
enabled => 1,
visible => 2,
current => 3,
geometry => 4,
);
sub widget_get
{
my ( $self, $widget, $property) = @_;
return $widget-> $property() if ! $virtual_properties{$property};
my ( $page, $number) = $self-> contains_widget( $widget);
return $widget-> $property()
if ! defined $page || $page == $self-> {pageIndex};
return $self-> {widgets}-> [$page]-> [$number]-> [$virtual_properties{$property}];
}
sub widget_set
{
my ( $self, $widget) = ( shift, shift );
my ( $page, $number) = $self-> contains_widget( $widget);
if ( ! defined $page || $page == $self-> {pageIndex} ) {
$widget-> set( @_ );
return;
}
$number = $self-> {widgets}-> [$page]-> [$number];
my %profile;
my $clear_current_flag = 0;
while ( @_ ) {
my ( $property, $value) = ( shift, shift );
if ( $virtual_properties{$property} ) {
$number-> [ $virtual_properties{ $property } ] = ( $value ? 1 : 0 );
$clear_current_flag = 1 if $property eq 'current' && $value;
} else {
$profile{$property} = $value;
}
}
if ( $clear_current_flag) {
for ( @{$self-> {widgets}-> [$page]} ) {
$$_[3] = 0 if $$_[0] != $widget;
}
}
$widget-> set( %profile ) if scalar keys %profile;
}
sub defaultInsertPage
{
$_[0]-> {defaultInsertPage} = $_[1];
}
sub pageIndex {($#_)?($_[0]-> set_page_index ( $_[1])) :return $_[0]-> {pageIndex}}
sub pageCount {($#_)?($_[0]-> set_page_count ( $_[1])) :return $_[0]-> {pageCount}}
# TabbedNotebook styles
package tns;
use constant Simple => 0;
use constant Standard => 1;
# TabbedNotebook orientations
package tno;
use constant Top => 0;
use constant Bottom => 1;
package Prima::TabbedNotebook;
use vars qw(@ISA %notebookProps);
@ISA = qw(Prima::Widget);
use constant DefBorderX => 11;
use constant DefBookmarkX => 32;
%notebookProps = (
pageCount => 1, defaultInsertPage=> 1,
attach_to_page => 1, insert_to_page => 1, insert => 1, insert_transparent => 1,
delete_widget => 1, detach_from_page => 1, move_widget => 1, contains_widget => 1,
widget_get => 1, widget_set => 1, widgets_from_page => 1,
);
for ( keys %notebookProps) {
eval <<GENPROC;
sub $_ { return shift-> {notebook}-> $_(\@_); }
GENPROC
}
sub profile_default
{
return {
%{Prima::Notebook-> profile_default},
%{$_[ 0]-> SUPER::profile_default},
ownerBackColor => 1,
tabs => [],
tabIndex => 0,
style => tns::Standard,
orientation => tno::Top,
tabsetClass => 'Prima::TabSet',
tabsetProfile => {},
tabsetDelegations => ['Change'],
notebookClass => 'Prima::Notebook',
notebookProfile => {},
notebookDelegations => ['Change'],
}
}
sub init
{
my $self = shift;
my %profile = @_;
my $visible = $profile{visible};
my $scaleChildren = $profile{scaleChildren};
$profile{visible} = 0;
$self-> {style} = tns::Standard;
$self-> {orientation} = tno::Top;
$self-> {tabs} = [];
%profile = $self-> SUPER::init(%profile);
my @size = $self-> size;
my $maxh = $self-> font-> height * 2;
$self-> {tabSet} = $profile{tabsetClass}-> create(
owner => $self,
name => 'TabSet',
left => 0,
width => $size[0],
top => $size[1] - 1,
growMode => gm::Ceiling,
height => $maxh > 28 ? $maxh : 28,
buffered => 1,
designScale => undef,
delegations => $profile{tabsetDelegations},
%{$profile{tabsetProfile}},
);
$self-> {notebook} = $profile{notebookClass}-> create(
owner => $self,
name => 'Notebook',
origin => [ DefBorderX + 1, DefBorderX + 1],
size => [ $size[0] - DefBorderX * 2 - 5,
$size[1] - DefBorderX * 2 - $self-> {tabSet}-> height - DefBookmarkX - 4],
growMode => gm::Client,
scaleChildren => $scaleChildren,
(map { $_ => $profile{$_}} keys %notebookProps),
designScale => undef,
pageCount => scalar @{$profile{tabs}},
delegations => $profile{notebookDelegations},
%{$profile{notebookProfile}},
);
$self-> {notebook}-> designScale( $self-> designScale); # propagate designScale
$self-> tabs( $profile{tabs});
$self-> pageIndex( $profile{pageIndex});
$self-> style($profile{style});
$self-> orientation($profile{orientation});
$self-> visible( $visible);
return %profile;
}
sub Notebook_Change
{
my ( $self, $book) = @_;
return if $self-> {changeLock};
$self-> pageIndex( $book-> pageIndex);
}
sub on_paint
{
my ($self,$canvas) = @_;
my @clr = ( $self-> color, $self-> backColor);
@clr = ( $self-> disabledColor, $self-> disabledBackColor) if ( !$self-> enabled);
my @c3d = ( $self-> dark3DColor, $self-> light3DColor);
my @size = $canvas-> size;
my $on_top = ($self-> {orientation} == tno::Top);
$canvas-> color( $clr[1]);
$canvas-> bar( 0, 0, @size);
if ($self-> {style} == tns::Standard) {
if ($on_top) {
$size[1] -= $self-> {tabSet}-> height;
} else {
$size[1] -= 5;
}
$canvas-> rect3d(
0, 0, $size[0] - 1, $size[1] - 1 + Prima::TabSet::DefGapY,
1, reverse @c3d
);
$canvas-> rect3d(
DefBorderX, $on_top ?
DefBorderX : $self-> {notebook}-> bottom - 1,
$size[0] - 1 - DefBorderX,
$size[1] - DefBorderX + Prima::TabSet::DefGapY,
1, @c3d
);
my $y = $size[1] - DefBorderX + Prima::TabSet::DefGapY;
my $x = $size[0] - DefBorderX - DefBookmarkX;
return if $y < DefBorderX * 2 + DefBookmarkX;
$canvas-> color( $c3d[0]);
$canvas-> line(
DefBorderX + 2, $y - 2,
$x - 2, $y - 2
);
$canvas-> line(
$x + DefBookmarkX - 4, $y - DefBookmarkX + 1,
$x + DefBookmarkX - 4, $on_top ?
(DefBorderX + 2) :
($self-> {notebook}-> bottom + 1)
);
my $fh = 24;
my $a = 0;
my ($pi, $mpi) = (
$self-> {notebook}-> pageIndex,
$self-> {notebook}-> pageCount - 1
);
$a |= 1 if $pi > 0;
$a |= 2 if $pi < $mpi;
$canvas-> line(
DefBorderX + 4, $y - $fh * 1.6,
$x - 6, $y - $fh * 1.6
);
$canvas-> polyline([
$x - 2, $y - 2,
$x - 2, $y - DefBookmarkX,
$x + DefBookmarkX - 4, $y - DefBookmarkX
]);
$canvas-> line( $x - 1, $y - 3, $x + DefBookmarkX - 5, $y - DefBookmarkX + 1);
$canvas-> line( $x - 1, $y - 4, $x + DefBookmarkX - 6, $y - DefBookmarkX + 1);
$canvas-> line( $x - 0, $y - 2, $x + DefBookmarkX - 4, $y - DefBookmarkX + 2);
$canvas-> line( $x + 5, $y - DefBookmarkX - 2, $x + DefBookmarkX - 5, $y - DefBookmarkX - 2);
$canvas-> polyline([
$x + 4, $y - DefBookmarkX + 6,
$x + 10, $y - DefBookmarkX + 6,
$x + 10, $y - DefBookmarkX + 8]) if $a & 1;
my $dx = DefBookmarkX / 2;
my ( $x1, $y1) = ( $x + $dx, $y - $dx);
$canvas-> line( $x1 + 1, $y1 + 4, $x1 + 3, $y1 + 4) if $a & 2;
$canvas-> line( $x1 + 5, $y1 + 6, $x1 + 5, $y1 + 8) if $a & 2;
$canvas-> polyline([ $x1 + 3, $y1 + 2, $x1 + 5, $y1 + 2,
$x1 + 5, $y1 + 4, $x1 + 7, $y1 + 4, $x1 + 7, $y1 + 6]) if $a & 2;
$canvas-> color( $c3d[1]);
$canvas-> line( $x - 1, $y - 7, $x + DefBookmarkX - 9, $y - DefBookmarkX + 1);
$canvas-> line( DefBorderX + 4, $y - $fh * 1.6 - 1, $x - 6, $y - $fh * 1.6 - 1);
$canvas-> polyline([ $x + 4, $y1 - 9, $x + 4, $y1 - 8, $x + 10, $y1 - 8]) if $a & 1;
$canvas-> line( $x1 + 3, $y1 + 2, $x1 + 3, $y1 + 3) if $a & 2;
$canvas-> line( $x1 + 6, $y1 + 6, $x1 + 7, $y1 + 6) if $a & 2;
$canvas-> polyline([ $x1 + 1, $y1 + 4, $x1 + 1, $y1 + 6,
$x1 + 3, $y1 + 6, $x1 + 3, $y1 + 8, $x1 + 5, $y1 + 8]) if $a & 2;
$canvas-> color( cl::Black);
$canvas-> line( $x - 1, $y - 2, $x + DefBookmarkX - 4, $y - DefBookmarkX + 1);
$canvas-> line( $x + 5, $y - DefBookmarkX - 1, $x + DefBookmarkX - 5, $y - DefBookmarkX - 1);
$canvas-> color( $clr[0]);
my $t = $self-> {tabs};
if ( scalar @{$t}) {
my $tx = $self-> {tabSet}-> tabIndex;
my $t1 = $$t[ $tx * 2];
my $yh = $y - $fh * 0.8 - $self-> font-> height / 2;
$canvas-> clipRect( DefBorderX + 1, $y - $fh * 1.6 + 1, $x - 4, $y - 3);
$canvas-> text_out( $t1, DefBorderX + 4, $yh);
if ( $$t[ $tx * 2 + 1] > 1) {
$t1 = sprintf("Page %d of %d ", $self-> pageIndex - $self-> tab2page( $tx) + 1, $$t[ $tx * 2 + 1]);
my $tl1 = $size[0] - DefBorderX - 3 - DefBookmarkX - $self-> get_text_width( $t1);
$canvas-> text_out( $t1, $tl1, $yh) if $tl1 > 4 + DefBorderX + $fh * 3;
}
}
} else {
# tns::Simple
$canvas-> rect3d(0, 0, $size[0]-1, $size[1]-1, 1, reverse @c3d);
}
}
sub event_in_page_flipper
{
my ( $self, $x, $y) = @_;
return if $self-> {style} != tns::Standard;
my @size = $self-> size;
my $th = ($self-> {orientation} == tno::Top) ? $self-> {tabSet}-> height : 5;
$x -= $size[0] - DefBorderX - DefBookmarkX - 1;
$y -= $size[1] - DefBorderX - $th - DefBookmarkX + 4;
return if $x < 0 || $x > DefBookmarkX || $y < 0 || $y > DefBookmarkX;
return ( $x, $y);
}
sub on_mousedown
{
my ( $self, $btn, $mod, $x, $y) = @_;
$self-> clear_event;
return unless ( $x, $y) = $self-> event_in_page_flipper( $x, $y);
$self-> pageIndex( $self-> pageIndex + (( -$x + DefBookmarkX < $y) ? 1 : -1));
}
sub on_mousewheel
{
my ( $self, $mod, $x, $y, $z) = @_;
$self-> clear_event;
return unless ( $x, $y) = $self-> event_in_page_flipper( $x, $y);
$self-> pageIndex( $self-> pageIndex + (( $z < 0) ? -1 : 1));
}
sub on_mouseclick
{
my $self = shift;
$self-> clear_event;
return unless pop;
$self-> clear_event unless $self-> notify( "MouseDown", @_);
}
sub page2tab
{
my ( $self, $index) = @_;
my $t = $self-> {tabs};
return 0 unless scalar @$t;
my $i = $$t[1] - 1;
my $j = 0;
while( $i < $index) {
$j++;
$i += $$t[ $j*2 + 1];
}
return $j;
}
sub tab2page
{
my ( $self, $index) = @_;
my $t = $self-> {tabs};
my $i;
my $j = 0;
for ( $i = 0; $i < $index; $i++) { $j += $$t[ $i * 2 + 1]; }
return $j;
}
sub TabSet_Change
{
my ( $self, $tabset) = @_;
return if $self-> {changeLock};
$self-> pageIndex( $self-> tab2page( $tabset-> tabIndex));
}
sub set_tabs
{
my $self = shift;
my @tabs = ( scalar @_ == 1 && ref( $_[0]) eq q(ARRAY)) ? @{$_[0]} : @_;
my @nTabs;
my @loc;
my $prev = undef;
for ( @tabs) {
if ( defined $prev && $_ eq $prev) {
$loc[-1]++;
} else {
push( @loc, $_);
push( @loc, 1);
push( @nTabs, $_);
}
$prev = $_;
}
my $pages = $self-> {notebook}-> pageCount;
$self-> {tabs} = \@loc;
$self-> {tabSet}-> tabs( \@nTabs);
my $i;
if ( $pages > scalar @tabs) {
for ( $i = scalar @tabs; $i < $pages; $i++) {
$self-> {notebook}-> delete_page( $i);
}
} elsif ( $pages < scalar @tabs) {
for ( $i = $pages; $i < scalar @tabs; $i++) {
$self-> {notebook}-> insert_page;
}
}
}
sub get_tabs
{
my $self = $_[0];
my $i;
my $t = $self-> {tabs};
my @ret;
for ( $i = 0; $i < scalar @{$t} / 2; $i++) {
my $j;
for ( $j = 0; $j < $$t[$i*2+1]; $j++) { push( @ret, $$t[$i*2]); }
}
return \@ret;
}
sub set_page_index
{
my ( $self, $pi) = @_;
my ($pix, $mpi) = ( $self-> {notebook}-> pageIndex, $self-> {notebook}-> pageCount - 1);
$self-> {changeLock} = 1;
$self-> {notebook}-> pageIndex( $pi);
$self-> {tabSet}-> tabIndex( $self-> page2tab( $self-> {notebook}-> pageIndex));
delete $self-> {changeLock};
my @size = $self-> size;
my $th = ($self-> {orientation} == tno::Top) ? $self-> {tabSet}-> height : 5;
my $a = 0;
$a |= 1 if $pix > 0;
$a |= 2 if $pix < $mpi;
my $newA = 0;
$pi = $self-> {notebook}-> pageIndex;
$newA |= 1 if $pi > 0;
$newA |= 2 if $pi < $mpi;
$self-> invalidate_rect(
DefBorderX + 1, $size[1] - DefBorderX - $th - DefBookmarkX - 1,
$size[0] - DefBorderX - (( $a == $newA) ? DefBookmarkX + 2 : 0),
$size[1] - DefBorderX - $th + 3
);
$self-> notify(q(Change), $pix, $pi);
}
sub orientation
{
my ($self, $tno) = @_;
return $self-> {orientation} unless (defined $tno);
$self-> {orientation} = $tno;
$self-> {tabSet}-> topMost($tno == tno::Top);
$self-> {tabSet}-> growMode(($tno == tno::Top) ? gm::Ceiling : gm::Floor);
$self-> adjust_widgets;
return $tno;
}
sub style
{
my ($self, $style) = @_;
return $self-> {style} unless (defined $style);
$self-> {style} = $style;
$self-> adjust_widgets;
return $style;
}
sub adjust_widgets
{
my ($self) = @_;
my $nb = $self-> {notebook};
my $ts = $self-> {tabSet};
my @size = $self-> size;
my @pos = (0,0);
$size[1] -= $ts-> height;
if ($self-> {style} == tns::Standard) {
$size[0] -= 2 * DefBorderX + 6;
$size[1] -= 2 * DefBorderX + DefBookmarkX + 4;
$pos[0] += DefBorderX + 1;
$pos[1] += DefBorderX + 1;
}
else {
$size[0] -= 2;
$size[1] -= 2;
$pos[0]++;
$pos[1]++;
}
if ($self-> {orientation} == tno::Top) {
$ts-> top($self-> height);
}
else {
$ts-> bottom(0);
$pos[1] += $ts-> height - 5;
}
$nb-> size(@size);
$nb-> origin(@pos);
$self-> repaint;
}
sub tabIndex {($#_)?($_[0]-> {tabSet}-> tabIndex( $_[1])) :return $_[0]-> {tabSet}-> tabIndex}
sub pageIndex {($#_)?($_[0]-> set_page_index ( $_[1])) :return $_[0]-> {notebook}-> pageIndex}
sub tabs {($#_)?(shift-> set_tabs ( @_ )) :return $_[0]-> get_tabs}
package Prima::ScrollNotebook::Client;
use vars qw(@ISA);
@ISA = qw(Prima::Notebook);
sub profile_default
{
my $def = $_[0]-> SUPER::profile_default;
my %prf = (
geometry => gt::Pack,
packInfo => { expand => 1, fill => 'both'},
);
@$def{keys %prf} = values %prf;
return $def;
}
sub geomSize
{
return $_[0]-> SUPER::geomSize unless $#_;
my $self = shift;
$self-> SUPER::geomSize( @_);
$self-> owner-> owner-> ClientWindow_geomSize( $self, @_);
}
package Prima::ScrollNotebook;
use vars qw(@ISA);
@ISA = qw(Prima::ScrollGroup);
for ( qw(pageIndex insert_page delete_page),
keys %Prima::TabbedNotebook::notebookProps) {
eval <<GENPROC;
sub $_ { return shift-> {client}-> $_(\@_); }
GENPROC
}
sub profile_default
{
return {
%{Prima::Notebook-> profile_default},
%{$_[ 0]-> SUPER::profile_default},
clientClass => 'Prima::ScrollNotebook::Client',
}
}
package Prima::TabbedScrollNotebook::Client;
use vars qw(@ISA);
@ISA = qw(Prima::ScrollNotebook);
sub update_geom_size
{
my ( $self, $x, $y) = @_;
my $owner = $self-> owner;
return unless $owner-> packPropagate;
my @o = $owner-> size;
my @s = $self-> get_virtual_size;
$owner-> geomSize( $o[0] - $s[0] + $x, $o[1] - $s[1] + $y);
}
package Prima::TabbedScrollNotebook;
use vars qw(@ISA);
@ISA = qw(Prima::TabbedNotebook);
sub profile_default
{
return {
%{$_[ 0]-> SUPER::profile_default},
notebookClass => 'Prima::TabbedScrollNotebook::Client',
clientProfile => {},
clientDelegations => [],
clientSize => [ 100, 100],
}
}
sub profile_check_in
{
my ( $self, $p, $default) = @_;
$self-> SUPER::profile_check_in( $p, $default);
$p-> {notebookProfile}-> {clientSize} = $p-> {clientSize}
if exists $p-> {clientSize} and not exists $p-> {notebookProfile}-> {clientSize};
if ( exists $p-> {clientProfile}) {
%{$p-> {notebookProfile}-> {clientProfile}} = (
($default-> {notebookProfile}-> {clientProfile} ?
%{$default-> {notebookProfile}-> {clientProfile}} : ()),
%{$p-> {clientProfile}},
);
}
if ( exists $p-> {clientDelegations}) {
@{$p-> {notebookProfile}-> {clientDelegations}} = (
( $default-> {notebookProfile}-> {clientDelegations} ?
@{$default-> {notebookProfile}-> {clientDelegations}} : ()),
@{$p-> {clientDelegations}},
);
}
}
sub client { shift-> {notebook}-> client }
sub packPropagate
{
return shift-> SUPER::packPropagate unless $#_;
my ( $self, $pack_propagate) = @_;
$self-> SUPER::packPropagate( $pack_propagate);
$self-> propagate_size if $pack_propagate;
}
sub propagate_size
{
my $self = $_[0];
$self-> {notebook}-> propagate_size
if $self-> {notebook};
}
sub clientSize
{
return $_[0]-> {notebook}-> clientSize unless $#_;
shift-> {notebook}-> clientSize(@_);
}
sub use_current_size
{
$_[0]-> {notebook}-> use_current_size;
}
1;
__DATA__
=pod
=head1 NAME
Prima::Notebooks - multipage widgets
=head1 DESCRIPTION
The module contains several widgets useful for organizing multipage ( notebook )
containers. C<Prima::Notebook> provides basic functionality of a widget container.
C<Prima::TabSet> is a page selector control, and C<Prima::TabbedNotebook> combines
these two into a ready-to-use multipage control with interactive navigation.
=head1 SYNOPSIS
my $nb = Prima::TabbedNotebook-> create(
tabs => [ 'First page', 'Second page', 'Second page' ],
);
$nb-> insert_to_page( 1, 'Prima::Button' );
$nb-> insert_to_page( 2, [
[ 'Prima::Button', bottom => 10 ],
[ 'Prima::Button', bottom => 150 ],
]);
$nb-> Notebook-> backColor( cl::Green );
=head1 Prima::Notebook
=head2 Properties
Provides basic widget container functionality. Acts as merely
a grouping widget, hiding and showing the children widgets when
C<pageIndex> property is changed.
=over
=item defaultInsertPage INTEGER
Selects the page where widgets, attached by C<insert>
call are assigned to. If set to C<undef>, the default
page is the current page.
Default value: C<undef>.
=item pageCount INTEGER
Selects number of pages. If the number of pages is reduced,
the widgets that belong to the rejected pages are removed
from the notebook's storage.
=item pageIndex INTEGER
Selects the index of the current page. Valid values are
from 0 to C<pageCount - 1>.
=back
=head2 Methods
=over
=item attach_to_page INDEX, @WIDGETS
Attaches list of WIDGETS to INDEXth page. The widgets are not
necessarily must be children of the notebook widget. If the
page is not current, the widgets get hidden and disabled;
otherwise their state is not changed.
=item contains_widget WIDGET
Searches for WIDGET in the attached widgets list. If
found, returns two integers: location page index and
widget list index. Otherwise returns an empty list.
=item delete_page [ INDEX = -1, REMOVE_CHILDREN = 1 ]
Deletes INDEXth page, and detaches the widgets associated with
it. If REMOVE_CHILDREN is 1, the detached widgets are
destroyed.
=item delete_widget WIDGET
Detaches WIDGET from the widget list and destroys the widget.
=item detach_from_page WIDGET
Detaches WIDGET from the widget list.
=item insert CLASS, %PROFILE [[ CLASS, %PROFILE], ... ]
Creates one or more widgets with C<owner> property set to the
caller widget, and returns the list of references to the newly
created widgets.
See L<Prima::Widget/insert> for details.
=item insert_page [ INDEX = -1 ]
Inserts a new empty page at INDEX. Valid range
is from 0 to C<pageCount>; setting INDEX equal
to C<pageCount> is equivalent to appending a page
to the end of the page list.
=item insert_to_page INDEX, CLASS, %PROFILE, [[ CLASS, %PROFILE], ... ]
Inserts one ore more widgets to INDEXth page. The semantics
of setting CLASS and PROFILE, as well as the return values
are fully equivalent to C<insert> method.
See L<Prima::Widget/insert> for details.
=item insert_transparent CLASS, %PROFILE, [[ CLASS, %PROFILE], ... ]
Inserts one or more widgets to the notebook widget, but does not
add widgets to the widget list, so the widgets are not flipped
together with pages. Useful for setting omnipresent ( or
transparent ) widgets, visible on all pages.
The semantics of setting CLASS and PROFILE, as well as
the return values are fully equivalent to C<insert> method.
See L<Prima::Widget/insert> for details.
=item move_widget WIDGET, INDEX
Moves WIDGET from its old page to INDEXth page.
=item widget_get WIDGET, PROPERTY
Returns PROPERTY value of WIDGET. If PROPERTY is
affected by the page flipping mechanism, the internal
flag value is returned instead.
=item widget_set WIDGET, %PROFILE
Calls C<set> on WIDGET with PROFILE and
updates the internal C<visible>, C<enabled>, C<current>, and C<geometry> properties
if these are present in PROFILE.
See L<Prima::Object/set>.
=item widgets_from_page INDEX
Returns list of widgets, associated with INDEXth page.
=back
=head2 Events
=over
=item Change OLD_PAGE_INDEX, NEW_PAGE_INDEX
Called when C<pageIndex> value is changed from
OLD_PAGE_INDEX to NEW_PAGE_INDEX. Current implementation
invokes this notification while the notebook widget
is in locked state, so no redraw requests are honored during
the notification execution.
=back
=head2 Bugs
Since the notebook operates directly on children widgets'
C<::visible> and C<::enable> properties, there is a problem when
a widget associated with a non-active page must be explicitly hidden
or disabled. As a result, such a widget would become visible and enabled anyway.
This happens because Prima API does not cache property requests. For example,
after execution of the following code
$notebook-> pageIndex(1);
my $widget = $notebook-> insert_to_page( 0, ... );
$widget-> visible(0);
$notebook-> pageIndex(0);
C<$widget> will still be visible. As a workaround, C<widget_set> method
can be suggested, to be called together with the explicit state calls.
Changing
$widget-> visible(0);
code to
$notebook-> widget_set( $widget, visible => 0);
solves the problem, but introduces an inconsistency in API.
=head1 Prima::TabSet
C<Prima::TabSet> class implements functionality of an interactive
page switcher. A widget is presented as a set of horizontal
bookmark-styled tabs with text identifiers.
=head2 Properties
=over
=item colored BOOLEAN
A boolean property, selects whether each tab uses unique color
( OS/2 Warp 4 style ), or all tabs are drawn with C<backColor>.
Default value: 1
=item firstTab INTEGER
Selects the first ( leftmost ) visible tab.
=item focusedTab INTEGER
Selects the currently focused tab. This property value is almost
always equals to C<tabIndex>, except when the widget is navigated
by arrow keys, and tab selection does not occur until the user
presses the return key.
=item topMost BOOLEAN
Selects the way the widget is oriented. If 1, the widget is drawn
as if it resides on top of another widget. If 0, it is drawn as
if it is at bottom.
Default value: 1
=item tabIndex INDEX
Selects the INDEXth tab. When changed, C<Change> notification
is triggered.
=item tabs ARRAY
Anonymous array of text scalars. Each scalar corresponds to
a tab and is displayed correspondingly. The class supports
single-line text strings only; newline characters are not respected.
=back
=head2 Methods
=over
=item get_item_width INDEX
Returns width in pixels of INDEXth tab.
=item tab2firstTab INDEX
Returns the index of a tab, that will be drawn leftmost if
INDEXth tab is to be displayed.
=back
=head2 Events
=over
=item Change
Triggered when C<tabIndex> property is changed.
=item DrawTab CANVAS, INDEX, COLOR_SET, POLYGON1, POLYGON2
Called when INDEXth tab is to be drawn on CANVAS. COLOR_SET is an array
reference, and consists of the four cached color values: foreground, background,
dark 3d color, and light 3d color. POLYGON1 and POLYGON2 are array references,
and contain four points as integer pairs in (X,Y)-coordinates. POLYGON1
keeps coordinates of the larger polygon of a tab, while POLYGON2 of the smaller. Text is
displayed inside the larger polygon:
POLYGON1
[2,3] [4,5]
o..........o
. .
[0,1]. TAB_TEXT . [6,7]
o................o
POLYGON2
[0,1] [2,3]
o................o
[6,7]o..............o[4,5]
Depending on C<topMost> property value, POLYGON1 and POLYGON2 change
their mutual vertical orientation.
The notification is always called from within C<begin_paint/end_paint> block.
=item MeasureTab INDEX, REF
Puts width of INDEXth tab in pixels into REF scalar value.
This notification must be called from within C<begin_paint_info/end_paint_info>
block.
=back
=head1 Prima::TabbedNotebook
The class combines functionality of C<Prima::TabSet> and C<Prima::Notebook>,
providing the interactive multipage widget functionality. The page indexing
scheme is two-leveled: the first level is equivalent to the C<Prima::TabSet> -
provided tab scheme. Each first-level tab, in turn, contains one or more second-level
pages, which can be switched using native C<Prima::TabbedNotebook> controls.
First-level tab is often referred as I<tab>, and second-level as I<page>.
=head2 Properties
=over
=item defaultInsertPage INTEGER
Selects the page where widgets, attached by C<insert>
call are assigned to. If set to C<undef>, the default
page is the current page.
Default value: C<undef>.
=item notebookClass STRING
Assigns the notebook widget class.
Create-only property.
Default value: C<Prima::Notebook>
=item notebookProfile HASH
Assigns hash of properties, passed to the notebook widget during the creation.
Create-only property.
=item notebookDelegations ARRAY
Assigns list of delegated notifications to the notebook widget.
Create-only property.
=item orientation INTEGER
Selects one of the following tno::XXX constants
=over
=item tno::Top
The TabSet will be drawn at the top of the widget.
=item tno::Bottom
The TabSet will be drawn at the bottom of the widget.
=back
Default value: tno::Top
=item pageIndex INTEGER
Selects the INDEXth page or a tabset widget ( the second-level tab ).
When this property is triggered, C<tabIndex> can change its value,
and C<Change> notification is triggered.
=item style INTEGER
Selects one of the following tns::XXX constants
=over
=item tns::Standard
The widget will have a raised border surrounding it and a +/- control
at the top for moving between pages.
=item tns::Simple
The widget will have no decorations (other than a standard border). It
is recommended to have only one second-level page per tab with this style.
=back
Default value: tns::Standard
=item tabIndex INTEGER
Selects the INDEXth tab on a tabset widget using the first-level tab numeration.
=item tabs ARRAY
Governs number and names of notebook pages. ARRAY is an anonymous array
of text scalars, where each corresponds to a single first-level tab
and a single notebook page, with the following exception. To define second-level
tabs, the same text string must be repeated as many times as many second-level
tabs are desired. For example, the code
$nb-> tabs('1st', ('2nd') x 3);
results in creation of a notebook of four pages and two first-level
tabs. The tab C<'2nd'> contains three second-level pages.
The property implicitly operates the underlying notebook's C<pageCount> property.
When changed at run-time, its effect on the children widgets is therefore the same.
See L<pageCount> for more information.
=item tabsetClass STRING
Assigns the tab set widget class.
Create-only property.
Default value: C<Prima::TabSet>
=item tabsetProfile HASH
Assigns hash of properties, passed to the tab set widget during the creation.
Create-only property.
=item tabsetDelegations ARRAY
Assigns list of delegated notifications to the tab set widget.
Create-only property.
=back
=head2 Methods
The class forwards the following methods of C<Prima::Notebook>, which are
described in L<Prima::Notebook>: C<attach_to_page>, C<insert_to_page>,
C<insert>, C<insert_transparent>, C<delete_widget>, C<detach_from_page>,
C<move_widget>, C<contains_widget>, C<widget_get>, C<widget_set>,
C<widgets_from_page>.
=over
=item tab2page INDEX
Returns second-level tab index, that corresponds to the INDEXth first-level tab.
=item page2tab INDEX
Returns first-level tab index, that corresponds to the INDEXth second-level
tab.
=back
=head2 Events
=over
=item Change OLD_PAGE_INDEX, NEW_PAGE_INDEX
Triggered when C<pageIndex> property is changes it s value from OLD_PAGE_INDEX
to NEW_PAGE_INDEX.
=back
=head1 AUTHORS
Dmitry Karasik, E<lt>dmitry@karasik.eu.orgE<gt>.
Teo Sankaro, E<lt>teo_sankaro@hotmail.comE<gt>.
=head1 SEE ALSO
L<Prima>, L<Prima::Widget>, F<examples/notebook.pl>.
=cut
|