1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <libxml/xmlwriter.h>
#include <hintids.hxx>
#include <svl/itemiter.hxx>
#include <svl/numformat.hxx>
#include <editeng/tstpitem.hxx>
#include <editeng/lrspitem.hxx>
#include <editeng/formatbreakitem.hxx>
#include <editeng/rsiditem.hxx>
#include <editeng/colritem.hxx>
#include <officecfg/Office/Common.hxx>
#include <osl/diagnose.h>
#include <svl/zforlist.hxx>
#include <comphelper/processfactory.hxx>
#include <unotools/configmgr.hxx>
#include <sal/log.hxx>
#include <com/sun/star/i18n/WordType.hpp>
#include <com/sun/star/i18n/XBreakIterator.hpp>
#include <fmtpdsc.hxx>
#include <fmthdft.hxx>
#include <fmtcntnt.hxx>
#include <doc.hxx>
#include <docfunc.hxx>
#include <drawdoc.hxx>
#include <MarkManager.hxx>
#include <IDocumentDrawModelAccess.hxx>
#include <IDocumentUndoRedo.hxx>
#include <DocumentContentOperationsManager.hxx>
#include <DocumentSettingManager.hxx>
#include <IDocumentFieldsAccess.hxx>
#include <IDocumentState.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <IDocumentRedlineAccess.hxx>
#include <IDocumentStylePoolAccess.hxx>
#include <rootfrm.hxx>
#include <txtfrm.hxx>
#include <hints.hxx>
#include <ndtxt.hxx>
#include <pam.hxx>
#include <UndoCore.hxx>
#include <UndoAttribute.hxx>
#include <UndoInsert.hxx>
#include <pagedesc.hxx>
#include <rolbck.hxx>
#include <mvsave.hxx>
#include <txatbase.hxx>
#include <swtblfmt.hxx>
#include <charfmt.hxx>
#include <docary.hxx>
#include <paratr.hxx>
#include <redline.hxx>
#include <reffld.hxx>
#include <fmtinfmt.hxx>
#include <breakit.hxx>
#include <SwUndoFmt.hxx>
#include <UndoManager.hxx>
#include <swmodule.hxx>
#include <modcfg.hxx>
#include <frameformats.hxx>
#include <textboxhelper.hxx>
#include <memory>
using namespace ::com::sun::star::i18n;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno;
/*
* Internal functions
*/
static void SetTextFormatCollNext( SwTextFormatColl* pTextColl, const SwTextFormatColl* pDel )
{
if ( &pTextColl->GetNextTextFormatColl() == pDel )
{
pTextColl->SetNextTextFormatColl( *pTextColl );
}
}
static bool lcl_RstAttr( SwNode* pNd, void* pArgs )
{
const sw::DocumentContentOperationsManager::ParaRstFormat* pPara = static_cast<sw::DocumentContentOperationsManager::ParaRstFormat*>(pArgs);
SwContentNode* pNode = pNd->GetContentNode();
if (pPara && pPara->pLayout && pPara->pLayout->HasMergedParas()
&& pNode && pNode->GetRedlineMergeFlag() == SwNode::Merge::Hidden)
{
return true;
}
if( pNode && pNode->HasSwAttrSet() )
{
const bool bLocked = pNode->IsModifyLocked();
pNode->LockModify();
SwDoc& rDoc = pNode->GetDoc();
// remove unused attribute RES_LR_SPACE
// add list attributes
SfxItemSetFixed<
RES_PARATR_NUMRULE, RES_PARATR_NUMRULE,
RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END - 1,
RES_PAGEDESC, RES_BREAK> aSavedAttrsSet(rDoc.GetAttrPool());
const SfxItemSet* pAttrSetOfNode = pNode->GetpSwAttrSet();
std::vector<sal_uInt16> aClearWhichIds;
// restoring all paragraph list attributes
{
SfxItemSetFixed<RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END - 1> aListAttrSet( rDoc.GetAttrPool() );
aListAttrSet.Set(*pAttrSetOfNode);
if ( aListAttrSet.Count() )
{
aSavedAttrsSet.Put(aListAttrSet);
SfxItemIter aIter( aListAttrSet );
const SfxPoolItem* pItem = aIter.GetCurItem();
while( pItem )
{
aClearWhichIds.push_back( pItem->Which() );
pItem = aIter.NextItem();
}
}
}
const SfxPoolItem* pItem;
sal_uInt16 const aSavIds[3] = { RES_PAGEDESC, RES_BREAK, RES_PARATR_NUMRULE };
for (sal_uInt16 aSavId : aSavIds)
{
if (SfxItemState::SET == pAttrSetOfNode->GetItemState(aSavId, false, &pItem))
{
bool bSave = false;
switch( aSavId )
{
case RES_PAGEDESC:
bSave = nullptr != pItem->StaticWhichCast(RES_PAGEDESC).GetPageDesc();
break;
case RES_BREAK:
bSave = SvxBreak::NONE != pItem->StaticWhichCast(RES_BREAK).GetBreak();
break;
case RES_PARATR_NUMRULE:
bSave = !pItem->StaticWhichCast(RES_PARATR_NUMRULE).GetValue().isEmpty();
break;
}
if( bSave )
{
aSavedAttrsSet.Put(*pItem);
aClearWhichIds.push_back(aSavId);
}
}
}
// do not clear items directly from item set and only clear to be kept
// attributes, if no deletion item set is found.
const bool bKeepAttributes =
!pPara || !pPara->pDelSet || pPara->pDelSet->Count() == 0;
if ( bKeepAttributes )
{
pNode->ResetAttr( aClearWhichIds );
}
if( !bLocked )
pNode->UnlockModify();
if( pPara )
{
SwRegHistory aRegH( pNode, *pNode, pPara->pHistory );
if( pPara->pDelSet && pPara->pDelSet->Count() )
{
OSL_ENSURE( !bKeepAttributes,
"<lcl_RstAttr(..)> - certain attributes are kept, but not needed." );
SfxItemIter aIter( *pPara->pDelSet );
for (pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
{
if ( ( pItem->Which() != RES_PAGEDESC &&
pItem->Which() != RES_BREAK &&
pItem->Which() != RES_PARATR_NUMRULE ) ||
( aSavedAttrsSet.GetItemState( pItem->Which(), false ) != SfxItemState::SET ) )
{
pNode->ResetAttr( pItem->Which() );
}
}
}
else if( pPara->bResetAll )
pNode->ResetAllAttr();
else
pNode->ResetAttr( RES_PARATR_BEGIN, POOLATTR_END - 1 );
}
else
pNode->ResetAllAttr();
// only restore saved attributes, if needed
if (bKeepAttributes && aSavedAttrsSet.Count())
{
pNode->LockModify();
pNode->SetAttr(aSavedAttrsSet);
if( !bLocked )
pNode->UnlockModify();
}
}
return true;
}
void SwDoc::RstTextAttrs(const SwPaM &rRg, bool bInclRefToxMark,
bool bExactRange, SwRootFrame const*const pLayout)
{
SwHistory* pHst = nullptr;
SwDataChanged aTmp( rRg );
if (GetIDocumentUndoRedo().DoesUndo())
{
std::unique_ptr<SwUndoResetAttr> pUndo(new SwUndoResetAttr( rRg, RES_CHRFMT ));
pHst = &pUndo->GetHistory();
GetIDocumentUndoRedo().AppendUndo(std::move(pUndo));
}
const SwPosition *pStt = rRg.Start(), *pEnd = rRg.End();
sw::DocumentContentOperationsManager::ParaRstFormat aPara(
pStt, pEnd, pHst, nullptr, pLayout );
aPara.bInclRefToxMark = bInclRefToxMark;
aPara.bExactRange = bExactRange;
GetNodes().ForEach( pStt->nNode.GetIndex(), pEnd->nNode.GetIndex()+1,
sw::DocumentContentOperationsManager::lcl_RstTextAttr, &aPara );
getIDocumentState().SetModified();
}
void SwDoc::ResetAttrs( const SwPaM &rRg,
bool bTextAttr,
const o3tl::sorted_vector<sal_uInt16> &rAttrs,
const bool bSendDataChangedEvents,
SwRootFrame const*const pLayout)
{
SwPaM* pPam = const_cast<SwPaM*>(&rRg);
if( !bTextAttr && !rAttrs.empty() && RES_TXTATR_END > *(rAttrs.begin()) )
bTextAttr = true;
if( !rRg.HasMark() )
{
SwTextNode* pTextNd = rRg.GetPoint()->nNode.GetNode().GetTextNode();
if( !pTextNd )
return ;
pPam = new SwPaM( *rRg.GetPoint() );
SwIndex& rSt = pPam->GetPoint()->nContent;
sal_Int32 nMkPos, nPtPos = rSt.GetIndex();
// Special case: if the Cursor is located within a URL attribute, we take over it's area
SwTextAttr const*const pURLAttr(
pTextNd->GetTextAttrAt(rSt.GetIndex(), RES_TXTATR_INETFMT));
if (pURLAttr && !pURLAttr->GetINetFormat().GetValue().isEmpty())
{
nMkPos = pURLAttr->GetStart();
nPtPos = *pURLAttr->End();
}
else
{
assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is());
Boundary aBndry = g_pBreakIt->GetBreakIter()->getWordBoundary(
pTextNd->GetText(), nPtPos,
g_pBreakIt->GetLocale( pTextNd->GetLang( nPtPos ) ),
WordType::ANY_WORD /*ANYWORD_IGNOREWHITESPACES*/,
true);
if( aBndry.startPos < nPtPos && nPtPos < aBndry.endPos )
{
nMkPos = aBndry.startPos;
nPtPos = aBndry.endPos;
}
else
{
nPtPos = nMkPos = rSt.GetIndex();
if( bTextAttr )
pTextNd->DontExpandFormat( rSt );
}
}
rSt = nMkPos;
pPam->SetMark();
pPam->GetPoint()->nContent = nPtPos;
}
// #i96644#
std::optional< SwDataChanged > oDataChanged;
if ( bSendDataChangedEvents )
{
oDataChanged.emplace( *pPam );
}
SwHistory* pHst = nullptr;
if (GetIDocumentUndoRedo().DoesUndo())
{
std::unique_ptr<SwUndoResetAttr> pUndo(new SwUndoResetAttr( rRg,
bTextAttr ? sal_uInt16(RES_CONDTXTFMTCOLL) : sal_uInt16(RES_TXTFMTCOLL) ));
if( !rAttrs.empty() )
{
pUndo->SetAttrs( o3tl::sorted_vector(rAttrs) );
}
pHst = &pUndo->GetHistory();
GetIDocumentUndoRedo().AppendUndo(std::move(pUndo));
}
const SwPosition *pStt = pPam->Start(), *pEnd = pPam->End();
sw::DocumentContentOperationsManager::ParaRstFormat aPara(
pStt, pEnd, pHst, nullptr, pLayout);
// mst: not including META here; it seems attrs with CH_TXTATR are omitted
SfxItemSetFixed<RES_CHRATR_BEGIN, RES_CHRATR_END - 1,
RES_TXTATR_INETFMT, RES_TXTATR_UNKNOWN_CONTAINER,
RES_PARATR_BEGIN, RES_FRMATR_END - 1,
RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END - 1>
aDelSet(GetAttrPool());
for( auto it = rAttrs.rbegin(); it != rAttrs.rend(); ++it )
{
if( POOLATTR_END > *it )
aDelSet.Put( *GetDfltAttr( *it ));
}
if( aDelSet.Count() )
aPara.pDelSet = &aDelSet;
bool bAdd = true;
SwNodeIndex aTmpStt( pStt->nNode );
SwNodeIndex aTmpEnd( pEnd->nNode );
if( pStt->nContent.GetIndex() ) // just one part
{
// set up a later, and all CharFormatAttr -> TextFormatAttr
SwTextNode* pTNd = aTmpStt.GetNode().GetTextNode();
if( pTNd && pTNd->HasSwAttrSet() && pTNd->GetpSwAttrSet()->Count() )
{
if (pHst)
{
SwRegHistory history(pTNd, *pTNd, pHst);
pTNd->FormatToTextAttr(pTNd);
}
else
{
pTNd->FormatToTextAttr(pTNd);
}
}
++aTmpStt;
}
if( pEnd->nContent.GetIndex() == pEnd->nNode.GetNode().GetContentNode()->Len() )
{
// set up a later, and all CharFormatAttr -> TextFormatAttr
++aTmpEnd;
bAdd = false;
}
else if( pStt->nNode != pEnd->nNode || !pStt->nContent.GetIndex() )
{
SwTextNode* pTNd = aTmpEnd.GetNode().GetTextNode();
if( pTNd && pTNd->HasSwAttrSet() && pTNd->GetpSwAttrSet()->Count() )
{
if (pHst)
{
SwRegHistory history(pTNd, *pTNd, pHst);
pTNd->FormatToTextAttr(pTNd);
}
else
{
pTNd->FormatToTextAttr(pTNd);
}
}
}
if( aTmpStt < aTmpEnd )
GetNodes().ForEach( pStt->nNode, aTmpEnd, lcl_RstAttr, &aPara );
else if( !rRg.HasMark() )
{
aPara.bResetAll = false ;
::lcl_RstAttr( &pStt->nNode.GetNode(), &aPara );
aPara.bResetAll = true ;
}
if( bTextAttr )
{
if( bAdd )
++aTmpEnd;
GetNodes().ForEach( pStt->nNode, aTmpEnd, sw::DocumentContentOperationsManager::lcl_RstTextAttr, &aPara );
}
getIDocumentState().SetModified();
oDataChanged.reset(); //before delete pPam
if( pPam != &rRg )
delete pPam;
}
/// Set the rsid of the next nLen symbols of rRg to the current session number
void SwDoc::UpdateRsid( const SwPaM &rRg, const sal_Int32 nLen )
{
if (!SW_MOD()->GetModuleConfig()->IsStoreRsid())
return;
SwTextNode *pTextNode = rRg.GetPoint()->nNode.GetNode().GetTextNode();
if (!pTextNode)
{
return;
}
const sal_Int32 nStart(rRg.GetPoint()->nContent.GetIndex() - nLen);
SvxRsidItem aRsid( mnRsid, RES_CHRATR_RSID );
SfxItemSetFixed<RES_CHRATR_RSID, RES_CHRATR_RSID> aSet(GetAttrPool());
aSet.Put(aRsid);
bool const bRet(pTextNode->SetAttr(aSet, nStart,
rRg.GetPoint()->nContent.GetIndex()));
if (bRet && GetIDocumentUndoRedo().DoesUndo())
{
SwUndo *const pLastUndo = GetUndoManager().GetLastUndo();
SwUndoInsert *const pUndoInsert(dynamic_cast<SwUndoInsert*>(pLastUndo));
// this function is called after Insert so expects to find SwUndoInsert
assert(pUndoInsert);
if (pUndoInsert)
{
pUndoInsert->SetWithRsid();
}
}
}
bool SwDoc::UpdateParRsid( SwTextNode *pTextNode, sal_uInt32 nVal )
{
if (!SW_MOD()->GetModuleConfig()->IsStoreRsid())
return false;
if (!pTextNode)
{
return false;
}
SvxRsidItem aRsid( nVal ? nVal : mnRsid, RES_PARATR_RSID );
return pTextNode->SetAttr( aRsid );
}
/// Set the attribute according to the stated format.
/// If Undo is enabled, the old values is added to the Undo history.
void SwDoc::SetAttr( const SfxPoolItem& rAttr, SwFormat& rFormat )
{
SfxItemSet aSet( GetAttrPool(), rAttr.Which(), rAttr.Which() );
aSet.Put( rAttr );
SetAttr( aSet, rFormat );
}
/// Set the attribute according to the stated format.
/// If Undo is enabled, the old values is added to the Undo history.
void SwDoc::SetAttr( const SfxItemSet& rSet, SwFormat& rFormat )
{
if (GetIDocumentUndoRedo().DoesUndo())
{
SwUndoFormatAttrHelper aTmp( rFormat );
rFormat.SetFormatAttr( rSet );
if ( aTmp.GetUndo() )
{
GetIDocumentUndoRedo().AppendUndo( aTmp.ReleaseUndo() );
}
else
{
GetIDocumentUndoRedo().ClearRedo();
}
}
else
{
rFormat.SetFormatAttr( rSet );
}
// If the format is a shape, and it has a textbox, sync.
auto pShapeFormat = dynamic_cast<SwFrameFormat*>(&rFormat);
if (pShapeFormat && SwTextBoxHelper::isTextBox(pShapeFormat, RES_DRAWFRMFMT))
{
if (auto pObj = pShapeFormat->FindRealSdrObject())
{
SwTextBoxHelper::syncFlyFrameAttr(*pShapeFormat, rSet, pObj);
SwTextBoxHelper::changeAnchor(pShapeFormat, pObj);
}
}
getIDocumentState().SetModified();
}
void SwDoc::ResetAttrAtFormat( const sal_uInt16 nWhichId,
SwFormat& rChangedFormat )
{
std::unique_ptr<SwUndo> pUndo;
if (GetIDocumentUndoRedo().DoesUndo())
pUndo.reset(new SwUndoFormatResetAttr( rChangedFormat, nWhichId ));
const bool bAttrReset = rChangedFormat.ResetFormatAttr( nWhichId );
if ( bAttrReset )
{
if ( pUndo )
{
GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) );
}
getIDocumentState().SetModified();
}
}
static bool lcl_SetNewDefTabStops( SwTwips nOldWidth, SwTwips nNewWidth,
SvxTabStopItem& rChgTabStop )
{
// Set the default values of all TabStops to the new value.
// Attention: we always work with the PoolAttribute here, so that
// we don't calculate the same value on the same TabStop (pooled!) for all sets.
// We send a FormatChg to modify.
sal_uInt16 nOldCnt = rChgTabStop.Count();
if( !nOldCnt || nOldWidth == nNewWidth )
return false;
// Find the default's beginning
sal_uInt16 n;
for( n = nOldCnt; n ; --n )
if( SvxTabAdjust::Default != rChgTabStop[n - 1].GetAdjustment() )
break;
++n;
if( n < nOldCnt ) // delete the DefTabStops
rChgTabStop.Remove( n, nOldCnt - n );
return true;
}
/// Set the attribute as new default attribute in this document.
/// If Undo is enabled, the old value is added to the Undo history.
void SwDoc::SetDefault( const SfxPoolItem& rAttr )
{
SfxItemSet aSet( GetAttrPool(), rAttr.Which(), rAttr.Which() );
aSet.Put( rAttr );
SetDefault( aSet );
}
void SwDoc::SetDefault( const SfxItemSet& rSet )
{
if( !rSet.Count() )
return;
sw::BroadcastingModify aCallMod;
SwAttrSet aOld( GetAttrPool(), rSet.GetRanges() ),
aNew( GetAttrPool(), rSet.GetRanges() );
SfxItemIter aIter( rSet );
const SfxPoolItem* pItem = aIter.GetCurItem();
SfxItemPool* pSdrPool = GetAttrPool().GetSecondaryPool();
do
{
bool bCheckSdrDflt = false;
const sal_uInt16 nWhich = pItem->Which();
aOld.Put( GetAttrPool().GetDefaultItem( nWhich ) );
GetAttrPool().SetPoolDefaultItem( *pItem );
aNew.Put( GetAttrPool().GetDefaultItem( nWhich ) );
if (isCHRATR(nWhich) || isTXTATR(nWhich))
{
aCallMod.Add( mpDfltTextFormatColl.get() );
aCallMod.Add( mpDfltCharFormat.get() );
bCheckSdrDflt = nullptr != pSdrPool;
}
else if ( isPARATR(nWhich) ||
isPARATR_LIST(nWhich) )
{
aCallMod.Add( mpDfltTextFormatColl.get() );
bCheckSdrDflt = nullptr != pSdrPool;
}
else if (isGRFATR(nWhich))
{
aCallMod.Add( mpDfltGrfFormatColl.get() );
}
else if (isFRMATR(nWhich) || isDrawingLayerAttribute(nWhich) )
{
aCallMod.Add( mpDfltGrfFormatColl.get() );
aCallMod.Add( mpDfltTextFormatColl.get() );
aCallMod.Add( mpDfltFrameFormat.get() );
}
else if (isBOXATR(nWhich))
{
aCallMod.Add( mpDfltFrameFormat.get() );
}
// also copy the defaults
if( bCheckSdrDflt )
{
sal_uInt16 nSlotId = GetAttrPool().GetSlotId( nWhich );
if( 0 != nSlotId && nSlotId != nWhich )
{
sal_uInt16 nEdtWhich = pSdrPool->GetWhich( nSlotId );
if( 0 != nEdtWhich && nSlotId != nEdtWhich )
{
std::unique_ptr<SfxPoolItem> pCpy(pItem->Clone());
pCpy->SetWhich( nEdtWhich );
pSdrPool->SetPoolDefaultItem( *pCpy );
}
}
}
pItem = aIter.NextItem();
} while (pItem);
if( aNew.Count() && aCallMod.HasWriterListeners() )
{
if (GetIDocumentUndoRedo().DoesUndo())
{
GetIDocumentUndoRedo().AppendUndo( std::make_unique<SwUndoDefaultAttr>( aOld, *this ) );
}
const SvxTabStopItem* pTmpItem = aNew.GetItemIfSet( RES_PARATR_TABSTOP, false );
if( pTmpItem && pTmpItem->Count() )
{
// Set the default values of all TabStops to the new value.
// Attention: we always work with the PoolAttribute here, so that
// we don't calculate the same value on the same TabStop (pooled!) for all sets.
// We send a FormatChg to modify.
SwTwips nNewWidth = (*pTmpItem)[ 0 ].GetTabPos(),
nOldWidth = aOld.Get(RES_PARATR_TABSTOP)[ 0 ].GetTabPos();
bool bChg = false;
for (const SfxPoolItem* pItem2 : GetAttrPool().GetItemSurrogates(RES_PARATR_TABSTOP))
{
if(auto pTabStopItem = pItem2->DynamicWhichCast(RES_PARATR_TABSTOP))
bChg |= lcl_SetNewDefTabStops( nOldWidth, nNewWidth,
*const_cast<SvxTabStopItem*>(pTabStopItem) );
}
aNew.ClearItem( RES_PARATR_TABSTOP );
aOld.ClearItem( RES_PARATR_TABSTOP );
if( bChg )
{
SwFormatChg aChgFormat( mpDfltCharFormat.get() );
// notify the frames
aCallMod.CallSwClientNotify(sw::LegacyModifyHint( &aChgFormat, &aChgFormat ));
}
}
}
if( aNew.Count() && aCallMod.HasWriterListeners() )
{
SwAttrSetChg aChgOld( aOld, aOld );
SwAttrSetChg aChgNew( aNew, aNew );
aCallMod.CallSwClientNotify(sw::LegacyModifyHint( &aChgOld, &aChgNew )); // all changed are sent
}
// remove the default formats from the object again
SwIterator<SwClient, sw::BroadcastingModify> aClientIter(aCallMod);
for(SwClient* pClient = aClientIter.First(); pClient; pClient = aClientIter.Next())
aCallMod.Remove( pClient );
getIDocumentState().SetModified();
}
/// Get the default attribute in this document
const SfxPoolItem& SwDoc::GetDefault( sal_uInt16 nFormatHint ) const
{
return GetAttrPool().GetDefaultItem( nFormatHint );
}
/// Delete the formats
void SwDoc::DelCharFormat(size_t nFormat, bool bBroadcast)
{
SwCharFormat * pDel = (*mpCharFormatTable)[nFormat];
if (bBroadcast)
BroadcastStyleOperation(pDel->GetName(), SfxStyleFamily::Char,
SfxHintId::StyleSheetErased);
if (GetIDocumentUndoRedo().DoesUndo())
{
GetIDocumentUndoRedo().AppendUndo(
std::make_unique<SwUndoCharFormatDelete>(pDel, *this));
}
delete (*mpCharFormatTable)[nFormat];
mpCharFormatTable->erase(mpCharFormatTable->begin() + nFormat);
getIDocumentState().SetModified();
}
void SwDoc::DelCharFormat( SwCharFormat const *pFormat, bool bBroadcast )
{
size_t nFormat = mpCharFormatTable->GetPos( pFormat );
OSL_ENSURE( SIZE_MAX != nFormat, "Format not found," );
DelCharFormat( nFormat, bBroadcast );
}
void SwDoc::DelFrameFormat( SwFrameFormat *pFormat, bool bBroadcast )
{
if( dynamic_cast<const SwTableBoxFormat*>( pFormat) != nullptr || dynamic_cast<const SwTableLineFormat*>( pFormat) != nullptr )
{
OSL_ENSURE( false, "Format is not in the DocArray any more, "
"so it can be deleted with delete" );
delete pFormat;
}
else
{
// The format has to be in the one or the other, we'll see in which one.
if (mpFrameFormatTable->ContainsFormat(*pFormat))
{
if (bBroadcast)
BroadcastStyleOperation(pFormat->GetName(),
SfxStyleFamily::Frame,
SfxHintId::StyleSheetErased);
if (GetIDocumentUndoRedo().DoesUndo())
{
GetIDocumentUndoRedo().AppendUndo(
std::make_unique<SwUndoFrameFormatDelete>(pFormat, *this));
}
mpFrameFormatTable->erase( pFormat );
delete pFormat;
}
else
{
bool contains = GetSpzFrameFormats()->ContainsFormat(*pFormat);
OSL_ENSURE( contains, "FrameFormat not found." );
if( contains )
{
GetSpzFrameFormats()->erase( pFormat );
delete pFormat;
}
}
}
}
void SwDoc::DelTableFrameFormat( SwTableFormat *pFormat )
{
SwFrameFormats::const_iterator it = mpTableFrameFormatTable->find( pFormat );
OSL_ENSURE( it != mpTableFrameFormatTable->end(), "Format not found," );
mpTableFrameFormatTable->erase( it );
delete pFormat;
}
SwFrameFormat* SwDoc::FindFrameFormatByName( const OUString& rName ) const
{
return mpFrameFormatTable->FindFormatByName( rName );
}
/// Create the formats
SwFlyFrameFormat *SwDoc::MakeFlyFrameFormat( const OUString &rFormatName,
SwFrameFormat *pDerivedFrom )
{
SwFlyFrameFormat *pFormat = new SwFlyFrameFormat( GetAttrPool(), rFormatName, pDerivedFrom );
GetSpzFrameFormats()->push_back(pFormat);
getIDocumentState().SetModified();
return pFormat;
}
SwDrawFrameFormat *SwDoc::MakeDrawFrameFormat( const OUString &rFormatName,
SwFrameFormat *pDerivedFrom )
{
SwDrawFrameFormat *pFormat = new SwDrawFrameFormat( GetAttrPool(), rFormatName, pDerivedFrom);
GetSpzFrameFormats()->push_back(pFormat);
getIDocumentState().SetModified();
return pFormat;
}
size_t SwDoc::GetTableFrameFormatCount(bool bUsed) const
{
if (!bUsed)
{
return mpTableFrameFormatTable->size();
}
SwAutoFormatGetDocNode aGetHt(&GetNodes());
size_t nCount = 0;
for (SwFrameFormat* const & pFormat : *mpTableFrameFormatTable)
{
if (!pFormat->GetInfo(aGetHt))
nCount++;
}
return nCount;
}
SwFrameFormat& SwDoc::GetTableFrameFormat(size_t nFormat, bool bUsed) const
{
if (!bUsed)
{
return *((*mpTableFrameFormatTable)[nFormat]);
}
SwAutoFormatGetDocNode aGetHt(&GetNodes());
size_t index = 0;
for (SwFrameFormat* const & pFormat : *mpTableFrameFormatTable)
{
if (!pFormat->GetInfo(aGetHt))
{
if (index == nFormat)
return *pFormat;
else
index++;
}
}
throw std::out_of_range("Format index out of range.");
}
SwTableFormat* SwDoc::MakeTableFrameFormat( const OUString &rFormatName,
SwFrameFormat *pDerivedFrom )
{
SwTableFormat* pFormat = new SwTableFormat( GetAttrPool(), rFormatName, pDerivedFrom );
mpTableFrameFormatTable->push_back( pFormat );
getIDocumentState().SetModified();
return pFormat;
}
SwFrameFormat *SwDoc::MakeFrameFormat(const OUString &rFormatName,
SwFrameFormat *pDerivedFrom,
bool bBroadcast, bool bAuto)
{
SwFrameFormat *pFormat = new SwFrameFormat( GetAttrPool(), rFormatName, pDerivedFrom );
pFormat->SetAuto(bAuto);
mpFrameFormatTable->push_back( pFormat );
getIDocumentState().SetModified();
if (GetIDocumentUndoRedo().DoesUndo())
{
GetIDocumentUndoRedo().AppendUndo(
std::make_unique<SwUndoFrameFormatCreate>(pFormat, pDerivedFrom, *this));
}
if (bBroadcast)
{
BroadcastStyleOperation(rFormatName, SfxStyleFamily::Frame,
SfxHintId::StyleSheetCreated);
}
return pFormat;
}
SwFormat *SwDoc::MakeFrameFormat_(const OUString &rFormatName,
SwFormat *pDerivedFrom,
bool bBroadcast, bool bAuto)
{
SwFrameFormat *pFrameFormat = dynamic_cast<SwFrameFormat*>(pDerivedFrom);
pFrameFormat = MakeFrameFormat( rFormatName, pFrameFormat, bBroadcast, bAuto );
return pFrameFormat;
}
SwCharFormat *SwDoc::MakeCharFormat( const OUString &rFormatName,
SwCharFormat *pDerivedFrom,
bool bBroadcast )
{
SwCharFormat *pFormat = new SwCharFormat( GetAttrPool(), rFormatName, pDerivedFrom );
mpCharFormatTable->insert( pFormat );
pFormat->SetAuto(false);
getIDocumentState().SetModified();
if (GetIDocumentUndoRedo().DoesUndo())
{
GetIDocumentUndoRedo().AppendUndo(
std::make_unique<SwUndoCharFormatCreate>(pFormat, pDerivedFrom, *this));
}
if (bBroadcast)
{
BroadcastStyleOperation(rFormatName, SfxStyleFamily::Char,
SfxHintId::StyleSheetCreated);
}
return pFormat;
}
SwFormat *SwDoc::MakeCharFormat_(const OUString &rFormatName,
SwFormat *pDerivedFrom,
bool bBroadcast, bool /*bAuto*/)
{
SwCharFormat *pCharFormat = dynamic_cast<SwCharFormat*>(pDerivedFrom);
pCharFormat = MakeCharFormat( rFormatName, pCharFormat, bBroadcast );
return pCharFormat;
}
/// Create the FormatCollections
SwTextFormatColl* SwDoc::MakeTextFormatColl( const OUString &rFormatName,
SwTextFormatColl *pDerivedFrom,
bool bBroadcast)
{
SwTextFormatColl *pFormatColl = new SwTextFormatColl( GetAttrPool(), rFormatName,
pDerivedFrom );
mpTextFormatCollTable->push_back(pFormatColl);
pFormatColl->SetAuto(false);
getIDocumentState().SetModified();
if (GetIDocumentUndoRedo().DoesUndo())
{
GetIDocumentUndoRedo().AppendUndo(
std::make_unique<SwUndoTextFormatCollCreate>(pFormatColl, pDerivedFrom,
*this));
}
if (bBroadcast)
BroadcastStyleOperation(rFormatName, SfxStyleFamily::Para,
SfxHintId::StyleSheetCreated);
return pFormatColl;
}
SwFormat *SwDoc::MakeTextFormatColl_(const OUString &rFormatName,
SwFormat *pDerivedFrom,
bool bBroadcast, bool /*bAuto*/)
{
SwTextFormatColl *pTextFormatColl = dynamic_cast<SwTextFormatColl*>(pDerivedFrom);
pTextFormatColl = MakeTextFormatColl( rFormatName, pTextFormatColl, bBroadcast );
return pTextFormatColl;
}
//FEATURE::CONDCOLL
SwConditionTextFormatColl* SwDoc::MakeCondTextFormatColl( const OUString &rFormatName,
SwTextFormatColl *pDerivedFrom,
bool bBroadcast)
{
SwConditionTextFormatColl*pFormatColl = new SwConditionTextFormatColl( GetAttrPool(),
rFormatName, pDerivedFrom );
mpTextFormatCollTable->push_back(pFormatColl);
pFormatColl->SetAuto(false);
getIDocumentState().SetModified();
if (GetIDocumentUndoRedo().DoesUndo())
{
GetIDocumentUndoRedo().AppendUndo(
std::make_unique<SwUndoCondTextFormatCollCreate>(pFormatColl, pDerivedFrom,
*this));
}
if (bBroadcast)
BroadcastStyleOperation(rFormatName, SfxStyleFamily::Para,
SfxHintId::StyleSheetCreated);
return pFormatColl;
}
//FEATURE::CONDCOLL
// GRF
SwGrfFormatColl* SwDoc::MakeGrfFormatColl( const OUString &rFormatName,
SwGrfFormatColl *pDerivedFrom )
{
SwGrfFormatColl *pFormatColl = new SwGrfFormatColl( GetAttrPool(), rFormatName,
pDerivedFrom );
mpGrfFormatCollTable->push_back( pFormatColl );
pFormatColl->SetAuto(false);
getIDocumentState().SetModified();
return pFormatColl;
}
void SwDoc::DelTextFormatColl(size_t nFormatColl, bool bBroadcast)
{
OSL_ENSURE( nFormatColl, "Remove of Coll 0." );
// Who has the to-be-deleted as their Next?
SwTextFormatColl *pDel = (*mpTextFormatCollTable)[nFormatColl];
if( mpDfltTextFormatColl.get() == pDel )
return; // never delete default!
if (bBroadcast)
BroadcastStyleOperation(pDel->GetName(), SfxStyleFamily::Para,
SfxHintId::StyleSheetErased);
if (GetIDocumentUndoRedo().DoesUndo())
{
std::unique_ptr<SwUndoTextFormatCollDelete> pUndo;
if (RES_CONDTXTFMTCOLL == pDel->Which())
{
pUndo.reset(new SwUndoCondTextFormatCollDelete(pDel, *this));
}
else
{
pUndo.reset(new SwUndoTextFormatCollDelete(pDel, *this));
}
GetIDocumentUndoRedo().AppendUndo(std::move(pUndo));
}
// Remove the FormatColl
mpTextFormatCollTable->erase(mpTextFormatCollTable->begin() + nFormatColl);
// Correct next
for( SwTextFormatColls::const_iterator it = mpTextFormatCollTable->begin() + 1; it != mpTextFormatCollTable->end(); ++it )
SetTextFormatCollNext( *it, pDel );
delete pDel;
getIDocumentState().SetModified();
}
void SwDoc::DelTextFormatColl( SwTextFormatColl const *pColl, bool bBroadcast )
{
size_t nFormat = mpTextFormatCollTable->GetPos( pColl );
OSL_ENSURE( SIZE_MAX != nFormat, "Collection not found," );
DelTextFormatColl( nFormat, bBroadcast );
}
static bool lcl_SetTextFormatColl( SwNode* pNode, void* pArgs )
{
SwContentNode* pCNd = pNode->GetTextNode();
if( pCNd == nullptr)
return true;
sw::DocumentContentOperationsManager::ParaRstFormat* pPara = static_cast<sw::DocumentContentOperationsManager::ParaRstFormat*>(pArgs);
if (pPara->pLayout && pPara->pLayout->HasMergedParas())
{
if (pCNd->GetRedlineMergeFlag() == SwNode::Merge::Hidden)
{
return true;
}
if (pCNd->IsTextNode())
{
pCNd = sw::GetParaPropsNode(*pPara->pLayout, SwNodeIndex(*pCNd));
}
}
SwTextFormatColl* pFormat = static_cast<SwTextFormatColl*>(pPara->pFormatColl);
if ( pPara->bReset )
{
lcl_RstAttr(pCNd, pPara);
// #i62675# check, if paragraph style has changed
if ( pPara->bResetListAttrs &&
pFormat != pCNd->GetFormatColl() &&
pFormat->GetItemState( RES_PARATR_NUMRULE ) == SfxItemState::SET )
{
// Check, if the list style of the paragraph will change.
bool bChangeOfListStyleAtParagraph( true );
SwTextNode& rTNd(dynamic_cast<SwTextNode&>(*pCNd));
{
SwNumRule* pNumRuleAtParagraph(rTNd.GetNumRule());
if ( pNumRuleAtParagraph )
{
const SwNumRuleItem& rNumRuleItemAtParagraphStyle =
pFormat->GetNumRule();
if ( rNumRuleItemAtParagraphStyle.GetValue() ==
pNumRuleAtParagraph->GetName() )
{
bChangeOfListStyleAtParagraph = false;
}
}
}
if ( bChangeOfListStyleAtParagraph )
{
std::unique_ptr< SwRegHistory > pRegH;
if ( pPara->pHistory )
{
pRegH.reset(new SwRegHistory(&rTNd, rTNd, pPara->pHistory));
}
pCNd->ResetAttr( RES_PARATR_NUMRULE );
// reset all list attributes
pCNd->ResetAttr( RES_PARATR_LIST_LEVEL );
pCNd->ResetAttr( RES_PARATR_LIST_ISRESTART );
pCNd->ResetAttr( RES_PARATR_LIST_RESTARTVALUE );
pCNd->ResetAttr( RES_PARATR_LIST_ISCOUNTED );
pCNd->ResetAttr( RES_PARATR_LIST_ID );
}
}
}
// add to History so that old data is saved, if necessary
if( pPara->pHistory )
pPara->pHistory->Add( pCNd->GetFormatColl(), pCNd->GetIndex(),
SwNodeType::Text );
pCNd->ChgFormatColl( pFormat );
pPara->nWhich++;
return true;
}
bool SwDoc::SetTextFormatColl(const SwPaM &rRg,
SwTextFormatColl *pFormat,
const bool bReset,
const bool bResetListAttrs,
SwRootFrame const*const pLayout)
{
SwDataChanged aTmp( rRg );
const SwPosition *pStt = rRg.Start(), *pEnd = rRg.End();
SwHistory* pHst = nullptr;
bool bRet = true;
if (GetIDocumentUndoRedo().DoesUndo())
{
std::unique_ptr<SwUndoFormatColl> pUndo(new SwUndoFormatColl( rRg, pFormat,
bReset,
bResetListAttrs ));
pHst = pUndo->GetHistory();
GetIDocumentUndoRedo().AppendUndo(std::move(pUndo));
}
sw::DocumentContentOperationsManager::ParaRstFormat aPara(
pStt, pEnd, pHst, nullptr, pLayout);
aPara.pFormatColl = pFormat;
aPara.bReset = bReset;
// #i62675#
aPara.bResetListAttrs = bResetListAttrs;
GetNodes().ForEach( pStt->nNode.GetIndex(), pEnd->nNode.GetIndex()+1,
lcl_SetTextFormatColl, &aPara );
if( !aPara.nWhich )
bRet = false; // didn't find a valid Node
if (bRet)
{
getIDocumentState().SetModified();
}
return bRet;
}
/// Copy the formats to itself
SwFormat* SwDoc::CopyFormat( const SwFormat& rFormat,
const SwFormatsBase& rFormatArr,
FNCopyFormat fnCopyFormat, const SwFormat& rDfltFormat )
{
// It's no autoformat, default format or collection format,
// then search for it.
if( !rFormat.IsAuto() || !rFormat.GetRegisteredIn() )
for( size_t n = 0; n < rFormatArr.GetFormatCount(); ++n )
{
// Does the Doc already contain the template?
if( rFormatArr.GetFormat(n)->GetName()==rFormat.GetName() )
return rFormatArr.GetFormat(n);
}
// Search for the "parent" first
SwFormat* pParent = const_cast<SwFormat*>(&rDfltFormat);
if( rFormat.DerivedFrom() && pParent != rFormat.DerivedFrom() )
pParent = CopyFormat( *rFormat.DerivedFrom(), rFormatArr,
fnCopyFormat, rDfltFormat );
// Create the format and copy the attributes
// #i40550#
SwFormat* pNewFormat = (this->*fnCopyFormat)( rFormat.GetName(), pParent, false, true );
pNewFormat->SetAuto( rFormat.IsAuto() );
pNewFormat->CopyAttrs( rFormat ); // copy the attributes
pNewFormat->SetPoolFormatId( rFormat.GetPoolFormatId() );
pNewFormat->SetPoolHelpId( rFormat.GetPoolHelpId() );
// Always set the HelpFile Id to default!
pNewFormat->SetPoolHlpFileId( UCHAR_MAX );
return pNewFormat;
}
/// copy the frame format
SwFrameFormat* SwDoc::CopyFrameFormat( const SwFrameFormat& rFormat )
{
return static_cast<SwFrameFormat*>(CopyFormat( rFormat, *GetFrameFormats(), &SwDoc::MakeFrameFormat_,
*GetDfltFrameFormat() ));
}
/// copy the char format
SwCharFormat* SwDoc::CopyCharFormat( const SwCharFormat& rFormat )
{
return static_cast<SwCharFormat*>(CopyFormat( rFormat, *GetCharFormats(),
&SwDoc::MakeCharFormat_,
*GetDfltCharFormat() ));
}
/// copy TextNodes
SwTextFormatColl* SwDoc::CopyTextColl( const SwTextFormatColl& rColl )
{
SwTextFormatColl* pNewColl = FindTextFormatCollByName( rColl.GetName() );
if( pNewColl )
return pNewColl;
// search for the "parent" first
SwTextFormatColl* pParent = mpDfltTextFormatColl.get();
if( pParent != rColl.DerivedFrom() )
pParent = CopyTextColl( *static_cast<SwTextFormatColl*>(rColl.DerivedFrom()) );
//FEATURE::CONDCOLL
if( RES_CONDTXTFMTCOLL == rColl.Which() )
{
pNewColl = new SwConditionTextFormatColl( GetAttrPool(), rColl.GetName(),
pParent);
mpTextFormatCollTable->push_back( pNewColl );
pNewColl->SetAuto(false);
getIDocumentState().SetModified();
// copy the conditions
static_cast<SwConditionTextFormatColl*>(pNewColl)->SetConditions(
static_cast<const SwConditionTextFormatColl&>(rColl).GetCondColls() );
}
else
//FEATURE::CONDCOLL
pNewColl = MakeTextFormatColl( rColl.GetName(), pParent );
// copy the auto formats or the attributes
pNewColl->CopyAttrs( rColl );
if(rColl.IsAssignedToListLevelOfOutlineStyle())
pNewColl->AssignToListLevelOfOutlineStyle(rColl.GetAssignedOutlineStyleLevel());
pNewColl->SetPoolFormatId( rColl.GetPoolFormatId() );
pNewColl->SetPoolHelpId( rColl.GetPoolHelpId() );
// Always set the HelpFile Id to default!
pNewColl->SetPoolHlpFileId( UCHAR_MAX );
if( &rColl.GetNextTextFormatColl() != &rColl )
pNewColl->SetNextTextFormatColl( *CopyTextColl( rColl.GetNextTextFormatColl() ));
// create the NumRule if necessary
if( this != rColl.GetDoc() )
{
const SwNumRuleItem* pItem = pNewColl->GetItemIfSet( RES_PARATR_NUMRULE,
false );
if( pItem )
{
const OUString& rName = pItem->GetValue();
if( !rName.isEmpty() )
{
const SwNumRule* pRule = rColl.GetDoc()->FindNumRulePtr( rName );
if( pRule && !pRule->IsAutoRule() )
{
SwNumRule* pDestRule = FindNumRulePtr( rName );
if( pDestRule )
pDestRule->SetInvalidRule( true );
else
MakeNumRule( rName, pRule );
}
}
}
}
return pNewColl;
}
/// copy the graphic nodes
SwGrfFormatColl* SwDoc::CopyGrfColl( const SwGrfFormatColl& rColl )
{
SwGrfFormatColl* pNewColl = mpGrfFormatCollTable->FindFormatByName( rColl.GetName() );
if( pNewColl )
return pNewColl;
// Search for the "parent" first
SwGrfFormatColl* pParent = mpDfltGrfFormatColl.get();
if( pParent != rColl.DerivedFrom() )
pParent = CopyGrfColl( *static_cast<SwGrfFormatColl*>(rColl.DerivedFrom()) );
// if not, copy them
pNewColl = MakeGrfFormatColl( rColl.GetName(), pParent );
// copy the attributes
pNewColl->CopyAttrs( rColl );
pNewColl->SetPoolFormatId( rColl.GetPoolFormatId() );
pNewColl->SetPoolHelpId( rColl.GetPoolHelpId() );
// Always set the HelpFile Id to default!
pNewColl->SetPoolHlpFileId( UCHAR_MAX );
return pNewColl;
}
void SwDoc::CopyFormatArr( const SwFormatsBase& rSourceArr,
SwFormatsBase const & rDestArr,
FNCopyFormat fnCopyFormat,
SwFormat& rDfltFormat )
{
SwFormat* pSrc, *pDest;
// 1st step: Create all formats (skip the 0th - it's the default one)
for( size_t nSrc = rSourceArr.GetFormatCount(); nSrc > 1; )
{
pSrc = rSourceArr.GetFormat( --nSrc );
if( pSrc->IsDefault() || pSrc->IsAuto() )
continue;
if( nullptr == rDestArr.FindFormatByName( pSrc->GetName() ) )
{
if( RES_CONDTXTFMTCOLL == pSrc->Which() )
MakeCondTextFormatColl( pSrc->GetName(), static_cast<SwTextFormatColl*>(&rDfltFormat) );
else
// #i40550#
(this->*fnCopyFormat)( pSrc->GetName(), &rDfltFormat, false, true );
}
}
// 2nd step: Copy all attributes, set the right parents
for( size_t nSrc = rSourceArr.GetFormatCount(); nSrc > 1; )
{
pSrc = rSourceArr.GetFormat( --nSrc );
if( pSrc->IsDefault() || pSrc->IsAuto() )
continue;
pDest = rDestArr.FindFormatByName( pSrc->GetName() );
pDest->SetAuto(false);
pDest->DelDiffs( *pSrc );
// #i94285#: existing <SwFormatPageDesc> instance, before copying attributes
const SwFormatPageDesc* pItem;
if( &GetAttrPool() != pSrc->GetAttrSet().GetPool()
&& (pItem = pSrc->GetAttrSet().GetItemIfSet( RES_PAGEDESC, false ))
&& pItem->GetPageDesc() )
{
SwFormatPageDesc aPageDesc( *pItem );
const OUString& rNm = aPageDesc.GetPageDesc()->GetName();
SwPageDesc* pPageDesc = FindPageDesc( rNm );
if( !pPageDesc )
{
pPageDesc = MakePageDesc(rNm);
}
aPageDesc.RegisterToPageDesc( *pPageDesc );
SwAttrSet aTmpAttrSet( pSrc->GetAttrSet() );
aTmpAttrSet.Put( aPageDesc );
pDest->SetFormatAttr( aTmpAttrSet );
}
else
{
pDest->SetFormatAttr( pSrc->GetAttrSet() );
}
pDest->SetPoolFormatId( pSrc->GetPoolFormatId() );
pDest->SetPoolHelpId( pSrc->GetPoolHelpId() );
// Always set the HelpFile Id to default!
pDest->SetPoolHlpFileId( UCHAR_MAX );
if( pSrc->DerivedFrom() )
pDest->SetDerivedFrom( rDestArr.FindFormatByName(
pSrc->DerivedFrom()->GetName() ) );
if( RES_TXTFMTCOLL == pSrc->Which() ||
RES_CONDTXTFMTCOLL == pSrc->Which() )
{
SwTextFormatColl* pSrcColl = static_cast<SwTextFormatColl*>(pSrc),
* pDstColl = static_cast<SwTextFormatColl*>(pDest);
if( &pSrcColl->GetNextTextFormatColl() != pSrcColl )
pDstColl->SetNextTextFormatColl(
*static_cast<SwTextFormatColl*>(rDestArr.FindFormatByName( pSrcColl->GetNextTextFormatColl().GetName() )) );
if(pSrcColl->IsAssignedToListLevelOfOutlineStyle())
pDstColl->AssignToListLevelOfOutlineStyle(pSrcColl->GetAssignedOutlineStyleLevel());
//FEATURE::CONDCOLL
if( RES_CONDTXTFMTCOLL == pSrc->Which() )
{
if (pDstColl->Which() != RES_CONDTXTFMTCOLL)
{
// Target already had a style with a matching name, but it's not a conditional
// style, then don't copy the conditions.
continue;
}
// Copy the conditions, but delete the old ones first!
static_cast<SwConditionTextFormatColl*>(pDstColl)->SetConditions(
static_cast<SwConditionTextFormatColl*>(pSrc)->GetCondColls() );
}
//FEATURE::CONDCOLL
}
}
}
void SwDoc::CopyPageDescHeaderFooterImpl( bool bCpyHeader,
const SwFrameFormat& rSrcFormat, SwFrameFormat& rDestFormat )
{
// Treat the header and footer attributes in the right way:
// Copy content nodes across documents!
sal_uInt16 nAttr = bCpyHeader ? sal_uInt16(RES_HEADER) : sal_uInt16(RES_FOOTER);
const SfxPoolItem* pItem;
if( SfxItemState::SET != rSrcFormat.GetAttrSet().GetItemState( nAttr, false, &pItem ))
return ;
// The header only contains the reference to the format from the other document!
std::unique_ptr<SfxPoolItem> pNewItem(pItem->Clone());
SwFrameFormat* pOldFormat;
if( bCpyHeader )
pOldFormat = pNewItem->StaticWhichCast(RES_HEADER).GetHeaderFormat();
else
pOldFormat = pNewItem->StaticWhichCast(RES_FOOTER).GetFooterFormat();
if( !pOldFormat )
return;
SwFrameFormat* pNewFormat = new SwFrameFormat( GetAttrPool(), "CpyDesc",
GetDfltFrameFormat() );
pNewFormat->CopyAttrs( *pOldFormat );
if( const SwFormatContent* pContent = pNewFormat->GetAttrSet().GetItemIfSet(
RES_CNTNT, false ) )
{
if( pContent->GetContentIdx() )
{
SwNodeIndex aTmpIdx( GetNodes().GetEndOfAutotext() );
const SwNodes& rSrcNds = rSrcFormat.GetDoc()->GetNodes();
SwStartNode* pSttNd = SwNodes::MakeEmptySection( aTmpIdx,
bCpyHeader
? SwHeaderStartNode
: SwFooterStartNode );
const SwNode& rCSttNd = pContent->GetContentIdx()->GetNode();
SwNodeRange aRg( rCSttNd, SwNodeOffset(0), *rCSttNd.EndOfSectionNode() );
aTmpIdx = *pSttNd->EndOfSectionNode();
rSrcNds.Copy_( aRg, aTmpIdx );
aTmpIdx = *pSttNd;
rSrcFormat.GetDoc()->GetDocumentContentOperationsManager().CopyFlyInFlyImpl(aRg, nullptr, aTmpIdx);
// TODO: investigate calling CopyWithFlyInFly?
SwPaM const source(aRg.aStart, aRg.aEnd);
SwPosition dest(aTmpIdx);
sw::CopyBookmarks(source, dest);
pNewFormat->SetFormatAttr( SwFormatContent( pSttNd ));
}
else
pNewFormat->ResetFormatAttr( RES_CNTNT );
}
if( bCpyHeader )
pNewItem->StaticWhichCast(RES_HEADER).RegisterToFormat(*pNewFormat);
else
pNewItem->StaticWhichCast(RES_FOOTER).RegisterToFormat(*pNewFormat);
rDestFormat.SetFormatAttr( *pNewItem );
}
void SwDoc::CopyPageDesc( const SwPageDesc& rSrcDesc, SwPageDesc& rDstDesc,
bool bCopyPoolIds )
{
bool bNotifyLayout = false;
SwRootFrame* pTmpRoot = getIDocumentLayoutAccess().GetCurrentLayout();
rDstDesc.SetLandscape( rSrcDesc.GetLandscape() );
rDstDesc.SetNumType( rSrcDesc.GetNumType() );
if( rDstDesc.ReadUseOn() != rSrcDesc.ReadUseOn() )
{
rDstDesc.WriteUseOn( rSrcDesc.ReadUseOn() );
bNotifyLayout = true;
}
if( bCopyPoolIds )
{
rDstDesc.SetPoolFormatId( rSrcDesc.GetPoolFormatId() );
rDstDesc.SetPoolHelpId( rSrcDesc.GetPoolHelpId() );
// Always set the HelpFile Id to default!
rDstDesc.SetPoolHlpFileId( UCHAR_MAX );
}
if( rSrcDesc.GetFollow() != &rSrcDesc )
{
const SwPageDesc* pSrcFollow = rSrcDesc.GetFollow();
SwPageDesc* pFollow = FindPageDesc( pSrcFollow->GetName() );
if( !pFollow )
{
// copy
pFollow = MakePageDesc( pSrcFollow->GetName() );
CopyPageDesc( *pSrcFollow, *pFollow );
}
rDstDesc.SetFollow( pFollow );
bNotifyLayout = true;
}
// the header and footer attributes are copied separately
// the content sections have to be copied in their entirety
{
SfxItemSet aAttrSet( rSrcDesc.GetMaster().GetAttrSet() );
aAttrSet.ClearItem( RES_HEADER );
aAttrSet.ClearItem( RES_FOOTER );
rDstDesc.GetMaster().DelDiffs( aAttrSet );
rDstDesc.GetMaster().SetFormatAttr( aAttrSet );
aAttrSet.ClearItem();
aAttrSet.Put( rSrcDesc.GetLeft().GetAttrSet() );
aAttrSet.ClearItem( RES_HEADER );
aAttrSet.ClearItem( RES_FOOTER );
rDstDesc.GetLeft().DelDiffs( aAttrSet );
rDstDesc.GetLeft().SetFormatAttr( aAttrSet );
aAttrSet.ClearItem();
aAttrSet.Put( rSrcDesc.GetFirstMaster().GetAttrSet() );
aAttrSet.ClearItem( RES_HEADER );
aAttrSet.ClearItem( RES_FOOTER );
rDstDesc.GetFirstMaster().DelDiffs( aAttrSet );
rDstDesc.GetFirstMaster().SetFormatAttr( aAttrSet );
aAttrSet.ClearItem();
aAttrSet.Put( rSrcDesc.GetFirstLeft().GetAttrSet() );
aAttrSet.ClearItem( RES_HEADER );
aAttrSet.ClearItem( RES_FOOTER );
rDstDesc.GetFirstLeft().DelDiffs( aAttrSet );
rDstDesc.GetFirstLeft().SetFormatAttr( aAttrSet );
}
CopyHeader( rSrcDesc.GetMaster(), rDstDesc.GetMaster() );
CopyFooter( rSrcDesc.GetMaster(), rDstDesc.GetMaster() );
if( !rDstDesc.IsHeaderShared() )
CopyHeader( rSrcDesc.GetLeft(), rDstDesc.GetLeft() );
else
rDstDesc.GetLeft().SetFormatAttr( rDstDesc.GetMaster().GetHeader() );
if( !rDstDesc.IsFirstShared() )
{
CopyHeader( rSrcDesc.GetFirstMaster(), rDstDesc.GetFirstMaster() );
rDstDesc.GetFirstLeft().SetFormatAttr(rDstDesc.GetFirstMaster().GetHeader());
}
else
{
rDstDesc.GetFirstMaster().SetFormatAttr( rDstDesc.GetMaster().GetHeader() );
rDstDesc.GetFirstLeft().SetFormatAttr(rDstDesc.GetLeft().GetHeader());
}
if( !rDstDesc.IsFooterShared() )
CopyFooter( rSrcDesc.GetLeft(), rDstDesc.GetLeft() );
else
rDstDesc.GetLeft().SetFormatAttr( rDstDesc.GetMaster().GetFooter() );
if( !rDstDesc.IsFirstShared() )
{
CopyFooter( rSrcDesc.GetFirstMaster(), rDstDesc.GetFirstMaster() );
rDstDesc.GetFirstLeft().SetFormatAttr(rDstDesc.GetFirstMaster().GetFooter());
}
else
{
rDstDesc.GetFirstMaster().SetFormatAttr( rDstDesc.GetMaster().GetFooter() );
rDstDesc.GetFirstLeft().SetFormatAttr(rDstDesc.GetLeft().GetFooter());
}
if( bNotifyLayout && pTmpRoot )
{
for( auto aLayout : GetAllLayouts() )
aLayout->AllCheckPageDescs();
}
// If foot notes change the pages have to be triggered
if( !(rDstDesc.GetFootnoteInfo() == rSrcDesc.GetFootnoteInfo()) )
{
sw::PageFootnoteHint aHint;
rDstDesc.SetFootnoteInfo( rSrcDesc.GetFootnoteInfo() );
rDstDesc.GetMaster().CallSwClientNotify(aHint);
rDstDesc.GetLeft().CallSwClientNotify(aHint);
rDstDesc.GetFirstMaster().CallSwClientNotify(aHint);
rDstDesc.GetFirstLeft().CallSwClientNotify(aHint);
}
// Copy the stashed formats as well between the page descriptors...
for (bool bFirst : { true, false })
for (bool bLeft : { true, false })
for (bool bHeader : { true, false })
{
if (!bLeft && !bFirst)
continue;
if (auto pStashedFormat = rSrcDesc.GetStashedFrameFormat(bHeader, bLeft, bFirst))
rDstDesc.StashFrameFormat(*pStashedFormat, bHeader, bLeft, bFirst);
}
}
void SwDoc::ReplaceStyles( const SwDoc& rSource, bool bIncludePageStyles )
{
::sw::UndoGuard const undoGuard(GetIDocumentUndoRedo());
CopyFormatArr( *rSource.mpCharFormatTable, *mpCharFormatTable,
&SwDoc::MakeCharFormat_, *mpDfltCharFormat );
CopyFormatArr( *rSource.mpFrameFormatTable, *mpFrameFormatTable,
&SwDoc::MakeFrameFormat_, *mpDfltFrameFormat );
CopyFormatArr( *rSource.mpTextFormatCollTable, *mpTextFormatCollTable,
&SwDoc::MakeTextFormatColl_, *mpDfltTextFormatColl );
//To-Do:
// a) in rtf export don't export our hideous pgdsctbl
// extension to rtf anymore
// b) in sd rtf import (View::InsertData) don't use
// a super-fragile test for mere presence of \trowd to
// indicate import of rtf into a table
// c) then drop use of bIncludePageStyles
if (bIncludePageStyles)
{
// and now the page templates
SwPageDescs::size_type nCnt = rSource.m_PageDescs.size();
if( nCnt )
{
// a different Doc -> Number formatter needs to be merged
SwTableNumFormatMerge aTNFM( rSource, *this );
// 1st step: Create all formats (skip the 0th - it's the default!)
while( nCnt )
{
const SwPageDesc &rSrc = *rSource.m_PageDescs[ --nCnt ];
if( nullptr == FindPageDesc( rSrc.GetName() ) )
MakePageDesc( rSrc.GetName() );
}
// 2nd step: Copy all attributes, set the right parents
for (SwPageDescs::size_type i = rSource.m_PageDescs.size(); i; )
{
const SwPageDesc &rSrc = *rSource.m_PageDescs[ --i ];
SwPageDesc* pDesc = FindPageDesc( rSrc.GetName() );
CopyPageDesc( rSrc, *pDesc);
}
}
}
// then there are the numbering templates
const SwNumRuleTable::size_type nCnt = rSource.GetNumRuleTable().size();
if( nCnt )
{
const SwNumRuleTable& rArr = rSource.GetNumRuleTable();
for( SwNumRuleTable::size_type n = 0; n < nCnt; ++n )
{
const SwNumRule& rR = *rArr[ n ];
SwNumRule* pNew = FindNumRulePtr( rR.GetName());
if( pNew )
pNew->CopyNumRule(*this, rR);
else
{
if( !rR.IsAutoRule() )
MakeNumRule( rR.GetName(), &rR );
else
{
// as we reset all styles, there shouldn't be any unknown
// automatic SwNumRules, because all should have been
// created by the style copying!
// So just warn and ignore.
SAL_WARN( "sw.core", "Found unknown auto SwNumRule during reset!" );
}
}
}
}
if (undoGuard.UndoWasEnabled())
{
// nodes array was modified!
GetIDocumentUndoRedo().DelAllUndoObj();
}
getIDocumentState().SetModified();
}
void SwDoc::MoveLeftMargin(const SwPaM& rPam, bool bRight, bool bModulus,
SwRootFrame const*const pLayout)
{
SwHistory* pHistory = nullptr;
if (GetIDocumentUndoRedo().DoesUndo())
{
std::unique_ptr<SwUndoMoveLeftMargin> pUndo(new SwUndoMoveLeftMargin( rPam, bRight,
bModulus ));
pHistory = &pUndo->GetHistory();
GetIDocumentUndoRedo().AppendUndo( std::move(pUndo) );
}
const SvxTabStopItem& rTabItem = GetDefault( RES_PARATR_TABSTOP );
const sal_Int32 nDefDist = rTabItem.Count() ? rTabItem[0].GetTabPos() : 1134;
const SwPosition &rStt = *rPam.Start(), &rEnd = *rPam.End();
SwNodeIndex aIdx( rStt.nNode );
while( aIdx <= rEnd.nNode )
{
SwTextNode* pTNd = aIdx.GetNode().GetTextNode();
if( pTNd )
{
pTNd = sw::GetParaPropsNode(*pLayout, aIdx);
SvxLRSpaceItem aLS(pTNd->SwContentNode::GetAttr(RES_LR_SPACE));
// #i93873# See also lcl_MergeListLevelIndentAsLRSpaceItem in thints.cxx
if ( pTNd->AreListLevelIndentsApplicable() )
{
const SwNumRule* pRule = pTNd->GetNumRule();
if ( pRule )
{
const int nListLevel = pTNd->GetActualListLevel();
if ( nListLevel >= 0 )
{
const SwNumFormat& rFormat = pRule->Get(o3tl::narrowing<sal_uInt16>(nListLevel));
if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
{
aLS.SetTextLeft( rFormat.GetIndentAt() );
aLS.SetTextFirstLineOffset( static_cast<short>(rFormat.GetFirstLineIndent()) );
}
}
}
}
tools::Long nNext = aLS.GetTextLeft();
if( bModulus )
nNext = ( nNext / nDefDist ) * nDefDist;
if( bRight )
nNext += nDefDist;
else
if(nNext >0) // fdo#75936 set limit for decreasing indent
nNext -= nDefDist;
aLS.SetTextLeft( nNext );
SwRegHistory aRegH( pTNd, *pTNd, pHistory );
pTNd->SetAttr( aLS );
aIdx = *sw::GetFirstAndLastNode(*pLayout, aIdx).second;
}
++aIdx;
}
getIDocumentState().SetModified();
}
bool SwDoc::DontExpandFormat( const SwPosition& rPos, bool bFlag )
{
bool bRet = false;
SwTextNode* pTextNd = rPos.nNode.GetNode().GetTextNode();
if( pTextNd )
{
bRet = pTextNd->DontExpandFormat( rPos.nContent, bFlag );
if( bRet && GetIDocumentUndoRedo().DoesUndo() )
{
GetIDocumentUndoRedo().AppendUndo( std::make_unique<SwUndoDontExpandFormat>(rPos) );
}
}
return bRet;
}
SwTableBoxFormat* SwDoc::MakeTableBoxFormat()
{
SwTableBoxFormat* pFormat = new SwTableBoxFormat( GetAttrPool(), mpDfltFrameFormat.get() );
pFormat->SetName("TableBox" + OUString::number(reinterpret_cast<sal_IntPtr>(pFormat)));
getIDocumentState().SetModified();
return pFormat;
}
SwTableLineFormat* SwDoc::MakeTableLineFormat()
{
SwTableLineFormat* pFormat = new SwTableLineFormat( GetAttrPool(), mpDfltFrameFormat.get() );
pFormat->SetName("TableLine" + OUString::number(reinterpret_cast<sal_IntPtr>(pFormat)));
getIDocumentState().SetModified();
return pFormat;
}
void SwDoc::EnsureNumberFormatter()
{
if (mpNumberFormatter == nullptr)
{
LanguageType eLang = LANGUAGE_SYSTEM;
mpNumberFormatter = new SvNumberFormatter(comphelper::getProcessComponentContext(), eLang);
mpNumberFormatter->SetEvalDateFormat( NF_EVALDATEFORMAT_FORMAT_INTL );
if (!utl::ConfigManager::IsFuzzing())
mpNumberFormatter->SetYear2000(
officecfg::Office::Common::DateFormat::TwoDigitYear::get());
};
}
SwTableNumFormatMerge::SwTableNumFormatMerge( const SwDoc& rSrc, SwDoc& rDest )
: pNFormat( nullptr )
{
// a different Doc -> Number formatter needs to be merged
if( &rSrc != &rDest )
{
SvNumberFormatter* pN = const_cast<SwDoc&>(rSrc).GetNumberFormatter( false );
if( pN )
{
pNFormat = rDest.GetNumberFormatter();
pNFormat->MergeFormatter( *pN );
}
}
if( &rSrc != &rDest )
static_cast<SwGetRefFieldType*>(rSrc.getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::GetRef ))->
MergeWithOtherDoc( rDest );
}
SwTableNumFormatMerge::~SwTableNumFormatMerge()
{
if( pNFormat )
pNFormat->ClearMergeTable();
}
void SwDoc::SetTextFormatCollByAutoFormat( const SwPosition& rPos, sal_uInt16 nPoolId,
const SfxItemSet* pSet )
{
SwPaM aPam( rPos );
SwTextNode* pTNd = rPos.nNode.GetNode().GetTextNode();
assert(pTNd);
if (mbIsAutoFormatRedline)
{
// create the redline object
const SwTextFormatColl& rColl = *pTNd->GetTextColl();
SwRangeRedline* pRedl = new SwRangeRedline( RedlineType::FmtColl, aPam );
pRedl->SetMark();
// Only those items that are not set by the Set again in the Node
// are of interest. Thus, we take the difference.
SwRedlineExtraData_FormatColl aExtraData( rColl.GetName(),
rColl.GetPoolFormatId() );
if( pSet && pTNd->HasSwAttrSet() )
{
SfxItemSet aTmp( *pTNd->GetpSwAttrSet() );
aTmp.Differentiate( *pSet );
// we handle the adjust item separately
const SfxPoolItem* pItem;
if( SfxItemState::SET == pTNd->GetpSwAttrSet()->GetItemState(
RES_PARATR_ADJUST, false, &pItem ))
aTmp.Put( *pItem );
aExtraData.SetItemSet( aTmp );
}
pRedl->SetExtraData( &aExtraData );
//TODO: Undo is still missing!
getIDocumentRedlineAccess().AppendRedline( pRedl, true );
}
SetTextFormatColl( aPam, getIDocumentStylePoolAccess().GetTextCollFromPool( nPoolId ) );
if (pSet && pSet->Count())
{
aPam.SetMark();
aPam.GetMark()->nContent.Assign(pTNd, pTNd->GetText().getLength());
// sw_redlinehide: don't need layout currently because the only caller
// passes in the properties node
assert(static_cast<SwTextFrame const*>(pTNd->getLayoutFrame(nullptr))->GetTextNodeForParaProps() == pTNd);
getIDocumentContentOperations().InsertItemSet( aPam, *pSet );
}
}
void SwDoc::SetFormatItemByAutoFormat( const SwPaM& rPam, const SfxItemSet& rSet )
{
SwTextNode* pTNd = rPam.GetPoint()->nNode.GetNode().GetTextNode();
assert(pTNd);
RedlineFlags eOld = getIDocumentRedlineAccess().GetRedlineFlags();
if (mbIsAutoFormatRedline)
{
// create the redline object
SwRangeRedline* pRedl = new SwRangeRedline( RedlineType::Format, rPam );
if( !pRedl->HasMark() )
pRedl->SetMark();
// Only those items that are not set by the Set again in the Node
// are of interest. Thus, we take the difference.
SwRedlineExtraData_Format aExtraData( rSet );
pRedl->SetExtraData( &aExtraData );
//TODO: Undo is still missing!
getIDocumentRedlineAccess().AppendRedline( pRedl, true );
getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld | RedlineFlags::Ignore );
}
const sal_Int32 nEnd(rPam.End()->nContent.GetIndex());
std::vector<WhichPair> whichIds;
SfxItemIter iter(rSet);
for (SfxPoolItem const* pItem = iter.GetCurItem(); pItem; pItem = iter.NextItem())
{
whichIds.push_back({pItem->Which(), pItem->Which()});
}
SfxItemSet currentSet(GetAttrPool(), WhichRangesContainer(whichIds.data(), whichIds.size()));
pTNd->GetParaAttr(currentSet, nEnd, nEnd);
for (const WhichPair& rPair : whichIds)
{ // yuk - want to explicitly set the pool defaults too :-/
currentSet.Put(currentSet.Get(rPair.first));
}
getIDocumentContentOperations().InsertItemSet( rPam, rSet, SetAttrMode::DONTEXPAND );
// fdo#62536: DONTEXPAND does not work when there is already an AUTOFMT
// here, so insert the old attributes as an empty hint to stop expand
SwPaM endPam(*pTNd, nEnd);
endPam.SetMark();
getIDocumentContentOperations().InsertItemSet(endPam, currentSet);
getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
}
void SwDoc::ChgFormat(SwFormat & rFormat, const SfxItemSet & rSet)
{
if (GetIDocumentUndoRedo().DoesUndo())
{
// copying <rSet> to <aSet>
SfxItemSet aSet(rSet);
// remove from <aSet> all items, which are already set at the format
aSet.Differentiate(rFormat.GetAttrSet());
// <aSet> contains now all *new* items for the format
// copying current format item set to <aOldSet>
SfxItemSet aOldSet(rFormat.GetAttrSet());
// insert new items into <aOldSet>
aOldSet.Put(aSet);
// invalidate all new items in <aOldSet> in order to clear these items,
// if the undo action is triggered.
{
SfxItemIter aIter(aSet);
for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
{
aOldSet.InvalidateItem(pItem->Which());
}
}
GetIDocumentUndoRedo().AppendUndo(
std::make_unique<SwUndoFormatAttr>(std::move(aOldSet), rFormat, /*bSaveDrawPt*/true));
}
rFormat.SetFormatAttr(rSet);
}
void SwDoc::RenameFormat(SwFormat & rFormat, const OUString & sNewName,
bool bBroadcast)
{
SfxStyleFamily eFamily = SfxStyleFamily::All;
if (GetIDocumentUndoRedo().DoesUndo())
{
std::unique_ptr<SwUndo> pUndo;
switch (rFormat.Which())
{
case RES_CHRFMT:
pUndo.reset(new SwUndoRenameCharFormat(rFormat.GetName(), sNewName, *this));
eFamily = SfxStyleFamily::Char;
break;
case RES_TXTFMTCOLL:
pUndo.reset(new SwUndoRenameFormatColl(rFormat.GetName(), sNewName, *this));
eFamily = SfxStyleFamily::Para;
break;
case RES_FRMFMT:
pUndo.reset(new SwUndoRenameFrameFormat(rFormat.GetName(), sNewName, *this));
eFamily = SfxStyleFamily::Frame;
break;
default:
break;
}
if (pUndo)
{
GetIDocumentUndoRedo().AppendUndo(std::move(pUndo));
}
}
// name change means the o3tl::sorted_array is not property sorted
if (rFormat.Which() == RES_CHRFMT)
mpCharFormatTable->SetFormatNameAndReindex(static_cast<SwCharFormat*>(&rFormat), sNewName);
else
rFormat.SetName(sNewName);
if (bBroadcast)
BroadcastStyleOperation(sNewName, eFamily, SfxHintId::StyleSheetModified);
}
void SwDoc::dumpAsXml(xmlTextWriterPtr pWriter) const
{
bool bOwns = false;
if (!pWriter)
{
pWriter = xmlNewTextWriterFilename("nodes.xml", 0);
xmlTextWriterSetIndent(pWriter,1);
(void)xmlTextWriterSetIndentString(pWriter, BAD_CAST(" "));
(void)xmlTextWriterStartDocument(pWriter, nullptr, nullptr, nullptr);
bOwns = true;
}
(void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwDoc"));
(void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
m_pNodes->dumpAsXml(pWriter);
m_PageDescs.dumpAsXml(pWriter);
maDBData.dumpAsXml(pWriter);
mpMarkManager->dumpAsXml(pWriter);
m_pUndoManager->dumpAsXml(pWriter);
m_pDocumentSettingManager->dumpAsXml(pWriter);
getIDocumentFieldsAccess().GetFieldTypes()->dumpAsXml(pWriter);
mpTextFormatCollTable->dumpAsXml(pWriter);
mpCharFormatTable->dumpAsXml(pWriter);
mpFrameFormatTable->dumpAsXml(pWriter, "frmFormatTable");
mpSpzFrameFormatTable->dumpAsXml(pWriter, "spzFrameFormatTable");
mpSectionFormatTable->dumpAsXml(pWriter);
mpTableFrameFormatTable->dumpAsXml(pWriter, "tableFrameFormatTable");
mpNumRuleTable->dumpAsXml(pWriter);
getIDocumentRedlineAccess().GetRedlineTable().dumpAsXml(pWriter);
getIDocumentRedlineAccess().GetExtraRedlineTable().dumpAsXml(pWriter);
if (const SdrModel* pModel = getIDocumentDrawModelAccess().GetDrawModel())
pModel->dumpAsXml(pWriter);
(void)xmlTextWriterStartElement(pWriter, BAD_CAST("mbModified"));
(void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(OString::boolean(getIDocumentState().IsModified()).getStr()));
(void)xmlTextWriterEndElement(pWriter);
(void)xmlTextWriterEndElement(pWriter);
if (bOwns)
{
(void)xmlTextWriterEndDocument(pWriter);
xmlFreeTextWriter(pWriter);
}
}
void SwDBData::dumpAsXml(xmlTextWriterPtr pWriter) const
{
(void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwDBData"));
(void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("sDataSource"), BAD_CAST(sDataSource.toUtf8().getStr()));
(void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("sCommand"), BAD_CAST(sCommand.toUtf8().getStr()));
(void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nCommandType"), BAD_CAST(OString::number(nCommandType).getStr()));
(void)xmlTextWriterEndElement(pWriter);
}
std::set<Color> SwDoc::GetDocColors()
{
std::set<Color> aDocColors;
SwAttrPool& rPool = GetAttrPool();
const sal_uInt16 pAttribs[] = {RES_CHRATR_COLOR, RES_CHRATR_HIGHLIGHT, RES_BACKGROUND};
for (sal_uInt16 nAttrib : pAttribs)
{
for (const SfxPoolItem* pItem : rPool.GetItemSurrogates(nAttrib))
{
auto pColorItem = static_cast<const SvxColorItem*>(pItem);
Color aColor( pColorItem->GetValue() );
if (COL_AUTO != aColor)
aDocColors.insert(aColor);
}
}
return aDocColors;
}
// #i69627#
namespace docfunc
{
bool HasOutlineStyleToBeWrittenAsNormalListStyle( SwDoc& rDoc )
{
// If a parent paragraph style of one of the paragraph styles, which
// are assigned to the list levels of the outline style, has a list style
// set or inherits a list style from its parent style, the outline style
// has to be written as a normal list style to the OpenDocument file
// format or the OpenOffice.org file format.
bool bRet( false );
const SwTextFormatColls* pTextFormatColls( rDoc.GetTextFormatColls() );
if ( pTextFormatColls )
{
for ( auto pTextFormatColl : *pTextFormatColls )
{
if ( pTextFormatColl->IsDefault() ||
! pTextFormatColl->IsAssignedToListLevelOfOutlineStyle() )
{
continue;
}
const SwTextFormatColl* pParentTextFormatColl =
dynamic_cast<const SwTextFormatColl*>( pTextFormatColl->DerivedFrom());
if ( !pParentTextFormatColl )
continue;
if ( SfxItemState::SET == pParentTextFormatColl->GetItemState( RES_PARATR_NUMRULE ) )
{
// #i106218# consider that the outline style is set
const SwNumRuleItem& rDirectItem = pParentTextFormatColl->GetNumRule();
if ( rDirectItem.GetValue() != rDoc.GetOutlineNumRule()->GetName() )
{
bRet = true;
break;
}
}
}
}
return bRet;
}
}
SwFrameFormats::SwFrameFormats()
: m_PosIndex( m_Array.get<0>() )
, m_TypeAndNameIndex( m_Array.get<1>() )
{
}
SwFrameFormats::~SwFrameFormats()
{
DeleteAndDestroyAll();
}
SwFrameFormats::const_iterator SwFrameFormats::find( const value_type& x ) const
{
ByTypeAndName::iterator it = m_TypeAndNameIndex.find(
std::make_tuple(x->GetName(), x->Which(), x) );
return m_Array.project<0>( it );
}
SwFrameFormats::ByTypeAndName::const_iterator
SwFrameFormats::findByTypeAndName( sal_uInt16 type, const OUString& name ) const
{
return m_TypeAndNameIndex.find( std::make_tuple(name, type) );
}
std::pair<SwFrameFormats::ByTypeAndName::const_iterator, SwFrameFormats::ByTypeAndName::const_iterator>
SwFrameFormats::findRangeByName( const OUString& rName ) const
{
auto it = m_TypeAndNameIndex.lower_bound( std::make_tuple(rName, sal_uInt16(0)) );
auto itEnd = m_TypeAndNameIndex.upper_bound( std::make_tuple(rName, SAL_MAX_UINT16) );
return { it, itEnd };
}
SwFrameFormat* SwFrameFormats::FindFormatByName( const OUString& rName ) const
{
auto it = m_TypeAndNameIndex.lower_bound( std::make_tuple(rName, sal_uInt16(0)) );
if (it != m_TypeAndNameIndex.end() && (*it)->GetName() == rName)
return *it;
return nullptr;
}
void SwFrameFormats::DeleteAndDestroyAll( bool keepDefault )
{
if ( empty() )
return;
const int _offset = keepDefault ? 1 : 0;
for( const_iterator it = begin() + _offset; it != end(); ++it )
delete *it;
if ( _offset )
m_PosIndex.erase( begin() + _offset, end() );
else
m_Array.clear();
}
std::pair<SwFrameFormats::const_iterator,bool> SwFrameFormats::push_back( const value_type& x )
{
SAL_WARN_IF(x->m_ffList != nullptr, "sw.core", "Inserting already assigned item");
assert(x->m_ffList == nullptr);
x->m_ffList = this;
return m_PosIndex.push_back( x );
}
bool SwFrameFormats::erase( const value_type& x )
{
const_iterator const ret = find( x );
SAL_WARN_IF(x->m_ffList != this, "sw.core", "Removing invalid / unassigned item");
if (ret != end()) {
assert( x == *ret );
m_PosIndex.erase( ret );
x->m_ffList = nullptr;
return true;
}
return false;
}
void SwFrameFormats::erase( size_type index_ )
{
erase( begin() + index_ );
}
void SwFrameFormats::erase( const_iterator const& position )
{
(*position)->m_ffList = nullptr;
m_PosIndex.erase( begin() + (position - begin()) );
}
bool SwFrameFormats::ContainsFormat(const SwFrameFormat& x) const
{
return (x.m_ffList == this);
}
bool SwFrameFormats::IsAlive(SwFrameFormat const*const p) const
{
return find(const_cast<SwFrameFormat*>(p)) != end();
}
bool SwFrameFormats::newDefault( const value_type& x )
{
std::pair<iterator,bool> res = m_PosIndex.push_front( x );
if( ! res.second )
newDefault( res.first );
return res.second;
}
void SwFrameFormats::newDefault( const_iterator const& position )
{
if (position == begin())
return;
m_PosIndex.relocate( begin(), position );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|