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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org 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 Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include "hintids.hxx"
#include <vcl/wrkwin.hxx>
#include <vcl/svapp.hxx>
#include <sot/storage.hxx>
#include <fmtornt.hxx>
#include <fmtfsize.hxx>
#include <frmfmt.hxx>
#include <docary.hxx>
#include "ndtxt.hxx"
#include "doc.hxx"
#include "swtable.hxx"
#include "rootfrm.hxx"
#include "docsh.hxx"
#include "flyfrm.hxx"
#include "poolfmt.hxx"
#include "viewsh.hxx"
#include "tabfrm.hxx"
#include "viewopt.hxx"
#include "htmltbl.hxx"
#include "ndindex.hxx"
#include "switerator.hxx"
using namespace ::com::sun::star;
#define COLFUZZY 20
#define MAX_TABWIDTH (USHRT_MAX - 2001)
class SwHTMLTableLayoutConstraints
{
sal_uInt16 nRow; // Start-Zeile
sal_uInt16 nCol; // Start-Spalte
sal_uInt16 nColSpan; // COLSPAN der Zelle
SwHTMLTableLayoutConstraints *pNext; // die naechste Bedingung
sal_uLong nMinNoAlign, nMaxNoAlign; // Zwischenergebnisse AL-Pass 1
public:
SwHTMLTableLayoutConstraints( sal_uLong nMin, sal_uLong nMax, sal_uInt16 nRow,
sal_uInt16 nCol, sal_uInt16 nColSp );
~SwHTMLTableLayoutConstraints();
sal_uLong GetMinNoAlign() const { return nMinNoAlign; }
sal_uLong GetMaxNoAlign() const { return nMaxNoAlign; }
SwHTMLTableLayoutConstraints *InsertNext( SwHTMLTableLayoutConstraints *pNxt );
SwHTMLTableLayoutConstraints* GetNext() const { return pNext; }
sal_uInt16 GetRow() const { return nRow; }
sal_uInt16 GetColSpan() const { return nColSpan; }
sal_uInt16 GetColumn() const { return nCol; }
};
SwHTMLTableLayoutCnts::SwHTMLTableLayoutCnts( const SwStartNode *pSttNd,
SwHTMLTableLayout* pTab,
sal_Bool bNoBrTag,
SwHTMLTableLayoutCnts* pNxt ) :
pNext( pNxt ), pBox( 0 ), pTable( pTab ), pStartNode( pSttNd ),
nPass1Done( 0 ), nWidthSet( 0 ), bNoBreakTag( bNoBrTag )
{}
SwHTMLTableLayoutCnts::~SwHTMLTableLayoutCnts()
{
delete pNext;
delete pTable;
}
const SwStartNode *SwHTMLTableLayoutCnts::GetStartNode() const
{
return pBox ? pBox->GetSttNd() : pStartNode;
}
SwHTMLTableLayoutCell::SwHTMLTableLayoutCell( SwHTMLTableLayoutCnts *pCnts,
sal_uInt16 nRSpan, sal_uInt16 nCSpan,
sal_uInt16 nWidth, sal_Bool bPrcWidth,
sal_Bool bNWrapOpt ) :
pContents( pCnts ),
nRowSpan( nRSpan ), nColSpan( nCSpan ),
nWidthOption( nWidth ), bPrcWidthOption( bPrcWidth ),
bNoWrapOption( bNWrapOpt )
{}
SwHTMLTableLayoutCell::~SwHTMLTableLayoutCell()
{
if( nRowSpan==1 && nColSpan==1 )
{
delete pContents;
}
}
SwHTMLTableLayoutColumn::SwHTMLTableLayoutColumn( sal_uInt16 nWidth,
sal_Bool bRelWidth,
sal_Bool bLBorder ) :
nMinNoAlign(MINLAY), nMaxNoAlign(MINLAY), nAbsMinNoAlign(MINLAY),
nMin(0), nMax(0),
nAbsColWidth(0), nRelColWidth(0),
nWidthOption( nWidth ), bRelWidthOption( bRelWidth ),
bLeftBorder( bLBorder )
{}
SwHTMLTableLayoutConstraints::SwHTMLTableLayoutConstraints(
sal_uLong nMin, sal_uLong nMax, sal_uInt16 nRw, sal_uInt16 nColumn, sal_uInt16 nColSp ):
nRow( nRw ), nCol( nColumn ), nColSpan( nColSp ),
pNext( 0 ),
nMinNoAlign( nMin ), nMaxNoAlign( nMax )
{}
SwHTMLTableLayoutConstraints::~SwHTMLTableLayoutConstraints()
{
delete pNext;
}
SwHTMLTableLayoutConstraints *SwHTMLTableLayoutConstraints::InsertNext(
SwHTMLTableLayoutConstraints *pNxt )
{
SwHTMLTableLayoutConstraints *pPrev = 0;
SwHTMLTableLayoutConstraints *pConstr = this;
while( pConstr )
{
if( pConstr->GetRow() > pNxt->GetRow() ||
pConstr->GetColumn() > pNxt->GetColumn() )
break;
pPrev = pConstr;
pConstr = pConstr->GetNext();
}
if( pPrev )
{
pNxt->pNext = pPrev->GetNext();
pPrev->pNext = pNxt;
pConstr = this;
}
else
{
pNxt->pNext = this;
pConstr = pNxt;
}
return pConstr;
}
typedef SwHTMLTableLayoutColumn *SwHTMLTableLayoutColumnPtr;
typedef SwHTMLTableLayoutCell *SwHTMLTableLayoutCellPtr;
SwHTMLTableLayout::SwHTMLTableLayout(
const SwTable * pSwTbl,
sal_uInt16 nRws, sal_uInt16 nCls, sal_Bool bColsOpt, sal_Bool bColTgs,
sal_uInt16 nWdth, sal_Bool bPrcWdth, sal_uInt16 nBorderOpt,
sal_uInt16 nCellPad, sal_uInt16 nCellSp, SvxAdjust eAdjust,
sal_uInt16 nLMargin, sal_uInt16 nRMargin,
sal_uInt16 nBWidth, sal_uInt16 nLeftBWidth,
sal_uInt16 nRightBWidth,
sal_uInt16 nInhLeftBWidth, sal_uInt16 nInhRightBWidth ) :
aColumns( new SwHTMLTableLayoutColumnPtr[nCls] ),
aCells( new SwHTMLTableLayoutCellPtr[nRws*nCls] ),
pSwTable( pSwTbl ), pLeftFillerBox( 0 ), pRightFillerBox( 0 ),
nMin( 0 ), nMax( 0 ),
nRows( nRws ), nCols( nCls ),
nLeftMargin( nLMargin ), nRightMargin( nRMargin ),
nInhAbsLeftSpace( 0 ), nInhAbsRightSpace( 0 ),
nRelLeftFill( 0 ), nRelRightFill( 0 ),
nRelTabWidth( 0 ), nWidthOption( nWdth ),
nCellPadding( nCellPad ), nCellSpacing( nCellSp ), nBorder( nBorderOpt ),
nLeftBorderWidth( nLeftBWidth ), nRightBorderWidth( nRightBWidth ),
nInhLeftBorderWidth( nInhLeftBWidth ),
nInhRightBorderWidth( nInhRightBWidth ),
nBorderWidth( nBWidth ),
nDelayedResizeAbsAvail( 0 ), nLastResizeAbsAvail( 0 ),
nPass1Done( 0 ), nWidthSet( 0 ), eTableAdjust( eAdjust ),
bColsOption( bColsOpt ), bColTags( bColTgs ),
bPrcWidthOption( bPrcWdth ), bUseRelWidth( sal_False ),
bMustResize( sal_True ), bExportable( sal_True ), bBordersChanged( sal_False ),
bMustNotResize( sal_False ), bMustNotRecalc( sal_False )
{
aResizeTimer.SetTimeoutHdl( STATIC_LINK( this, SwHTMLTableLayout,
DelayedResize_Impl ) );
}
SwHTMLTableLayout::~SwHTMLTableLayout()
{
sal_uInt16 i;
for( i = 0; i < nCols; i++ )
delete aColumns[i];
delete[] aColumns;
sal_uInt16 nCount = nRows*nCols;
for( i=0; i<nCount; i++ )
delete aCells[i];
delete[] aCells;
}
// Die Breiten der Umrandung werden zunaechst wie in Netscape berechnet:
// Aussere Umrandung: BORDER + CELLSPACING + CELLPADDING
// Innere Umrandung: CELLSPACING + CELLPADDING
// Allerdings wird die Breite der Umrandung im SW trotzdem beachtet, wenn
// bSwBorders gesetzt ist, damit nicht faellschlich umgebrochen wird.
// MIB 27.6.97: Dabei muss auch der Abstand zum Inhalt berueckichtigt werden,
// und zwar auch dann, wenn wenn nur die gegenueberliegende Seite
// eine Umrandung hat.
sal_uInt16 SwHTMLTableLayout::GetLeftCellSpace( sal_uInt16 nCol, sal_uInt16 nColSpan,
sal_Bool bSwBorders ) const
{
sal_uInt16 nSpace = nCellSpacing + nCellPadding;
if( nCol == 0 )
{
nSpace = nSpace + nBorder;
if( bSwBorders && nSpace < nLeftBorderWidth )
nSpace = nLeftBorderWidth;
}
else if( bSwBorders )
{
if( GetColumn(nCol)->HasLeftBorder() )
{
if( nSpace < nBorderWidth )
nSpace = nBorderWidth;
}
else if( nCol+nColSpan == nCols && nRightBorderWidth &&
nSpace < MIN_BORDER_DIST )
{
OSL_ENSURE( !nCellPadding, "GetLeftCellSpace: CELLPADDING!=0" );
// Wenn die Gegenueberliegende Seite umrandet ist muessen
// wir zumindest den minimalen Abstand zum Inhalt
// beruecksichtigen. (Koennte man zusaetzlich auch an
// nCellPadding festmachen.)
nSpace = MIN_BORDER_DIST;
}
}
return nSpace;
}
sal_uInt16 SwHTMLTableLayout::GetRightCellSpace( sal_uInt16 nCol, sal_uInt16 nColSpan,
sal_Bool bSwBorders ) const
{
sal_uInt16 nSpace = nCellPadding;
if( nCol+nColSpan == nCols )
{
nSpace += nBorder + nCellSpacing;
if( bSwBorders && nSpace < nRightBorderWidth )
nSpace = nRightBorderWidth;
}
else if( bSwBorders && GetColumn(nCol)->HasLeftBorder() &&
nSpace < MIN_BORDER_DIST )
{
OSL_ENSURE( !nCellPadding, "GetRightCellSpace: CELLPADDING!=0" );
// Wenn die Gegenueberliegende Seite umrandet ist muessen
// wir zumindest den minimalen Abstand zum Inhalt
// beruecksichtigen. (Koennte man zusaetzlich auch an
// nCellPadding festmachen.)
nSpace = MIN_BORDER_DIST;
}
return nSpace;
}
void SwHTMLTableLayout::AddBorderWidth( sal_uLong &rMin, sal_uLong &rMax,
sal_uLong &rAbsMin,
sal_uInt16 nCol, sal_uInt16 nColSpan,
sal_Bool bSwBorders ) const
{
sal_uLong nAdd = GetLeftCellSpace( nCol, nColSpan, bSwBorders ) +
GetRightCellSpace( nCol, nColSpan, bSwBorders );
rMin += nAdd;
rMax += nAdd;
rAbsMin += nAdd;
}
void SwHTMLTableLayout::SetBoxWidth( SwTableBox *pBox, sal_uInt16 nCol,
sal_uInt16 nColSpan ) const
{
SwFrmFmt *pFrmFmt = pBox->GetFrmFmt();
// die Breite der Box berechnen
SwTwips nFrmWidth = 0;
while( nColSpan-- )
nFrmWidth += GetColumn( nCol++ )->GetRelColWidth();
// und neu setzen
pFrmFmt->SetFmtAttr( SwFmtFrmSize( ATT_VAR_SIZE, nFrmWidth, 0 ));
}
void SwHTMLTableLayout::GetAvail( sal_uInt16 nCol, sal_uInt16 nColSpan,
sal_uInt16& rAbsAvail, sal_uInt16& rRelAvail ) const
{
rAbsAvail = 0;
rRelAvail = 0;
for( sal_uInt16 i=nCol; i<nCol+nColSpan;i++ )
{
const SwHTMLTableLayoutColumn *pColumn = GetColumn(i);
rAbsAvail = rAbsAvail + pColumn->GetAbsColWidth();
rRelAvail = rRelAvail + pColumn->GetRelColWidth();
}
}
sal_uInt16 SwHTMLTableLayout::GetBrowseWidthByVisArea( const SwDoc& rDoc )
{
ViewShell *pVSh = 0;
rDoc.GetEditShell( &pVSh );
if( pVSh )
{
return (sal_uInt16)pVSh->GetBrowseWidth();
}
return 0;
}
sal_uInt16 SwHTMLTableLayout::GetBrowseWidth( const SwDoc& rDoc )
{
// Wenn ein Layout da ist, koennen wir die Breite dort herholen.
const SwRootFrm *pRootFrm = rDoc.GetCurrentLayout(); //swmod 080218
if( pRootFrm )
{
const SwFrm *pPageFrm = pRootFrm->GetLower();
if( pPageFrm )
return (sal_uInt16)pPageFrm->Prt().Width();
}
// #i91658#
// Assertion removed which state that no browse width is available.
// Investigation reveals that all calls can handle the case that no browse
// width is provided.
return GetBrowseWidthByVisArea( rDoc );
}
sal_uInt16 SwHTMLTableLayout::GetBrowseWidthByTabFrm(
const SwTabFrm& rTabFrm ) const
{
SwTwips nWidth = 0;
const SwFrm *pUpper = rTabFrm.GetUpper();
if( MayBeInFlyFrame() && pUpper->IsFlyFrm() &&
((const SwFlyFrm *)pUpper)->GetAnchorFrm() )
{
// Wenn die Tabelle in einem selbst angelegten Rahmen steht, dann ist
// die Breite Ankers und nicht die Breite Rahmens von Bedeutung.
// Bei Absatz-gebundenen Rahmen werden Absatz-Einzuege nicht beachtet.
const SwFrm *pAnchor = ((const SwFlyFrm *)pUpper)->GetAnchorFrm();
if( pAnchor->IsTxtFrm() )
nWidth = pAnchor->Frm().Width();
else
nWidth = pAnchor->Prt().Width();
}
else
{
nWidth = pUpper->Prt().Width();
}
SwTwips nUpperDummy = 0;
long nRightOffset = 0,
nLeftOffset = 0;
rTabFrm.CalcFlyOffsets( nUpperDummy, nLeftOffset, nRightOffset );
nWidth -= (nLeftOffset + nRightOffset);
return nWidth < USHRT_MAX ? static_cast<sal_uInt16>(nWidth) : USHRT_MAX;
}
sal_uInt16 SwHTMLTableLayout::GetBrowseWidthByTable( const SwDoc& rDoc ) const
{
sal_uInt16 nBrowseWidth = 0;
SwTabFrm* pFrm = SwIterator<SwTabFrm,SwFmt>::FirstElement( *pSwTable->GetFrmFmt() );
if( pFrm )
{
nBrowseWidth = GetBrowseWidthByTabFrm( *pFrm );
}
else
{
nBrowseWidth = SwHTMLTableLayout::GetBrowseWidth( rDoc );
}
return nBrowseWidth;
}
const SwStartNode *SwHTMLTableLayout::GetAnyBoxStartNode() const
{
const SwStartNode *pBoxSttNd;
const SwTableBox* pBox = pSwTable->GetTabLines()[0]->GetTabBoxes()[0];
while( 0 == (pBoxSttNd = pBox->GetSttNd()) )
{
OSL_ENSURE( pBox->GetTabLines().Count() > 0,
"Box ohne Start-Node und Lines" );
OSL_ENSURE( pBox->GetTabLines()[0]->GetTabBoxes().Count() > 0,
"Line ohne Boxen" );
pBox = pBox->GetTabLines()[0]->GetTabBoxes()[0];
}
return pBoxSttNd;
}
SwFrmFmt *SwHTMLTableLayout::FindFlyFrmFmt() const
{
const SwTableNode *pTblNd = GetAnyBoxStartNode()->FindTableNode();
OSL_ENSURE( pTblNd, "Kein Table-Node?" );
return pTblNd->GetFlyFmt();
}
static void lcl_GetMinMaxSize( sal_uLong& rMinNoAlignCnts, sal_uLong& rMaxNoAlignCnts,
sal_uLong& rAbsMinNoAlignCnts,
SwTxtNode *pTxtNd, sal_uLong nIdx, sal_Bool bNoBreak )
{
pTxtNd->GetMinMaxSize( nIdx, rMinNoAlignCnts, rMaxNoAlignCnts,
rAbsMinNoAlignCnts );
OSL_ENSURE( rAbsMinNoAlignCnts <= rMinNoAlignCnts,
"GetMinMaxSize: absmin > min" );
OSL_ENSURE( rMinNoAlignCnts <= rMaxNoAlignCnts,
"GetMinMaxSize: max > min" );
//Bei einen <PRE>-Absatz entspricht die maximale Breite der
// minimalen breite
const SwFmtColl *pColl = &pTxtNd->GetAnyFmtColl();
while( pColl && !pColl->IsDefault() &&
(USER_FMT & pColl->GetPoolFmtId()) )
{
pColl = (const SwFmtColl *)pColl->DerivedFrom();
}
// <NOBR> in der gesamten Zelle bezieht sich auf Text, aber nicht
// auf Tabellen. Netscape beruecksichtigt dies nur fuer Grafiken.
if( (pColl && RES_POOLCOLL_HTML_PRE==pColl->GetPoolFmtId()) || bNoBreak )
{
rMinNoAlignCnts = rMaxNoAlignCnts;
rAbsMinNoAlignCnts = rMaxNoAlignCnts;
}
}
void SwHTMLTableLayout::AutoLayoutPass1()
{
nPass1Done++;
ClearPass1Info();
sal_Bool bFixRelWidths = sal_False;
sal_uInt16 i;
SwHTMLTableLayoutConstraints *pConstraints = 0;
for( i=0; i<nCols; i++ )
{
SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
pColumn->ClearPass1Info( !HasColTags() );
sal_uInt16 nMinColSpan = USHRT_MAX; // Spaltenzahl, auf die sich dir
// berechnete Breite bezieht
sal_uInt16 nColSkip = USHRT_MAX; // Wie viele Spalten muessen
// uebersprungen werden
for( sal_uInt16 j=0; j<nRows; j++ )
{
SwHTMLTableLayoutCell *pCell = GetCell(j,i);
SwHTMLTableLayoutCnts *pCnts = pCell->GetContents();
// Zum Ermitteln der naechsten zu berechnenden
// Spalte muessen alle Zeilen herangezogen werden
sal_uInt16 nColSpan = pCell->GetColSpan();
if( nColSpan < nColSkip )
nColSkip = nColSpan;
if( !pCnts || (pCnts && !pCnts->IsPass1Done(nPass1Done)) )
{
// die Zelle ist leer oder ihr Inhalt wurde nich nicht
// bearbeitet
if( nColSpan < nMinColSpan )
nMinColSpan = nColSpan;
sal_uLong nMinNoAlignCell = 0;
sal_uLong nMaxNoAlignCell = 0;
sal_uLong nAbsMinNoAlignCell = 0;
sal_uLong nMaxTableCell = 0;
sal_uLong nAbsMinTableCell = 0;
while( pCnts )
{
const SwStartNode *pSttNd = pCnts->GetStartNode();
if( pSttNd )
{
const SwDoc *pDoc = pSttNd->GetDoc();
sal_uLong nIdx = pSttNd->GetIndex();
while( !(pDoc->GetNodes()[nIdx])->IsEndNode() )
{
SwTxtNode *pTxtNd = (pDoc->GetNodes()[nIdx])->GetTxtNode();
if( pTxtNd )
{
sal_uLong nMinNoAlignCnts = 0;
sal_uLong nMaxNoAlignCnts = 0;
sal_uLong nAbsMinNoAlignCnts = 0;
lcl_GetMinMaxSize( nMinNoAlignCnts,
nMaxNoAlignCnts,
nAbsMinNoAlignCnts,
pTxtNd, nIdx,
pCnts->HasNoBreakTag() );
if( nMinNoAlignCnts > nMinNoAlignCell )
nMinNoAlignCell = nMinNoAlignCnts;
if( nMaxNoAlignCnts > nMaxNoAlignCell )
nMaxNoAlignCell = nMaxNoAlignCnts;
if( nAbsMinNoAlignCnts > nAbsMinNoAlignCell )
nAbsMinNoAlignCell = nAbsMinNoAlignCnts;
}
else
{
SwTableNode *pTabNd = (pDoc->GetNodes()[nIdx])->GetTableNode();
if( pTabNd )
{
SwHTMLTableLayout *pChild = pTabNd->GetTable().GetHTMLTableLayout();
if( pChild )
{
pChild->AutoLayoutPass1();
sal_uLong nMaxTableCnts = pChild->nMax;
sal_uLong nAbsMinTableCnts = pChild->nMin;
// Eine feste Tabellen-Breite wird als Minimum
// und Maximum gleichzeitig uebernommen
if( !pChild->bPrcWidthOption && pChild->nWidthOption )
{
sal_uLong nTabWidth = pChild->nWidthOption;
if( nTabWidth >= nAbsMinTableCnts )
{
nMaxTableCnts = nTabWidth;
nAbsMinTableCnts = nTabWidth;
}
else
{
nMaxTableCnts = nAbsMinTableCnts;
}
}
if( nMaxTableCnts > nMaxTableCell )
nMaxTableCell = nMaxTableCnts;
if( nAbsMinTableCnts > nAbsMinTableCell )
nAbsMinTableCell = nAbsMinTableCnts;
}
nIdx = pTabNd->EndOfSectionNode()->GetIndex();
}
}
nIdx++;
}
}
else
{
OSL_ENSURE( !this, "Sub tables in HTML import?" );
SwHTMLTableLayout *pChild = pCnts->GetTable();
pChild->AutoLayoutPass1();
sal_uLong nMaxTableCnts = pChild->nMax;
sal_uLong nAbsMinTableCnts = pChild->nMin;
// Eine feste Tabellen-Breite wird als Minimum
// und Maximum gleichzeitig uebernommen
if( !pChild->bPrcWidthOption && pChild->nWidthOption )
{
sal_uLong nTabWidth = pChild->nWidthOption;
if( nTabWidth >= nAbsMinTableCnts )
{
nMaxTableCnts = nTabWidth;
nAbsMinTableCnts = nTabWidth;
}
else
{
nMaxTableCnts = nAbsMinTableCnts;
}
}
if( nMaxTableCnts > nMaxTableCell )
nMaxTableCell = nMaxTableCnts;
if( nAbsMinTableCnts > nAbsMinTableCell )
nAbsMinTableCell = nAbsMinTableCnts;
}
pCnts->SetPass1Done( nPass1Done );
pCnts = pCnts->GetNext();
}
// War frueher hinter AddBorderWidth
// Wenn die Breite einer Tabelle in der Zelle breiter ist als
// das, was wir fuer sonstigen Inhalt berechnet haben, mussen
// wir die Breite der Tabelle nutzen
if( nMaxTableCell > nMaxNoAlignCell )
nMaxNoAlignCell = nMaxTableCell;
if( nAbsMinTableCell > nAbsMinNoAlignCell )
{
nAbsMinNoAlignCell = nAbsMinTableCell;
if( nMinNoAlignCell < nAbsMinNoAlignCell )
nMinNoAlignCell = nAbsMinNoAlignCell;
if( nMaxNoAlignCell < nMinNoAlignCell )
nMaxNoAlignCell = nMinNoAlignCell;
}
// War frueher hinter AddBorderWidth
sal_Bool bRelWidth = pCell->IsPrcWidthOption();
sal_uInt16 nWidth = pCell->GetWidthOption();
// Eine NOWRAP-Option bezieht sich auf Text und auf
// Tabellen, wird aber bei fester Zellenbreite
// nicht uebernommen. Stattdessen wirkt die angegebene
// Zellenbreite wie eine Mindestbreite.
if( pCell->HasNoWrapOption() )
{
if( nWidth==0 || bRelWidth )
{
nMinNoAlignCell = nMaxNoAlignCell;
nAbsMinNoAlignCell = nMaxNoAlignCell;
}
else
{
if( nWidth>nMinNoAlignCell )
nMinNoAlignCell = nWidth;
if( nWidth>nAbsMinNoAlignCell )
nAbsMinNoAlignCell = nWidth;
}
}
// Mindestbreite fuer Inhalt einhalten
if( nMinNoAlignCell < MINLAY )
nMinNoAlignCell = MINLAY;
if( nMaxNoAlignCell < MINLAY )
nMaxNoAlignCell = MINLAY;
if( nAbsMinNoAlignCell < MINLAY )
nAbsMinNoAlignCell = MINLAY;
// Umrandung und Abstand zum Inhalt beachten.
AddBorderWidth( nMinNoAlignCell, nMaxNoAlignCell,
nAbsMinNoAlignCell, i, nColSpan );
if( 1==nColSpan )
{
// die Werte direkt uebernehmen
pColumn->MergeMinMaxNoAlign( nMinNoAlignCell,
nMaxNoAlignCell,
nAbsMinNoAlignCell );
// bei den WIDTH angaben gewinnt die breiteste
if( !HasColTags() )
pColumn->MergeCellWidthOption( nWidth, bRelWidth );
}
else
{
// die Angaben erst am Ende, und zwar zeilenweise von
// links nach rechts bearbeiten
// Wann welche Werte wie uebernommen werden ist weiter
// unten erklaert.
if( !HasColTags() && nWidth && !bRelWidth )
{
sal_uLong nAbsWidth = nWidth, nDummy = 0, nDummy2 = 0;
AddBorderWidth( nAbsWidth, nDummy, nDummy2,
i, nColSpan, sal_False );
if( nAbsWidth >= nMinNoAlignCell )
{
nMaxNoAlignCell = nAbsWidth;
if( HasColsOption() )
nMinNoAlignCell = nAbsWidth;
}
else if( nAbsWidth >= nAbsMinNoAlignCell )
{
nMaxNoAlignCell = nAbsWidth;
nMinNoAlignCell = nAbsWidth;
}
else
{
nMaxNoAlignCell = nAbsMinNoAlignCell;
nMinNoAlignCell = nAbsMinNoAlignCell;
}
}
else if( HasColsOption() || HasColTags() )
nMinNoAlignCell = nAbsMinNoAlignCell;
SwHTMLTableLayoutConstraints *pConstr =
new SwHTMLTableLayoutConstraints( nMinNoAlignCell,
nMaxNoAlignCell, j, i, nColSpan );
if( pConstraints )
pConstraints = pConstraints->InsertNext( pConstr );
else
pConstraints = pConstr;
}
}
}
OSL_ENSURE( nMinColSpan>0 && nColSkip>0 && nColSkip <= nMinColSpan,
"Layout Pass 1: Da werden Spalten vergessen!" );
OSL_ENSURE( nMinColSpan!=USHRT_MAX,
"Layout Pass 1: unnoetiger Schleifendurchlauf oder Bug" );
if( 1==nMinColSpan )
{
// es gibt Zellen mit COLSPAN 1 und demnach auch sinnvolle
// Werte in pColumn
// Werte anhand folgender Tabelle (Netscape 4.0 pv 3) uebernehmen:
//
// WIDTH: kein COLS COLS
//
// keine min = min min = absmin
// max = max max = max
//
// >= min min = min min = width
// max = width max = width
//
// >= absmin min = wdith(*) min = width
// max = width max = width
//
// < absmin min = absmin min = absmin
// max = absmin max = absmin
//
// (*) Netscape benutzt hier die Mindestbreite ohne einen
// Umbruch vor der letzten Grafik. Haben wir (noch?) nicht,
// also belassen wir es bei width.^
if( pColumn->GetWidthOption() && !pColumn->IsRelWidthOption() )
{
// absolute Breiten als Minimal- und Maximalbreite
// uebernehmen.
sal_uLong nAbsWidth = pColumn->GetWidthOption();
sal_uLong nDummy = 0, nDummy2 = 0;
AddBorderWidth( nAbsWidth, nDummy, nDummy2, i, 1, sal_False );
if( nAbsWidth >= pColumn->GetMinNoAlign() )
{
pColumn->SetMinMax( HasColsOption() ? nAbsWidth
: pColumn->GetMinNoAlign(),
nAbsWidth );
}
else if( nAbsWidth >= pColumn->GetAbsMinNoAlign() )
{
pColumn->SetMinMax( nAbsWidth, nAbsWidth );
}
else
{
pColumn->SetMinMax( pColumn->GetAbsMinNoAlign(),
pColumn->GetAbsMinNoAlign() );
}
}
else
{
pColumn->SetMinMax( HasColsOption() ? pColumn->GetAbsMinNoAlign()
: pColumn->GetMinNoAlign(),
pColumn->GetMaxNoAlign() );
}
}
else if( USHRT_MAX!=nMinColSpan )
{
// kann irgendwas !=0 sein, weil es durch die Constraints
// angepasst wird.
pColumn->SetMinMax( MINLAY, MINLAY );
// die naechsten Spalten muessen nicht bearbeitet werden
i += (nColSkip-1);
}
nMin += pColumn->GetMin();
nMax += pColumn->GetMax();
bFixRelWidths |= pColumn->IsRelWidthOption();
}
// jetzt noch die Constrains verarbeiten
SwHTMLTableLayoutConstraints *pConstr = pConstraints;
while( pConstr )
{
// Erstmal muss die Breite analog zu den den Spaltenbreiten
// aufbereitet werden
sal_uInt16 nCol = pConstr->GetColumn();
sal_uInt16 nColSpan = pConstr->GetColSpan();
sal_uLong nConstrMin = pConstr->GetMinNoAlign();
sal_uLong nConstrMax = pConstr->GetMaxNoAlign();
// jetzt holen wir uns die bisherige Breite der ueberspannten
// Spalten
sal_uLong nColsMin = 0;
sal_uLong nColsMax = 0;
for( sal_uInt16 j=nCol; j<nCol+nColSpan; j++ )
{
SwHTMLTableLayoutColumn *pColumn = GetColumn( j );
nColsMin += pColumn->GetMin();
nColsMax += pColumn->GetMax();
}
if( nColsMin<nConstrMin )
{
// den Minimalwert anteilig auf die Spalten verteilen
sal_uLong nMinD = nConstrMin-nColsMin;
if( nConstrMin > nColsMax )
{
// Anteilig anhand der Mindestbreiten
sal_uInt16 nEndCol = nCol+nColSpan;
sal_uLong nDiff = nMinD;
for( sal_uInt16 ic=nCol; ic<nEndCol; ic++ )
{
SwHTMLTableLayoutColumn *pColumn = GetColumn( ic );
sal_uLong nColMin = pColumn->GetMin();
sal_uLong nColMax = pColumn->GetMax();
nMin -= nColMin;
sal_uLong nAdd = ic<nEndCol-1 ? (nColMin * nMinD) / nColsMin
: nDiff;
nColMin += nAdd;
nMin += nColMin;
OSL_ENSURE( nDiff >= nAdd, "Ooops: nDiff stimmt nicht mehr" );
nDiff -= nAdd;
if( nColMax < nColMin )
{
nMax -= nColMax;
nColsMax -= nColMax;
nColMax = nColMin;
nMax += nColMax;
nColsMax += nColMax;
}
pColumn->SetMinMax( nColMin, nColMax );
}
}
else
{
// Anteilig anhand der Differenz zwischen Max und Min
for( sal_uInt16 ic=nCol; ic<nCol+nColSpan; ic++ )
{
SwHTMLTableLayoutColumn *pColumn = GetColumn( ic );
sal_uLong nDiff = pColumn->GetMax()-pColumn->GetMin();
if( nMinD < nDiff )
nDiff = nMinD;
pColumn->AddToMin( nDiff );
OSL_ENSURE( pColumn->GetMax() >= pColumn->GetMin(),
"Wieso ist die SPalte auf einmal zu schmal?" );
nMin += nDiff;
nMinD -= nDiff;
}
}
}
if( !HasColTags() && nColsMax<nConstrMax )
{
sal_uLong nMaxD = nConstrMax-nColsMax;
for( sal_uInt16 ic=nCol; ic<nCol+nColSpan; ic++ )
{
SwHTMLTableLayoutColumn *pColumn = GetColumn( ic );
nMax -= pColumn->GetMax();
pColumn->AddToMax( (pColumn->GetMax() * nMaxD) / nColsMax );
nMax += pColumn->GetMax();
}
}
pConstr = pConstr->GetNext();
}
if( bFixRelWidths )
{
if( HasColTags() )
{
// Zum Anpassen der relativen Breiten werden im 1. Schritt die
// Minmalbreiten aller anzupassenden Zellen jeweils mit der
// relativen Breite einer Spalte multipliziert. Dadurch stimmen
// dann die Breitenverhaeltnisse der Spalten untereinander.
// Ausserdem wird der Faktor berechnet, um den die Zelle dadurch
// breiter gworden ist als die Minmalbreite.
// Im 2. Schritt werden dann die berechneten Breiten durch diesen
// Faktor geteilt. Dadurch bleibt die Breite (nimd.) einer Zelle
// erhalten und dient als Ausgangsbasis fuer die andern Breiten.
// Es werden auch hier nur die Maximalbreiten beeinflusst!
sal_uLong nAbsMin = 0; // absolte Min-Breite alter Spalten mit
// relativer Breite
sal_uLong nRel = 0; // Summe der relativen Breiten aller Spalten
for( i=0; i<nCols; i++ )
{
SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
if( pColumn->IsRelWidthOption() && pColumn->GetWidthOption() )
{
nAbsMin += pColumn->GetMin();
nRel += pColumn->GetWidthOption();
}
}
sal_uLong nQuot = ULONG_MAX;
for( i=0; i<nCols; i++ )
{
SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
if( pColumn->IsRelWidthOption() )
{
nMax -= pColumn->GetMax();
if( pColumn->GetWidthOption() && pColumn->GetMin() )
{
pColumn->SetMax( nAbsMin * pColumn->GetWidthOption() );
sal_uLong nColQuot = pColumn->GetMax() / pColumn->GetMin();
if( nColQuot<nQuot )
nQuot = nColQuot;
}
}
}
OSL_ENSURE( 0==nRel || nQuot!=ULONG_MAX,
"Wo sind die relativen Spalten geblieben?" );
for( i=0; i<nCols; i++ )
{
SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
if( pColumn->IsRelWidthOption() )
{
if( pColumn->GetWidthOption() )
pColumn->SetMax( pColumn->GetMax() / nQuot );
else
pColumn->SetMax( pColumn->GetMin() );
OSL_ENSURE( pColumn->GetMax() >= pColumn->GetMin(),
"Maximale Spaltenbreite kleiner als Minimale" );
nMax += pColumn->GetMax();
}
}
}
else
{
sal_uInt16 nRel = 0; // Summe der relativen Breiten aller Spalten
sal_uInt16 nRelCols = 0; // Anzahl Spalten mit relativer Angabe
sal_uLong nRelMax = 0; // Anteil am Maximum dieser Spalten
for( i=0; i<nCols; i++ )
{
OSL_ENSURE( nRel<=100, "relative Breite aller Spalten>100%" );
SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
if( pColumn->IsRelWidthOption() && pColumn->GetWidthOption() )
{
// Sicherstellen, dass die relativen breiten nicht
// ueber 100% landen
sal_uInt16 nColWidth = pColumn->GetWidthOption();
if( nRel+nColWidth > 100 )
{
nColWidth = 100 - nRel;
pColumn->SetWidthOption( nColWidth, sal_True, sal_False );
}
nRelMax += pColumn->GetMax();
nRel = nRel + nColWidth;
nRelCols++;
}
else if( !pColumn->GetMin() )
{
// Die Spalte ist leer (wurde also auschliesslich
// durch COLSPAN erzeugt) und darf deshalb auch
// keine %-Breite zugewiesen bekommen.
nRelCols++;
}
}
// Eventuell noch vorhandene Prozente werden auf die Spalten ohne
// eine Breiten-Angabe verteilt. Wie in Netscape werden die
// verbleibenden Prozente enstprechend der Verhaeltnisse
// der Maximalbreiten der in Frage kommenden Spalten
// untereinander verteilt.
// ??? Wie beruecksichtigen bei den Maximalbreiten auch Spalten
// mit fester Breite. Ist das richtig???
if( nRel < 100 && nRelCols < nCols )
{
sal_uInt16 nRelLeft = 100 - nRel;
sal_uLong nFixMax = nMax - nRelMax;
for( i=0; i<nCols; i++ )
{
SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
if( !pColumn->IsRelWidthOption() &&
!pColumn->GetWidthOption() &&
pColumn->GetMin() )
{
// den Rest bekommt die naechste Spalte
sal_uInt16 nColWidth =
(sal_uInt16)((pColumn->GetMax() * nRelLeft) / nFixMax);
pColumn->SetWidthOption( nColWidth, sal_True, sal_False );
}
}
}
// nun die Maximalbreiten entsprechend anpassen
sal_uLong nQuotMax = ULONG_MAX;
sal_uLong nOldMax = nMax;
nMax = 0;
for( i=0; i<nCols; i++ )
{
// Spalten mit %-Angaben werden enstprechend angepasst.
// Spalten, die
// - keine %-Angabe besitzen und in einer Tabelle mit COLS
// oder WIDTH vorkommen, oder
// - als Breite 0% angegeben haben erhalten die Minimalbreite
SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
if( pColumn->IsRelWidthOption() && pColumn->GetWidthOption() )
{
sal_uLong nNewMax;
sal_uLong nColQuotMax;
if( !nWidthOption )
{
nNewMax = nOldMax * pColumn->GetWidthOption();
nColQuotMax = nNewMax / pColumn->GetMax();
}
else
{
nNewMax = nMin * pColumn->GetWidthOption();
nColQuotMax = nNewMax / pColumn->GetMin();
}
pColumn->SetMax( nNewMax );
if( nColQuotMax < nQuotMax )
nQuotMax = nColQuotMax;
}
else if( HasColsOption() || nWidthOption ||
(pColumn->IsRelWidthOption() &&
!pColumn->GetWidthOption()) )
pColumn->SetMax( pColumn->GetMin() );
}
// und durch den Quotienten teilen
OSL_ENSURE( nQuotMax!=ULONG_MAX, "Wo sind die relativen Spalten geblieben?" );
for( i=0; i<nCols; i++ )
{
SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
if( pColumn->IsRelWidthOption() && pColumn->GetWidthOption() )
{
if( pColumn->GetWidthOption() )
{
pColumn->SetMax( pColumn->GetMax() / nQuotMax );
OSL_ENSURE( pColumn->GetMax() >= pColumn->GetMin(),
"Minimalbreite ein Spalte Groesser Maximum" );
if( pColumn->GetMax() < pColumn->GetMin() )
pColumn->SetMax( pColumn->GetMin() );
}
}
nMax += pColumn->GetMax();
}
}
}
delete pConstraints;
}
// nAbsAvail ist der verfuegbare Platz in TWIPS.
// nRelAvail ist der auf USHRT_MAX bezogene verfuegbare Platz oder 0
// nAbsSpace ist der Anteil von nAbsAvail, der durch der umgebende Zelle
// fur die Umrandung und den Abstand zum Inhalt reserviert ist.
void SwHTMLTableLayout::AutoLayoutPass2( sal_uInt16 nAbsAvail, sal_uInt16 nRelAvail,
sal_uInt16 nAbsLeftSpace,
sal_uInt16 nAbsRightSpace,
sal_uInt16 nParentInhAbsSpace )
{
// Erstmal fuehren wie jede Menge Plausibilaets-Test durch
// Eine abolute zur Verfuegung stehende Breite muss immer uebergeben
// werden.
OSL_ENSURE( nAbsAvail, "AutoLayout Pass 2: Keine absolute Breite gegeben" );
// Eine realtive zur Verfuegung stehende Breite darf nur und muss fuer
// Tabellen in Tabellen uebergeben
OSL_ENSURE( IsTopTable() == (nRelAvail==0),
"AutoLayout Pass 2: Rel. Breite bei Tab in Tab oder umgekehrt" );
// Die Minimalbreite der Tabelle darf natuerlich nie groesser sein
// als das die Maximalbreite.
OSL_ENSURE( nMin<=nMax, "AutoLayout Pass2: nMin > nMax" );
// Die verfuegbare Breite, fuer die die Tabelle berechnet wurde, merken.
// (Dies ist ein guter Ort, denn hier kommer wir bei der Erstberechnung
// der Tabelle aus dem Parser und bei jedem _Resize-Aufruf vorbei.)
nLastResizeAbsAvail = nAbsAvail;
// Schritt 1: Der verfuegbar Platz wird an linke/rechte Raender,
// vorhandene Filler-Zellen und Abstande angepasst
// Abstand zum Inhalt und Unrandung
sal_uInt16 nAbsLeftFill = 0, nAbsRightFill = 0;
if( !IsTopTable() &&
GetMin() + nAbsLeftSpace + nAbsRightSpace <= nAbsAvail )
{
nAbsLeftFill = nAbsLeftSpace;
nAbsRightFill = nAbsRightSpace;
}
// Linker und rechter Abstand
if( nLeftMargin || nRightMargin )
{
if( IsTopTable() )
{
// fuer die Top-Table beruecksichtigen wir die Raender immer,
// den die Minimalbreite der Tabelle wird hier nie unterschritten
nAbsAvail -= (nLeftMargin + nRightMargin);
}
else if( GetMin() + nLeftMargin + nRightMargin <= nAbsAvail )
{
// sonst beruecksichtigen wir die Raender nur, wenn auch Platz
// fuer sie da ist (nMin ist hier bereits berechnet!)
nAbsLeftFill = nAbsLeftFill + nLeftMargin;
nAbsRightFill = nAbsRightFill + nRightMargin;
}
}
// Filler-Zellen
if( !IsTopTable() )
{
if( pLeftFillerBox && nAbsLeftFill<MINLAY+nInhLeftBorderWidth )
nAbsLeftFill = MINLAY+nInhLeftBorderWidth;
if( pRightFillerBox && nAbsRightFill<MINLAY+nInhRightBorderWidth )
nAbsRightFill = MINLAY+nInhRightBorderWidth;
}
// Anpassen des verfuegbaren Platzes.
nRelLeftFill = 0;
nRelRightFill = 0;
if( !IsTopTable() && (nAbsLeftFill>0 || nAbsRightFill) )
{
sal_uLong nAbsLeftFillL = nAbsLeftFill, nAbsRightFillL = nAbsRightFill;
nRelLeftFill = (sal_uInt16)((nAbsLeftFillL * nRelAvail) / nAbsAvail);
nRelRightFill = (sal_uInt16)((nAbsRightFillL * nRelAvail) / nAbsAvail);
nAbsAvail -= (nAbsLeftFill + nAbsRightFill);
if( nRelAvail )
nRelAvail -= (nRelLeftFill + nRelRightFill);
}
// Schritt 2: Die absolute Tabellenbreite wird berechnet.
sal_uInt16 nAbsTabWidth = 0;
bUseRelWidth = sal_False;
if( nWidthOption )
{
if( bPrcWidthOption )
{
OSL_ENSURE( nWidthOption<=100, "Prozentangabe zu gross" );
if( nWidthOption > 100 )
nWidthOption = 100;
// Die absolute Breite entspricht den angegeben Prozent der
// zur Verfuegung stehenden Breite.
// Top-Tabellen bekommen nur eine relative Breite, wenn der
// verfuegbare Platz *echt groesser* ist als die Minimalbreite.
// ACHTUNG: Das "echte groesser" ist noetig, weil der Wechsel
// von einer relativen Breite zu einer absoluten Breite durch
// Resize sonst zu einer Endlosschleife fuehrt.
// Weil bei Tabellen in Rahmen kein Resize aufgerufen wird,
// wenn der Rahmen eine nicht-relative Breite besitzt, koennen
// wir da solche Spielchen nicht spielen
// Spielen wir solche Spielchen
// jetzt doch. Dort war eine Grafik in einer 1%-breiten
// Tabelle und hat da natuerlich nicht hineingepasst.
nAbsTabWidth = (sal_uInt16)( ((sal_uLong)nAbsAvail * nWidthOption) / 100 );
if( IsTopTable() &&
( /*MayBeInFlyFrame() ||*/ (sal_uLong)nAbsTabWidth > nMin ) )
{
nRelAvail = USHRT_MAX;
bUseRelWidth = sal_True;
}
}
else
{
nAbsTabWidth = nWidthOption;
if( nAbsTabWidth > MAX_TABWIDTH )
nAbsTabWidth = MAX_TABWIDTH;
// Tabellen in Tabellen duerfen niemals breiter werden als der
// verfuegbare Platz.
if( !IsTopTable() && nAbsTabWidth > nAbsAvail )
nAbsTabWidth = nAbsAvail;
}
}
OSL_ENSURE( IsTopTable() || nAbsTabWidth<=nAbsAvail,
"AutoLayout Pass2: nAbsTabWidth > nAbsAvail fuer Tab in Tab" );
OSL_ENSURE( !nRelAvail || nAbsTabWidth<=nAbsAvail,
"AutoLayout Pass2: nAbsTabWidth > nAbsAvail fuer relative Breite" );
// Catch fuer die beiden Asserts von oben (man weiss ja nie!)
if( (!IsTopTable() || nRelAvail>0) && nAbsTabWidth>nAbsAvail )
nAbsTabWidth = nAbsAvail;
// Schritt 3: Bestimmen der Spaltenbreiten und ggf. auch der
// absoluten und relativen Tabellenbreiten.
if( (!IsTopTable() && nMin > (sal_uLong)nAbsAvail) ||
nMin > MAX_TABWIDTH )
{
// Wenn
// - das Minumum einer inneren Tabelle groesser ist als der
// verfuegbare Platz, oder
// - das Minumum einer Top-Table groesser ist als USHRT_MAX
// muss die Tabelle an den verfuegbaren Platz bzw. USHRT_MAX
// abgepasst werden. Dabei bleiben die Verhaeltnisse der Breiten
// untereinander erhalten.
nAbsTabWidth = IsTopTable() ? MAX_TABWIDTH : nAbsAvail;
nRelTabWidth = (nRelAvail ? nRelAvail : nAbsTabWidth );
// First of all, we check wether we can fit the layout constrains,
// that are: Every cell's width excluding the borders must be at least
// MINLAY:
sal_uLong nRealMin = 0;
for( sal_uInt16 i=0; i<nCols; i++ )
{
sal_uLong nRealColMin = MINLAY, nDummy1, nDummy2;
AddBorderWidth( nRealColMin, nDummy1, nDummy2, i, 1 );
nRealMin += nRealColMin;
}
if( (nRealMin >= nAbsTabWidth) || (nRealMin >= nMin) )
{
// "Nichts geht mehr". We cannot get the minimum column widths
// the layout wants to have.
sal_uInt16 nAbs = 0, nRel = 0;
SwHTMLTableLayoutColumn *pColumn;
for( sal_uInt16 i=0; i<nCols-1; i++ )
{
pColumn = GetColumn( i );
sal_uLong nColMin = pColumn->GetMin();
if( nColMin <= USHRT_MAX )
{
pColumn->SetAbsColWidth(
(sal_uInt16)((nColMin * nAbsTabWidth) / nMin) );
pColumn->SetRelColWidth(
(sal_uInt16)((nColMin * nRelTabWidth) / nMin) );
}
else
{
double nColMinD = nColMin;
pColumn->SetAbsColWidth(
(sal_uInt16)((nColMinD * nAbsTabWidth) / nMin) );
pColumn->SetRelColWidth(
(sal_uInt16)((nColMinD * nRelTabWidth) / nMin) );
}
nAbs = nAbs + (sal_uInt16)pColumn->GetAbsColWidth();
nRel = nRel + (sal_uInt16)pColumn->GetRelColWidth();
}
pColumn = GetColumn( nCols-1 );
pColumn->SetAbsColWidth( nAbsTabWidth - nAbs );
pColumn->SetRelColWidth( nRelTabWidth - nRel );
}
else
{
sal_uLong nDistAbs = nAbsTabWidth - nRealMin;
sal_uLong nDistRel = nRelTabWidth - nRealMin;
sal_uLong nDistMin = nMin - nRealMin;
sal_uInt16 nAbs = 0, nRel = 0;
SwHTMLTableLayoutColumn *pColumn;
for( sal_uInt16 i=0; i<nCols-1; i++ )
{
pColumn = GetColumn( i );
sal_uLong nColMin = pColumn->GetMin();
sal_uLong nRealColMin = MINLAY, nDummy1, nDummy2;
AddBorderWidth( nRealColMin, nDummy1, nDummy2, i, 1 );
if( nColMin <= USHRT_MAX )
{
pColumn->SetAbsColWidth(
(sal_uInt16)((((nColMin-nRealColMin) * nDistAbs) / nDistMin) + nRealColMin) );
pColumn->SetRelColWidth(
(sal_uInt16)((((nColMin-nRealColMin) * nDistRel) / nDistMin) + nRealColMin) );
}
else
{
double nColMinD = nColMin;
pColumn->SetAbsColWidth(
(sal_uInt16)((((nColMinD-nRealColMin) * nDistAbs) / nDistMin) + nRealColMin) );
pColumn->SetRelColWidth(
(sal_uInt16)((((nColMinD-nRealColMin) * nDistRel) / nDistMin) + nRealColMin) );
}
nAbs = nAbs + (sal_uInt16)pColumn->GetAbsColWidth();
nRel = nRel + (sal_uInt16)pColumn->GetRelColWidth();
}
pColumn = GetColumn( nCols-1 );
pColumn->SetAbsColWidth( nAbsTabWidth - nAbs );
pColumn->SetRelColWidth( nRelTabWidth - nRel );
}
}
else if( nMax <= (sal_uLong)(nAbsTabWidth ? nAbsTabWidth : nAbsAvail) )
{
// Wenn
// - die Tabelle eine fixe Breite besitzt und das Maximum der
// Tabelle kleiner ist, oder
// - das Maximum kleiner ist als der verfuegbare Platz
// kann das Maximum direkt uebernommen werden bzw. die Tabelle nur
// unter Beruecksichtigung des Maxumums an die fixe Breite
// angepasst werden.
// Keine fixe Breite, dann das Maximum nehmen.
if( !nAbsTabWidth )
nAbsTabWidth = (sal_uInt16)nMax;
// Eine Top-Table darf auch beriter werden als der verfuegbare Platz.
if( nAbsTabWidth > nAbsAvail )
{
OSL_ENSURE( IsTopTable(),
"Tabelle in Tabelle soll breiter werden als umgebende Zelle" );
nAbsAvail = nAbsTabWidth;
}
// Nur den Anteil der relativen Breite verwenden, der auch fuer
// die absolute Breite verwendet wuerde.
sal_uLong nAbsTabWidthL = nAbsTabWidth;
nRelTabWidth =
( nRelAvail ? (sal_uInt16)((nAbsTabWidthL * nRelAvail) / nAbsAvail)
: nAbsTabWidth );
// Gibt es Spalten mit und Spalten ohne %-Angabe?
sal_uLong nFixMax = nMax;
for( sal_uInt16 i=0; i<nCols; i++ )
{
const SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
if( pColumn->IsRelWidthOption() && pColumn->GetWidthOption()>0 )
nFixMax -= pColumn->GetMax();
}
if( nFixMax > 0 && nFixMax < nMax )
{
// ja, dann den zu verteilenden Platz nur auf die Spalten
// mit %-Angabe verteilen.
// In diesem (und nur in diesem) Fall gibt es Spalten,
// die ihre Maximalbreite genau einhalten, also weder
// schmaler noch breiter werden. Beim zurueckrechnen der
// absoluten Breite aus der relativen Breite kann es
// zu Rundungsfehlern kommen. Um die auszugeleichen
// werden zuerst die fixen Breiten entsprechend korrigiert
// eingestellt und erst danach die relativen.
sal_uInt16 nAbs = 0, nRel = 0;
sal_uInt16 nFixedCols = 0;
sal_uInt16 i;
for( i = 0; i < nCols; i++ )
{
SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
if( !pColumn->IsRelWidthOption() || !pColumn->GetWidthOption() )
{
// Die Spalte behaelt ihre Breite bei.
nFixedCols++;
sal_uLong nColMax = pColumn->GetMax();
pColumn->SetAbsColWidth( (sal_uInt16)nColMax );
sal_uLong nRelColWidth =
(nColMax * nRelTabWidth) / nAbsTabWidth;
sal_uLong nChkWidth =
(nRelColWidth * nAbsTabWidth) / nRelTabWidth;
if( nChkWidth < nColMax )
nRelColWidth++;
else if( nChkWidth > nColMax )
nRelColWidth--;
pColumn->SetRelColWidth( (sal_uInt16)nRelColWidth );
nAbs = nAbs + (sal_uInt16)nColMax;
nRel = nRel + (sal_uInt16)nRelColWidth;
}
}
// Zu verteilende Anteile des Maximums und der relativen und
// absoluten Breiten. nFixMax entspricht an dieser Stelle
// nAbs, so dass man gleich nFixMax haette nehmen koennen.
// Der Code ist so aber verstaendlicher.
OSL_ENSURE( nFixMax == nAbs, "Zwei Schleifen, zwei Summen?" );
sal_uLong nDistMax = nMax - nFixMax;
sal_uInt16 nDistAbsTabWidth = nAbsTabWidth - nAbs;
sal_uInt16 nDistRelTabWidth = nRelTabWidth - nRel;
for( i=0; i<nCols; i++ )
{
SwHTMLTableLayoutColumn *pColumn = GetColumn( i );
if( pColumn->IsRelWidthOption() && pColumn->GetWidthOption() > 0 )
{
// Die Spalte wird anteilig breiter.
nFixedCols++;
if( nFixedCols == nCols )
{
pColumn->SetAbsColWidth( nAbsTabWidth-nAbs );
pColumn->SetRelColWidth( nRelTabWidth-nRel );
}
else
{
sal_uLong nColMax = pColumn->GetMax();
pColumn->SetAbsColWidth(
(sal_uInt16)((nColMax * nDistAbsTabWidth) / nDistMax) );
pColumn->SetRelColWidth(
(sal_uInt16)((nColMax * nDistRelTabWidth) / nDistMax) );
}
nAbs = nAbs + pColumn->GetAbsColWidth();
nRel = nRel + pColumn->GetRelColWidth();
}
}
OSL_ENSURE( nCols==nFixedCols, "Spalte vergessen!" );
}
else
{
// nein, dann den zu verteilenden Platz auf alle Spalten
// gleichmaessig vertilen.
for( sal_uInt16 i=0; i<nCols; i++ )
{
sal_uLong nColMax = GetColumn( i )->GetMax();
GetColumn( i )->SetAbsColWidth(
(sal_uInt16)((nColMax * nAbsTabWidth) / nMax) );
GetColumn( i )->SetRelColWidth(
(sal_uInt16)((nColMax * nRelTabWidth) / nMax) );
}
}
}
else
{
// den ueber die Minimalbreite herausgehenden Platz entsprechend
// den einzelnen Spalten anteilig zuschlagen
if( !nAbsTabWidth )
nAbsTabWidth = nAbsAvail;
if( nAbsTabWidth < nMin )
nAbsTabWidth = (sal_uInt16)nMin;
if( nAbsTabWidth > nAbsAvail )
{
OSL_ENSURE( IsTopTable(),
"Tabelle in Tabelle soll breiter werden als Platz da ist" );
nAbsAvail = nAbsTabWidth;
}
sal_uLong nAbsTabWidthL = nAbsTabWidth;
nRelTabWidth =
( nRelAvail ? (sal_uInt16)((nAbsTabWidthL * nRelAvail) / nAbsAvail)
: nAbsTabWidth );
double nW = nAbsTabWidth - nMin;
double nD = (nMax==nMin ? 1 : nMax-nMin);
sal_uInt16 nAbs = 0, nRel = 0;
for( sal_uInt16 i=0; i<nCols-1; i++ )
{
double nd = GetColumn( i )->GetMax() - GetColumn( i )->GetMin();
sal_uLong nAbsColWidth = GetColumn( i )->GetMin() + (sal_uLong)((nd*nW)/nD);
sal_uLong nRelColWidth = nRelAvail
? (nAbsColWidth * nRelTabWidth) / nAbsTabWidth
: nAbsColWidth;
GetColumn( i )->SetAbsColWidth( (sal_uInt16)nAbsColWidth );
GetColumn( i )->SetRelColWidth( (sal_uInt16)nRelColWidth );
nAbs = nAbs + (sal_uInt16)nAbsColWidth;
nRel = nRel + (sal_uInt16)nRelColWidth;
}
GetColumn( nCols-1 )->SetAbsColWidth( nAbsTabWidth - nAbs );
GetColumn( nCols-1 )->SetRelColWidth( nRelTabWidth - nRel );
}
// Schritt 4: Fuer Tabellen in Tabellen kann es links und/oder rechts
// noch Ausgleichzellen geben. Deren Breite wird jetzt berechnet.
nInhAbsLeftSpace = 0;
nInhAbsRightSpace = 0;
if( !IsTopTable() && (nRelLeftFill>0 || nRelRightFill>0 ||
nAbsTabWidth<nAbsAvail) )
{
// Die Breite von zusaetzlichen Zellen zur Ausrichtung der
// inneren Tabelle bestimmen
sal_uInt16 nAbsDist = (sal_uInt16)(nAbsAvail-nAbsTabWidth);
sal_uInt16 nRelDist = (sal_uInt16)(nRelAvail-nRelTabWidth);
sal_uInt16 nParentInhAbsLeftSpace = 0, nParentInhAbsRightSpace = 0;
// Groesse und Position der zusaetzlichen Zellen bestimmen
switch( eTableAdjust )
{
case SVX_ADJUST_RIGHT:
nAbsLeftFill = nAbsLeftFill + nAbsDist;
nRelLeftFill = nRelLeftFill + nRelDist;
nParentInhAbsLeftSpace = nParentInhAbsSpace;
break;
case SVX_ADJUST_CENTER:
{
sal_uInt16 nAbsLeftDist = nAbsDist / 2;
nAbsLeftFill = nAbsLeftFill + nAbsLeftDist;
nAbsRightFill += nAbsDist - nAbsLeftDist;
sal_uInt16 nRelLeftDist = nRelDist / 2;
nRelLeftFill = nRelLeftFill + nRelLeftDist;
nRelRightFill += nRelDist - nRelLeftDist;
nParentInhAbsLeftSpace = nParentInhAbsSpace / 2;
nParentInhAbsRightSpace = nParentInhAbsSpace -
nParentInhAbsLeftSpace;
}
break;
case SVX_ADJUST_LEFT:
default:
nAbsRightFill = nAbsRightFill + nAbsDist;
nRelRightFill = nRelRightFill + nRelDist;
nParentInhAbsRightSpace = nParentInhAbsSpace;
break;
}
OSL_ENSURE( !pLeftFillerBox || nRelLeftFill>0,
"Fuer linke Filler-Box ist keine Breite da!" );
OSL_ENSURE( !pRightFillerBox || nRelRightFill>0,
"Fuer rechte Filler-Box ist keine Breite da!" );
// Filler-Breiten werden auf die ausseren Spalten geschlagen, wenn
// es nach dem ersten Durchlauf keine Boxen fuer sie gibt (nWidth>0)
// oder ihre Breite zu klein wuerde oder wenn es COL-Tags gibt und
// die Filler-Breite der Umrandung-Breite entspricht (dann haben wir
// die Tabelle wahrscheinlich selbst exportiert)
if( nRelLeftFill && !pLeftFillerBox &&
( nWidthSet>0 || nAbsLeftFill<MINLAY+nInhLeftBorderWidth ||
(HasColTags() && nAbsLeftFill < nAbsLeftSpace+nParentInhAbsLeftSpace+20) ) )
{
SwHTMLTableLayoutColumn *pColumn = GetColumn( 0 );
pColumn->SetAbsColWidth( pColumn->GetAbsColWidth()+nAbsLeftFill );
pColumn->SetRelColWidth( pColumn->GetRelColWidth()+nRelLeftFill );
nRelLeftFill = 0;
nInhAbsLeftSpace = nAbsLeftSpace + nParentInhAbsLeftSpace;
}
if( nRelRightFill && !pRightFillerBox &&
( nWidthSet>0 || nAbsRightFill<MINLAY+nInhRightBorderWidth ||
(HasColTags() && nAbsRightFill < nAbsRightSpace+nParentInhAbsRightSpace+20) ) )
{
SwHTMLTableLayoutColumn *pColumn = GetColumn( nCols-1 );
pColumn->SetAbsColWidth( pColumn->GetAbsColWidth()+nAbsRightFill );
pColumn->SetRelColWidth( pColumn->GetRelColWidth()+nRelRightFill );
nRelRightFill = 0;
nInhAbsRightSpace = nAbsRightSpace + nParentInhAbsRightSpace;
}
}
}
static sal_Bool lcl_ResizeLine( const SwTableLine*& rpLine, void* pPara );
static sal_Bool lcl_ResizeBox( const SwTableBox*& rpBox, void* pPara )
{
sal_uInt16 *pWidth = (sal_uInt16 *)pPara;
if( !rpBox->GetSttNd() )
{
sal_uInt16 nWidth = 0;
((SwTableBox *)rpBox)->GetTabLines().ForEach( &lcl_ResizeLine, &nWidth );
rpBox->GetFrmFmt()->SetFmtAttr( SwFmtFrmSize( ATT_VAR_SIZE, nWidth, 0 ));
*pWidth = *pWidth + nWidth;
}
else
{
*pWidth = *pWidth + (sal_uInt16)rpBox->GetFrmFmt()->GetFrmSize().GetSize().Width();
}
return sal_True;
}
static sal_Bool lcl_ResizeLine( const SwTableLine*& rpLine, void* pPara )
{
sal_uInt16 *pWidth = (sal_uInt16 *)pPara;
#if OSL_DEBUG_LEVEL > 0
sal_uInt16 nOldWidth = *pWidth;
#endif
*pWidth = 0;
((SwTableLine *)rpLine)->GetTabBoxes().ForEach( &lcl_ResizeBox, pWidth );
#if OSL_DEBUG_LEVEL > 0
OSL_ENSURE( !nOldWidth || Abs(*pWidth-nOldWidth) < COLFUZZY,
"Zeilen einer Box sind unterschiedlich lang" );
#endif
return sal_True;
}
void SwHTMLTableLayout::SetWidths( sal_Bool bCallPass2, sal_uInt16 nAbsAvail,
sal_uInt16 nRelAvail, sal_uInt16 nAbsLeftSpace,
sal_uInt16 nAbsRightSpace,
sal_uInt16 nParentInhAbsSpace )
{
// SetWidth muss am Ende einmal mehr fuer jede Zelle durchlaufen
// worden sein.
nWidthSet++;
// Schritt 0: Wenn noetig, wird hier noch der Pass2 des Layout-Alogithmus
// aufgerufen.
if( bCallPass2 )
AutoLayoutPass2( nAbsAvail, nRelAvail, nAbsLeftSpace, nAbsRightSpace,
nParentInhAbsSpace );
// Schritt 1: Setzten der neuen Breite an allen Content-Boxen.
// Da die Boxen nichts von der HTML-Tabellen-Struktur wissen, wird
// ueber die HTML-Tabellen-Struktur iteriert. Fuer Tabellen in Tabellen
// in Tabellen wird rekursiv SetWidth aufgerufen.
for( sal_uInt16 i=0; i<nRows; i++ )
{
for( sal_uInt16 j=0; j<nCols; j++ )
{
SwHTMLTableLayoutCell *pCell = GetCell( i, j );
SwHTMLTableLayoutCnts* pCntnts = pCell->GetContents();
while( pCntnts && !pCntnts->IsWidthSet(nWidthSet) )
{
SwTableBox *pBox = pCntnts->GetTableBox();
if( pBox )
{
SetBoxWidth( pBox, j, pCell->GetColSpan() );
}
else
{
sal_uInt16 nAbs = 0, nRel = 0, nLSpace = 0, nRSpace = 0,
nInhSpace = 0;
if( bCallPass2 )
{
sal_uInt16 nColSpan = pCell->GetColSpan();
GetAvail( j, nColSpan, nAbs, nRel );
nLSpace = GetLeftCellSpace( j, nColSpan );
nRSpace = GetRightCellSpace( j, nColSpan );
nInhSpace = GetInhCellSpace( j, nColSpan );
}
pCntnts->GetTable()->SetWidths( bCallPass2, nAbs, nRel,
nLSpace, nRSpace,
nInhSpace );
}
pCntnts->SetWidthSet( nWidthSet );
pCntnts = pCntnts->GetNext();
}
}
}
// Schritt 2: Wenn eine Top-Tabelle vorliegt, werden jetzt die Formate
// der Nicht-Content-Boxen angepasst. Da diese aufgrund der
// Garbage-Collection in der HTML-Tabelle nicht bekannt sind, muessen
// wir hier ueber die Tabelle iterieren. Bei der Gelegenheit wird auch
// das Tabellen-Frameformat angepasst. Fuer Tabellen in Tabellen werden
// stattdessen die Breiten der Filler-Zellen gesetzt.
if( IsTopTable() )
{
sal_uInt16 nCalcTabWidth = 0;
((SwTable *)pSwTable)->GetTabLines().ForEach( &lcl_ResizeLine,
&nCalcTabWidth );
OSL_ENSURE( Abs( nRelTabWidth-nCalcTabWidth ) < COLFUZZY,
"Tabellebreite stimmt nicht mit Zeilenbreite ueberein." );
// Beim Anpassen des Tabellen-Formats dieses locken, weil sonst
// die Boxformate erneut angepasst werden. Ausserdem muss eine
// evtl. vorhandene %-Angabe in jedem Fall erhalten bleiben.
SwFrmFmt *pFrmFmt = pSwTable->GetFrmFmt();
((SwTable *)pSwTable)->LockModify();
SwFmtFrmSize aFrmSize( pFrmFmt->GetFrmSize() );
aFrmSize.SetWidth( nRelTabWidth );
sal_Bool bRel = bUseRelWidth &&
text::HoriOrientation::FULL!=pFrmFmt->GetHoriOrient().GetHoriOrient();
aFrmSize.SetWidthPercent( (sal_uInt8)(bRel ? nWidthOption : 0) );
pFrmFmt->SetFmtAttr( aFrmSize );
((SwTable *)pSwTable)->UnlockModify();
// Wenn die Tabelle in einem Rahmen steht, muss auch noch dessen
// breite angepasst werden.
if( MayBeInFlyFrame() )
{
SwFrmFmt *pFlyFrmFmt = FindFlyFrmFmt();
if( pFlyFrmFmt )
{
SwFmtFrmSize aFlyFrmSize( ATT_VAR_SIZE, nRelTabWidth, MINLAY );
if( bUseRelWidth )
{
// Bei %-Angaben wird die Breite auf das Minimum gesetzt.
aFlyFrmSize.SetWidth( nMin > USHRT_MAX ? USHRT_MAX
: nMin );
aFlyFrmSize.SetWidthPercent( (sal_uInt8)nWidthOption );
}
pFlyFrmFmt->SetFmtAttr( aFlyFrmSize );
}
}
#ifdef DBG_UTIL
{
// steht im tblrwcl.cxx
extern void _CheckBoxWidth( const SwTableLine&, SwTwips );
// checke doch mal ob die Tabellen korrekte Breiten haben
SwTwips nSize = pSwTable->GetFrmFmt()->GetFrmSize().GetWidth();
const SwTableLines& rLines = pSwTable->GetTabLines();
for( sal_uInt16 n = 0; n < rLines.Count(); ++n )
_CheckBoxWidth( *rLines[ n ], nSize );
}
#endif
}
else
{
if( pLeftFillerBox )
{
pLeftFillerBox->GetFrmFmt()->SetFmtAttr(
SwFmtFrmSize( ATT_VAR_SIZE, nRelLeftFill, 0 ));
}
if( pRightFillerBox )
{
pRightFillerBox->GetFrmFmt()->SetFmtAttr(
SwFmtFrmSize( ATT_VAR_SIZE, nRelRightFill, 0 ));
}
}
}
void SwHTMLTableLayout::_Resize( sal_uInt16 nAbsAvail, sal_Bool bRecalc )
{
// Wenn bRecalc gestzt ist, hat sich am Inhalt der Tabelle etwas
// geaendert. Es muss dann der erste Pass noch einmal durchgefuehrt
// werden.
if( bRecalc )
AutoLayoutPass1();
SwRootFrm *pRoot = (SwRootFrm*)GetDoc()->GetCurrentViewShell()->GetLayout();
if ( pRoot && pRoot->IsCallbackActionEnabled() )
pRoot->StartAllAction(); //swmod 071108//swmod 071225
// Sonst koennen die Breiten gesetzt werden, wobei zuvor aber jewils
// noch der Pass 2 laufen muss.
SetWidths( sal_True, nAbsAvail );
if ( pRoot && pRoot->IsCallbackActionEnabled() )
pRoot->EndAllAction( sal_True ); //True per VirDev (Browsen ruhiger) //swmod 071108//swmod 071225
}
IMPL_STATIC_LINK( SwHTMLTableLayout, DelayedResize_Impl, void*, EMPTYARG )
{
pThis->aResizeTimer.Stop();
pThis->_Resize( pThis->nDelayedResizeAbsAvail,
pThis->bDelayedResizeRecalc );
return 0;
}
sal_Bool SwHTMLTableLayout::Resize( sal_uInt16 nAbsAvail, sal_Bool bRecalc,
sal_Bool bForce, sal_uLong nDelay )
{
if( 0 == nAbsAvail )
return sal_False;
OSL_ENSURE( IsTopTable(), "Resize darf nur an Top-Tabellen aufgerufen werden" );
// Darf die Tabelle uberhaupt Resized werden oder soll sie es trotzdem?
if( bMustNotResize && !bForce )
return sal_False;
// Darf ein Recalc der Tabelle durchgefuehrt werden?
if( bMustNotRecalc && !bForce )
bRecalc = sal_False;
const SwDoc *pDoc = GetDoc();
// Wenn es ein Layout gibt, wurde evtl. die Groesse der Root-Frames
// und nicht die der VisArea uebergeben. Wenn wir nicht in einem Rahmen
// stehen, muss die Tabelle allerdings fuer die VisArea berechnet werden,
// weil sond die Umschaltung von relativ nach absolut nicht funktioniert.
if( pDoc->GetCurrentViewShell() && pDoc->GetCurrentViewShell()->GetViewOptions()->getBrowseMode() )
{
const sal_uInt16 nVisAreaWidth = GetBrowseWidthByVisArea( *pDoc );
if( nVisAreaWidth < nAbsAvail && !FindFlyFrmFmt() )
nAbsAvail = nVisAreaWidth;
}
if( nDelay==0 && aResizeTimer.IsActive() )
{
// Wenn beim Aufruf eines synchronen Resize noch ein asynchrones
// Resize aussteht, dann werden nur die neuen Werte uebernommen.
bRecalc |= bDelayedResizeRecalc;
nDelayedResizeAbsAvail = nAbsAvail;
return sal_False;
}
// Optimierung:
// Wenn die Minima/Maxima nicht neu berechnet werden sollen und
// - die Breite der Tabelle nie neu berechnet werden muss, oder
// - die Tabelle schon fuer die uebergebene Breite berechnet wurde, oder
// - der verfuegbare Platz kleiner oder gleich der Minimalbreite ist
// und die Tabelle bereits die Minimalbreite besitzt, oder
// - der verfuegbare Platz groesser ist als die Maximalbreite und
// die Tabelle bereits die Maximalbreite besitzt
// wird sich an der Tabelle nichts aendern.
if( !bRecalc && ( !bMustResize ||
(nLastResizeAbsAvail==nAbsAvail) ||
(nAbsAvail<=nMin && nRelTabWidth==nMin) ||
(!bPrcWidthOption && nAbsAvail>=nMax && nRelTabWidth==nMax) ) )
return sal_False;
if( nDelay==HTMLTABLE_RESIZE_NOW )
{
if( aResizeTimer.IsActive() )
aResizeTimer.Stop();
_Resize( nAbsAvail, bRecalc );
}
else if( nDelay > 0 )
{
nDelayedResizeAbsAvail = nAbsAvail;
bDelayedResizeRecalc = bRecalc;
aResizeTimer.SetTimeout( nDelay );
aResizeTimer.Start();
}
else
{
_Resize( nAbsAvail, bRecalc );
}
return sal_True;
}
void SwHTMLTableLayout::BordersChanged( sal_uInt16 nAbsAvail, sal_Bool bRecalc )
{
bBordersChanged = sal_True;
Resize( nAbsAvail, bRecalc );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|