1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143
|
/* Tabs Widget for XEmacs.
Copyright (C) 1999 Edward A. Falk
This file is part of XEmacs.
XEmacs is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
XEmacs is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with XEmacs; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* Synched up with: Tabs.c 1.27.
#### This file contains essential XEmacs related fixes to the original
verison of the Tabs widget. Be VERY careful about syncing if you ever
update to a more recent version. In general this is probably now a
bad idea. */
/*
* Tabs.c - Index Tabs composite widget
*
* Author: Edward A. Falk
* falk@falconer.vip.best.com
*
* Date: July 29, 1997
*
*
* Overall layout of this widget is as follows:
*
* ________ ,---------. _________
* | label || Label || Label | \ tabs
* |________|| ||_________| /
* |+----------------------------+| \
* || || |
* || child widget window || > frame
* |+----------------------------+| |
* +------------------------------+ /
*
* The height of the tabs includes the shadow width, top and bottom
* margins, and the height of the text.
*
* The height of the frame includes the top and bottom shadow width and the
* size of the child widget window.
*
* The tabs overlap the frame and each other vertically by the shadow
* width, so that when the topmost tab is drawn, it obliterates part of
* the frame.
*/
/*
* TODO: min child height = tab height
*/
#include <config.h>
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include "lwlib-internal.h"
#include "../src/xmu.h"
#include "xlwtabsP.h"
#include "xlwgcs.h"
#define MIN_WID 10
#define MIN_HGT 10
#define INDENT 3 /* tabs indented from edge by this much */
#define SPACING 0 /* distance between tabs */
#define SHADWID 1 /* default shadow width */
#define TABDELTA 2 /* top tab grows this many pixels */
#define TABLDELTA 2 /* top tab label offset this many pixels */
/****************************************************************
*
* IndexTabs Resources
*
****************************************************************/
static char defaultTranslations[] = "\
<BtnUp>: select() \n\
<FocusIn>: highlight() \n\
<FocusOut>: unhighlight() \n\
<Key>Page_Up: page(up) \n\
<Key>KP_Page_Up: page(up) \n\
<Key>Prior: page(up) \n\
<Key>KP_Prior: page(up) \n\
<Key>Page_Down: page(down) \n\
<Key>KP_Page_Down: page(down) \n\
<Key>Next: page(down) \n\
<Key>KP_Next: page(down) \n\
<Key>Home: page(home) \n\
<Key>KP_Home: page(home) \n\
<Key>End: page(end) \n\
<Key>KP_End: page(end) \n\
<Key>Up: highlight(up) \n\
<Key>KP_Up: highlight(up) \n\
<Key>Down: highlight(down) \n\
<Key>KP_Down: highlight(down) \n\
<Key> : page(select) \n\
" ;
static char accelTable[] = " #augment\n\
<Key>Page_Up: page(up) \n\
<Key>KP_Page_Up: page(up) \n\
<Key>Prior: page(up) \n\
<Key>KP_Prior: page(up) \n\
<Key>Page_Down: page(down) \n\
<Key>KP_Page_Down: page(down) \n\
<Key>Next: page(down) \n\
<Key>KP_Next: page(down) \n\
<Key>Home: page(home) \n\
<Key>KP_Home: page(home) \n\
<Key>End: page(end) \n\
<Key>KP_End: page(end) \n\
<Key>Up: highlight(up) \n\
<Key>KP_Up: highlight(up) \n\
<Key>Down: highlight(down) \n\
<Key>KP_Down: highlight(down) \n\
<Key> : page(select) \n\
" ;
static XtAccelerators defaultAccelerators ; /* #### Never used */
#define offset(field) XtOffsetOf(TabsRec, tabs.field)
static XtResource resources[] = {
{XtNselectInsensitive, XtCSelectInsensitive, XtRBoolean, sizeof(Boolean),
offset(selectInsensitive), XtRImmediate, (XtPointer) True},
{XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
offset(font), XtRString, (XtPointer) XtDefaultFont},
{XtNinternalWidth, XtCWidth, XtRDimension, sizeof(Dimension),
offset(internalWidth), XtRImmediate, (XtPointer)4 },
{XtNinternalHeight, XtCHeight, XtRDimension, sizeof(Dimension),
offset(internalHeight), XtRImmediate, (XtPointer)4 },
{XtNborderWidth, XtCBorderWidth, XtRDimension, sizeof(Dimension),
XtOffsetOf(RectObjRec,rectangle.border_width), XtRImmediate, (XtPointer)0},
{XtNtopWidget, XtCTopWidget, XtRWidget, sizeof(Widget),
offset(topWidget), XtRImmediate, NULL},
{XtNhighlightWidget, XtCHighlightWidget, XtRWidget, sizeof(Widget),
offset(hilight), XtRImmediate, NULL},
{XtNcallback, XtCCallback, XtRCallback, sizeof(XtPointer),
offset(callbacks), XtRCallback, NULL},
{XtNpopdownCallback, XtCCallback, XtRCallback, sizeof(XtPointer),
offset(popdownCallbacks), XtRCallback, NULL},
{XtNbeNiceToColormap, XtCBeNiceToColormap, XtRBoolean, sizeof(Boolean),
offset(be_nice_to_cmap), XtRImmediate, (XtPointer) True},
{XtNtopShadowContrast, XtCTopShadowContrast, XtRInt, sizeof(int),
offset(top_shadow_contrast), XtRImmediate, (XtPointer) 20},
{XtNbottomShadowContrast, XtCBottomShadowContrast, XtRInt, sizeof(int),
offset(bot_shadow_contrast), XtRImmediate, (XtPointer) 40},
{XtNinsensitiveContrast, XtCInsensitiveContrast, XtRInt, sizeof(int),
offset(insensitive_contrast), XtRImmediate, (XtPointer) 33},
{XtNaccelerators, XtCAccelerators, XtRAcceleratorTable,sizeof(XtTranslations),
XtOffsetOf(TabsRec,core.accelerators), XtRString, accelTable},
};
#undef offset
/* constraint resources */
#define offset(field) XtOffsetOf(TabsConstraintsRec, tabs.field)
static XtResource tabsConstraintResources[] = {
{XtNtabLabel, XtCLabel, XtRString, sizeof(String),
offset(label), XtRString, NULL},
{XtNtabLeftBitmap, XtCLeftBitmap, XtRBitmap, sizeof(Pixmap),
offset(left_bitmap), XtRImmediate, None},
{XtNtabForeground, XtCForeground, XtRPixel, sizeof(Pixel),
offset(foreground), XtRString, (XtPointer) XtDefaultForeground},
{XtNresizable, XtCResizable, XtRBoolean, sizeof(Boolean),
offset(resizable), XtRImmediate, (XtPointer) True},
} ;
#undef offset
#if !NeedFunctionPrototypes
/* FORWARD REFERENCES: */
/* member functions */
static void TabsClassInit();
static void TabsInit();
static void TabsResize();
static void TabsExpose();
static void TabsDestroy();
static void TabsRealize();
static Boolean TabsSetValues();
static Boolean TabsAcceptFocus();
static XtGeometryResult TabsQueryGeometry();
static XtGeometryResult TabsGeometryManager();
static void TabsChangeManaged();
static void TabsConstraintInitialize() ;
static Boolean TabsConstraintSetValues() ;
/* action procs */
static void TabsSelect() ;
static void TabsPage() ;
static void TabsHighlight() ;
static void TabsUnhighlight() ;
/* internal privates */
static void TabsAllocGCs() ; /* get rendering GCs */
static void TabsFreeGCs() ; /* return rendering GCs */
static void DrawTabs() ; /* draw all tabs */
static void DrawTab() ; /* draw one index tab */
static void DrawFrame() ; /* draw frame around contents */
static void DrawTrim() ; /* draw trim around a tab */
static void DrawBorder() ; /* draw border */
static void DrawHighlight() ; /* draw highlight */
static void UndrawTab() ; /* undraw interior of a tab */
static void TabWidth() ; /* recompute tab size */
static void GetPreferredSizes() ; /* query all children for their sizes */
static void MaxChild() ; /* find max preferred child size */
static int PreferredSize() ; /* compute preferred size */
static int PreferredSize2() ; /* compute preferred size */
static int PreferredSize3() ; /* compute preferred size */
static void MakeSizeRequest() ; /* try to change size */
static void getBitmapInfo() ;
static int TabLayout() ; /* lay out tabs */
static void TabsShuffleRows() ; /* bring current tab to bottom row */
static void TabsAllocFgGC() ;
static void TabsAllocGreyGC() ;
#else
static void TabsClassInit(void) ;
static void TabsInit( Widget req, Widget new, ArgList, Cardinal *nargs) ;
static void TabsConstraintInitialize(Widget, Widget, ArgList, Cardinal *) ;
static void TabsRealize(Widget, Mask *, XSetWindowAttributes *) ;
static void TabsDestroy( Widget w) ;
static void TabsResize( Widget w) ;
static void TabsExpose( Widget w, XEvent *event, Region region) ;
static Boolean TabsSetValues(Widget, Widget, Widget, ArgList, Cardinal *) ;
static Boolean TabsAcceptFocus(Widget, Time *);
static Boolean TabsConstraintSetValues(Widget, Widget, Widget,
ArgList, Cardinal *) ;
static XtGeometryResult TabsQueryGeometry(Widget,
XtWidgetGeometry *, XtWidgetGeometry *) ;
static XtGeometryResult TabsGeometryManager(Widget,
XtWidgetGeometry *, XtWidgetGeometry *) ;
static void TabsChangeManaged( Widget w) ;
static void TabsSelect(Widget, XEvent *, String *, Cardinal *) ;
static void TabsPage(Widget, XEvent *, String *, Cardinal *) ;
static void TabsHighlight(Widget, XEvent *, String *, Cardinal *) ;
static void TabsUnhighlight(Widget, XEvent *, String *, Cardinal *) ;
static void DrawTabs( TabsWidget tw, Bool labels) ;
static void DrawTab( TabsWidget tw, Widget child, Bool labels) ;
static void DrawFrame( TabsWidget tw) ;
static void DrawTrim( TabsWidget, int x, int y,
int wid, int hgt, Bool bottom, Bool undraw) ;
static void DrawBorder( TabsWidget tw, Widget child, Bool undraw) ;
static void DrawHighlight( TabsWidget tw, Widget child, Bool undraw) ;
static void UndrawTab( TabsWidget tw, Widget child) ;
static void TabWidth( Widget w) ;
static int TabLayout( TabsWidget, Dimension wid, Dimension hgt, Dimension *r_hgt,
Bool query_only) ;
static void GetPreferredSizes(TabsWidget) ;
static void MaxChild(TabsWidget, Widget except, Dimension, Dimension) ;
static void TabsShuffleRows( TabsWidget tw) ;
static int PreferredSize( TabsWidget,
Dimension *reply_width, Dimension *reply_height,
Dimension *reply_cw, Dimension *reply_ch) ;
static int PreferredSize2( TabsWidget, Dimension cw, Dimension ch,
Dimension *rw, Dimension *rh) ;
static int PreferredSize3( TabsWidget, Dimension wid, Dimension hgt,
Dimension *rw, Dimension *rh) ;
static void MakeSizeRequest(TabsWidget) ;
static void TabsAllocGCs(TabsWidget) ;
static void TabsFreeGCs(TabsWidget) ;
static void getBitmapInfo( TabsWidget tw, TabsConstraints tab) ;
static void TabsAllocFgGC( TabsWidget tw) ;
static void TabsAllocGreyGC( TabsWidget tw) ;
#endif
#define AddRect(i,xx,yy,w,h) \
do{rects[(i)].x=(xx); rects[i].y=(yy); \
rects[i].width=(w); rects[i].height=(h);}while(0)
static XtActionsRec actionsList[] =
{
{"select", TabsSelect},
{"page", TabsPage},
{"highlight", TabsHighlight},
{"unhighlight", TabsUnhighlight},
} ;
/****************************************************************
*
* Full class record constant
*
****************************************************************/
#ifndef NEED_MOTIF
#define SuperClass (&constraintClassRec)
#else
#define SuperClass (&xmManagerClassRec)
#endif
TabsClassRec tabsClassRec = {
{
/* core_class fields */
/* superclass */ (WidgetClass) SuperClass,
/* class_name */ "Tabs",
/* widget_size */ sizeof(TabsRec),
/* class_initialize */ TabsClassInit,
/* class_part_init */ NULL, /* TODO? */
/* class_inited */ FALSE,
/* initialize */ TabsInit,
/* initialize_hook */ NULL,
/* realize */ TabsRealize,
/* actions */ actionsList,
/* num_actions */ XtNumber(actionsList),
/* resources */ resources,
/* num_resources */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ TRUE,
#if XtSpecificationRelease < 6
/* compress_exposure */ XtExposeCompressMaximal,
#else
/* compress_exposure */ XtExposeCompressMaximal|XtExposeNoRegion,
#endif
/* compress_enterleave*/ TRUE,
/* visible_interest */ TRUE,
/* destroy */ TabsDestroy,
/* resize */ TabsResize,
/* expose */ TabsExpose,
/* set_values */ TabsSetValues,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ TabsAcceptFocus,
/* version */ XtVersion,
/* callback_private */ NULL,
/* tm_table */ defaultTranslations,
/* query_geometry */ TabsQueryGeometry,
/* display_accelerator*/ XtInheritDisplayAccelerator,
/* extension */ NULL
},
{
/* composite_class fields */
/* geometry_manager */ TabsGeometryManager,
/* change_managed */ TabsChangeManaged,
/* insert_child */ XtInheritInsertChild, /* TODO? */
/* delete_child */ XtInheritDeleteChild, /* TODO? */
/* extension */ NULL
},
{
/* constraint_class fields */
/* subresources */ tabsConstraintResources,
/* subresource_count */ XtNumber(tabsConstraintResources),
/* constraint_size */ sizeof(TabsConstraintsRec),
/* initialize */ TabsConstraintInitialize,
/* destroy */ NULL,
/* set_values */ TabsConstraintSetValues,
/* extension */ NULL,
},
#ifdef NEED_MOTIF
/* Manager Class fields */
{
/* translations */ NULL,
/* syn_resources */ NULL,
/* num_syn_resources */ 0,
/* syn_constraint_resources */ NULL,
/* num_syn_constraint_resources */ 0,
/* parent_process */ XmInheritParentProcess,
/* extension */ NULL
},
#endif
{
/* Tabs class fields */
/* extension */ NULL,
}
};
WidgetClass tabsWidgetClass = (WidgetClass)&tabsClassRec;
#define TabsNumChildren(tw) (((TabsWidget)tw)->composite.num_children)
#define TabVisible(tab) \
(XtIsManaged(tab) && \
((TabsConstraints)((tab)->core.constraints))->tabs.visible)
/****************************************************************
*
* Member Procedures
*
****************************************************************/
static void
TabsClassInit(void)
{
defaultAccelerators = XtParseAcceleratorTable(accelTable) ;
/* TODO: register converter for labels? */
}
/* Init a newly created tabs widget. Compute height of tabs
* and optionally compute size of widget. */
/* ARGSUSED */
static void
TabsInit(Widget request, Widget new, ArgList args, Cardinal *num_args)
{
TabsWidget newTw = (TabsWidget)new;
newTw->tabs.numRows = 0 ;
newTw->tabs.realRows = 0;
GetPreferredSizes(newTw) ;
/* height is easy, it's the same for all tabs:
* TODO: font height + height of tallest bitmap.
*/
newTw->tabs.tab_height = 2 * newTw->tabs.internalHeight + SHADWID ;
if( newTw->tabs.font != NULL )
newTw->tabs.tab_height += newTw->tabs.font->max_bounds.ascent +
newTw->tabs.font->max_bounds.descent ;
/* GC allocation is deferred until XtRealize() */
/* if size not explicitly set, set it to our preferred size now. */
if( request->core.width == 0 || request->core.height == 0 )
{
Dimension w,h ;
PreferredSize(newTw, &w, &h, NULL,NULL) ;
if( request->core.width == 0 ) new->core.width = w ;
if( request->core.height == 0 ) new->core.height = h ;
XtClass(new)->core_class.resize(new) ;
}
/* defer GC allocation, etc., until Realize() time. */
newTw->tabs.foregroundGC =
newTw->tabs.backgroundGC =
newTw->tabs.greyGC =
newTw->tabs.topGC =
newTw->tabs.botGC = None ;
newTw->tabs.grey50 = None ;
newTw->tabs.needs_layout = False ;
newTw->tabs.hilight = NULL ;
#ifdef NEED_MOTIF
newTw->manager.navigation_type = XmTAB_GROUP ;
newTw->manager.traversal_on = True ;
#endif
}
/* Init the constraint part of a new tab child. Compute the
* size of the tab.
*/
/* ARGSUSED */
static void
TabsConstraintInitialize(Widget request, Widget new,
ArgList args, Cardinal *num_args)
{
TabsConstraints tab = (TabsConstraints) new->core.constraints ;
tab->tabs.greyAlloc = False ; /* defer allocation of pixel */
tab->tabs.visible = False ;
getBitmapInfo((TabsWidget)XtParent(new), tab) ;
TabWidth(new) ;
}
/* Called when tabs widget first realized. Create the window
* and allocate the GCs
*/
static void
TabsRealize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
{
TabsWidget tw = (TabsWidget) w;
attributes->bit_gravity = NorthWestGravity;
*valueMask |= CWBitGravity;
SuperClass->core_class.realize(w, valueMask, attributes);
TabsAllocGCs(tw) ;
}
static void
TabsDestroy(Widget w)
{
TabsFreeGCs((TabsWidget)w) ;
}
/* Parent has resized us. This will require that the tabs be
* laid out again.
*/
static void
TabsResize(Widget w)
{
TabsWidget tw = (TabsWidget) w;
int i ;
int num_children = tw->composite.num_children ;
Widget *childP ;
TabsConstraints tab ; /* #### unused */
Dimension cw,ch,bw ;
/* Our size has now been dictated by the parent. Lay out the
* tabs, lay out the frame, lay out the children. Remember
* that the tabs overlap each other and the frame by shadowWidth.
* Also, the top tab is larger than the others, so if there's only
* one row, the widget must be made taller to accommodate this.
*
* Once the tabs are laid out, if there is more than one
* row, we may need to shuffle the rows to bring the top tab
* to the bottom row.
*/
tw->tabs.needs_layout = False ;
if( num_children > 0 && tw->composite.children != NULL )
{
/* Loop through the tabs and assign rows & x positions */
(void) TabLayout(tw, tw->core.width, tw->core.height, NULL, False) ;
num_children = TabsNumChildren (tw);
/* assign a top widget, bring it to bottom row. */
TabsShuffleRows(tw) ;
/* now assign child positions & sizes. Positions are all the
* same: just inside the frame. Sizes are also all the same.
*/
tw->tabs.child_width = cw = tw->core.width - 2 * SHADWID ;
tw->tabs.child_height = ch =
tw->core.height < (tw->tabs.tab_total + 2 * SHADWID) ? 0 :
tw->core.height - tw->tabs.tab_total - 2 * SHADWID ;
for(i=0, childP=tw->composite.children;
i < num_children;
++i, ++childP)
if( XtIsManaged(*childP) )
{
tab = (TabsConstraints) (*childP)->core.constraints ;
bw = (*childP)->core.border_width ;
/* Don't do anything if we can't see any of the child. */
if (ch >= bw*2 && ch > 0 && cw >= bw*2 && cw > 0)
XtConfigureWidget(*childP, SHADWID,tw->tabs.tab_total+SHADWID,
cw-bw*2,ch-bw*2, bw) ;
}
if( XtIsRealized(w) ) {
XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
/* should not be necessary to explicitly repaint after a
* resize, but XEmacs folks tell me it is.
*/
XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
}
}
} /* Resize */
/* Redraw entire Tabs widget */
/* ARGSUSED */
static void
TabsExpose(Widget w, XEvent *event, Region region)
{
TabsWidget tw = (TabsWidget) w;
if( tw->tabs.needs_layout )
XtClass(w)->core_class.resize(w) ;
DrawTabs(tw, True) ;
}
/* Called when any Tabs widget resources are changed. */
/* ARGSUSED */
static Boolean
TabsSetValues(Widget current, Widget request, Widget new,
ArgList args, Cardinal *num_args)
{
TabsWidget curtw = (TabsWidget) current ;
TabsWidget tw = (TabsWidget) new ;
Boolean needRedraw = False ;
Widget *childP ;
int i ;
if( tw->tabs.font != curtw->tabs.font ||
tw->tabs.internalWidth != curtw->tabs.internalWidth ||
tw->tabs.internalHeight != curtw->tabs.internalHeight )
{
tw->tabs.tab_height = 2 * tw->tabs.internalHeight + SHADWID ;
if( tw->tabs.font != NULL )
tw->tabs.tab_height += tw->tabs.font->max_bounds.ascent +
tw->tabs.font->max_bounds.descent ;
/* Tab size has changed. Resize all tabs and request a new size */
for(i=0, childP=tw->composite.children;
i < tw->composite.num_children;
++i, ++childP)
if( XtIsManaged(*childP) )
TabWidth(*childP) ;
PreferredSize(tw, &tw->core.width, &tw->core.height, NULL,NULL) ;
needRedraw = True ;
tw->tabs.needs_layout = True ;
}
/* TODO: if any color changes, need to recompute GCs and redraw */
if( tw->core.background_pixel != curtw->core.background_pixel ||
tw->core.background_pixmap != curtw->core.background_pixmap ||
tw->tabs.font != curtw->tabs.font )
if( XtIsRealized(new) )
{
TabsFreeGCs(tw) ;
TabsAllocGCs(tw) ;
needRedraw = True ;
}
if( tw->core.sensitive != curtw->core.sensitive )
needRedraw = True ;
/* Highlit widget changed */
if ( tw->tabs.hilight != curtw->tabs.hilight )
{
needRedraw = True ;
}
/* If top widget changes, need to change stacking order, redraw tabs.
* Window system will handle the redraws.
*/
if( tw->tabs.topWidget != curtw->tabs.topWidget )
{
if( XtIsRealized(tw->tabs.topWidget) )
{
Widget w = tw->tabs.topWidget ;
TabsConstraints tab = (TabsConstraints) w->core.constraints ;
XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
#ifdef NEED_MOTIF
XtVaSetValues(curtw->tabs.topWidget, XmNtraversalOn, False, 0) ;
XtVaSetValues(w, XmNtraversalOn, True, 0) ;
#endif
if( tab->tabs.row != tw->tabs.numRows-1 )
TabsShuffleRows(tw) ;
needRedraw = True ;
}
else
tw->tabs.needs_layout = True ;
}
return needRedraw ;
}
/* Called when any child constraint resources change. */
/* ARGSUSED */
static Boolean
TabsConstraintSetValues(Widget current, Widget request, Widget new,
ArgList args, Cardinal *num_args)
{
TabsWidget tw = (TabsWidget) XtParent(new) ;
TabsConstraints ctab = (TabsConstraints) current->core.constraints ;
TabsConstraints tab = (TabsConstraints) new->core.constraints ;
/* if label changes, need to re-layout the entire widget */
/* if foreground changes, need to redraw tab label */
/* TODO: only need resize of new bitmap has different dimensions
* from old bitmap.
*/
if( tab->tabs.label != ctab->tabs.label || /* Tab size has changed. */
tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
{
TabWidth(new) ;
tw->tabs.needs_layout = True ;
if( tab->tabs.left_bitmap != ctab->tabs.left_bitmap )
getBitmapInfo(tw, tab) ;
/* If there are no subclass ConstraintSetValues procedures remaining
* to be invoked, and if the preferred size has changed, ask
* for a resize.
*/
if( XtClass((Widget)tw) == tabsWidgetClass )
MakeSizeRequest(tw) ;
}
/* The child widget itself never needs a redisplay, but the parent
* Tabs widget might.
*/
if( XtIsRealized(new) )
{
if( tw->tabs.needs_layout ) {
XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
}
else if( tab->tabs.foreground != ctab->tabs.foreground )
DrawTab(tw, new, True) ;
}
return False ;
}
static Boolean
TabsAcceptFocus(Widget w, Time *t)
{
if( !w->core.being_destroyed && XtIsRealized(w) &&
XtIsSensitive(w) && XtIsManaged(w) && w->core.visible )
{
Widget p ;
for(p = XtParent(w); !XtIsShell(p); p = XtParent(p)) ;
XtSetKeyboardFocus(p,w) ;
return True ;
}
else
return False ;
}
/*
* Return preferred size. Happily accept anything >= our preferred size.
* (TODO: is that the right thing to do? Should we always return "almost"
* if offered more than we need?)
*/
static XtGeometryResult
TabsQueryGeometry(Widget w,
XtWidgetGeometry *intended, XtWidgetGeometry *preferred)
{
register TabsWidget tw = (TabsWidget)w ;
XtGeometryMask mode = intended->request_mode ;
preferred->request_mode = CWWidth | CWHeight ;
PreferredSize(tw, &preferred->width, &preferred->height, NULL,NULL) ;
if( (!(mode & CWWidth) || intended->width == w->core.width) &&
(!(mode & CWHeight) || intended->height == w->core.height) )
return XtGeometryNo ;
if( (!(mode & CWWidth) || intended->width >= preferred->width) &&
(!(mode & CWHeight) || intended->height >= preferred->height) )
return XtGeometryYes;
return XtGeometryAlmost;
}
/*
* Geometry Manager; called when a child wants to be resized.
*/
static XtGeometryResult
TabsGeometryManager(Widget w, XtWidgetGeometry *req, XtWidgetGeometry *reply)
{
TabsWidget tw = (TabsWidget) XtParent(w);
Dimension s = SHADWID ;
TabsConstraints tab = (TabsConstraints)w->core.constraints;
XtGeometryResult result ;
Dimension rw, rh ;
/* Position request always denied */
if( ((req->request_mode & CWX) && req->x != w->core.x) ||
((req->request_mode & CWY) && req->y != w->core.y) ||
!tab->tabs.resizable )
return XtGeometryNo ;
/* Make all three fields in the request valid */
if( !(req->request_mode & CWWidth) )
req->width = w->core.width;
if( !(req->request_mode & CWHeight) )
req->height = w->core.height;
if( !(req->request_mode & CWBorderWidth) )
req->border_width = w->core.border_width;
if( req->width == w->core.width &&
req->height == w->core.height &&
req->border_width == w->core.border_width )
return XtGeometryNo ;
rw = req->width + 2 * req->border_width ;
rh = req->height + 2 * req->border_width ;
/* find out how big the children want to be now */
MaxChild(tw, w, rw, rh) ;
/* Size changes must see if the new size can be accommodated.
* The Tabs widget keeps all of its children the same
* size. A request to shrink will be accepted only if the
* new size is still big enough for all other children. A
* request to shrink that is not big enough for all children
* returns an "almost" response with the new proposed size
* or a "no" response if unable to shrink at all.
*
* A request to grow will be accepted only if the Tabs parent can
* grow to accommodate.
*
* TODO:
* We could get fancy here and re-arrange the tabs if it is
* necessary to compromise with the parent, but we'll save that
* for another day.
*/
if (req->request_mode & (CWWidth | CWHeight | CWBorderWidth))
{
Dimension cw,ch ; /* children's preferred size */
Dimension aw,ah ; /* available size we can give child */
Dimension th ; /* space used by tabs */
Dimension wid,hgt ; /* Tabs widget size */
cw = tw->tabs.max_cw ;
ch = tw->tabs.max_ch ;
/* find out what *my* resulting preferred size would be */
PreferredSize2(tw, cw, ch, &wid, &hgt) ;
/* Would my size change? If so, ask to be resized. */
if( wid != tw->core.width || hgt != tw->core.height )
{
Dimension oldWid = tw->core.width, oldHgt = tw->core.height ;
XtWidgetGeometry myrequest, myreply ;
myrequest.width = wid ;
myrequest.height = hgt ;
myrequest.request_mode = CWWidth | CWHeight ;
assert (wid > 0 && hgt > 0);
/* If child is only querying, or if we're going to have to
* offer the child a compromise, then make this a query only.
*/
if( (req->request_mode & XtCWQueryOnly) || rw < cw || rh < ch )
myrequest.request_mode |= XtCWQueryOnly ;
result = XtMakeGeometryRequest((Widget)tw, &myrequest, &myreply) ;
/* !$@# Athena Box widget changes the core size even if QueryOnly
* is set. I'm convinced this is a bug. At any rate, to work
* around the bug, we need to restore the core size after every
* query geometry request. This is only partly effective,
* as there may be other boxes further up the tree.
*/
if( myrequest.request_mode & XtCWQueryOnly ) {
tw->core.width = oldWid ;
tw->core.height = oldHgt ;
}
/* based on the parent's response, determine what the
* resulting Tabs widget size would be.
*/
switch( result ) {
case XtGeometryYes:
case XtGeometryDone:
tw->tabs.needs_layout = True ;
break ;
case XtGeometryNo:
wid = tw->core.width ;
hgt = tw->core.height ;
break ;
case XtGeometryAlmost:
wid = myreply.width ;
hgt = myreply.height ;
tw->tabs.needs_layout = True ;
break ;
}
}
/* Within the constraints imposed by the parent, what is
* the max size we can give the child?
*/
(void) TabLayout(tw, wid, hgt, &th, True) ;
aw = wid - 2*s ;
ah = hgt - th - 2*s ;
/* OK, make our decision. If requested size is >= max sibling
* preferred size, AND requested size <= available size, then
* we accept. Otherwise, we offer a compromise.
*/
if( rw == aw && rh == ah )
{
/* Acceptable. If this wasn't a query, change *all* children
* to this size.
*/
if( req->request_mode & XtCWQueryOnly )
return XtGeometryYes ;
else
{
Widget *childP = tw->composite.children ;
int i,bw ;
w->core.border_width = req->border_width ;
for(i=TabsNumChildren (tw); --i >= 0; ++childP)
if( TabVisible(*childP) )
{
bw = (*childP)->core.border_width ;
XtConfigureWidget(*childP, s,tw->tabs.tab_total+s,
rw-2*bw, rh-2*bw, bw) ;
}
#ifdef COMMENT
/* TODO: under what conditions will we need to redraw? */
XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
XtClass(tw)->core_class.expose((Widget)tw,NULL,NULL) ;
#endif /* COMMENT */
return XtGeometryDone ;
}
}
/* Cannot grant child's request. Describe what we *can* do
* and return counter-offer.
*/
reply->width = aw - 2 * req->border_width ;
reply->height = ah - 2 * req->border_width ;
reply->border_width = req->border_width ;
reply->request_mode = CWWidth | CWHeight | CWBorderWidth ;
return XtGeometryAlmost ;
}
return XtGeometryYes ;
}
/* The number of children we manage has changed; recompute
* size from scratch.
*/
static void
TabsChangeManaged(Widget w)
{
TabsWidget tw = (TabsWidget)w ;
Widget *childP = tw->composite.children ;
int i ;
if( tw->tabs.topWidget != NULL &&
( !XtIsManaged(tw->tabs.topWidget) ||
tw->tabs.topWidget->core.being_destroyed ) )
tw->tabs.topWidget = NULL ;
/* Check whether the highlight tab is still valid. */
if( tw->tabs.hilight != NULL &&
( !XtIsManaged(tw->tabs.hilight) ||
tw->tabs.hilight->core.being_destroyed ) )
tw->tabs.hilight = NULL ;
GetPreferredSizes(tw) ;
MakeSizeRequest(tw) ;
XtClass(w)->core_class.resize(w) ;
if( XtIsRealized(w) )
{
Display *dpy = XtDisplay(w) ;
XClearWindow(dpy, XtWindow(w)) ;
XtClass(w)->core_class.expose(w,NULL,NULL) ;
/* make sure the top widget stays on top. This requires
* making sure that all new children are realized first.
*/
if( tw->tabs.topWidget != NULL && XtIsRealized(tw->tabs.topWidget) )
{
for(i=TabsNumChildren (tw); --i >= 0; ++childP)
if( !XtIsRealized(*childP) )
XtRealizeWidget(*childP) ;
XRaiseWindow(dpy, XtWindow(tw->tabs.topWidget)) ;
}
}
#ifdef NEED_MOTIF
/* Only top widget may receive input */
for(childP = tw->composite.children, i=tw->composite.num_children;
--i >= 0;
++childP)
{
XtVaSetValues(*childP, XmNtraversalOn, False, 0) ;
}
if( tw->tabs.topWidget != NULL )
XtVaSetValues(tw->tabs.topWidget, XmNtraversalOn, True, 0) ;
#endif
}
/****************************************************************
*
* Action Procedures
*
****************************************************************/
/* User clicks on a tab, figure out which one it was. */
/* ARGSUSED */
static void
TabsSelect(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
TabsWidget tw = (TabsWidget) w ;
Widget *childP ;
Position x,y ;
Dimension h = tw->tabs.tab_height ;
int i ;
#ifdef NEED_MOTIF
XmProcessTraversal (w, XmTRAVERSE_CURRENT) ;
#endif
/* TODO: is there an Xmu function or something to do this instead? */
switch( event->type ) {
case ButtonPress:
case ButtonRelease:
x = event->xbutton.x ; y = event->xbutton.y ; break ;
case KeyPress:
case KeyRelease:
x = event->xkey.x ; y = event->xkey.y ; break ;
default:
return ;
}
/* TODO: determine which tab was clicked, if any. Set that
* widget to be top of stacking order with XawTabsSetTop().
*/
for(i=0, childP=tw->composite.children;
i < TabsNumChildren (tw);
++i, ++childP)
if( TabVisible(*childP) )
{
TabsConstraints tab = (TabsConstraints)(*childP)->core.constraints;
if( x > tab->tabs.x && x < tab->tabs.x + tab->tabs.width &&
y > tab->tabs.y && y < tab->tabs.y + h )
{
if( *childP != tw->tabs.topWidget &&
(XtIsSensitive(*childP) || tw->tabs.selectInsensitive) )
XawTabsSetTop(*childP, True) ;
break ;
}
}
}
/* User hits a key */
static void
TabsPage(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
TabsWidget tw = (TabsWidget) w ;
Widget newtop = NULL;
Widget *childP ;
int idx ;
int nc = TabsNumChildren (tw) ;
if( nc <= 0 )
return ;
if( *num_params < 1 ) {
XtAppWarning(XtWidgetToApplicationContext(w),
"Tabs: page() action called with no arguments") ;
return ;
}
if( tw->tabs.topWidget == NULL )
tw->tabs.topWidget = tw->composite.children[0] ;
for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
if( tw->tabs.topWidget == *childP )
break ;
switch( params[0][0] ) {
case 'u': /* up */
case 'U':
if( --idx < 0 )
idx = nc-1 ;
newtop = tw->composite.children[idx] ;
break ;
case 'd': /* down */
case 'D':
if( ++idx >= nc )
idx = 0 ;
newtop = tw->composite.children[idx] ;
break ;
case 'h':
case 'H':
default:
newtop = tw->composite.children[0] ;
break ;
case 'e':
case 'E':
newtop = tw->composite.children[nc-1] ;
break ;
case 's': /* selected */
case 'S':
if( (newtop = tw->tabs.hilight) == NULL )
return ;
break ;
}
XawTabsSetTop(newtop, True) ;
}
/* User hits up/down key */
static void
TabsHighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
TabsWidget tw = (TabsWidget) w ;
Widget newhl = NULL;
Widget *childP ;
int idx ;
int nc = TabsNumChildren (tw) ;
if( nc <= 0 )
return ;
if( *num_params < 1 )
{
if( tw->tabs.hilight != NULL )
DrawHighlight(tw, tw->tabs.hilight, False) ;
return ;
}
if( tw->tabs.hilight == NULL )
newhl = tw->composite.children[0] ;
else
{
/* find index of currently highlit child */
for(idx=0, childP=tw->composite.children; idx < nc; ++idx, ++childP )
if( tw->tabs.hilight == *childP )
break ;
switch( params[0][0] ) {
case 'u': /* up */
case 'U':
if( --idx < 0 )
idx = nc-1 ;
newhl = tw->composite.children[idx] ;
break ;
case 'd': /* down */
case 'D':
if( ++idx >= nc )
idx = 0 ;
newhl = tw->composite.children[idx] ;
break ;
case 'h':
case 'H':
newhl = tw->composite.children[0] ;
break ;
case 'e':
case 'E':
newhl = tw->composite.children[nc-1] ;
break ;
default:
newhl = tw->tabs.hilight ;
break ;
}
}
XawTabsSetHighlight(w, newhl) ;
}
static void
TabsUnhighlight(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
TabsWidget tw = (TabsWidget) w ;
int nc = tw->composite.num_children ;
if( nc <= 0 )
return ;
if( tw->tabs.hilight != NULL )
DrawHighlight(tw, tw->tabs.hilight, True) ;
}
/****************************************************************
*
* Public Procedures
*
****************************************************************/
/* Set the top tab, optionally call all callbacks. */
void
XawTabsSetTop(Widget w, Bool callCallbacks)
{
TabsWidget tw = (TabsWidget)w->core.parent ;
TabsConstraints tab ;
Widget oldtop = tw->tabs.topWidget ;
if( !XtIsSubclass(w->core.parent, tabsWidgetClass) )
{
char line[256] ;
sprintf(line, "XawTabsSetTop: widget \"%.64s\" is not the child of a tabs widget.", XtName(w)) ;
XtAppWarning(XtWidgetToApplicationContext(w), line) ;
return ;
}
if( callCallbacks )
XtCallCallbackList(w, tw->tabs.popdownCallbacks,
(XtPointer)tw->tabs.topWidget) ;
if( !XtIsRealized(w) ) {
tw->tabs.topWidget = w ;
tw->tabs.needs_layout = True ;
tw->tabs.hilight = NULL; /* The highlight tab might disappear. */
return ;
}
XRaiseWindow(XtDisplay(w), XtWindow(w)) ;
#ifdef NEED_MOTIF
XtVaSetValues(oldtop, XmNtraversalOn, False, 0) ;
XtVaSetValues(w, XmNtraversalOn, True, 0) ;
#endif
tab = (TabsConstraints) w->core.constraints ;
/* Unhighlight before we start messing with the stacking order. */
if( tw->tabs.hilight != NULL )
{
DrawHighlight(tw, tw->tabs.hilight, True) ;
tw->tabs.hilight = NULL;
}
if( tab->tabs.row == 0 )
{
/* Easy case; undraw current top, undraw new top, assign new
* top, redraw all borders.
* We *could* just erase and execute a full redraw, but I like to
* reduce screen flicker.
*/
UndrawTab(tw, oldtop) ; /* undraw old */
DrawBorder(tw, oldtop, True) ;
UndrawTab(tw, w) ; /* undraw new */
DrawBorder(tw, w, True) ;
tw->tabs.topWidget = w ;
DrawTab(tw, oldtop, True) ; /* redraw old */
DrawTab(tw, w, True) ; /* redraw new */
DrawTabs(tw, False) ;
}
else
{
tw->tabs.topWidget = w ;
TabsShuffleRows(tw) ;
XClearWindow(XtDisplay((Widget)tw), XtWindow((Widget)tw)) ;
XtClass(tw)->core_class.expose((Widget)tw,NULL,None) ;
}
XawTabsSetHighlight((Widget)tw, w) ;
if( callCallbacks )
XtCallCallbackList(w, tw->tabs.callbacks, (XtPointer)w) ;
}
/* Set the top tab, optionally call all callbacks. */
void
XawTabsSetHighlight(Widget t, Widget w)
{
TabsWidget tw = (TabsWidget)t ;
if( !XtIsSubclass(t, tabsWidgetClass) )
return ;
if( XtIsRealized(t) && w != tw->tabs.hilight )
{
if( w != NULL )
DrawHighlight(tw, w, False) ;
}
tw->tabs.hilight = w ;
}
/****************************************************************
*
* Private Procedures
*
****************************************************************/
static void
TabsAllocGCs(TabsWidget tw)
{
TabsAllocFgGC(tw) ;
TabsAllocGreyGC(tw) ;
tw->tabs.backgroundGC = AllocBackgroundGC((Widget)tw, None) ;
tw->tabs.topGC = AllocTopShadowGC((Widget)tw,
tw->tabs.top_shadow_contrast, tw->tabs.be_nice_to_cmap) ;
tw->tabs.botGC = AllocBotShadowGC((Widget)tw,
tw->tabs.bot_shadow_contrast, tw->tabs.be_nice_to_cmap) ;
}
static void
TabsFreeGCs(TabsWidget tw)
{
Widget w = (Widget) tw;
XtReleaseGC(w, tw->tabs.foregroundGC) ;
XtReleaseGC(w, tw->tabs.greyGC) ;
XtReleaseGC(w, tw->tabs.backgroundGC) ;
XtReleaseGC(w, tw->tabs.topGC) ;
XtReleaseGC(w, tw->tabs.botGC) ;
#ifdef HAVE_XMU
XmuReleaseStippledPixmap(XtScreen(w), tw->tabs.grey50) ;
#endif
}
/* Redraw entire Tabs widget */
static void
DrawTabs(TabsWidget tw, Bool labels)
{
Widget *childP ;
int i,j ;
Dimension s = SHADWID ;
Dimension th = tw->tabs.tab_height ;
Position y ;
TabsConstraints tab ;
if( !XtIsRealized((Widget)tw))
return ;
/* draw tabs and frames by row except for the top tab, which
* is drawn last. (This is inefficiently written, but should not
* be too slow as long as there are not a lot of rows.)
*/
y = tw->tabs.numRows == 1 ? TABDELTA : 0 ;
for(i=0; i<tw->tabs.numRows; ++i, y += th)
{
for( j=TabsNumChildren (tw), childP=tw->composite.children;
--j >= 0; ++childP )
if( TabVisible(*childP) )
{
tab = (TabsConstraints)(*childP)->core.constraints;
if( tab->tabs.row == i && *childP != tw->tabs.topWidget )
DrawTab(tw, *childP, labels) ;
}
if( i != tw->tabs.numRows -1 )
DrawTrim(tw, 0,y+th, tw->core.width, th+s, False,False) ;
}
DrawFrame(tw) ;
/* and now the top tab */
if( tw->tabs.topWidget != NULL )
DrawTab(tw, tw->tabs.topWidget, labels) ;
}
/* Draw one tab. Corners are rounded very slightly. */
static void
DrawTab(TabsWidget tw, Widget child, Bool labels)
{
GC gc ;
int x,y ;
if( !XtIsRealized((Widget)tw))
return ;
DrawBorder(tw, child, False) ;
if( labels )
{
TabsConstraints tab = (TabsConstraints)child->core.constraints;
Display *dpy = XtDisplay((Widget)tw) ;
Window win = XtWindow((Widget)tw) ;
String lbl = tab->tabs.label != NULL ?
tab->tabs.label : XtName(child) ;
if( XtIsSensitive(child) )
{
gc = tw->tabs.foregroundGC ;
XSetForeground(dpy, gc, tab->tabs.foreground) ;
}
else
{
/* grey pixel allocation deferred until now */
if( !tab->tabs.greyAlloc )
{
if( tw->tabs.be_nice_to_cmap || tw->core.depth == 1 )
tab->tabs.grey = tab->tabs.foreground ;
else
tab->tabs.grey = AllocGreyPixel((Widget)tw,
tab->tabs.foreground,
tw->core.background_pixel,
tw->tabs.insensitive_contrast ) ;
tab->tabs.greyAlloc = True ;
}
gc = tw->tabs.greyGC ;
XSetForeground(dpy, gc, tab->tabs.grey) ;
}
x = tab->tabs.x ;
y = tab->tabs.y ;
if( child == tw->tabs.topWidget )
y -= TABLDELTA ;
if( tab->tabs.left_bitmap != None && tab->tabs.lbm_width > 0 )
{
if( tab->tabs.lbm_depth == 1 )
XCopyPlane(dpy, tab->tabs.left_bitmap, win,gc,
0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
x+tab->tabs.lbm_x, y+tab->tabs.lbm_y, 1L) ;
else
XCopyArea(dpy, tab->tabs.left_bitmap, win,gc,
0,0, tab->tabs.lbm_width, tab->tabs.lbm_height,
x+tab->tabs.lbm_x, y+tab->tabs.lbm_y) ;
}
if( lbl != NULL && tw->tabs.font != NULL )
XDrawString(dpy,win,gc,
x+tab->tabs.l_x, y+tab->tabs.l_y,
lbl, (int)strlen(lbl)) ;
}
if( child == tw->tabs.hilight )
DrawHighlight(tw, child, False) ;
}
/* draw frame all the way around the child windows. */
static void
DrawFrame(TabsWidget tw)
{
GC topgc = tw->tabs.topGC ;
GC botgc = tw->tabs.botGC ;
Dimension s = SHADWID ;
Dimension ch = tw->tabs.child_height ;
if (ch > 0)
Draw3dBox((Widget)tw, 0,tw->tabs.tab_total,
tw->core.width, ch+2*s, s, topgc, botgc) ;
else
{
Widget w = tw->tabs.topWidget ;
if (w != NULL)
{
TabsConstraints tab = (TabsConstraints) w->core.constraints ;
Draw3dBox((Widget)tw, 0,tw->core.height - 2*s,
tab->tabs.x, 2*s, s, topgc, botgc);
Draw3dBox((Widget)tw, tab->tabs.x + tab->tabs.width,
tw->core.height - 2*s,
tw->core.width - tab->tabs.x - tab->tabs.width, 2*s, s,
topgc, botgc);
}
else
Draw3dBox((Widget)tw, 0,tw->core.height - 2*s,
tw->core.width, 2*s, s, topgc, botgc) ;
}
}
/* draw trim around a tab or underneath a row of tabs */
static void
DrawTrim(TabsWidget tw, /* widget */
int x, /* upper-left corner */
int y,
int wid, /* total size */
int hgt,
Bool bottom, /* draw bottom? */
Bool undraw) /* undraw all */
{
Display *dpy = XtDisplay((Widget)tw) ;
Window win = XtWindow((Widget)tw) ;
GC bggc = tw->tabs.backgroundGC ;
GC topgc = undraw ? bggc : tw->tabs.topGC ;
GC botgc = undraw ? bggc : tw->tabs.botGC ;
if( bottom )
XDrawLine(dpy,win,bggc, x,y+hgt-1, x+wid-1,y+hgt-1) ; /* bottom */
XDrawLine(dpy,win,topgc, x,y+2, x,y+hgt-2) ; /* left */
XDrawPoint(dpy,win,topgc, x+1,y+1) ; /* corner */
XDrawLine(dpy,win,topgc, x+2,y, x+wid-3,y) ; /* top */
XDrawLine(dpy,win,botgc, x+wid-2,y+1, x+wid-2,y+hgt-2) ; /* right */
XDrawLine(dpy,win,botgc, x+wid-1,y+2, x+wid-1,y+hgt-2) ; /* right */
}
/* Draw one tab border. */
static void
DrawBorder(TabsWidget tw, Widget child, Bool undraw)
{
TabsConstraints tab = (TabsConstraints)child->core.constraints;
Position x = tab->tabs.x ;
Position y = tab->tabs.y ;
Dimension twid = tab->tabs.width ;
Dimension thgt = tw->tabs.tab_height ;
/* top tab requires a little special attention; it overlaps
* neighboring tabs slightly, so the background must be cleared
* in the region of the overlap to partially erase those neighbors.
* TODO: is this worth doing with regions instead?
*/
if( child == tw->tabs.topWidget )
{
Display *dpy = XtDisplay((Widget)tw) ;
Window win = XtWindow((Widget)tw) ;
GC bggc = tw->tabs.backgroundGC ;
XRectangle rects[3] ;
x -= TABDELTA ;
y -= TABDELTA ;
twid += TABDELTA*2 ;
thgt += TABDELTA ;
AddRect(0, x,y+1,twid,TABDELTA) ;
AddRect(1, x+1,y,TABDELTA,thgt) ;
AddRect(2, x+twid-TABDELTA-1,y,TABDELTA,thgt) ;
XFillRectangles(dpy,win,bggc, rects, 3) ;
}
DrawTrim(tw, x,y,twid,thgt+1, child == tw->tabs.topWidget, undraw) ;
}
/* Draw highlight around tab that has focus */
static void
DrawHighlight(TabsWidget tw, Widget child, Bool undraw)
{
TabsConstraints tab = (TabsConstraints)child->core.constraints;
Display *dpy = XtDisplay((Widget)tw) ;
Window win = XtWindow((Widget)tw) ;
GC gc ;
Position x = tab->tabs.x ;
Position y = tab->tabs.y ;
Dimension wid = tab->tabs.width ;
Dimension hgt = tw->tabs.tab_height ;
XPoint points[6] ;
/* top tab does not have a highlight */
if( child == tw->tabs.topWidget )
return ;
if( undraw )
gc = tw->tabs.backgroundGC ;
else if( XtIsSensitive(child) )
{
gc = tw->tabs.foregroundGC ;
XSetForeground(dpy, gc, tab->tabs.foreground) ;
}
else
{
gc = tw->tabs.greyGC ;
XSetForeground(dpy, gc, tab->tabs.grey) ;
}
points[0].x = x+1 ; points[0].y = y+hgt-1 ;
points[1].x = x+1 ; points[1].y = y+2 ;
points[2].x = x+2 ; points[2].y = y+1 ;
points[3].x = x+wid-4 ; points[3].y = y+1 ;
points[4].x = x+wid-3 ; points[4].y = y+2 ;
points[5].x = x+wid-3 ; points[5].y = y+hgt-1 ;
XDrawLines(dpy,win,gc, points,6, CoordModeOrigin) ;
}
/* Undraw one tab interior */
static void
UndrawTab(TabsWidget tw, Widget child)
{
TabsConstraints tab = (TabsConstraints)child->core.constraints;
Position x = tab->tabs.x ;
Position y = tab->tabs.y ;
Dimension twid = tab->tabs.width ;
Dimension thgt = tw->tabs.tab_height ;
Display *dpy = XtDisplay((Widget)tw) ;
Window win = XtWindow((Widget)tw) ;
GC bggc = tw->tabs.backgroundGC ;
XFillRectangle(dpy,win,bggc, x,y, twid,thgt) ;
}
/* GEOMETRY UTILITIES */
/* Overview:
*
* MaxChild(): ask all children (except possibly one) their
* preferred sizes, set max_cw, max_ch accordingly.
*
* GetPreferredSizes(): ask all children their preferred sizes,
* set max_cw, max_ch accordingly.
*
* PreferredSize(): given max_cw, max_ch, return tabs widget
* preferred size. Iterate with other widths in order to get
* a reasonable aspect ratio.
*
* PreferredSize2(): Given child dimensions, return Tabs
* widget dimensions.
*
* PreferredSize3(): Same, except given child dimensions plus
* shadow.
*/
/* Compute the width of one child's tab. Positions will be computed
* elsewhere.
*
* height: font height + vertical_space*2 + shadowWid*2
* width: string width + horizontal_space*2 + shadowWid*2
*
* All tabs are the same height, so that is computed elsewhere.
*/
static void
TabWidth(Widget w)
{
TabsConstraints tab = (TabsConstraints) w->core.constraints ;
TabsWidget tw = (TabsWidget)XtParent(w) ;
String lbl = tab->tabs.label != NULL ?
tab->tabs.label : XtName(w) ;
XFontStruct *font = tw->tabs.font ;
int iw = tw->tabs.internalWidth ;
tab->tabs.width = iw + SHADWID*2 ;
tab->tabs.l_x = tab->tabs.lbm_x = SHADWID + iw ;
if( tab->tabs.left_bitmap != None )
{
tab->tabs.width += tab->tabs.lbm_width + iw ;
tab->tabs.l_x += tab->tabs.lbm_width + iw ;
tab->tabs.lbm_y = (tw->tabs.tab_height - tab->tabs.lbm_height)/2 ;
}
if( lbl != NULL && font != NULL )
{
tab->tabs.width += XTextWidth( font, lbl, (int)strlen(lbl) ) + iw ;
tab->tabs.l_y = (tw->tabs.tab_height +
tw->tabs.font->max_bounds.ascent -
tw->tabs.font->max_bounds.descent)/2 ;
}
}
/* Lay out tabs to fit in given width. Compute x,y position and
* row number for each tab. Return number of rows and total height
* required by all tabs. If there is only one row, add TABDELTA
* height to the total. Rows are assigned bottom to top.
*
* Tabs are indented from the edges by INDENT.
*
* TODO: if they require more than two rows and the total height:width
* ratio is more than 2:1, then try something else.
*/
static int
TabLayout(TabsWidget tw,
Dimension wid,
Dimension hgt,
Dimension *reply_height, Bool query_only)
{
int i, row, done = 0, display_rows = 0 ;
int num_children = tw->composite.num_children ;
Widget *childP ;
Dimension w ;
Position x,y ;
TabsConstraints tab ;
/* Algorithm: loop through children, assign X positions. If a tab
* would extend beyond the right edge, start a new row. After all
* rows are assigned, make a second pass and assign Y positions.
*/
if( num_children > 0 )
{
/* Loop through the tabs and see how much space they need. */
row = 0 ;
x = INDENT ;
y = 0 ;
wid -= INDENT ;
for(i=num_children, childP=tw->composite.children; --i >= 0; ++childP)
if( XtIsManaged(*childP) )
{
tab = (TabsConstraints) (*childP)->core.constraints ;
w = tab->tabs.width ;
if( x + w > wid ) { /* new row */
if (y + tw->tabs.tab_height > hgt && !done)
{
display_rows = row;
done = 1;
}
++row;
x = INDENT ;
y += tw->tabs.tab_height ;
}
if( !query_only ) {
tab->tabs.x = x ;
tab->tabs.y = y ;
tab->tabs.row = row ;
}
x += w + SPACING ;
if (!query_only && !done)
tab->tabs.visible = 1;
}
/* If there was only one row, increase the height by TABDELTA */
if( ++display_rows == 1 )
{
row++;
y = TABDELTA ;
if( !query_only )
for(i=num_children, childP=tw->composite.children;
--i >= 0 ; ++childP)
if( XtIsManaged(*childP) )
{
tab = (TabsConstraints) (*childP)->core.constraints ;
tab->tabs.y = y ;
}
}
y += tw->tabs.tab_height ;
}
else
display_rows = row = y = 0 ;
if( !query_only ) {
tw->tabs.tab_total = y ;
tw->tabs.numRows = display_rows ;
tw->tabs.realRows = row;
}
if( reply_height != NULL )
*reply_height = y ;
return display_rows ;
}
/* Find max preferred child size. Returned sizes include child
* border widths.
*/
static void
GetPreferredSizes(TabsWidget tw)
{
MaxChild(tw, NULL, 0,0) ;
}
/* Find max preferred child size. Returned sizes include child
* border widths. If except is non-null, don't ask that one.
*/
static void
MaxChild(TabsWidget tw, Widget except, Dimension cw, Dimension ch)
{
int i ;
Widget *childP = tw->composite.children ;
XtWidgetGeometry preferred ;
for(i=tw->composite.num_children; --i >=0; ++childP)
if( TabVisible (*childP) /*XtIsManaged(*childP)*/ && *childP != except )
{
(void) XtQueryGeometry(*childP, NULL, &preferred) ;
cw = Max(cw, preferred.width + preferred.border_width * 2 ) ;
ch = Max(ch, preferred.height + preferred.border_width * 2 ) ;
}
tw->tabs.max_cw = cw ;
tw->tabs.max_ch = ch ;
}
/* rotate row numbers to bring current widget to bottom row,
* compute y positions for all tabs
*/
static void
TabsShuffleRows(TabsWidget tw)
{
TabsConstraints tab ;
int move ;
int real_rows, display_rows ;
Widget *childP ;
Dimension th = tw->tabs.tab_height ;
Position bottom ;
int i ;
/* There must be a top widget. If not, assign one. */
if( tw->tabs.topWidget == NULL && tw->composite.children != NULL )
for(i=TabsNumChildren (tw), childP=tw->composite.children;
--i >= 0;
++childP)
if( XtIsManaged(*childP) ) {
tw->tabs.topWidget = *childP ;
break ;
}
if( tw->tabs.topWidget != NULL )
{
display_rows = tw->tabs.numRows ;
real_rows = tw->tabs.realRows ;
assert( display_rows <= real_rows ) ;
if( real_rows > 1 )
{
tab = (TabsConstraints) tw->tabs.topWidget->core.constraints ;
assert( tab != NULL ) ;
/* How far to move top row. The selected tab must be on
the bottom row of the *visible* rows. */
move = (real_rows + 1 - display_rows) - tab->tabs.row ;
if (move < 0)
move = real_rows - move;
bottom = tw->tabs.tab_total - th ;
for(i=tw->composite.num_children, childP=tw->composite.children;
--i >= 0;
++childP)
if( XtIsManaged(*childP) )
{
tab = (TabsConstraints) (*childP)->core.constraints ;
tab->tabs.row = (tab->tabs.row + move) % real_rows ;
tab->tabs.y = bottom - tab->tabs.row * th ;
tab->tabs.visible = (tab->tabs.row < display_rows);
}
}
}
}
/* Find preferred size. Ask children, find size of largest,
* add room for tabs & return. This can get a little involved,
* as we don't want to have too many rows of tabs; we may widen
* the widget to reduce # of rows.
*
* This function requires that max_cw, max_ch already be set.
*/
static int
PreferredSize(
TabsWidget tw,
Dimension *reply_width, /* total widget size */
Dimension *reply_height,
Dimension *reply_cw, /* child widget size */
Dimension *reply_ch)
{
Dimension cw,ch ; /* child width, height */
Dimension wid,hgt ;
Dimension rwid,rhgt ;
int nrow ;
wid = cw = tw->tabs.max_cw ;
hgt = ch = tw->tabs.max_ch ;
nrow = PreferredSize2(tw, wid,hgt, &rwid, &rhgt) ;
/* Check for absurd results (more than 2 rows, high aspect
* ratio). Try wider size if needed.
* TODO: make sure this terminates.
*/
if( nrow > 2 && rhgt > rwid )
{
Dimension w0, w1 ;
int maxloop = 20 ;
/* step 1: start doubling size until it's too big */
do {
w0 = wid ;
wid = Max(wid*2, wid+20) ;
nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
} while( nrow > 2 && rhgt > rwid ) ;
w1 = wid ;
/* step 2: use Newton's method to find ideal size. Stop within
* 8 pixels.
*/
while( --maxloop > 0 && w1 > w0 + 8 )
{
wid = (w0+w1)/2 ;
nrow = PreferredSize2(tw, wid,hgt, &rwid,&rhgt) ;
if( nrow > 2 && rhgt > rwid )
w0 = wid ;
else
w1 = wid ;
}
wid = w1 ;
}
*reply_width = rwid ;
*reply_height = rhgt ;
if( reply_cw != NULL ) *reply_cw = cw ;
if( reply_ch != NULL ) *reply_ch = ch ;
return nrow ;
}
/* Find preferred size, given size of children. */
static int
PreferredSize2(
TabsWidget tw,
Dimension cw, /* child width, height */
Dimension ch,
Dimension *reply_width, /* total widget size */
Dimension *reply_height)
{
Dimension s = SHADWID ;
int ret;
/* make room for shadow frame */
cw += s*2 ;
ch += s*2 ;
ret = PreferredSize3(tw, cw, ch, reply_width, reply_height) ;
assert (*reply_width > 0 && *reply_height > 0);
return ret;
}
/* Find preferred size, given size of children+shadow. */
static int
PreferredSize3(
TabsWidget tw,
Dimension wid, /* child width, height */
Dimension hgt,
Dimension *reply_width, /* total widget size */
Dimension *reply_height)
{
Dimension th ; /* space used by tabs */
int nrows ;
if( tw->composite.num_children > 0 )
nrows = TabLayout(tw, wid, hgt, &th, True) ;
else {
th = 0 ;
nrows = 0 ;
}
*reply_width = Max(wid, MIN_WID) ;
*reply_height = Max(th+hgt, MIN_HGT) ;
return nrows ;
}
static void
MakeSizeRequest(TabsWidget tw)
{
Widget w = (Widget)tw ;
XtWidgetGeometry request, reply ;
XtGeometryResult result ;
Dimension cw,ch ;
request.request_mode = CWWidth | CWHeight ;
PreferredSize(tw, &request.width, &request.height, &cw, &ch) ;
if( request.width == tw->core.width &&
request.height == tw->core.height )
return ;
result = XtMakeGeometryRequest(w, &request, &reply) ;
if( result == XtGeometryAlmost )
{
/* Bugger. Didn't get what we want, but were offered a
* compromise. If the width was too small, recompute
* based on the too-small width and try again.
* If the height was too small, make a wild-ass guess
* at a wider width and try again.
*/
if( reply.width < request.width && reply.height >= request.height )
{
Dimension s = SHADWID ;
ch += s*2 ;
PreferredSize3(tw, reply.width,ch, &request.width, &request.height);
result = XtMakeGeometryRequest(w, &request, &reply) ;
if( result == XtGeometryAlmost )
(void) XtMakeGeometryRequest(w, &reply, NULL) ;
}
else
(void) XtMakeGeometryRequest(w, &reply, NULL) ;
}
}
static void
getBitmapInfo(TabsWidget tw, TabsConstraints tab)
{
Window root ;
int x,y ;
unsigned int bw ;
if( tab->tabs.left_bitmap == None ||
!XGetGeometry(XtDisplay(tw), tab->tabs.left_bitmap, &root, &x, &y,
&tab->tabs.lbm_width, &tab->tabs.lbm_height,
&bw, &tab->tabs.lbm_depth) )
tab->tabs.lbm_width = tab->tabs.lbm_height = 0 ;
}
/* Code copied & modified from Gcs.c. This version has dynamic
* foreground.
*/
static void
TabsAllocFgGC(TabsWidget tw)
{
Widget w = (Widget) tw;
XGCValues values ;
values.background = tw->core.background_pixel ;
values.font = tw->tabs.font->fid ;
values.line_style = LineOnOffDash ;
values.line_style = LineSolid ;
tw->tabs.foregroundGC =
XtAllocateGC(w, w->core.depth,
GCBackground|GCFont|GCLineStyle, &values,
GCForeground,
GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
GCDashList|GCArcMode) ;
}
static void
TabsAllocGreyGC(TabsWidget tw)
{
Widget w = (Widget) tw;
XGCValues values ;
values.background = tw->core.background_pixel ;
values.font = tw->tabs.font->fid ;
#ifdef HAVE_XMU
if( tw->tabs.be_nice_to_cmap || w->core.depth == 1)
{
values.fill_style = FillStippled ;
tw->tabs.grey50 =
values.stipple = XmuCreateStippledPixmap(XtScreen(w), 1L, 0L, 1) ;
tw->tabs.greyGC =
XtAllocateGC(w, w->core.depth,
GCBackground|GCFont|GCStipple|GCFillStyle, &values,
GCForeground,
GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
GCDashList|GCArcMode) ;
}
else
#endif
{
tw->tabs.greyGC =
XtAllocateGC(w, w->core.depth,
GCFont, &values,
GCForeground,
GCBackground|GCSubwindowMode|GCGraphicsExposures|GCDashOffset|
GCDashList|GCArcMode) ;
}
}
|