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 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337
|
/* -*- 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 "scitems.hxx"
#include <vcl/virdev.hxx>
#include <vcl/waitobj.hxx>
#include <editeng/boxitem.hxx>
#include <editeng/justifyitem.hxx>
#include <sfx2/app.hxx>
#include "undoblk.hxx"
#include "undoutil.hxx"
#include "document.hxx"
#include "patattr.hxx"
#include "docsh.hxx"
#include "tabvwsh.hxx"
#include "rangenam.hxx"
#include "rangeutl.hxx"
#include "dbdata.hxx"
#include "stlpool.hxx"
#include "stlsheet.hxx"
#include "globstr.hrc"
#include "global.hxx"
#include "target.hxx"
#include "docpool.hxx"
#include "docfunc.hxx"
#include "attrib.hxx"
#include "chgtrack.hxx"
#include "transobj.hxx"
#include "refundo.hxx"
#include "undoolk.hxx"
#include "clipparam.hxx"
#include <brdcst.hxx>
#include "sc.hrc"
#include <rowheightcontext.hxx>
#include <refhint.hxx>
#include <refupdatecontext.hxx>
#include <validat.hxx>
#include <gridwin.hxx>
#include <svl/listener.hxx>
#include <memory>
#include <set>
// TODO:
/*A*/ // SetOptimalHeight on Document, if no View
/*B*/ // linked sheets
/*C*/ // ScArea
//? // check later
ScUndoInsertCells::ScUndoInsertCells( ScDocShell* pNewDocShell,
const ScRange& rRange, SCTAB nNewCount, SCTAB* pNewTabs, SCTAB* pNewScenarios,
InsCellCmd eNewCmd, ScDocument* pUndoDocument, ScRefUndoData* pRefData,
bool bNewPartOfPaste ) :
ScMoveUndo( pNewDocShell, pUndoDocument, pRefData, SC_UNDO_REFLAST ),
aEffRange( rRange ),
nCount( nNewCount ),
pTabs( pNewTabs ),
pScenarios( pNewScenarios ),
eCmd( eNewCmd ),
bPartOfPaste( bNewPartOfPaste ),
pPasteUndo( nullptr )
{
if (eCmd == INS_INSROWS_BEFORE || eCmd == INS_INSROWS_AFTER) // whole row?
{
aEffRange.aStart.SetCol(0);
aEffRange.aEnd.SetCol(MAXCOL);
}
if (eCmd == INS_INSCOLS_BEFORE || eCmd == INS_INSCOLS_AFTER) // whole column?
{
aEffRange.aStart.SetRow(0);
aEffRange.aEnd.SetRow(MAXROW);
}
SetChangeTrack();
}
ScUndoInsertCells::~ScUndoInsertCells()
{
delete pPasteUndo;
delete []pTabs;
delete []pScenarios;
}
OUString ScUndoInsertCells::GetComment() const
{
return ScGlobal::GetRscString( pPasteUndo ? STR_UNDO_PASTE : STR_UNDO_INSERTCELLS );
}
bool ScUndoInsertCells::Merge( SfxUndoAction* pNextAction )
{
// If a paste undo action has already been added, append (detective) action there.
if ( pPasteUndo )
return pPasteUndo->Merge( pNextAction );
if ( bPartOfPaste && dynamic_cast<const ScUndoWrapper*>( pNextAction) != nullptr )
{
ScUndoWrapper* pWrapper = static_cast<ScUndoWrapper*>(pNextAction);
SfxUndoAction* pWrappedAction = pWrapper->GetWrappedUndo();
if ( pWrappedAction && dynamic_cast<const ScUndoPaste*>( pWrappedAction) != nullptr )
{
// Store paste action if this is part of paste with inserting cells.
// A list action isn't used because Repeat wouldn't work (insert wrong cells).
pPasteUndo = pWrappedAction;
pWrapper->ForgetWrappedUndo(); // pWrapper is deleted by UndoManager
return true;
}
}
// Call base class for detective handling
return ScMoveUndo::Merge( pNextAction );
}
void ScUndoInsertCells::SetChangeTrack()
{
ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
if ( pChangeTrack )
{
pChangeTrack->AppendInsert( aEffRange );
nEndChangeAction = pChangeTrack->GetActionMax();
}
else
nEndChangeAction = 0;
}
void ScUndoInsertCells::DoChange( const bool bUndo )
{
ScDocument& rDoc = pDocShell->GetDocument();
SCTAB i;
if ( bUndo )
{
ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
if ( pChangeTrack )
pChangeTrack->Undo( nEndChangeAction, nEndChangeAction );
}
else
SetChangeTrack();
// refresh of merged cells has to be after inserting/deleting
switch (eCmd)
{
case INS_INSROWS_BEFORE:
case INS_INSROWS_AFTER:
case INS_CELLSDOWN:
for( i=0; i<nCount; i++ )
{
if (bUndo)
rDoc.DeleteRow( aEffRange.aStart.Col(), pTabs[i], aEffRange.aEnd.Col(), pTabs[i]+pScenarios[i],
aEffRange.aStart.Row(), static_cast<SCSIZE>(aEffRange.aEnd.Row()-aEffRange.aStart.Row()+1));
else
rDoc.InsertRow( aEffRange.aStart.Col(), pTabs[i], aEffRange.aEnd.Col(), pTabs[i]+pScenarios[i],
aEffRange.aStart.Row(), static_cast<SCSIZE>(aEffRange.aEnd.Row()-aEffRange.aStart.Row()+1));
}
break;
case INS_INSCOLS_BEFORE:
case INS_INSCOLS_AFTER:
case INS_CELLSRIGHT:
for( i=0; i<nCount; i++ )
{
if (bUndo)
rDoc.DeleteCol( aEffRange.aStart.Row(), pTabs[i], aEffRange.aEnd.Row(), pTabs[i]+pScenarios[i],
aEffRange.aStart.Col(), static_cast<SCSIZE>(aEffRange.aEnd.Col()-aEffRange.aStart.Col()+1));
else
rDoc.InsertCol( aEffRange.aStart.Row(), pTabs[i], aEffRange.aEnd.Row(), pTabs[i]+pScenarios[i],
aEffRange.aStart.Col(), static_cast<SCSIZE>(aEffRange.aEnd.Col()-aEffRange.aStart.Col()+1));
}
break;
default:
{
// added to avoid warnings
}
}
ScRange aWorkRange( aEffRange );
if ( eCmd == INS_CELLSRIGHT ) // only "shift right" requires refresh of the moved area
aWorkRange.aEnd.SetCol(MAXCOL);
for( i=0; i<nCount; i++ )
{
if ( rDoc.HasAttrib( aWorkRange.aStart.Col(), aWorkRange.aStart.Row(), pTabs[i],
aWorkRange.aEnd.Col(), aWorkRange.aEnd.Row(), pTabs[i], HASATTR_MERGED ) )
{
SCCOL nEndCol = aWorkRange.aEnd.Col();
SCROW nEndRow = aWorkRange.aEnd.Row();
rDoc.ExtendMerge( aWorkRange.aStart.Col(), aWorkRange.aStart.Row(), nEndCol, nEndRow, pTabs[i], true );
}
}
// Undo for displaced attributes?
sal_uInt16 nPaint = PAINT_GRID;
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
switch (eCmd)
{
case INS_INSROWS_BEFORE:
case INS_INSROWS_AFTER:
nPaint |= PAINT_LEFT;
aWorkRange.aEnd.SetRow(MAXROW);
break;
case INS_CELLSDOWN:
for( i=0; i<nCount; i++ )
{
aWorkRange.aEnd.SetRow(MAXROW);
if ( pDocShell->AdjustRowHeight( aWorkRange.aStart.Row(), aWorkRange.aEnd.Row(), pTabs[i] ))
{
aWorkRange.aStart.SetCol(0);
aWorkRange.aEnd.SetCol(MAXCOL);
nPaint |= PAINT_LEFT;
}
}
break;
case INS_INSCOLS_BEFORE:
case INS_INSCOLS_AFTER:
nPaint |= PAINT_TOP; // top bar
SAL_FALLTHROUGH;
case INS_CELLSRIGHT:
for( i=0; i<nCount; i++ )
{
aWorkRange.aEnd.SetCol(MAXCOL); // to the far right
if ( pDocShell->AdjustRowHeight( aWorkRange.aStart.Row(), aWorkRange.aEnd.Row(), pTabs[i]) )
{ // AdjustDraw does not paint PAINT_TOP,
aWorkRange.aStart.SetCol(0); // thus solved like this
aWorkRange.aEnd.SetRow(MAXROW);
nPaint |= PAINT_LEFT;
}
}
break;
default:
{
// added to avoid warnings
}
}
for( i=0; i<nCount; i++ )
{
pDocShell->PostPaint( aWorkRange.aStart.Col(), aWorkRange.aStart.Row(), pTabs[i],
aWorkRange.aEnd.Col(), aWorkRange.aEnd.Row(), pTabs[i]+pScenarios[i], nPaint );
}
pDocShell->PostDataChanged();
if (pViewShell)
pViewShell->CellContentChanged();
}
void ScUndoInsertCells::Undo()
{
if ( pPasteUndo )
pPasteUndo->Undo(); // undo paste first
WaitObject aWait( ScDocShell::GetActiveDialogParent() ); // important due to TrackFormulas in UpdateReference
BeginUndo();
DoChange( true );
EndUndo();
ScDocument& rDoc = pDocShell->GetDocument();
for (SCTAB i = 0; i < nCount; ++i)
rDoc.SetDrawPageSize(pTabs[i]);
}
void ScUndoInsertCells::Redo()
{
WaitObject aWait( ScDocShell::GetActiveDialogParent() ); // important due to TrackFormulas in UpdateReference
BeginRedo();
DoChange( false );
EndRedo();
if ( pPasteUndo )
pPasteUndo->Redo(); // redo paste last
ScDocument& rDoc = pDocShell->GetDocument();
for (SCTAB i = 0; i < nCount; ++i)
rDoc.SetDrawPageSize(pTabs[i]);
}
void ScUndoInsertCells::Repeat(SfxRepeatTarget& rTarget)
{
if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr)
{
if ( pPasteUndo )
{
// Repeat for paste with inserting cells is handled completely
// by the Paste undo action
pPasteUndo->Repeat( rTarget );
}
else
static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->InsertCells( eCmd );
}
}
bool ScUndoInsertCells::CanRepeat(SfxRepeatTarget& rTarget) const
{
return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr;
}
ScUndoDeleteCells::ScUndoDeleteCells( ScDocShell* pNewDocShell,
const ScRange& rRange, SCTAB nNewCount, SCTAB* pNewTabs, SCTAB* pNewScenarios,
DelCellCmd eNewCmd, ScDocument* pUndoDocument, ScRefUndoData* pRefData ) :
ScMoveUndo( pNewDocShell, pUndoDocument, pRefData, SC_UNDO_REFLAST ),
aEffRange( rRange ),
nCount( nNewCount ),
pTabs( pNewTabs ),
pScenarios( pNewScenarios ),
eCmd( eNewCmd )
{
if (eCmd == DEL_DELROWS) // whole row?
{
aEffRange.aStart.SetCol(0);
aEffRange.aEnd.SetCol(MAXCOL);
}
if (eCmd == DEL_DELCOLS) // whole column?
{
aEffRange.aStart.SetRow(0);
aEffRange.aEnd.SetRow(MAXROW);
}
SetChangeTrack();
}
ScUndoDeleteCells::~ScUndoDeleteCells()
{
delete []pTabs;
delete []pScenarios;
}
OUString ScUndoDeleteCells::GetComment() const
{
return ScGlobal::GetRscString( STR_UNDO_DELETECELLS ); // "Delete"
}
void ScUndoDeleteCells::SetChangeTrack()
{
ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
if ( pChangeTrack )
pChangeTrack->AppendDeleteRange( aEffRange, pRefUndoDoc,
nStartChangeAction, nEndChangeAction );
else
nStartChangeAction = nEndChangeAction = 0;
}
void ScUndoDeleteCells::DoChange( const bool bUndo )
{
ScDocument& rDoc = pDocShell->GetDocument();
SCTAB i;
if ( bUndo )
{
ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
if ( pChangeTrack )
pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
}
else
SetChangeTrack();
switch (eCmd)
{
case DEL_DELROWS:
case DEL_CELLSUP:
for( i=0; i<nCount; i++ )
{
if (bUndo)
rDoc.InsertRow( aEffRange.aStart.Col(), pTabs[i], aEffRange.aEnd.Col(), pTabs[i]+pScenarios[i],
aEffRange.aStart.Row(), static_cast<SCSIZE>(aEffRange.aEnd.Row()-aEffRange.aStart.Row()+1));
else
rDoc.DeleteRow( aEffRange.aStart.Col(), pTabs[i], aEffRange.aEnd.Col(), pTabs[i]+pScenarios[i],
aEffRange.aStart.Row(), static_cast<SCSIZE>(aEffRange.aEnd.Row()-aEffRange.aStart.Row()+1));
}
break;
case DEL_DELCOLS:
case DEL_CELLSLEFT:
for( i=0; i<nCount; i++ )
{
if (bUndo)
rDoc.InsertCol( aEffRange.aStart.Row(), pTabs[i], aEffRange.aEnd.Row(), pTabs[i]+pScenarios[i],
aEffRange.aStart.Col(), static_cast<SCSIZE>(aEffRange.aEnd.Col()-aEffRange.aStart.Col()+1));
else
rDoc.DeleteCol( aEffRange.aStart.Row(), pTabs[i], aEffRange.aEnd.Row(), pTabs[i]+pScenarios[i],
aEffRange.aStart.Col(), static_cast<SCSIZE>(aEffRange.aEnd.Col()-aEffRange.aStart.Col()+1));
}
break;
default:
{
// added to avoid warnings
}
}
// if Undo, restore references
for( i=0; i<nCount && bUndo; i++ )
{
pRefUndoDoc->CopyToDocument( aEffRange.aStart.Col(), aEffRange.aStart.Row(), pTabs[i], aEffRange.aEnd.Col(), aEffRange.aEnd.Row(), pTabs[i]+pScenarios[i],
InsertDeleteFlags::ALL | InsertDeleteFlags::NOCAPTIONS, false, &rDoc );
}
ScRange aWorkRange( aEffRange );
if ( eCmd == DEL_CELLSLEFT ) // only "shift left" requires refresh of the moved area
aWorkRange.aEnd.SetCol(MAXCOL);
for( i=0; i<nCount; i++ )
{
if ( rDoc.HasAttrib( aWorkRange.aStart.Col(), aWorkRange.aStart.Row(), pTabs[i],
aWorkRange.aEnd.Col(), aWorkRange.aEnd.Row(), pTabs[i], HASATTR_MERGED | HASATTR_OVERLAPPED ) )
{
// #i51445# old merge flag attributes must be deleted also for single cells,
// not only for whole columns/rows
if ( !bUndo )
{
if ( eCmd==DEL_DELCOLS || eCmd==DEL_CELLSLEFT )
aWorkRange.aEnd.SetCol(MAXCOL);
if ( eCmd==DEL_DELROWS || eCmd==DEL_CELLSUP )
aWorkRange.aEnd.SetRow(MAXROW);
ScMarkData aMarkData;
aMarkData.SelectOneTable( aWorkRange.aStart.Tab() );
ScPatternAttr aPattern( rDoc.GetPool() );
aPattern.GetItemSet().Put( ScMergeFlagAttr() );
rDoc.ApplyPatternArea( aWorkRange.aStart.Col(), aWorkRange.aStart.Row(),
aWorkRange.aEnd.Col(), aWorkRange.aEnd.Row(),
aMarkData, aPattern );
}
SCCOL nEndCol = aWorkRange.aEnd.Col();
SCROW nEndRow = aWorkRange.aEnd.Row();
rDoc.ExtendMerge( aWorkRange.aStart.Col(), aWorkRange.aStart.Row(), nEndCol, nEndRow, pTabs[i], true );
}
}
// paint
sal_uInt16 nPaint = PAINT_GRID;
switch (eCmd)
{
case DEL_DELROWS:
nPaint |= PAINT_LEFT;
aWorkRange.aEnd.SetRow(MAXROW);
break;
case DEL_CELLSUP:
for( i=0; i<nCount; i++ )
{
aWorkRange.aEnd.SetRow(MAXROW);
if ( pDocShell->AdjustRowHeight( aWorkRange.aStart.Row(), aWorkRange.aEnd.Row(), pTabs[i] ))
{
aWorkRange.aStart.SetCol(0);
aWorkRange.aEnd.SetCol(MAXCOL);
nPaint |= PAINT_LEFT;
}
}
break;
case DEL_DELCOLS:
nPaint |= PAINT_TOP; // top bar
SAL_FALLTHROUGH;
case DEL_CELLSLEFT:
for( i=0; i<nCount; i++ )
{
aWorkRange.aEnd.SetCol(MAXCOL); // to the far right
if ( pDocShell->AdjustRowHeight( aWorkRange.aStart.Row(), aWorkRange.aEnd.Row(), pTabs[i] ) )
{
aWorkRange.aStart.SetCol(0);
aWorkRange.aEnd.SetRow(MAXROW);
nPaint |= PAINT_LEFT;
}
}
break;
default:
{
// added to avoid warnings
}
}
for( i=0; i<nCount; i++ )
{
pDocShell->PostPaint( aWorkRange.aStart.Col(), aWorkRange.aStart.Row(), pTabs[i],
aWorkRange.aEnd.Col(), aWorkRange.aEnd.Row(), pTabs[i]+pScenarios[i], nPaint, SC_PF_LINES );
}
// Selection not until EndUndo
pDocShell->PostDataChanged();
// CellContentChanged comes with the selection
}
void ScUndoDeleteCells::Undo()
{
WaitObject aWait( ScDocShell::GetActiveDialogParent() ); // important because of TrackFormulas in UpdateReference
BeginUndo();
DoChange( true );
EndUndo();
SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
// Selection not until EndUndo
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
if (pViewShell)
{
for( SCTAB i=0; i<nCount; i++ )
{
pViewShell->MarkRange( ScRange(aEffRange.aStart.Col(), aEffRange.aStart.Row(), pTabs[i], aEffRange.aEnd.Col(), aEffRange.aEnd.Row(), pTabs[i]+pScenarios[i]) );
}
}
ScDocument& rDoc = pDocShell->GetDocument();
for (SCTAB i = 0; i < nCount; ++i)
rDoc.SetDrawPageSize(pTabs[i]);
}
void ScUndoDeleteCells::Redo()
{
WaitObject aWait( ScDocShell::GetActiveDialogParent() ); // important because of TrackFormulas in UpdateReference
BeginRedo();
DoChange( false);
EndRedo();
SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
if (pViewShell)
pViewShell->DoneBlockMode(); // current way
ScDocument& rDoc = pDocShell->GetDocument();
for (SCTAB i = 0; i < nCount; ++i)
rDoc.SetDrawPageSize(pTabs[i]);
}
void ScUndoDeleteCells::Repeat(SfxRepeatTarget& rTarget)
{
if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr)
static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->DeleteCells( eCmd );
}
bool ScUndoDeleteCells::CanRepeat(SfxRepeatTarget& rTarget) const
{
return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr;
}
// delete cells in multiselection
ScUndoDeleteMulti::ScUndoDeleteMulti(
ScDocShell* pNewDocShell,
bool bNewRows, bool bNeedsRefresh, SCTAB nNewTab,
const std::vector<sc::ColRowSpan>& rSpans,
ScDocument* pUndoDocument, ScRefUndoData* pRefData ) :
ScMoveUndo( pNewDocShell, pUndoDocument, pRefData, SC_UNDO_REFLAST ),
mbRows(bNewRows),
mbRefresh(bNeedsRefresh),
nTab( nNewTab ),
maSpans(rSpans)
{
SetChangeTrack();
}
ScUndoDeleteMulti::~ScUndoDeleteMulti()
{
}
OUString ScUndoDeleteMulti::GetComment() const
{
return ScGlobal::GetRscString( STR_UNDO_DELETECELLS ); // like DeleteCells
}
void ScUndoDeleteMulti::DoChange() const
{
SCCOL nStartCol;
SCROW nStartRow;
sal_uInt16 nPaint;
if (mbRows)
{
nStartCol = 0;
nStartRow = static_cast<SCROW>(maSpans[0].mnStart);
nPaint = PAINT_GRID | PAINT_LEFT;
}
else
{
nStartCol = static_cast<SCCOL>(maSpans[0].mnStart);
nStartRow = 0;
nPaint = PAINT_GRID | PAINT_TOP;
}
if (mbRefresh)
{
ScDocument& rDoc = pDocShell->GetDocument();
SCCOL nEndCol = MAXCOL;
SCROW nEndRow = MAXROW;
rDoc.RemoveFlagsTab( nStartCol, nStartRow, nEndCol, nEndRow, nTab, ScMF::Hor | ScMF::Ver );
rDoc.ExtendMerge( nStartCol, nStartRow, nEndCol, nEndRow, nTab, true );
}
pDocShell->PostPaint( nStartCol, nStartRow, nTab, MAXCOL, MAXROW, nTab, nPaint );
pDocShell->PostDataChanged();
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
if (pViewShell)
pViewShell->CellContentChanged();
ShowTable( nTab );
}
void ScUndoDeleteMulti::SetChangeTrack()
{
ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
if ( pChangeTrack )
{
nStartChangeAction = pChangeTrack->GetActionMax() + 1;
ScRange aRange( 0, 0, nTab, 0, 0, nTab );
if (mbRows)
aRange.aEnd.SetCol( MAXCOL );
else
aRange.aEnd.SetRow( MAXROW );
// delete in reverse
std::vector<sc::ColRowSpan>::const_reverse_iterator ri = maSpans.rbegin(), riEnd = maSpans.rend();
for (; ri != riEnd; ++ri)
{
SCCOLROW nEnd = ri->mnEnd;
SCCOLROW nStart = ri->mnStart;
if (mbRows)
{
aRange.aStart.SetRow( nStart );
aRange.aEnd.SetRow( nEnd );
}
else
{
aRange.aStart.SetCol( static_cast<SCCOL>(nStart) );
aRange.aEnd.SetCol( static_cast<SCCOL>(nEnd) );
}
sal_uLong nDummyStart;
pChangeTrack->AppendDeleteRange( aRange, pRefUndoDoc,
nDummyStart, nEndChangeAction );
}
}
else
nStartChangeAction = nEndChangeAction = 0;
}
void ScUndoDeleteMulti::Undo()
{
WaitObject aWait( ScDocShell::GetActiveDialogParent() ); // important because of TrackFormulas in UpdateReference
BeginUndo();
ScDocument& rDoc = pDocShell->GetDocument();
// reverse delete -> forward insert
std::vector<sc::ColRowSpan>::const_iterator it = maSpans.begin(), itEnd = maSpans.end();
for (; it != itEnd; ++it)
{
SCCOLROW nStart = it->mnStart;
SCCOLROW nEnd = it->mnEnd;
if (mbRows)
rDoc.InsertRow( 0,nTab, MAXCOL,nTab, nStart,static_cast<SCSIZE>(nEnd-nStart+1) );
else
rDoc.InsertCol( 0,nTab, MAXROW,nTab, static_cast<SCCOL>(nStart), static_cast<SCSIZE>(nEnd-nStart+1) );
}
it = maSpans.begin();
for (; it != itEnd; ++it)
{
SCCOLROW nStart = it->mnStart;
SCCOLROW nEnd = it->mnEnd;
if (mbRows)
pRefUndoDoc->CopyToDocument( 0,nStart,nTab, MAXCOL,nEnd,nTab, InsertDeleteFlags::ALL,false, &rDoc );
else
pRefUndoDoc->CopyToDocument( static_cast<SCCOL>(nStart),0,nTab,
static_cast<SCCOL>(nEnd),MAXROW,nTab, InsertDeleteFlags::ALL,false, &rDoc );
}
ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
if ( pChangeTrack )
pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
DoChange();
//! redrawing the selection is not possible at the moment
//! since no data for selection exist
EndUndo();
SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
}
void ScUndoDeleteMulti::Redo()
{
WaitObject aWait( ScDocShell::GetActiveDialogParent() ); // important because of TrackFormulas in UpdateReference
BeginRedo();
ScDocument& rDoc = pDocShell->GetDocument();
// reverse delete
std::vector<sc::ColRowSpan>::const_reverse_iterator ri = maSpans.rbegin(), riEnd = maSpans.rend();
for (; ri != riEnd; ++ri)
{
SCCOLROW nEnd = ri->mnEnd;
SCCOLROW nStart = ri->mnStart;
if (mbRows)
rDoc.DeleteRow( 0,nTab, MAXCOL,nTab, nStart,static_cast<SCSIZE>(nEnd-nStart+1) );
else
rDoc.DeleteCol( 0,nTab, MAXROW,nTab, static_cast<SCCOL>(nStart), static_cast<SCSIZE>(nEnd-nStart+1) );
}
SetChangeTrack();
DoChange();
EndRedo();
SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
}
void ScUndoDeleteMulti::Repeat(SfxRepeatTarget& rTarget)
{
// if single selection
if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr)
static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->DeleteCells( DEL_DELROWS );
}
bool ScUndoDeleteMulti::CanRepeat(SfxRepeatTarget& rTarget) const
{
return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr;
}
ScUndoCut::ScUndoCut( ScDocShell* pNewDocShell,
ScRange aRange, ScAddress aOldEnd, const ScMarkData& rMark,
ScDocument* pNewUndoDoc ) :
ScBlockUndo( pNewDocShell, ScRange(aRange.aStart, aOldEnd), SC_UNDO_AUTOHEIGHT ),
aMarkData( rMark ),
pUndoDoc( pNewUndoDoc ),
aExtendedRange( aRange )
{
SetChangeTrack();
}
ScUndoCut::~ScUndoCut()
{
delete pUndoDoc;
}
OUString ScUndoCut::GetComment() const
{
return ScGlobal::GetRscString( STR_UNDO_CUT ); // "cut"
}
void ScUndoCut::SetChangeTrack()
{
ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
if ( pChangeTrack )
pChangeTrack->AppendContentRange( aBlockRange, pUndoDoc,
nStartChangeAction, nEndChangeAction, SC_CACM_CUT );
else
nStartChangeAction = nEndChangeAction = 0;
}
void ScUndoCut::DoChange( const bool bUndo )
{
ScDocument& rDoc = pDocShell->GetDocument();
sal_uInt16 nExtFlags = 0;
// do not undo/redo objects and note captions, they are handled via drawing undo
InsertDeleteFlags nUndoFlags = (InsertDeleteFlags::ALL & ~InsertDeleteFlags::OBJECTS) | InsertDeleteFlags::NOCAPTIONS;
if (bUndo) // only for Undo
{
// all sheets - CopyToDocument skips those that don't exist in pUndoDoc
SCTAB nTabCount = rDoc.GetTableCount();
ScRange aCopyRange = aExtendedRange;
aCopyRange.aStart.SetTab(0);
aCopyRange.aEnd.SetTab(nTabCount-1);
pUndoDoc->CopyToDocument( aCopyRange, nUndoFlags, false, &rDoc );
ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
if ( pChangeTrack )
pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
BroadcastChanges(aCopyRange);
}
else // only for Redo
{
pDocShell->UpdatePaintExt( nExtFlags, aExtendedRange );
rDoc.DeleteArea( aBlockRange.aStart.Col(), aBlockRange.aStart.Row(),
aBlockRange.aEnd.Col(), aBlockRange.aEnd.Row(), aMarkData, nUndoFlags );
SetChangeTrack();
}
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
if ( !( (pViewShell) && pViewShell->AdjustBlockHeight() ) )
/*A*/ pDocShell->PostPaint( aExtendedRange, PAINT_GRID, nExtFlags );
if ( !bUndo ) // draw redo after updating row heights
RedoSdrUndoAction( pDrawUndo ); //! include in ScBlockUndo?
pDocShell->PostDataChanged();
if (pViewShell)
pViewShell->CellContentChanged();
}
void ScUndoCut::Undo()
{
BeginUndo();
DoChange( true );
EndUndo();
}
void ScUndoCut::Redo()
{
BeginRedo();
ScDocument& rDoc = pDocShell->GetDocument();
EnableDrawAdjust( &rDoc, false ); //! include in ScBlockUndo?
DoChange( false );
EnableDrawAdjust( &rDoc, true ); //! include in ScBlockUndo?
EndRedo();
}
void ScUndoCut::Repeat(SfxRepeatTarget& rTarget)
{
if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr)
static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->CutToClip();
}
bool ScUndoCut::CanRepeat(SfxRepeatTarget& rTarget) const
{
return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr;
}
ScUndoPaste::ScUndoPaste( ScDocShell* pNewDocShell, const ScRangeList& rRanges,
const ScMarkData& rMark,
ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc,
InsertDeleteFlags nNewFlags,
ScRefUndoData* pRefData,
bool bRedoIsFilled, const ScUndoPasteOptions* pOptions ) :
ScMultiBlockUndo( pNewDocShell, rRanges ),
aMarkData( rMark ),
pUndoDoc( pNewUndoDoc ),
pRedoDoc( pNewRedoDoc ),
nFlags( nNewFlags ),
pRefUndoData( pRefData ),
pRefRedoData( nullptr ),
bRedoFilled( bRedoIsFilled )
{
if ( pRefUndoData )
pRefUndoData->DeleteUnchanged( &pDocShell->GetDocument() );
if ( pOptions )
aPasteOptions = *pOptions; // used only for Repeat
SetChangeTrack();
}
ScUndoPaste::~ScUndoPaste()
{
delete pUndoDoc;
delete pRedoDoc;
delete pRefUndoData;
delete pRefRedoData;
}
OUString ScUndoPaste::GetComment() const
{
return ScGlobal::GetRscString( STR_UNDO_PASTE ); // "paste"
}
void ScUndoPaste::SetChangeTrack()
{
ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
if ( pChangeTrack && (nFlags & InsertDeleteFlags::CONTENTS) )
{
for (size_t i = 0, n = maBlockRanges.size(); i < n; ++i)
{
pChangeTrack->AppendContentRange(*maBlockRanges[i], pUndoDoc,
nStartChangeAction, nEndChangeAction, SC_CACM_PASTE );
}
}
else
nStartChangeAction = nEndChangeAction = 0;
}
void ScUndoPaste::DoChange(bool bUndo)
{
ScDocument& rDoc = pDocShell->GetDocument();
// RefUndoData for redo is created before first undo
// (with DeleteUnchanged after the DoUndo call)
bool bCreateRedoData = ( bUndo && pRefUndoData && !pRefRedoData );
if ( bCreateRedoData )
pRefRedoData = new ScRefUndoData( &rDoc );
ScRefUndoData* pWorkRefData = bUndo ? pRefUndoData : pRefRedoData;
// Always back-up either all or none of the content for Undo
InsertDeleteFlags nUndoFlags = InsertDeleteFlags::NONE;
if (nFlags & InsertDeleteFlags::CONTENTS)
nUndoFlags |= InsertDeleteFlags::CONTENTS;
if (nFlags & InsertDeleteFlags::ATTRIB)
nUndoFlags |= InsertDeleteFlags::ATTRIB;
// do not undo/redo objects and note captions, they are handled via drawing undo
nUndoFlags &= ~InsertDeleteFlags::OBJECTS;
nUndoFlags |= InsertDeleteFlags::NOCAPTIONS;
bool bPaintAll = false;
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
SCTAB nTabCount = rDoc.GetTableCount();
if ( bUndo && !bRedoFilled )
{
if (!pRedoDoc)
{
bool bColInfo = true;
bool bRowInfo = true;
for (size_t i = 0, n = maBlockRanges.size(); i < n; ++i)
{
const ScRange& r = *maBlockRanges[i];
bColInfo &= (r.aStart.Row() == 0 && r.aEnd.Row() == MAXROW);
bRowInfo &= (r.aStart.Col() == 0 && r.aEnd.Col() == MAXCOL);
if (!bColInfo && !bRowInfo)
break;
}
pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
pRedoDoc->InitUndoSelected( &rDoc, aMarkData, bColInfo, bRowInfo );
}
// read "redo" data from the document in the first undo
// all sheets - CopyToDocument skips those that don't exist in pRedoDoc
for (size_t i = 0, n = maBlockRanges.size(); i < n; ++i)
{
ScRange aCopyRange = *maBlockRanges[i];
aCopyRange.aStart.SetTab(0);
aCopyRange.aEnd.SetTab(nTabCount-1);
rDoc.CopyToDocument( aCopyRange, nUndoFlags, false, pRedoDoc );
bRedoFilled = true;
}
}
sal_uInt16 nExtFlags = 0;
pDocShell->UpdatePaintExt(nExtFlags, maBlockRanges.Combine());
rDoc.ForgetNoteCaptions(maBlockRanges);
aMarkData.MarkToMulti();
rDoc.DeleteSelection(nUndoFlags, aMarkData, false); // no broadcasting here
for (size_t i = 0, n = maBlockRanges.size(); i < n; ++i)
rDoc.BroadcastCells(*maBlockRanges[i], SC_HINT_DATACHANGED);
aMarkData.MarkToSimple();
SCTAB nFirstSelected = aMarkData.GetFirstSelected();
if ( !bUndo && pRedoDoc ) // Redo: UndoToDocument before handling RefData
{
for (size_t i = 0, n = maBlockRanges.size(); i < n; ++i)
{
ScRange aRange = *maBlockRanges[i];
aRange.aStart.SetTab(nFirstSelected);
aRange.aEnd.SetTab(nFirstSelected);
pRedoDoc->UndoToDocument(aRange, nUndoFlags, false, &rDoc);
ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
for (; itr != itrEnd && *itr < nTabCount; ++itr)
{
if (*itr == nFirstSelected)
continue;
aRange.aStart.SetTab(*itr);
aRange.aEnd.SetTab(*itr);
pRedoDoc->CopyToDocument( aRange, nUndoFlags, false, &rDoc );
}
}
}
if (pWorkRefData)
{
pWorkRefData->DoUndo( &rDoc, true ); // true = bSetChartRangeLists for SetChartListenerCollection
if (!maBlockRanges.empty() &&
rDoc.RefreshAutoFilter(0, 0, MAXCOL, MAXROW, maBlockRanges[0]->aStart.Tab()))
bPaintAll = true;
}
if ( bCreateRedoData && pRefRedoData )
pRefRedoData->DeleteUnchanged( &rDoc );
if (bUndo) // Undo: UndoToDocument after handling RefData
{
for (size_t i = 0, n = maBlockRanges.size(); i < n; ++i)
{
ScRange aRange = *maBlockRanges[i];
ScMarkData::iterator itr = aMarkData.begin(), itrEnd = aMarkData.end();
for (; itr != itrEnd && *itr < nTabCount; ++itr)
{
aRange.aStart.SetTab(*itr);
aRange.aEnd.SetTab(*itr);
pUndoDoc->UndoToDocument(aRange, nUndoFlags, false, &rDoc);
}
}
}
if ( bUndo )
{
ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
if ( pChangeTrack )
pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
}
else
SetChangeTrack();
ScRangeList aDrawRanges(maBlockRanges);
sal_uInt16 nPaint = PAINT_GRID;
for (size_t i = 0, n = aDrawRanges.size(); i < n; ++i)
{
ScRange& rDrawRange = *aDrawRanges[i];
rDoc.ExtendMerge(rDrawRange, true); // only needed for single sheet (text/rtf etc.)
if (bPaintAll)
{
rDrawRange.aStart.SetCol(0);
rDrawRange.aStart.SetRow(0);
rDrawRange.aEnd.SetCol(MAXCOL);
rDrawRange.aEnd.SetRow(MAXROW);
nPaint |= PAINT_TOP | PAINT_LEFT;
if (pViewShell)
pViewShell->AdjustBlockHeight(false);
}
else
{
if (maBlockRanges[i]->aStart.Row() == 0 && maBlockRanges[i]->aEnd.Row() == MAXROW) // whole column
{
nPaint |= PAINT_TOP;
rDrawRange.aEnd.SetCol(MAXCOL);
}
if (maBlockRanges[i]->aStart.Col() == 0 && maBlockRanges[i]->aEnd.Col() == MAXCOL) // whole row
{
nPaint |= PAINT_LEFT;
rDrawRange.aEnd.SetRow(MAXROW);
}
if (pViewShell && pViewShell->AdjustBlockHeight(false))
{
rDrawRange.aStart.SetCol(0);
rDrawRange.aStart.SetRow(0);
rDrawRange.aEnd.SetCol(MAXCOL);
rDrawRange.aEnd.SetRow(MAXROW);
nPaint |= PAINT_LEFT;
}
pDocShell->UpdatePaintExt(nExtFlags, rDrawRange);
}
}
if ( !bUndo ) // draw redo after updating row heights
RedoSdrUndoAction(mpDrawUndo);
pDocShell->PostPaint(aDrawRanges, nPaint, nExtFlags);
pDocShell->PostDataChanged();
if (pViewShell)
pViewShell->CellContentChanged();
}
void ScUndoPaste::Undo()
{
BeginUndo();
DoChange(true);
if (!maBlockRanges.empty())
ShowTable(*maBlockRanges.front());
EndUndo();
SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
}
void ScUndoPaste::Redo()
{
BeginRedo();
ScDocument& rDoc = pDocShell->GetDocument();
EnableDrawAdjust( &rDoc, false ); //! include in ScBlockUndo?
DoChange( false );
EnableDrawAdjust( &rDoc, true ); //! include in ScBlockUndo?
EndRedo();
SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
}
void ScUndoPaste::Repeat(SfxRepeatTarget& rTarget)
{
if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr)
{
ScTabViewShell* pViewSh = static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pViewSh->GetActiveWin() );
if (pOwnClip)
{
// keep a reference in case the clipboard is changed during PasteFromClip
css::uno::Reference<css::datatransfer::XTransferable> aOwnClipRef( pOwnClip );
pViewSh->PasteFromClip( nFlags, pOwnClip->GetDocument(),
aPasteOptions.nFunction, aPasteOptions.bSkipEmpty, aPasteOptions.bTranspose,
aPasteOptions.bAsLink, aPasteOptions.eMoveMode, InsertDeleteFlags::NONE,
true ); // allow warning dialog
}
}
}
bool ScUndoPaste::CanRepeat(SfxRepeatTarget& rTarget) const
{
return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr;
}
ScUndoDragDrop::ScUndoDragDrop( ScDocShell* pNewDocShell,
const ScRange& rRange, ScAddress aNewDestPos, bool bNewCut,
ScDocument* pUndoDocument, ScRefUndoData* pRefData, bool bScenario ) :
ScMoveUndo( pNewDocShell, pUndoDocument, pRefData, SC_UNDO_REFLAST ),
mnPaintExtFlags( 0 ),
aSrcRange( rRange ),
bCut( bNewCut ),
bKeepScenarioFlags( bScenario )
{
ScAddress aDestEnd(aNewDestPos);
aDestEnd.IncRow(aSrcRange.aEnd.Row() - aSrcRange.aStart.Row());
aDestEnd.IncCol(aSrcRange.aEnd.Col() - aSrcRange.aStart.Col());
aDestEnd.IncTab(aSrcRange.aEnd.Tab() - aSrcRange.aStart.Tab());
bool bIncludeFiltered = bCut;
if ( !bIncludeFiltered )
{
// find number of non-filtered rows
SCROW nPastedCount = pDocShell->GetDocument().CountNonFilteredRows(
aSrcRange.aStart.Row(), aSrcRange.aEnd.Row(), aSrcRange.aStart.Tab());
if ( nPastedCount == 0 )
nPastedCount = 1;
aDestEnd.SetRow( aNewDestPos.Row() + nPastedCount - 1 );
}
aDestRange.aStart = aNewDestPos;
aDestRange.aEnd = aDestEnd;
SetChangeTrack();
}
ScUndoDragDrop::~ScUndoDragDrop()
{
}
OUString ScUndoDragDrop::GetComment() const
{ // "Move" : "Copy"
return bCut ?
ScGlobal::GetRscString( STR_UNDO_MOVE ) :
ScGlobal::GetRscString( STR_UNDO_COPY );
}
void ScUndoDragDrop::SetChangeTrack()
{
ScChangeTrack* pChangeTrack = pDocShell->GetDocument().GetChangeTrack();
if ( pChangeTrack )
{
if ( bCut )
{
nStartChangeAction = pChangeTrack->GetActionMax() + 1;
pChangeTrack->AppendMove( aSrcRange, aDestRange, pRefUndoDoc );
nEndChangeAction = pChangeTrack->GetActionMax();
}
else
pChangeTrack->AppendContentRange( aDestRange, pRefUndoDoc,
nStartChangeAction, nEndChangeAction );
}
else
nStartChangeAction = nEndChangeAction = 0;
}
void ScUndoDragDrop::PaintArea( ScRange aRange, sal_uInt16 nExtFlags ) const
{
sal_uInt16 nPaint = PAINT_GRID;
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
ScDocument& rDoc = pDocShell->GetDocument();
if (pViewShell)
{
ScopedVclPtrInstance< VirtualDevice > pVirtDev;
ScViewData& rViewData = pViewShell->GetViewData();
sc::RowHeightContext aCxt(
rViewData.GetPPTX(), rViewData.GetPPTY(), rViewData.GetZoomX(), rViewData.GetZoomY(),
pVirtDev);
if (rDoc.SetOptimalHeight(aCxt, aRange.aStart.Row(), aRange.aEnd.Row(), aRange.aStart.Tab()))
{
aRange.aStart.SetCol(0);
aRange.aEnd.SetCol(MAXCOL);
aRange.aEnd.SetRow(MAXROW);
nPaint |= PAINT_LEFT;
}
}
if ( bKeepScenarioFlags )
{
// Copy scenario -> also paint scenario boarder
aRange.aStart.SetCol(0);
aRange.aStart.SetRow(0);
aRange.aEnd.SetCol(MAXCOL);
aRange.aEnd.SetRow(MAXROW);
}
// column/row info (width/height) included if whole columns/rows were copied
if ( aSrcRange.aStart.Col() == 0 && aSrcRange.aEnd.Col() == MAXCOL )
{
nPaint |= PAINT_LEFT;
aRange.aEnd.SetRow(MAXROW);
}
if ( aSrcRange.aStart.Row() == 0 && aSrcRange.aEnd.Row() == MAXROW )
{
nPaint |= PAINT_TOP;
aRange.aEnd.SetCol(MAXCOL);
}
pDocShell->PostPaint( aRange, nPaint, nExtFlags );
}
void ScUndoDragDrop::DoUndo( ScRange aRange )
{
ScDocument& rDoc = pDocShell->GetDocument();
ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
if ( pChangeTrack )
pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
// Database range before data, so that the Autofilter button match up in ExtendMerge
ScRange aPaintRange = aRange;
rDoc.ExtendMerge( aPaintRange ); // before deleting
pDocShell->UpdatePaintExt(mnPaintExtFlags, aPaintRange);
// do not undo objects and note captions, they are handled via drawing undo
InsertDeleteFlags nUndoFlags = (InsertDeleteFlags::ALL & ~InsertDeleteFlags::OBJECTS) | InsertDeleteFlags::NOCAPTIONS;
// Additionally discard/forget caption ownership during deletion, as
// Drag&Drop is a special case in that the Undo holds captions of the
// transferred target range, which would get deleted and
// SdrGroupUndo::Undo() would attempt to access invalidated captions and
// crash, tdf#92995
InsertDeleteFlags nDelFlags = nUndoFlags | InsertDeleteFlags::FORGETCAPTIONS;
rDoc.DeleteAreaTab( aRange, nDelFlags );
pRefUndoDoc->CopyToDocument( aRange, nUndoFlags, false, &rDoc );
if ( rDoc.HasAttrib( aRange, HASATTR_MERGED ) )
rDoc.ExtendMerge( aRange, true );
aPaintRange.aEnd.SetCol( std::max( aPaintRange.aEnd.Col(), aRange.aEnd.Col() ) );
aPaintRange.aEnd.SetRow( std::max( aPaintRange.aEnd.Row(), aRange.aEnd.Row() ) );
pDocShell->UpdatePaintExt(mnPaintExtFlags, aPaintRange);
maPaintRanges.Join(aPaintRange);
}
namespace {
class DataChangeNotifier : public std::unary_function<SvtListener*, void>
{
ScHint maHint;
public:
DataChangeNotifier() : maHint(SC_HINT_DATACHANGED, ScAddress()) {}
void operator() ( SvtListener* p )
{
p->Notify(maHint);
}
};
}
void ScUndoDragDrop::Undo()
{
mnPaintExtFlags = 0;
maPaintRanges.RemoveAll();
BeginUndo();
if (bCut)
{
// During undo, we move cells from aDestRange to aSrcRange.
ScDocument& rDoc = pDocShell->GetDocument();
SCCOL nColDelta = aSrcRange.aStart.Col() - aDestRange.aStart.Col();
SCROW nRowDelta = aSrcRange.aStart.Row() - aDestRange.aStart.Row();
SCTAB nTabDelta = aSrcRange.aStart.Tab() - aDestRange.aStart.Tab();
sc::RefUpdateContext aCxt(rDoc);
aCxt.meMode = URM_MOVE;
aCxt.maRange = aSrcRange;
aCxt.mnColDelta = nColDelta;
aCxt.mnRowDelta = nRowDelta;
aCxt.mnTabDelta = nTabDelta;
// Global range names.
ScRangeName* pName = rDoc.GetRangeName();
if (pName)
pName->UpdateReference(aCxt);
SCTAB nTabCount = rDoc.GetTableCount();
for (SCTAB nTab = 0; nTab < nTabCount; ++nTab)
{
// Sheet-local range names.
pName = rDoc.GetRangeName(nTab);
if (pName)
pName->UpdateReference(aCxt, nTab);
}
// Notify all listeners of the destination range, and have them update their references.
sc::RefMovedHint aHint(aDestRange, ScAddress(nColDelta, nRowDelta, nTabDelta), aCxt);
rDoc.BroadcastRefMoved(aHint);
ScValidationDataList* pValidList = rDoc.GetValidationList();
if (pValidList)
{
// Update the references of validation entries.
pValidList->UpdateReference(aCxt);
}
DoUndo(aDestRange);
DoUndo(aSrcRange);
// Notify all area listeners whose listened areas are partially moved, to
// recalculate.
std::vector<SvtListener*> aListeners;
rDoc.CollectAllAreaListeners(aListeners, aSrcRange, sc::AreaPartialOverlap);
// Remove any duplicate listener entries. We must ensure that we notify
// each unique listener only once.
std::sort(aListeners.begin(), aListeners.end());
aListeners.erase(std::unique(aListeners.begin(), aListeners.end()), aListeners.end());
std::for_each(aListeners.begin(), aListeners.end(), DataChangeNotifier());
}
else
DoUndo(aDestRange);
for (size_t i = 0; i < maPaintRanges.size(); ++i)
{
const ScRange* p = maPaintRanges[i];
PaintArea(*p, mnPaintExtFlags);
}
EndUndo();
SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
}
void ScUndoDragDrop::Redo()
{
BeginRedo();
ScDocument& rDoc = pDocShell->GetDocument();
std::unique_ptr<ScDocument> pClipDoc(new ScDocument( SCDOCMODE_CLIP ));
EnableDrawAdjust( &rDoc, false ); //! include in ScBlockUndo?
// do not undo/redo objects and note captions, they are handled via drawing undo
InsertDeleteFlags nRedoFlags = (InsertDeleteFlags::ALL & ~InsertDeleteFlags::OBJECTS) | InsertDeleteFlags::NOCAPTIONS;
/* TODO: Redoing note captions is quite tricky due to the fact that a
helper clip document is used. While (re-)pasting the contents to the
destination area, the original pointers to the captions created while
dropping have to be restored. A simple CopyFromClip() would create new
caption objects that are not tracked by drawing undo, and the captions
restored by drawing redo would live without cell note objects pointing
to them. So, first, CopyToClip() and CopyFromClip() are called without
cloning the caption objects. This leads to cell notes pointing to the
wrong captions from source area that will be removed by drawing redo
later. Second, the pointers to the new captions have to be restored.
Sadly, currently these pointers are not stored anywhere but in the list
of drawing undo actions. */
SCTAB nTab;
ScMarkData aSourceMark;
for (nTab=aSrcRange.aStart.Tab(); nTab<=aSrcRange.aEnd.Tab(); nTab++)
aSourceMark.SelectTable( nTab, true );
// do not clone objects and note captions into clipdoc (see above)
// but at least copy notes
ScClipParam aClipParam(aSrcRange, bCut);
rDoc.CopyToClip(aClipParam, pClipDoc.get(), &aSourceMark, bKeepScenarioFlags, false);
if (bCut)
{
ScRange aSrcPaintRange = aSrcRange;
rDoc.ExtendMerge( aSrcPaintRange ); // before deleting
sal_uInt16 nExtFlags = 0;
pDocShell->UpdatePaintExt( nExtFlags, aSrcPaintRange );
rDoc.DeleteAreaTab( aSrcRange, nRedoFlags );
PaintArea( aSrcPaintRange, nExtFlags );
}
ScMarkData aDestMark;
for (nTab=aDestRange.aStart.Tab(); nTab<=aDestRange.aEnd.Tab(); nTab++)
aDestMark.SelectTable( nTab, true );
bool bIncludeFiltered = bCut;
// TODO: restore old note captions instead of cloning new captions...
rDoc.CopyFromClip( aDestRange, aDestMark, InsertDeleteFlags::ALL & ~InsertDeleteFlags::OBJECTS, nullptr, pClipDoc.get(), true, false, bIncludeFiltered );
if (bCut)
for (nTab=aSrcRange.aStart.Tab(); nTab<=aSrcRange.aEnd.Tab(); nTab++)
rDoc.RefreshAutoFilter( aSrcRange.aStart.Col(), aSrcRange.aStart.Row(),
aSrcRange.aEnd.Col(), aSrcRange.aEnd.Row(), nTab );
// skipped rows and merged cells don't mix
if ( !bIncludeFiltered && pClipDoc->HasClipFilteredRows() )
pDocShell->GetDocFunc().UnmergeCells( aDestRange, false, nullptr );
for (nTab=aDestRange.aStart.Tab(); nTab<=aDestRange.aEnd.Tab(); nTab++)
{
SCCOL nEndCol = aDestRange.aEnd.Col();
SCROW nEndRow = aDestRange.aEnd.Row();
rDoc.ExtendMerge( aDestRange.aStart.Col(), aDestRange.aStart.Row(),
nEndCol, nEndRow, nTab, true );
PaintArea( ScRange( aDestRange.aStart.Col(), aDestRange.aStart.Row(), nTab,
nEndCol, nEndRow, nTab ), 0 );
}
SetChangeTrack();
pClipDoc.reset();
ShowTable( aDestRange.aStart.Tab() );
RedoSdrUndoAction( pDrawUndo ); //! include in ScBlockUndo?
EnableDrawAdjust( &rDoc, true ); //! include in ScBlockUndo?
EndRedo();
SfxGetpApp()->Broadcast( SfxSimpleHint( SC_HINT_AREALINKS_CHANGED ) );
}
void ScUndoDragDrop::Repeat(SfxRepeatTarget& /* rTarget */)
{
}
bool ScUndoDragDrop::CanRepeat(SfxRepeatTarget& /* rTarget */) const
{
return false; // not possible
}
// Insert list containing range names
// (Insert|Name|Insert =>[List])
ScUndoListNames::ScUndoListNames( ScDocShell* pNewDocShell, const ScRange& rRange,
ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc ) :
ScBlockUndo( pNewDocShell, rRange, SC_UNDO_AUTOHEIGHT ),
pUndoDoc( pNewUndoDoc ),
pRedoDoc( pNewRedoDoc )
{
}
ScUndoListNames::~ScUndoListNames()
{
delete pUndoDoc;
delete pRedoDoc;
}
OUString ScUndoListNames::GetComment() const
{
return ScGlobal::GetRscString( STR_UNDO_LISTNAMES );
}
void ScUndoListNames::DoChange( ScDocument* pSrcDoc ) const
{
ScDocument& rDoc = pDocShell->GetDocument();
rDoc.DeleteAreaTab( aBlockRange, InsertDeleteFlags::ALL );
pSrcDoc->CopyToDocument( aBlockRange, InsertDeleteFlags::ALL, false, &rDoc );
pDocShell->PostPaint( aBlockRange, PAINT_GRID );
pDocShell->PostDataChanged();
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
if (pViewShell)
pViewShell->CellContentChanged();
}
void ScUndoListNames::Undo()
{
BeginUndo();
DoChange(pUndoDoc);
EndUndo();
}
void ScUndoListNames::Redo()
{
BeginRedo();
DoChange(pRedoDoc);
EndRedo();
}
void ScUndoListNames::Repeat(SfxRepeatTarget& rTarget)
{
if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr)
static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->InsertNameList();
}
bool ScUndoListNames::CanRepeat(SfxRepeatTarget& rTarget) const
{
return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr;
}
ScUndoConditionalFormat::ScUndoConditionalFormat(ScDocShell* pNewDocShell,
ScDocument* pUndoDoc, ScDocument* pRedoDoc, const ScRange& rRange):
ScSimpleUndo( pNewDocShell ),
mpUndoDoc(pUndoDoc),
mpRedoDoc(pRedoDoc),
maRange(rRange)
{
}
ScUndoConditionalFormat::~ScUndoConditionalFormat()
{
}
OUString ScUndoConditionalFormat::GetComment() const
{
return ScGlobal::GetRscString( STR_UNDO_CONDFORMAT );
}
void ScUndoConditionalFormat::Undo()
{
DoChange(mpUndoDoc.get());
}
void ScUndoConditionalFormat::Redo()
{
DoChange(mpRedoDoc.get());
}
void ScUndoConditionalFormat::DoChange(ScDocument* pSrcDoc)
{
ScDocument& rDoc = pDocShell->GetDocument();
rDoc.DeleteAreaTab( maRange, InsertDeleteFlags::ALL );
pSrcDoc->CopyToDocument( maRange, InsertDeleteFlags::ALL, false, &rDoc );
pDocShell->PostPaint( maRange, PAINT_GRID );
pDocShell->PostDataChanged();
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
if (pViewShell)
pViewShell->CellContentChanged();
}
void ScUndoConditionalFormat::Repeat(SfxRepeatTarget& )
{
}
bool ScUndoConditionalFormat::CanRepeat(SfxRepeatTarget& ) const
{
return false;
}
ScUndoUseScenario::ScUndoUseScenario( ScDocShell* pNewDocShell,
const ScMarkData& rMark,
/*C*/ const ScArea& rDestArea,
ScDocument* pNewUndoDoc,
const OUString& rNewName ) :
ScSimpleUndo( pNewDocShell ),
pUndoDoc( pNewUndoDoc ),
aMarkData( rMark ),
aName( rNewName )
{
aRange.aStart.SetCol(rDestArea.nColStart);
aRange.aStart.SetRow(rDestArea.nRowStart);
aRange.aStart.SetTab(rDestArea.nTab);
aRange.aEnd.SetCol(rDestArea.nColEnd);
aRange.aEnd.SetRow(rDestArea.nRowEnd);
aRange.aEnd.SetTab(rDestArea.nTab);
}
ScUndoUseScenario::~ScUndoUseScenario()
{
delete pUndoDoc;
}
OUString ScUndoUseScenario::GetComment() const
{
return ScGlobal::GetRscString( STR_UNDO_USESCENARIO );
}
void ScUndoUseScenario::Undo()
{
BeginUndo();
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
if (pViewShell)
{
pViewShell->DoneBlockMode();
pViewShell->InitOwnBlockMode();
}
ScDocument& rDoc = pDocShell->GetDocument();
rDoc.DeleteSelection( InsertDeleteFlags::ALL, aMarkData );
pUndoDoc->CopyToDocument( aRange, InsertDeleteFlags::ALL, true, &rDoc, &aMarkData );
// scenario table
bool bFrame = false;
SCTAB nTab = aRange.aStart.Tab();
SCTAB nEndTab = nTab;
while ( pUndoDoc->HasTable(nEndTab+1) && pUndoDoc->IsScenario(nEndTab+1) )
++nEndTab;
for (SCTAB i = nTab+1; i<=nEndTab; i++)
{
// Flags always
OUString aComment;
Color aColor;
sal_uInt16 nScenFlags;
pUndoDoc->GetScenarioData( i, aComment, aColor, nScenFlags );
rDoc.SetScenarioData( i, aComment, aColor, nScenFlags );
bool bActive = pUndoDoc->IsActiveScenario( i );
rDoc.SetActiveScenario( i, bActive );
// For copy-back scenario also consider content
if ( nScenFlags & SC_SCENARIO_TWOWAY )
{
rDoc.DeleteAreaTab( 0,0, MAXCOL,MAXROW, i, InsertDeleteFlags::ALL );
pUndoDoc->CopyToDocument( 0,0,i, MAXCOL,MAXROW,i, InsertDeleteFlags::ALL,false, &rDoc );
}
if ( nScenFlags & SC_SCENARIO_SHOWFRAME )
bFrame = true;
}
// if visible borders, then paint all
if (bFrame)
pDocShell->PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID | PAINT_EXTRAS );
else
pDocShell->PostPaint( aRange, PAINT_GRID | PAINT_EXTRAS );
pDocShell->PostDataChanged();
if (pViewShell)
pViewShell->CellContentChanged();
ShowTable( aRange.aStart.Tab() );
EndUndo();
}
void ScUndoUseScenario::Redo()
{
SCTAB nTab = aRange.aStart.Tab();
BeginRedo();
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
if (pViewShell)
{
pViewShell->SetTabNo( nTab );
pViewShell->DoneBlockMode();
pViewShell->InitOwnBlockMode();
}
pDocShell->UseScenario( nTab, aName, false );
EndRedo();
}
void ScUndoUseScenario::Repeat(SfxRepeatTarget& rTarget)
{
if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr)
{
OUString aTemp = aName;
static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->UseScenario(aTemp);
}
}
bool ScUndoUseScenario::CanRepeat(SfxRepeatTarget& rTarget) const
{
if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr)
{
ScViewData& rViewData = static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->GetViewData();
return !rViewData.GetDocument()->IsScenario( rViewData.GetTabNo() );
}
return false;
}
ScUndoSelectionStyle::ScUndoSelectionStyle( ScDocShell* pNewDocShell,
const ScMarkData& rMark,
const ScRange& rRange,
const OUString& rName,
ScDocument* pNewUndoDoc ) :
ScSimpleUndo( pNewDocShell ),
aMarkData( rMark ),
pUndoDoc( pNewUndoDoc ),
aStyleName( rName ),
aRange( rRange )
{
aMarkData.MarkToMulti();
}
ScUndoSelectionStyle::~ScUndoSelectionStyle()
{
delete pUndoDoc;
}
OUString ScUndoSelectionStyle::GetComment() const
{
return ScGlobal::GetRscString( STR_UNDO_APPLYCELLSTYLE );
}
void ScUndoSelectionStyle::DoChange( const bool bUndo )
{
ScDocument& rDoc = pDocShell->GetDocument();
SetViewMarkData( aMarkData );
ScRange aWorkRange( aRange );
if ( rDoc.HasAttrib( aWorkRange, HASATTR_MERGED ) ) // Merged cells?
rDoc.ExtendMerge( aWorkRange, true );
sal_uInt16 nExtFlags = 0;
pDocShell->UpdatePaintExt( nExtFlags, aWorkRange );
if (bUndo) // if Undo then push back all old data again
{
SCTAB nTabCount = rDoc.GetTableCount();
ScRange aCopyRange = aWorkRange;
aCopyRange.aStart.SetTab(0);
aCopyRange.aEnd.SetTab(nTabCount-1);
pUndoDoc->CopyToDocument( aCopyRange, InsertDeleteFlags::ATTRIB, true, &rDoc, &aMarkData );
}
else // if Redo, then reapply style
{
ScStyleSheetPool* pStlPool = rDoc.GetStyleSheetPool();
ScStyleSheet* pStyleSheet =
static_cast<ScStyleSheet*>( pStlPool->Find( aStyleName, SfxStyleFamily::Para ) );
if (!pStyleSheet)
{
OSL_FAIL("StyleSheet not found");
return;
}
rDoc.ApplySelectionStyle( *pStyleSheet, aMarkData );
}
pDocShell->UpdatePaintExt( nExtFlags, aWorkRange );
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
if ( !( (pViewShell) && pViewShell->AdjustBlockHeight() ) )
/*A*/ pDocShell->PostPaint( aWorkRange, PAINT_GRID | PAINT_EXTRAS, nExtFlags );
ShowTable( aWorkRange.aStart.Tab() );
}
void ScUndoSelectionStyle::Undo()
{
BeginUndo();
DoChange( true );
EndUndo();
}
void ScUndoSelectionStyle::Redo()
{
BeginRedo();
DoChange( false );
EndRedo();
}
void ScUndoSelectionStyle::Repeat(SfxRepeatTarget& rTarget)
{
if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr)
{
ScDocument& rDoc = pDocShell->GetDocument();
ScStyleSheetPool* pStlPool = rDoc.GetStyleSheetPool();
ScStyleSheet* pStyleSheet = static_cast<ScStyleSheet*>( pStlPool->
Find( aStyleName, SfxStyleFamily::Para ));
if (!pStyleSheet)
{
OSL_FAIL("StyleSheet not found");
return;
}
ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
rViewShell.SetStyleSheetToMarked( pStyleSheet );
}
}
bool ScUndoSelectionStyle::CanRepeat(SfxRepeatTarget& rTarget) const
{
return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr;
}
sal_uInt16 ScUndoSelectionStyle::GetId() const
{
return STR_UNDO_APPLYCELLSTYLE;
}
ScUndoEnterMatrix::ScUndoEnterMatrix( ScDocShell* pNewDocShell, const ScRange& rArea,
ScDocument* pNewUndoDoc, const OUString& rForm ) :
ScBlockUndo( pNewDocShell, rArea, SC_UNDO_SIMPLE ),
pUndoDoc( pNewUndoDoc ),
aFormula( rForm )
{
SetChangeTrack();
}
ScUndoEnterMatrix::~ScUndoEnterMatrix()
{
delete pUndoDoc;
}
OUString ScUndoEnterMatrix::GetComment() const
{
return ScGlobal::GetRscString( STR_UNDO_ENTERMATRIX );
}
void ScUndoEnterMatrix::SetChangeTrack()
{
ScDocument& rDoc = pDocShell->GetDocument();
ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
if ( pChangeTrack )
pChangeTrack->AppendContentRange( aBlockRange, pUndoDoc,
nStartChangeAction, nEndChangeAction );
else
nStartChangeAction = nEndChangeAction = 0;
}
void ScUndoEnterMatrix::Undo()
{
BeginUndo();
ScDocument& rDoc = pDocShell->GetDocument();
rDoc.DeleteAreaTab( aBlockRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE );
pUndoDoc->CopyToDocument( aBlockRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, &rDoc );
pDocShell->PostPaint( aBlockRange, PAINT_GRID );
pDocShell->PostDataChanged();
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
if (pViewShell)
pViewShell->CellContentChanged();
ScChangeTrack* pChangeTrack = rDoc.GetChangeTrack();
if ( pChangeTrack )
pChangeTrack->Undo( nStartChangeAction, nEndChangeAction );
EndUndo();
}
void ScUndoEnterMatrix::Redo()
{
BeginRedo();
ScDocument& rDoc = pDocShell->GetDocument();
ScMarkData aDestMark;
aDestMark.SelectOneTable( aBlockRange.aStart.Tab() );
aDestMark.SetMarkArea( aBlockRange );
rDoc.InsertMatrixFormula( aBlockRange.aStart.Col(), aBlockRange.aStart.Row(),
aBlockRange.aEnd.Col(), aBlockRange.aEnd.Row(),
aDestMark, aFormula );
SetChangeTrack();
EndRedo();
}
void ScUndoEnterMatrix::Repeat(SfxRepeatTarget& rTarget)
{
if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr)
{
OUString aTemp = aFormula;
ScDocument& rDoc = pDocShell->GetDocument();
static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->EnterMatrix(aTemp, rDoc.GetGrammar());
}
}
bool ScUndoEnterMatrix::CanRepeat(SfxRepeatTarget& rTarget) const
{
return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr;
}
static ScRange lcl_GetMultiMarkRange( const ScMarkData& rMark )
{
OSL_ENSURE( rMark.IsMultiMarked(), "wrong mark type" );
ScRange aRange;
rMark.GetMultiMarkArea( aRange );
return aRange;
}
ScUndoIndent::ScUndoIndent( ScDocShell* pNewDocShell, const ScMarkData& rMark,
ScDocument* pNewUndoDoc, bool bIncrement ) :
ScBlockUndo( pNewDocShell, lcl_GetMultiMarkRange(rMark), SC_UNDO_AUTOHEIGHT ),
aMarkData( rMark ),
pUndoDoc( pNewUndoDoc ),
bIsIncrement( bIncrement )
{
}
ScUndoIndent::~ScUndoIndent()
{
delete pUndoDoc;
}
OUString ScUndoIndent::GetComment() const
{
sal_uInt16 nId = bIsIncrement ? STR_UNDO_INC_INDENT : STR_UNDO_DEC_INDENT;
return ScGlobal::GetRscString( nId );
}
void ScUndoIndent::Undo()
{
BeginUndo();
ScDocument& rDoc = pDocShell->GetDocument();
SCTAB nTabCount = rDoc.GetTableCount();
ScRange aCopyRange = aBlockRange;
aCopyRange.aStart.SetTab(0);
aCopyRange.aEnd.SetTab(nTabCount-1);
pUndoDoc->CopyToDocument( aCopyRange, InsertDeleteFlags::ATTRIB, true, &rDoc, &aMarkData );
pDocShell->PostPaint( aBlockRange, PAINT_GRID, SC_PF_LINES | SC_PF_TESTMERGE );
EndUndo();
}
void ScUndoIndent::Redo()
{
BeginRedo();
ScDocument& rDoc = pDocShell->GetDocument();
rDoc.ChangeSelectionIndent( bIsIncrement, aMarkData );
pDocShell->PostPaint( aBlockRange, PAINT_GRID, SC_PF_LINES | SC_PF_TESTMERGE );
EndRedo();
}
void ScUndoIndent::Repeat(SfxRepeatTarget& rTarget)
{
if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr)
static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->ChangeIndent( bIsIncrement );
}
bool ScUndoIndent::CanRepeat(SfxRepeatTarget& rTarget) const
{
return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr;
}
ScUndoTransliterate::ScUndoTransliterate( ScDocShell* pNewDocShell, const ScMarkData& rMark,
ScDocument* pNewUndoDoc, sal_Int32 nType ) :
ScBlockUndo( pNewDocShell, lcl_GetMultiMarkRange(rMark), SC_UNDO_AUTOHEIGHT ),
aMarkData( rMark ),
pUndoDoc( pNewUndoDoc ),
nTransliterationType( nType )
{
}
ScUndoTransliterate::~ScUndoTransliterate()
{
delete pUndoDoc;
}
OUString ScUndoTransliterate::GetComment() const
{
return ScGlobal::GetRscString( STR_UNDO_TRANSLITERATE );
}
void ScUndoTransliterate::Undo()
{
BeginUndo();
ScDocument& rDoc = pDocShell->GetDocument();
SCTAB nTabCount = rDoc.GetTableCount();
ScRange aCopyRange = aBlockRange;
aCopyRange.aStart.SetTab(0);
aCopyRange.aEnd.SetTab(nTabCount-1);
pUndoDoc->CopyToDocument( aCopyRange, InsertDeleteFlags::CONTENTS, true, &rDoc, &aMarkData );
pDocShell->PostPaint( aBlockRange, PAINT_GRID, SC_PF_LINES | SC_PF_TESTMERGE );
EndUndo();
}
void ScUndoTransliterate::Redo()
{
BeginRedo();
ScDocument& rDoc = pDocShell->GetDocument();
rDoc.TransliterateText( aMarkData, nTransliterationType );
pDocShell->PostPaint( aBlockRange, PAINT_GRID, SC_PF_LINES | SC_PF_TESTMERGE );
EndRedo();
}
void ScUndoTransliterate::Repeat(SfxRepeatTarget& rTarget)
{
if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr)
static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->TransliterateText( nTransliterationType );
}
bool ScUndoTransliterate::CanRepeat(SfxRepeatTarget& rTarget) const
{
return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr;
}
ScUndoClearItems::ScUndoClearItems( ScDocShell* pNewDocShell, const ScMarkData& rMark,
ScDocument* pNewUndoDoc, const sal_uInt16* pW ) :
ScBlockUndo( pNewDocShell, lcl_GetMultiMarkRange(rMark), SC_UNDO_AUTOHEIGHT ),
aMarkData( rMark ),
pUndoDoc( pNewUndoDoc ),
pWhich( nullptr )
{
OSL_ENSURE( pW, "ScUndoClearItems: Which-Pointer ist 0" );
sal_uInt16 nCount = 0;
while ( pW[nCount] )
++nCount;
pWhich = new sal_uInt16[nCount+1];
for (sal_uInt16 i=0; i<=nCount; i++)
pWhich[i] = pW[i];
}
ScUndoClearItems::~ScUndoClearItems()
{
delete pUndoDoc;
delete pWhich;
}
OUString ScUndoClearItems::GetComment() const
{
return ScGlobal::GetRscString( STR_UNDO_DELETECONTENTS );
}
void ScUndoClearItems::Undo()
{
BeginUndo();
ScDocument& rDoc = pDocShell->GetDocument();
pUndoDoc->CopyToDocument( aBlockRange, InsertDeleteFlags::ATTRIB, true, &rDoc, &aMarkData );
pDocShell->PostPaint( aBlockRange, PAINT_GRID, SC_PF_LINES | SC_PF_TESTMERGE );
EndUndo();
}
void ScUndoClearItems::Redo()
{
BeginRedo();
ScDocument& rDoc = pDocShell->GetDocument();
rDoc.ClearSelectionItems( pWhich, aMarkData );
pDocShell->PostPaint( aBlockRange, PAINT_GRID, SC_PF_LINES | SC_PF_TESTMERGE );
EndRedo();
}
void ScUndoClearItems::Repeat(SfxRepeatTarget& rTarget)
{
if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr)
{
ScViewData& rViewData = static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->GetViewData();
rViewData.GetDocFunc().ClearItems( rViewData.GetMarkData(), pWhich, false );
}
}
bool ScUndoClearItems::CanRepeat(SfxRepeatTarget& rTarget) const
{
return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr;
}
// remove all line breaks of a table
ScUndoRemoveBreaks::ScUndoRemoveBreaks( ScDocShell* pNewDocShell,
SCTAB nNewTab, ScDocument* pNewUndoDoc ) :
ScSimpleUndo( pNewDocShell ),
nTab( nNewTab ),
pUndoDoc( pNewUndoDoc )
{
}
ScUndoRemoveBreaks::~ScUndoRemoveBreaks()
{
delete pUndoDoc;
}
OUString ScUndoRemoveBreaks::GetComment() const
{
return ScGlobal::GetRscString( STR_UNDO_REMOVEBREAKS );
}
void ScUndoRemoveBreaks::Undo()
{
BeginUndo();
ScDocument& rDoc = pDocShell->GetDocument();
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
pUndoDoc->CopyToDocument( 0,0,nTab, MAXCOL,MAXROW,nTab, InsertDeleteFlags::NONE, false, &rDoc );
if (pViewShell)
pViewShell->UpdatePageBreakData( true );
pDocShell->PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID );
EndUndo();
}
void ScUndoRemoveBreaks::Redo()
{
BeginRedo();
ScDocument& rDoc = pDocShell->GetDocument();
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
rDoc.RemoveManualBreaks(nTab);
rDoc.UpdatePageBreaks(nTab);
if (pViewShell)
pViewShell->UpdatePageBreakData( true );
pDocShell->PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID );
EndRedo();
}
void ScUndoRemoveBreaks::Repeat(SfxRepeatTarget& rTarget)
{
if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr)
{
ScTabViewShell& rViewShell = *static_cast<ScTabViewTarget&>(rTarget).GetViewShell();
rViewShell.RemoveManualBreaks();
}
}
bool ScUndoRemoveBreaks::CanRepeat(SfxRepeatTarget& rTarget) const
{
return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr;
}
ScUndoRemoveMerge::ScUndoRemoveMerge( ScDocShell* pNewDocShell,
const ScCellMergeOption& rOption, ScDocument* pNewUndoDoc ) :
ScBlockUndo( pNewDocShell, rOption.getFirstSingleRange(), SC_UNDO_SIMPLE ),
pUndoDoc( pNewUndoDoc )
{
maOptions.push_back( rOption);
}
ScUndoRemoveMerge::ScUndoRemoveMerge( ScDocShell* pNewDocShell,
const ScRange& rRange, ScDocument* pNewUndoDoc ) :
ScBlockUndo( pNewDocShell, rRange, SC_UNDO_SIMPLE ),
pUndoDoc( pNewUndoDoc )
{
}
ScUndoRemoveMerge::~ScUndoRemoveMerge()
{
delete pUndoDoc;
}
OUString ScUndoRemoveMerge::GetComment() const
{
return ScGlobal::GetRscString( STR_UNDO_REMERGE ); // "remove merge"
}
ScDocument* ScUndoRemoveMerge::GetUndoDoc()
{
return pUndoDoc;
}
void ScUndoRemoveMerge::AddCellMergeOption( const ScCellMergeOption& rOption )
{
maOptions.push_back( rOption);
}
void ScUndoRemoveMerge::Undo()
{
using ::std::set;
SetCurTab();
BeginUndo();
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
ScDocument& rDoc = pDocShell->GetDocument();
for (const auto & rOption : maOptions)
{
for (set<SCTAB>::const_iterator itr = rOption.maTabs.begin(), itrEnd = rOption.maTabs.end();
itr != itrEnd; ++itr)
{
OSL_ENSURE(pUndoDoc, "NULL pUndoDoc!");
if (!pUndoDoc)
continue;
// There is no need to extend merge area because it's already been extended.
ScRange aRange = rOption.getSingleRange(*itr);
rDoc.DeleteAreaTab(aRange, InsertDeleteFlags::ATTRIB);
pUndoDoc->CopyToDocument(aRange, InsertDeleteFlags::ATTRIB, false, &rDoc);
bool bDidPaint = false;
if ( pViewShell )
{
pViewShell->SetTabNo(*itr);
bDidPaint = pViewShell->AdjustRowHeight(rOption.mnStartRow, rOption.mnEndRow);
}
if (!bDidPaint)
ScUndoUtil::PaintMore(pDocShell, aRange);
}
}
EndUndo();
}
void ScUndoRemoveMerge::Redo()
{
using ::std::set;
SetCurTab();
BeginRedo();
ScDocument& rDoc = pDocShell->GetDocument();
ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
for (const auto & rOption : maOptions)
{
for (set<SCTAB>::const_iterator itr = rOption.maTabs.begin(), itrEnd = rOption.maTabs.end();
itr != itrEnd; ++itr)
{
SCTAB nTab = *itr;
// There is no need to extend merge area because it's already been extended.
ScRange aRange = rOption.getSingleRange(nTab);
const SfxPoolItem& rDefAttr = rDoc.GetPool()->GetDefaultItem( ATTR_MERGE );
ScPatternAttr aPattern( rDoc.GetPool() );
aPattern.GetItemSet().Put( rDefAttr );
rDoc.ApplyPatternAreaTab( rOption.mnStartCol, rOption.mnStartRow,
rOption.mnEndCol, rOption.mnEndRow, nTab,
aPattern );
rDoc.RemoveFlagsTab( rOption.mnStartCol, rOption.mnStartRow,
rOption.mnEndCol, rOption.mnEndRow, nTab,
ScMF::Hor | ScMF::Ver );
rDoc.ExtendMerge(aRange, true);
// Paint
bool bDidPaint = false;
if ( pViewShell )
{
pViewShell->SetTabNo(nTab);
bDidPaint = pViewShell->AdjustRowHeight(rOption.mnStartRow, rOption.mnEndRow);
}
if (!bDidPaint)
ScUndoUtil::PaintMore(pDocShell, aRange);
}
}
EndRedo();
}
void ScUndoRemoveMerge::Repeat(SfxRepeatTarget& rTarget)
{
if (dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr)
static_cast<ScTabViewTarget&>(rTarget).GetViewShell()->RemoveMerge();
}
bool ScUndoRemoveMerge::CanRepeat(SfxRepeatTarget& rTarget) const
{
return dynamic_cast<const ScTabViewTarget*>( &rTarget) != nullptr;
}
void ScUndoRemoveMerge::SetCurTab()
{
SCTAB nCurTab = ScDocShell::GetCurTab();
aBlockRange.aStart.SetTab(nCurTab);
aBlockRange.aEnd.SetTab(nCurTab);
}
/** set only border, for ScRangeList (StarOne) */
static ScRange lcl_TotalRange( const ScRangeList& rRanges )
{
ScRange aTotal;
if ( !rRanges.empty() )
{
aTotal = *rRanges[ 0 ];
for ( size_t i = 1, nCount = rRanges.size(); i < nCount; ++i )
{
ScRange aRange = *rRanges[ i ];
if (aRange.aStart.Col() < aTotal.aStart.Col()) aTotal.aStart.SetCol(aRange.aStart.Col());
if (aRange.aStart.Row() < aTotal.aStart.Row()) aTotal.aStart.SetRow(aRange.aStart.Row());
if (aRange.aStart.Tab() < aTotal.aStart.Tab()) aTotal.aStart.SetTab(aRange.aStart.Tab());
if (aRange.aEnd.Col() > aTotal.aEnd.Col() ) aTotal.aEnd.SetCol( aRange.aEnd.Col() );
if (aRange.aEnd.Row() > aTotal.aEnd.Row() ) aTotal.aEnd.SetRow( aRange.aEnd.Row() );
if (aRange.aEnd.Tab() > aTotal.aEnd.Tab() ) aTotal.aEnd.SetTab(aRange.aEnd.Tab() );
}
}
return aTotal;
}
ScUndoBorder::ScUndoBorder( ScDocShell* pNewDocShell,
const ScRangeList& rRangeList, ScDocument* pNewUndoDoc,
const SvxBoxItem& rNewOuter, const SvxBoxInfoItem& rNewInner ) :
ScBlockUndo( pNewDocShell, lcl_TotalRange(rRangeList), SC_UNDO_SIMPLE ),
pUndoDoc( pNewUndoDoc )
{
pRanges = new ScRangeList(rRangeList);
pOuter = new SvxBoxItem(rNewOuter);
pInner = new SvxBoxInfoItem(rNewInner);
}
ScUndoBorder::~ScUndoBorder()
{
delete pUndoDoc;
delete pRanges;
delete pOuter;
delete pInner;
}
OUString ScUndoBorder::GetComment() const
{
return ScGlobal::GetRscString( STR_UNDO_SELATTRLINES ); //! own string?
}
void ScUndoBorder::Undo()
{
BeginUndo();
ScDocument& rDoc = pDocShell->GetDocument();
ScMarkData aMarkData;
aMarkData.MarkFromRangeList( *pRanges, false );
pUndoDoc->CopyToDocument( aBlockRange, InsertDeleteFlags::ATTRIB, true, &rDoc, &aMarkData );
pDocShell->PostPaint( aBlockRange, PAINT_GRID, SC_PF_LINES | SC_PF_TESTMERGE );
EndUndo();
}
void ScUndoBorder::Redo()
{
BeginRedo();
ScDocument& rDoc = pDocShell->GetDocument(); // call function at docfunc
size_t nCount = pRanges->size();
for (size_t i = 0; i < nCount; ++i )
{
ScRange aRange = *(*pRanges)[i];
SCTAB nTab = aRange.aStart.Tab();
ScMarkData aMark;
aMark.SetMarkArea( aRange );
aMark.SelectTable( nTab, true );
rDoc.ApplySelectionFrame( aMark, pOuter, pInner );
}
for (size_t i = 0; i < nCount; ++i)
pDocShell->PostPaint( *(*pRanges)[i], PAINT_GRID, SC_PF_LINES | SC_PF_TESTMERGE );
EndRedo();
}
void ScUndoBorder::Repeat(SfxRepeatTarget& /* rTarget */)
{
//TODO later (when the function has moved from cellsuno to docfunc)
}
bool ScUndoBorder::CanRepeat(SfxRepeatTarget& /* rTarget */) const
{
return false; // See above
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|