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 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include <hintids.hxx>
#include <tools/errinf.hxx>
#include <vcl/svapp.hxx>
#include <basegfx/vector/b2dvector.hxx>
#include <svx/svxids.hrc>
#include <editeng/protitem.hxx>
#include <editeng/brshitem.hxx>
#include <editeng/frmdiritem.hxx>
#include <svtools/ruler.hxx>
#include <swwait.hxx>
#include <fmtfsize.hxx>
#include <fmtornt.hxx>
#include <frmatr.hxx>
#include <docary.hxx>
#include <fesh.hxx>
#include <doc.hxx>
#include <cntfrm.hxx>
#include <rootfrm.hxx>
#include <pagefrm.hxx>
#include <tabfrm.hxx>
#include <rowfrm.hxx>
#include <cellfrm.hxx>
#include <flyfrm.hxx>
#include <dflyobj.hxx>
#include <swtable.hxx>
#include <swddetbl.hxx>
#include <ndtxt.hxx>
#include <calc.hxx>
#include <tabcol.hxx>
#include <cellatr.hxx>
#include <pam.hxx>
#include <viscrs.hxx>
#include <tblsel.hxx>
#include <swtblfmt.hxx>
#include <swerror.h>
#include <swundo.hxx>
#include <frmtool.hxx>
#include <node.hxx> // #i23726#
// OD 2004-05-24 #i28701#
#include <sortedobjs.hxx>
using namespace ::com::sun::star;
//siehe auch swtable.cxx
#define COLFUZZY 20L
inline sal_Bool IsSame( long nA, long nB ) { return Abs(nA-nB) <= COLFUZZY; }
inline sal_Bool IsNear( long nA, long nB, long nTolerance ) { return Abs( nA - nB ) <= nTolerance; }
// table column cache
SwTabCols *pLastCols = 0;
const SwTable *pColumnCacheLastTable = 0;
const SwTabFrm *pColumnCacheLastTabFrm = 0;
const SwFrm *pColumnCacheLastCellFrm = 0;
// table row cache
SwTabCols *pLastRows = 0;
const SwTable *pRowCacheLastTable = 0;
const SwTabFrm *pRowCacheLastTabFrm = 0;
const SwFrm *pRowCacheLastCellFrm = 0;
class TblWait
{
SwWait *pWait;
public:
TblWait( sal_uInt16 nCnt, SwFrm *pFrm, SwDocShell &rDocShell, sal_uInt16 nCnt2 = 0);
~TblWait() { delete pWait; }
};
TblWait::TblWait( sal_uInt16 nCnt, SwFrm *pFrm, SwDocShell &rDocShell, sal_uInt16 nCnt2):
pWait( 0 )
{
sal_Bool bWait = 20 < nCnt || 20 < nCnt2 || (pFrm &&
20 < pFrm->ImplFindTabFrm()->GetTable()->GetTabLines().Count());
if( bWait )
pWait = new SwWait( rDocShell, sal_True );
}
void SwFEShell::ParkCursorInTab()
{
SwCursor * pSwCrsr = GetSwCrsr();
OSL_ENSURE(pSwCrsr, "no SwCursor");
SwPosition aStartPos = *pSwCrsr->GetPoint(), aEndPos = aStartPos;
SwCursor * pTmpCrsr = (SwCursor *) pSwCrsr;
/* Search least and greatest position in current cursor ring.
*/
do
{
const SwPosition * pPt = pTmpCrsr->GetPoint(),
* pMk = pTmpCrsr->GetMark();
if (*pPt < aStartPos)
aStartPos = *pPt;
if (*pPt > aEndPos)
aEndPos = *pPt;
if (*pMk < aStartPos)
aStartPos = *pMk;
if (*pMk > aEndPos)
aEndPos = *pMk;
pTmpCrsr = (SwCursor *) pTmpCrsr->GetNext();
}
while (pTmpCrsr != pSwCrsr);
KillPams();
/* @@@ semantic: SwCursor::operator=() is not implemented @@@ */
/* Set cursor to end of selection to ensure IsLastCellInRow works
properly. */
{
SwCursor aTmpCrsr( aEndPos, 0, false );
*pSwCrsr = aTmpCrsr;
}
/* Move the cursor out of the columns to delete and stay in the
same row. If the table has only one column the cursor will
stay in the row and the shell will take care of it. */
if (IsLastCellInRow())
{
/* If the cursor is in the last row of the table, first
try to move it to the previous cell. If that fails move
it to the next cell. */
{
SwCursor aTmpCrsr( aStartPos, 0, false );
*pSwCrsr = aTmpCrsr;
}
if (! pSwCrsr->GoPrevCell())
{
SwCursor aTmpCrsr( aEndPos, 0, false );
*pSwCrsr = aTmpCrsr;
pSwCrsr->GoNextCell();
}
}
else
{
/* If the cursor is not in the last row of the table, first
try to move it to the next cell. If that fails move it
to the previous cell. */
{
SwCursor aTmpCrsr( aEndPos, 0, false );
*pSwCrsr = aTmpCrsr;
}
if (! pSwCrsr->GoNextCell())
{
SwCursor aTmpCrsr( aStartPos, 0, false );
*pSwCrsr = aTmpCrsr;
pSwCrsr->GoPrevCell();
}
}
}
/***********************************************************************
#* Class : SwFEShell
#* Methoden : InsertRow(), InsertCol
#***********************************************************************/
sal_Bool SwFEShell::InsertRow( sal_uInt16 nCnt, sal_Bool bBehind )
{
// pruefe ob vom aktuellen Crsr der Point/Mark in einer Tabelle stehen
SwFrm *pFrm = GetCurrFrm();
if( !pFrm || !pFrm->IsInTab() )
return sal_False;
if( pFrm->ImplFindTabFrm()->GetTable()->ISA( SwDDETable ))
{
ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
return sal_False;
}
SET_CURR_SHELL( this );
StartAllAction();
// lasse ueber das Layout die Boxen suchen
SwSelBoxes aBoxes;
GetTblSel( *this, aBoxes, nsSwTblSearchType::TBLSEARCH_ROW );
TblWait( nCnt, pFrm, *GetDoc()->GetDocShell(), aBoxes.Count() );
sal_Bool bRet = sal_False;
if ( aBoxes.Count() )
bRet = GetDoc()->InsertRow( aBoxes, nCnt, bBehind );
EndAllActionAndCall();
return bRet;
}
sal_Bool SwFEShell::InsertCol( sal_uInt16 nCnt, sal_Bool bBehind )
{
// pruefe ob vom aktuellen Crsr der Point/Mark in einer Tabelle stehen
SwFrm *pFrm = GetCurrFrm();
if( !pFrm || !pFrm->IsInTab() )
return sal_False;
if( pFrm->ImplFindTabFrm()->GetTable()->ISA( SwDDETable ))
{
ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
return sal_False;
}
SET_CURR_SHELL( this );
if( !CheckSplitCells( *this, nCnt + 1, nsSwTblSearchType::TBLSEARCH_COL ) )
{
ErrorHandler::HandleError( ERR_TBLINSCOL_ERROR,
ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
return sal_False;
}
StartAllAction();
// lasse ueber das Layout die Boxen suchen
SwSelBoxes aBoxes;
GetTblSel( *this, aBoxes, nsSwTblSearchType::TBLSEARCH_COL );
TblWait( nCnt, pFrm, *GetDoc()->GetDocShell(), aBoxes.Count() );
sal_Bool bRet = sal_False;
if( aBoxes.Count() )
bRet = GetDoc()->InsertCol( aBoxes, nCnt, bBehind );
EndAllActionAndCall();
return bRet;
}
/***********************************************************************
#* Class : SwFEShell
#* Methoden : DeleteRow(), DeleteCol()
#***********************************************************************/
/**
Determines if the current cursor is in the last row of the table.
*/
sal_Bool SwFEShell::IsLastCellInRow() const
{
SwTabCols aTabCols;
GetTabCols( aTabCols );
sal_Bool bResult = sal_False;
if (IsTableRightToLeft())
/* If the table is right-to-left the last row is the most left one. */
bResult = 0 == GetCurTabColNum();
else
/* If the table is left-to-right the last row is the most right one. */
bResult = aTabCols.Count() == GetCurTabColNum();
return bResult;
}
sal_Bool SwFEShell::DeleteCol()
{
// pruefe ob vom aktuellen Crsr der SPoint/Mark in einer Tabelle stehen
SwFrm *pFrm = GetCurrFrm();
if( !pFrm || !pFrm->IsInTab() )
return sal_False;
if( pFrm->ImplFindTabFrm()->GetTable()->ISA( SwDDETable ))
{
ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
return sal_False;
}
SET_CURR_SHELL( this );
StartAllAction();
// lasse ueber das Layout die Boxen suchen
sal_Bool bRet;
SwSelBoxes aBoxes;
GetTblSel( *this, aBoxes, nsSwTblSearchType::TBLSEARCH_COL );
if ( aBoxes.Count() )
{
TblWait( aBoxes.Count(), pFrm, *GetDoc()->GetDocShell() );
// die Crsr muessen noch aus dem Loesch Bereich entfernt
// werden. Setze sie immer hinter/auf die Tabelle; ueber die
// Dokument-Position werden sie dann immer an die alte Position gesetzt.
while( !pFrm->IsCellFrm() )
pFrm = pFrm->GetUpper();
ParkCursorInTab();
// dann loesche doch die Spalten
StartUndo(UNDO_COL_DELETE);
bRet = GetDoc()->DeleteRowCol( aBoxes, true );
EndUndo(UNDO_COL_DELETE);
}
else
bRet = sal_False;
EndAllActionAndCall();
return bRet;
}
sal_Bool SwFEShell::DeleteRow()
{
// pruefe ob vom aktuellen Crsr der SPoint/Mark in einer Tabelle stehen
SwFrm *pFrm = GetCurrFrm();
if( !pFrm || !pFrm->IsInTab() )
return sal_False;
if( pFrm->ImplFindTabFrm()->GetTable()->ISA( SwDDETable ))
{
ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
return sal_False;
}
SET_CURR_SHELL( this );
StartAllAction();
// lasse ueber das Layout die Boxen suchen
sal_Bool bRet;
SwSelBoxes aBoxes;
GetTblSel( *this, aBoxes, nsSwTblSearchType::TBLSEARCH_ROW );
if( aBoxes.Count() )
{
TblWait( aBoxes.Count(), pFrm, *GetDoc()->GetDocShell() );
// die Crsr aus dem Loeschbereich entfernen.
// Der Cursor steht danach:
// - es folgt noch eine Zeile, in dieser
// - vorher steht noch eine Zeile, in dieser
// - sonst immer dahinter
{
SwTableNode* pTblNd = ((SwCntntFrm*)pFrm)->GetNode()->FindTableNode();
// suche alle Boxen / Lines
_FndBox aFndBox( 0, 0 );
{
_FndPara aPara( aBoxes, &aFndBox );
pTblNd->GetTable().GetTabLines().ForEach( &_FndLineCopyCol, &aPara );
}
if( !aFndBox.GetLines().Count() )
{
EndAllActionAndCall();
return sal_False;
}
KillPams();
_FndBox* pFndBox = &aFndBox;
while( 1 == pFndBox->GetLines().Count() &&
1 == pFndBox->GetLines()[0]->GetBoxes().Count() )
{
_FndBox* pTmp = pFndBox->GetLines()[0]->GetBoxes()[0];
if( pTmp->GetBox()->GetSttNd() )
break; // das ist sonst zu weit
pFndBox = pTmp;
}
SwTableLine* pDelLine = pFndBox->GetLines()[
pFndBox->GetLines().Count()-1 ]->GetLine();
SwTableBox* pDelBox = pDelLine->GetTabBoxes()[
pDelLine->GetTabBoxes().Count() - 1 ];
while( !pDelBox->GetSttNd() )
{
SwTableLine* pLn = pDelBox->GetTabLines()[
pDelBox->GetTabLines().Count()-1 ];
pDelBox = pLn->GetTabBoxes()[ pLn->GetTabBoxes().Count() - 1 ];
}
SwTableBox* pNextBox = pDelLine->FindNextBox( pTblNd->GetTable(),
pDelBox, sal_True );
while( pNextBox &&
pNextBox->GetFrmFmt()->GetProtect().IsCntntProtected() )
pNextBox = pNextBox->FindNextBox( pTblNd->GetTable(), pNextBox );
if( !pNextBox ) // keine nachfolgende? dann die vorhergehende
{
pDelLine = pFndBox->GetLines()[ 0 ]->GetLine();
pDelBox = pDelLine->GetTabBoxes()[ 0 ];
while( !pDelBox->GetSttNd() )
pDelBox = pDelBox->GetTabLines()[0]->GetTabBoxes()[0];
pNextBox = pDelLine->FindPreviousBox( pTblNd->GetTable(),
pDelBox, sal_True );
while( pNextBox &&
pNextBox->GetFrmFmt()->GetProtect().IsCntntProtected() )
pNextBox = pNextBox->FindPreviousBox( pTblNd->GetTable(), pNextBox );
}
sal_uLong nIdx;
if( pNextBox ) // dann den Cursor hier hinein
nIdx = pNextBox->GetSttIdx() + 1;
else // ansonsten hinter die Tabelle
nIdx = pTblNd->EndOfSectionIndex() + 1;
SwNodeIndex aIdx( GetDoc()->GetNodes(), nIdx );
SwCntntNode* pCNd = aIdx.GetNode().GetCntntNode();
if( !pCNd )
pCNd = GetDoc()->GetNodes().GoNext( &aIdx );
if( pCNd )
{
SwPaM* pPam = GetCrsr();
pPam->GetPoint()->nNode = aIdx;
pPam->GetPoint()->nContent.Assign( pCNd, 0 );
pPam->SetMark(); // beide wollen etwas davon haben
pPam->DeleteMark();
}
}
// dann loesche doch die Zeilen
StartUndo(UNDO_ROW_DELETE);
bRet = GetDoc()->DeleteRowCol( aBoxes );
EndUndo(UNDO_ROW_DELETE);
}
else
bRet = sal_False;
EndAllActionAndCall();
return bRet;
}
/***********************************************************************
#* Class : SwFEShell
#* Methoden : MergeTab(), SplitTab()
#***********************************************************************/
sal_uInt16 SwFEShell::MergeTab()
{
// pruefe ob vom aktuellen Crsr der SPoint/Mark in einer Tabelle stehen
sal_uInt16 nRet = TBLMERGE_NOSELECTION;
if( IsTableMode() )
{
SwShellTableCrsr* pTableCrsr = GetTableCrsr();
const SwTableNode* pTblNd = pTableCrsr->GetNode()->FindTableNode();
if( pTblNd->GetTable().ISA( SwDDETable ))
{
ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
}
else
{
SET_CURR_SHELL( this );
StartAllAction();
TblWait( pTableCrsr->GetBoxesCount(), 0, *GetDoc()->GetDocShell(),
pTblNd->GetTable().GetTabLines().Count() );
nRet = GetDoc()->MergeTbl( *pTableCrsr );
KillPams();
EndAllActionAndCall();
}
}
return nRet;
}
sal_Bool SwFEShell::SplitTab( sal_Bool bVert, sal_uInt16 nCnt, sal_Bool bSameHeight )
{
// pruefe ob vom aktuellen Crsr der SPoint/Mark in einer Tabelle stehen
SwFrm *pFrm = GetCurrFrm();
if( !pFrm || !pFrm->IsInTab() )
return sal_False;
if( pFrm->ImplFindTabFrm()->GetTable()->ISA( SwDDETable ))
{
ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
return sal_False;
}
SET_CURR_SHELL( this );
if( bVert && !CheckSplitCells( *this, nCnt + 1 ) )
{
ErrorHandler::HandleError( ERR_TBLSPLIT_ERROR,
ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
return sal_False;
}
StartAllAction();
// lasse ueber das Layout die Boxen suchen
sal_Bool bRet;
SwSelBoxes aBoxes;
GetTblSel( *this, aBoxes );
if( aBoxes.Count() )
{
TblWait( nCnt, pFrm, *GetDoc()->GetDocShell(), aBoxes.Count() );
// dann loesche doch die Spalten
bRet = GetDoc()->SplitTbl( aBoxes, bVert, nCnt, bSameHeight );
DELETEZ( pLastCols );
DELETEZ( pLastRows );
}
else
bRet = sal_False;
EndAllActionAndCall();
return bRet;
}
/***********************************************************************
#* Class : SwFEShell
#* Methoden : _GetTabCols
#***********************************************************************/
void SwFEShell::_GetTabCols( SwTabCols &rToFill, const SwFrm *pBox ) const
{
const SwTabFrm *pTab = pBox->FindTabFrm();
if ( pLastCols )
{
//Paar Kleinigkeiten muessen wir schon noch sicherstellen
sal_Bool bDel = sal_True;
if ( pColumnCacheLastTable == pTab->GetTable() )
{
bDel = sal_False;
SWRECTFN( pTab )
const SwPageFrm* pPage = pTab->FindPageFrm();
const sal_uLong nLeftMin = (pTab->Frm().*fnRect->fnGetLeft)() -
(pPage->Frm().*fnRect->fnGetLeft)();
const sal_uLong nRightMax = (pTab->Frm().*fnRect->fnGetRight)() -
(pPage->Frm().*fnRect->fnGetLeft)();
if ( pColumnCacheLastTabFrm != pTab )
{
//Wenn der TabFrm gewechselt hat, brauchen wir bei gleicher
//Breite nur ein wenig shiften.
SWRECTFNX( pColumnCacheLastTabFrm )
if( (pColumnCacheLastTabFrm->Frm().*fnRectX->fnGetWidth)() ==
(pTab->Frm().*fnRect->fnGetWidth)() )
{
pLastCols->SetLeftMin( nLeftMin );
pColumnCacheLastTabFrm = pTab;
}
else
bDel = sal_True;
}
if ( !bDel &&
pLastCols->GetLeftMin () == (sal_uInt16)nLeftMin &&
pLastCols->GetLeft () == (sal_uInt16)(pTab->Prt().*fnRect->fnGetLeft)() &&
pLastCols->GetRight () == (sal_uInt16)(pTab->Prt().*fnRect->fnGetRight)()&&
pLastCols->GetRightMax() == (sal_uInt16)nRightMax - pLastCols->GetLeftMin() )
{
if ( pColumnCacheLastCellFrm != pBox )
{
pTab->GetTable()->GetTabCols( *pLastCols,
((SwCellFrm*)pBox)->GetTabBox(), sal_True);
pColumnCacheLastCellFrm = pBox;
}
rToFill = *pLastCols;
}
else
bDel = sal_True;
}
if ( bDel )
DELETEZ(pLastCols);
}
if ( !pLastCols )
{
GetDoc()->GetTabCols( rToFill, 0, (SwCellFrm*)pBox );
pLastCols = new SwTabCols( rToFill );
pColumnCacheLastTable = pTab->GetTable();
pColumnCacheLastTabFrm = pTab;
pColumnCacheLastCellFrm= pBox;
}
#if OSL_DEBUG_LEVEL > 1
SwTabColsEntry aEntry;
for ( sal_uInt16 i = 0; i < rToFill.Count(); ++i )
{
aEntry = rToFill.GetEntry( i );
(void)aEntry;
}
#endif
}
/***********************************************************************
#* Class : SwFEShell
#* Methoden : _GetTabRows
#***********************************************************************/
void SwFEShell::_GetTabRows( SwTabCols &rToFill, const SwFrm *pBox ) const
{
const SwTabFrm *pTab = pBox->FindTabFrm();
if ( pLastRows )
{
//Paar Kleinigkeiten muessen wir schon noch sicherstellen
sal_Bool bDel = sal_True;
if ( pRowCacheLastTable == pTab->GetTable() )
{
bDel = sal_False;
SWRECTFN( pTab )
const SwPageFrm* pPage = pTab->FindPageFrm();
const long nLeftMin = ( bVert ?
pTab->GetPrtLeft() - pPage->Frm().Left() :
pTab->GetPrtTop() - pPage->Frm().Top() );
const long nLeft = bVert ? LONG_MAX : 0;
const long nRight = (pTab->Prt().*fnRect->fnGetHeight)();
const long nRightMax = bVert ? nRight : LONG_MAX;
if ( pRowCacheLastTabFrm != pTab ||
pRowCacheLastCellFrm != pBox )
bDel = sal_True;
if ( !bDel &&
pLastRows->GetLeftMin () == nLeftMin &&
pLastRows->GetLeft () == nLeft &&
pLastRows->GetRight () == nRight &&
pLastRows->GetRightMax() == nRightMax )
{
rToFill = *pLastRows;
}
else
bDel = sal_True;
}
if ( bDel )
DELETEZ(pLastRows);
}
if ( !pLastRows )
{
GetDoc()->GetTabRows( rToFill, 0, (SwCellFrm*)pBox );
pLastRows = new SwTabCols( rToFill );
pRowCacheLastTable = pTab->GetTable();
pRowCacheLastTabFrm = pTab;
pRowCacheLastCellFrm= pBox;
}
}
/***********************************************************************
#* Class : SwFEShell
#* Methoden : SetTabCols(), GetTabCols()
#***********************************************************************/
void SwFEShell::SetTabCols( const SwTabCols &rNew, sal_Bool bCurRowOnly )
{
SwFrm *pBox = GetCurrFrm();
if( !pBox || !pBox->IsInTab() )
return;
SET_CURR_SHELL( this );
StartAllAction();
do {
pBox = pBox->GetUpper();
} while ( !pBox->IsCellFrm() );
GetDoc()->SetTabCols( rNew, bCurRowOnly, 0, (SwCellFrm*)pBox );
EndAllActionAndCall();
}
void SwFEShell::GetTabCols( SwTabCols &rToFill ) const
{
const SwFrm *pFrm = GetCurrFrm();
if( !pFrm || !pFrm->IsInTab() )
return;
do
{ pFrm = pFrm->GetUpper();
} while ( !pFrm->IsCellFrm() );
_GetTabCols( rToFill, pFrm );
}
void SwFEShell::GetTabRows( SwTabCols &rToFill ) const
{
const SwFrm *pFrm = GetCurrFrm();
if( !pFrm || !pFrm->IsInTab() )
return;
do
{ pFrm = pFrm->GetUpper();
} while ( !pFrm->IsCellFrm() );
_GetTabRows( rToFill, pFrm );
}
void SwFEShell::SetTabRows( const SwTabCols &rNew, sal_Bool bCurColOnly )
{
SwFrm *pBox = GetCurrFrm();
if( !pBox || !pBox->IsInTab() )
return;
SET_CURR_SHELL( this );
StartAllAction();
do {
pBox = pBox->GetUpper();
} while ( !pBox->IsCellFrm() );
GetDoc()->SetTabRows( rNew, bCurColOnly, 0, (SwCellFrm*)pBox );
EndAllActionAndCall();
}
void SwFEShell::GetMouseTabRows( SwTabCols &rToFill, const Point &rPt ) const
{
const SwFrm *pBox = GetBox( rPt );
if ( pBox )
_GetTabRows( rToFill, pBox );
}
void SwFEShell::SetMouseTabRows( const SwTabCols &rNew, sal_Bool bCurColOnly, const Point &rPt )
{
const SwFrm *pBox = GetBox( rPt );
if( pBox )
{
SET_CURR_SHELL( this );
StartAllAction();
GetDoc()->SetTabRows( rNew, bCurColOnly, 0, (SwCellFrm*)pBox );
EndAllActionAndCall();
}
}
/***********************************************************************
* Class : SwFEShell
* Methoden : SetRowSplit(), GetRowSplit()
***********************************************************************/
void SwFEShell::SetRowSplit( const SwFmtRowSplit& rNew )
{
SET_CURR_SHELL( this );
StartAllAction();
GetDoc()->SetRowSplit( *getShellCrsr( false ), rNew );
EndAllActionAndCall();
}
void SwFEShell::GetRowSplit( SwFmtRowSplit*& rpSz ) const
{
GetDoc()->GetRowSplit( *getShellCrsr( false ), rpSz );
}
/***********************************************************************
#* Class : SwFEShell
#* Methoden : SetRowHeight(), GetRowHeight()
#***********************************************************************/
void SwFEShell::SetRowHeight( const SwFmtFrmSize &rNew )
{
SET_CURR_SHELL( this );
StartAllAction();
GetDoc()->SetRowHeight( *getShellCrsr( false ), rNew );
EndAllActionAndCall();
}
/******************************************************************************
* SwTwips SwFEShell::GetRowHeight() const
******************************************************************************/
void SwFEShell::GetRowHeight( SwFmtFrmSize *& rpSz ) const
{
GetDoc()->GetRowHeight( *getShellCrsr( false ), rpSz );
}
sal_Bool SwFEShell::BalanceRowHeight( sal_Bool bTstOnly )
{
SET_CURR_SHELL( this );
if( !bTstOnly )
StartAllAction();
sal_Bool bRet = GetDoc()->BalanceRowHeight( *getShellCrsr( false ), bTstOnly );
if( !bTstOnly )
EndAllActionAndCall();
return bRet;
}
/******************************************************************************
* void SwFEShell::SetRowBackground()
******************************************************************************/
void SwFEShell::SetRowBackground( const SvxBrushItem &rNew )
{
SET_CURR_SHELL( this );
StartAllAction();
GetDoc()->SetRowBackground( *getShellCrsr( false ), rNew );
EndAllActionAndCall();
}
/******************************************************************************
* SwTwips SwFEShell::GetRowBackground() const
******************************************************************************/
sal_Bool SwFEShell::GetRowBackground( SvxBrushItem &rToFill ) const
{
return GetDoc()->GetRowBackground( *getShellCrsr( false ), rToFill );
}
/***********************************************************************
#* Class : SwFEShell
#* Methoden : SetTabBorders(), GetTabBorders()
#***********************************************************************/
void SwFEShell::SetTabBorders( const SfxItemSet& rSet )
{
SET_CURR_SHELL( this );
StartAllAction();
GetDoc()->SetTabBorders( *getShellCrsr( false ), rSet );
EndAllActionAndCall();
}
void SwFEShell::SetTabLineStyle( const Color* pColor, sal_Bool bSetLine,
const editeng::SvxBorderLine* pBorderLine )
{
SET_CURR_SHELL( this );
StartAllAction();
GetDoc()->SetTabLineStyle( *getShellCrsr( false ),
pColor, bSetLine, pBorderLine );
EndAllActionAndCall();
}
void SwFEShell::GetTabBorders( SfxItemSet& rSet ) const
{
GetDoc()->GetTabBorders( *getShellCrsr( false ), rSet );
}
/***********************************************************************
#* Class : SwFEShell
#* Methoden : SetBoxBackground(), GetBoxBackground()
#***********************************************************************/
void SwFEShell::SetBoxBackground( const SvxBrushItem &rNew )
{
SET_CURR_SHELL( this );
StartAllAction();
GetDoc()->SetBoxAttr( *getShellCrsr( false ), rNew );
EndAllActionAndCall();
}
sal_Bool SwFEShell::GetBoxBackground( SvxBrushItem &rToFill ) const
{
return GetDoc()->GetBoxAttr( *getShellCrsr( false ), rToFill );
}
/***********************************************************************
#* Class : SwFEShell
#* Methoden : SetBoxDirection(), GetBoxDirection()
#***********************************************************************/
void SwFEShell::SetBoxDirection( const SvxFrameDirectionItem& rNew )
{
SET_CURR_SHELL( this );
StartAllAction();
GetDoc()->SetBoxAttr( *getShellCrsr( false ), rNew );
EndAllActionAndCall();
}
sal_Bool SwFEShell::GetBoxDirection( SvxFrameDirectionItem& rToFill ) const
{
return GetDoc()->GetBoxAttr( *getShellCrsr( false ), rToFill );
}
/***********************************************************************
#* Class : SwFEShell
#* Methoden : SetBoxAlign, SetBoxAlign
#***********************************************************************/
void SwFEShell::SetBoxAlign( sal_uInt16 nAlign )
{
SET_CURR_SHELL( this );
StartAllAction();
GetDoc()->SetBoxAlign( *getShellCrsr( false ), nAlign );
EndAllActionAndCall();
}
sal_uInt16 SwFEShell::GetBoxAlign() const
{
return GetDoc()->GetBoxAlign( *getShellCrsr( false ) );
}
/***********************************************************************
#* Class : SwFEShell
#* Methoden : SetTabBackground(), GetTabBackground()
#***********************************************************************/
void SwFEShell::SetTabBackground( const SvxBrushItem &rNew )
{
SwFrm *pFrm = GetCurrFrm();
if( !pFrm || !pFrm->IsInTab() )
return;
SET_CURR_SHELL( this );
StartAllAction();
GetDoc()->SetAttr( rNew, *pFrm->ImplFindTabFrm()->GetFmt() );
EndAllAction(); //Kein Call, denn es veraendert sich nichts!
GetDoc()->SetModified();
}
void SwFEShell::GetTabBackground( SvxBrushItem &rToFill ) const
{
SwFrm *pFrm = GetCurrFrm();
if( pFrm && pFrm->IsInTab() )
rToFill = pFrm->ImplFindTabFrm()->GetFmt()->GetBackground();
}
/***********************************************************************
#* Class : SwFEShell
#* Methoden : HasWholeTabSelection()
#***********************************************************************/
sal_Bool SwFEShell::HasWholeTabSelection() const
{
//Ist die ganze Tabelle Selektiert?
if ( IsTableMode() )
{
SwSelBoxes aBoxes;
::GetTblSelCrs( *this, aBoxes );
if( aBoxes.Count() )
{
const SwTableNode *pTblNd = IsCrsrInTbl();
return ( pTblNd && aBoxes[0]->GetSttIdx()-1 == pTblNd->
EndOfSectionNode()->StartOfSectionIndex() &&
aBoxes[aBoxes.Count()-1]->GetSttNd()->EndOfSectionIndex()+1
== pTblNd->EndOfSectionIndex() );
}
}
return sal_False;
}
sal_Bool SwFEShell::HasBoxSelection() const
{
if(!IsCrsrInTbl())
return sal_False;
//Ist die ganze Tabelle Selektiert?
if( IsTableMode() )
return sal_True;
SwPaM* pPam = GetCrsr();
// empty boxes are also selected as the absence of selection
sal_Bool bChg = sal_False;
if( pPam->GetPoint() == pPam->End())
{
bChg = sal_True;
pPam->Exchange();
}
SwNode* pNd;
if( pPam->GetPoint()->nNode.GetIndex() -1 ==
( pNd = pPam->GetNode())->StartOfSectionIndex() &&
!pPam->GetPoint()->nContent.GetIndex() &&
pPam->GetMark()->nNode.GetIndex() + 1 ==
pNd->EndOfSectionIndex())
{
SwNodeIndex aIdx( *pNd->EndOfSectionNode(), -1 );
SwCntntNode* pCNd = aIdx.GetNode().GetCntntNode();
if( !pCNd )
{
pCNd = GetDoc()->GetNodes().GoPrevious( &aIdx );
OSL_ENSURE( pCNd, "kein ContentNode in der Box ??" );
}
if( pPam->GetMark()->nContent == pCNd->Len() )
{
if( bChg )
pPam->Exchange();
return sal_True;
}
}
if( bChg )
pPam->Exchange();
return sal_False;
}
/***********************************************************************
#* Class : SwFEShell
#* Methoden : ProtectCells(), UnProtectCells()
#***********************************************************************/
void SwFEShell::ProtectCells()
{
SvxProtectItem aProt( RES_PROTECT );
aProt.SetCntntProtect( sal_True );
SET_CURR_SHELL( this );
StartAllAction();
GetDoc()->SetBoxAttr( *getShellCrsr( false ), aProt );
if( !IsCrsrReadonly() )
{
if( IsTableMode() )
ClearMark();
ParkCursorInTab();
}
EndAllActionAndCall();
}
// die Tabellenselektion aufheben
void SwFEShell::UnProtectCells()
{
SET_CURR_SHELL( this );
StartAllAction();
SwSelBoxes aBoxes;
if( IsTableMode() )
::GetTblSelCrs( *this, aBoxes );
else
{
SwFrm *pFrm = GetCurrFrm();
do {
pFrm = pFrm->GetUpper();
} while ( pFrm && !pFrm->IsCellFrm() );
if( pFrm )
{
SwTableBox *pBox = (SwTableBox*)((SwCellFrm*)pFrm)->GetTabBox();
aBoxes.Insert( pBox );
}
}
if( aBoxes.Count() )
GetDoc()->UnProtectCells( aBoxes );
EndAllActionAndCall();
}
void SwFEShell::UnProtectTbls()
{
SET_CURR_SHELL( this );
StartAllAction();
GetDoc()->UnProtectTbls( *GetCrsr() );
EndAllActionAndCall();
}
sal_Bool SwFEShell::HasTblAnyProtection( const String* pTblName,
sal_Bool* pFullTblProtection )
{
return GetDoc()->HasTblAnyProtection( GetCrsr()->GetPoint(), pTblName,
pFullTblProtection );
}
sal_Bool SwFEShell::CanUnProtectCells() const
{
sal_Bool bUnProtectAvailable = sal_False;
const SwTableNode *pTblNd = IsCrsrInTbl();
if( pTblNd && !pTblNd->IsProtect() )
{
SwSelBoxes aBoxes;
if( IsTableMode() )
::GetTblSelCrs( *this, aBoxes );
else
{
SwFrm *pFrm = GetCurrFrm();
do {
pFrm = pFrm->GetUpper();
} while ( pFrm && !pFrm->IsCellFrm() );
if( pFrm )
{
SwTableBox *pBox = (SwTableBox*)((SwCellFrm*)pFrm)->GetTabBox();
aBoxes.Insert( pBox );
}
}
if( aBoxes.Count() )
bUnProtectAvailable = ::HasProtectedCells( aBoxes );
}
return bUnProtectAvailable;
}
/***********************************************************************
#* Class : SwFEShell
#* Methoden : GetRowsToRepeat(), SetRowsToRepeat()
#***********************************************************************/
sal_uInt16 SwFEShell::GetRowsToRepeat() const
{
const SwFrm *pFrm = GetCurrFrm();
const SwTabFrm *pTab = pFrm ? pFrm->FindTabFrm() : 0;
if( pTab )
return pTab->GetTable()->GetRowsToRepeat();
return 0;
}
void SwFEShell::SetRowsToRepeat( sal_uInt16 nSet )
{
SwFrm *pFrm = GetCurrFrm();
SwTabFrm *pTab = pFrm ? pFrm->FindTabFrm() : 0;
if( pTab && pTab->GetTable()->GetRowsToRepeat() != nSet )
{
SwWait aWait( *GetDoc()->GetDocShell(), sal_True );
SET_CURR_SHELL( this );
StartAllAction();
GetDoc()->SetRowsToRepeat( *pTab->GetTable(), nSet );
EndAllActionAndCall();
}
}
/*-------------------------------------------------------------------------
returns the number of rows consecutively selected from top
-----------------------------------------------------------------------*/
sal_uInt16 lcl_GetRowNumber( const SwPosition& rPos )
{
sal_uInt16 nRet = USHRT_MAX;
Point aTmpPt;
const SwCntntNode *pNd;
const SwCntntFrm *pFrm;
if( 0 != ( pNd = rPos.nNode.GetNode().GetCntntNode() ))
pFrm = pNd->getLayoutFrm( pNd->GetDoc()->GetCurrentLayout(), &aTmpPt, &rPos, sal_False );
else
pFrm = 0;
if ( pFrm && pFrm->IsInTab() )
{
const SwFrm* pRow = pFrm->GetUpper();
while ( !pRow->GetUpper()->IsTabFrm() )
pRow = pRow->GetUpper();
const SwTabFrm* pTabFrm = (const SwTabFrm*)pRow->GetUpper();
const SwTableLine* pTabLine = static_cast<const SwRowFrm*>(pRow)->GetTabLine();
sal_uInt16 nI = 0;
while ( nI < pTabFrm->GetTable()->GetTabLines().Count() )
{
if ( pTabFrm->GetTable()->GetTabLines()[ nI ] == pTabLine )
{
nRet = nI;
break;
}
++nI;
}
}
return nRet;
}
sal_uInt16 SwFEShell::GetRowSelectionFromTop() const
{
sal_uInt16 nRet = 0;
const SwPaM* pPaM = IsTableMode() ? GetTableCrsr() : _GetCrsr();
const sal_uInt16 nPtLine = lcl_GetRowNumber( *pPaM->GetPoint() );
if ( !IsTableMode() )
{
nRet = 0 == nPtLine ? 1 : 0;
}
else
{
const sal_uInt16 nMkLine = lcl_GetRowNumber( *pPaM->GetMark() );
if ( ( nPtLine == 0 && nMkLine != USHRT_MAX ) ||
( nMkLine == 0 && nPtLine != USHRT_MAX ) )
{
nRet = Max( nPtLine, nMkLine ) + 1;
}
}
return nRet;
}
/*
* 1. case: bRepeat = true
* returns true if the current frame is located inside a table headline in
* a follow frame
*
* 2. case: bRepeat = false
* returns true if the current frame is localed inside a table headline OR
* inside the first line of a table!!!
*/
sal_Bool SwFEShell::CheckHeadline( bool bRepeat ) const
{
sal_Bool bRet = sal_False;
if ( !IsTableMode() )
{
SwFrm *pFrm = GetCurrFrm(); // DONE MULTIIHEADER
if ( pFrm && pFrm->IsInTab() )
{
SwTabFrm* pTab = pFrm->FindTabFrm();
if ( bRepeat )
{
bRet = pTab->IsFollow() && pTab->IsInHeadline( *pFrm );
}
else
{
bRet = ((SwLayoutFrm*)pTab->Lower())->IsAnLower( pFrm ) ||
pTab->IsInHeadline( *pFrm );
}
}
}
return bRet;
}
/***********************************************************************
#* Class : SwFEShell
#* Methoden : AdjustCellWidth()
#***********************************************************************/
void SwFEShell::AdjustCellWidth( sal_Bool bBalance )
{
SET_CURR_SHELL( this );
StartAllAction();
//WarteCrsr immer einschalten, weil sich im vorraus nicht so recht
//ermitteln laesst wieviel Inhalt betroffen ist.
TblWait aWait( USHRT_MAX, 0, *GetDoc()->GetDocShell() );
GetDoc()->AdjustCellWidth( *getShellCrsr( false ), bBalance );
EndAllActionAndCall();
}
sal_Bool SwFEShell::IsAdjustCellWidthAllowed( sal_Bool bBalance ) const
{
//Es muss mindestens eine Zelle mit Inhalt in der Selektion enthalten
//sein.
SwFrm *pFrm = GetCurrFrm();
if( !pFrm || !pFrm->IsInTab() )
return sal_False;
SwSelBoxes aBoxes;
::GetTblSelCrs( *this, aBoxes );
if ( bBalance )
return aBoxes.Count() > 1;
if ( !aBoxes.Count() )
{
do
{ pFrm = pFrm->GetUpper();
} while ( !pFrm->IsCellFrm() );
SwTableBox *pBox = (SwTableBox*)((SwCellFrm*)pFrm)->GetTabBox();
aBoxes.Insert( pBox );
}
for ( sal_uInt16 i = 0; i < aBoxes.Count(); ++i )
{
SwTableBox *pBox = aBoxes[i];
if ( pBox->GetSttNd() )
{
SwNodeIndex aIdx( *pBox->GetSttNd(), 1 );
SwTxtNode* pCNd = aIdx.GetNode().GetTxtNode();
if( !pCNd )
pCNd = (SwTxtNode*)GetDoc()->GetNodes().GoNext( &aIdx );
while ( pCNd )
{
if ( pCNd->GetTxt().Len() )
return sal_True;
++aIdx;
pCNd = aIdx.GetNode().GetTxtNode();
}
}
}
return sal_False;
}
// AutoFormat fuer die Tabelle/TabellenSelection
sal_Bool SwFEShell::SetTableAutoFmt( const SwTableAutoFmt& rNew )
{
SwTableNode *pTblNd = (SwTableNode*)IsCrsrInTbl();
if( !pTblNd || pTblNd->GetTable().IsTblComplex() )
return sal_False;
SwSelBoxes aBoxes;
if ( !IsTableMode() ) // falls Crsr noch nicht akt. sind
GetCrsr();
// gesamte Tabelle oder nur auf die akt. Selektion
if( IsTableMode() )
::GetTblSelCrs( *this, aBoxes );
else
{
const SwTableSortBoxes& rTBoxes = pTblNd->GetTable().GetTabSortBoxes();
for( sal_uInt16 n = 0; n < rTBoxes.Count(); ++n )
{
SwTableBox* pBox = rTBoxes[ n ];
aBoxes.Insert( pBox );
}
}
sal_Bool bRet;
if( aBoxes.Count() )
{
SET_CURR_SHELL( this );
StartAllAction();
bRet = GetDoc()->SetTableAutoFmt( aBoxes, rNew );
DELETEZ( pLastCols );
DELETEZ( pLastRows );
EndAllActionAndCall();
}
else
bRet = sal_False;
return bRet;
}
sal_Bool SwFEShell::GetTableAutoFmt( SwTableAutoFmt& rGet )
{
const SwTableNode *pTblNd = IsCrsrInTbl();
if( !pTblNd || pTblNd->GetTable().IsTblComplex() )
return sal_False;
SwSelBoxes aBoxes;
if ( !IsTableMode() ) // falls Crsr noch nicht akt. sind
GetCrsr();
// gesamte Tabelle oder nur auf die akt. Selektion
if( IsTableMode() )
::GetTblSelCrs( *this, aBoxes );
else
{
const SwTableSortBoxes& rTBoxes = pTblNd->GetTable().GetTabSortBoxes();
for( sal_uInt16 n = 0; n < rTBoxes.Count(); ++n )
{
SwTableBox* pBox = rTBoxes[ n ];
aBoxes.Insert( pBox );
}
}
return GetDoc()->GetTableAutoFmt( aBoxes, rGet );
}
/***********************************************************************
#* Class : SwFEShell
#* Methoden : DeleteTblSel()
#***********************************************************************/
sal_Bool SwFEShell::DeleteTblSel()
{
// pruefe ob vom aktuellen Crsr der SPoint/Mark in einer Tabelle stehen
SwFrm *pFrm = GetCurrFrm();
if( !pFrm || !pFrm->IsInTab() )
return sal_False;
if( pFrm->ImplFindTabFrm()->GetTable()->ISA( SwDDETable ))
{
ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
return sal_False;
}
SET_CURR_SHELL( this );
StartAllAction();
// lasse ueber das Layout die Boxen suchen
sal_Bool bRet;
SwSelBoxes aBoxes;
GetTblSelCrs( *this, aBoxes );
if( aBoxes.Count() )
{
TblWait( aBoxes.Count(), pFrm, *GetDoc()->GetDocShell() );
// die Crsr muessen noch aus dem Loesch Bereich entfernt
// werden. Setze sie immer hinter/auf die Tabelle; ueber die
// Dokument-Position werden sie dann immer an die alte Position gesetzt.
while( !pFrm->IsCellFrm() )
pFrm = pFrm->GetUpper();
ParkCrsr( SwNodeIndex( *((SwCellFrm*)pFrm)->GetTabBox()->GetSttNd() ));
bRet = GetDoc()->DeleteRowCol( aBoxes );
DELETEZ( pLastCols );
DELETEZ( pLastRows );
}
else
bRet = sal_False;
EndAllActionAndCall();
return bRet;
}
/*************************************************************************
|*
|* SwFEShell::GetCurTabColNum()
|*
|*************************************************************************/
sal_uInt16 SwFEShell::GetCurTabColNum() const
{
//!!!GetCurMouseTabColNum() mitpflegen!!!!
sal_uInt16 nRet = 0;
SwFrm *pFrm = GetCurrFrm();
OSL_ENSURE( pFrm, "Crsr geparkt?" );
// pruefe ob vom aktuellen Crsr der SPoint/Mark in einer Tabelle stehen
if( pFrm && pFrm->IsInTab() )
{
do { // JP 26.09.95: warum mit dem CntntFrame und nicht mit
// dem CellFrame vergleichen????
pFrm = pFrm->GetUpper();
} while ( !pFrm->IsCellFrm() );
SWRECTFN( pFrm )
const SwPageFrm* pPage = pFrm->FindPageFrm();
//TabCols besorgen, den nur ueber diese erreichen wir die Position.
SwTabCols aTabCols;
GetTabCols( aTabCols );
if( pFrm->FindTabFrm()->IsRightToLeft() )
{
long nX = (pFrm->Frm().*fnRect->fnGetRight)() - (pPage->Frm().*fnRect->fnGetLeft)();
const long nRight = aTabCols.GetLeftMin() + aTabCols.GetRight();;
if ( !::IsSame( nX, nRight ) )
{
nX = nRight - nX + aTabCols.GetLeft();
for ( sal_uInt16 i = 0; i < aTabCols.Count(); ++i )
if ( ::IsSame( nX, aTabCols[i] ) )
{
nRet = i + 1;
break;
}
}
}
else
{
const long nX = (pFrm->Frm().*fnRect->fnGetLeft)() -
(pPage->Frm().*fnRect->fnGetLeft)();
const long nLeft = aTabCols.GetLeftMin();
if ( !::IsSame( nX, nLeft + aTabCols.GetLeft() ) )
{
for ( sal_uInt16 i = 0; i < aTabCols.Count(); ++i )
if ( ::IsSame( nX, nLeft + aTabCols[i] ) )
{
nRet = i + 1;
break;
}
}
}
}
return nRet;
}
/*************************************************************************
|*
|* SwFEShell::GetBox()
|*
|*************************************************************************/
const SwFrm *lcl_FindFrmInTab( const SwLayoutFrm *pLay, const Point &rPt, SwTwips nFuzzy )
{
const SwFrm *pFrm = pLay->Lower();
while( pFrm && pLay->IsAnLower( pFrm ) )
{
if ( pFrm->Frm().IsNear( rPt, nFuzzy ) )
{
if ( pFrm->IsLayoutFrm() )
{
const SwFrm *pTmp = ::lcl_FindFrmInTab( (SwLayoutFrm*)pFrm, rPt, nFuzzy );
if ( pTmp )
return pTmp;
}
return pFrm;
}
pFrm = pFrm->FindNext();
}
return 0;
}
const SwCellFrm *lcl_FindFrm( const SwLayoutFrm *pLay, const Point &rPt,
SwTwips nFuzzy, bool* pbRow, bool* pbCol )
{
// bMouseMoveRowCols :
// Method is called for
// - Moving columns/rows with the mouse or
// - Enhanced table selection
const bool bMouseMoveRowCols = 0 == pbCol;
bool bCloseToRow = false;
bool bCloseToCol = false;
const SwFrm *pFrm = pLay->ContainsCntnt();
const SwFrm* pRet = 0;
if ( pFrm )
{
do
{
if ( pFrm->IsInTab() )
pFrm = ((SwFrm*)pFrm)->ImplFindTabFrm();
if ( pFrm->IsTabFrm() )
{
Point aPt( rPt );
bool bSearchForFrmInTab = true;
SwTwips nTmpFuzzy = nFuzzy;
if ( !bMouseMoveRowCols )
{
// We ignore nested tables for the enhanced table selection:
while ( pFrm->GetUpper()->IsInTab() )
pFrm = pFrm->GetUpper()->FindTabFrm();
// We first check if the given point is 'close' to the left or top
// border of the table frame:
OSL_ENSURE( pFrm, "Nested table frame without outer table" );
SWRECTFN( pFrm )
const bool bRTL = pFrm->IsRightToLeft();
SwRect aTabRect = pFrm->Prt();
aTabRect.Pos() += pFrm->Frm().Pos();
const SwTwips nLeft = bRTL ?
(aTabRect.*fnRect->fnGetRight)() :
(aTabRect.*fnRect->fnGetLeft)();
const SwTwips nTop = (aTabRect.*fnRect->fnGetTop)();
SwTwips& rPointX = bVert ? aPt.Y() : aPt.X();
SwTwips& rPointY = bVert ? aPt.X() : aPt.Y();
const SwTwips nXDiff = (*fnRect->fnXDiff)( nLeft, rPointX ) * ( bRTL ? (-1) : 1 );
const SwTwips nYDiff = (*fnRect->fnYDiff)( nTop, rPointY );
bCloseToRow = nXDiff >= 0 && nXDiff < nFuzzy;
bCloseToCol = nYDiff >= 0 && nYDiff < nFuzzy;
if ( bCloseToCol && 2 * nYDiff > nFuzzy )
{
const SwFrm* pPrev = pFrm->GetPrev();
if ( pPrev )
{
SwRect aPrevRect = pPrev->Prt();
aPrevRect.Pos() += pPrev->Frm().Pos();
if( aPrevRect.IsInside( rPt ) )
{
bCloseToCol = false;
}
}
}
// If we found the point to be 'close' to the left or top border
// of the table frame, we adjust the point to be on that border:
if ( bCloseToRow && bCloseToCol )
aPt = bRTL ? aTabRect.TopRight() : (aTabRect.*fnRect->fnGetPos)();
else if ( bCloseToRow )
rPointX = nLeft;
else if ( bCloseToCol )
rPointY = nTop;
if ( !bCloseToRow && !bCloseToCol )
bSearchForFrmInTab = false;
// Since the point has been adjusted, we call lcl_FindFrmInTab()
// with a fuzzy value of 1:
nTmpFuzzy = 1;
}
const SwFrm* pTmp = bSearchForFrmInTab ?
::lcl_FindFrmInTab( (SwLayoutFrm*)pFrm, aPt, nTmpFuzzy ) :
0;
if ( pTmp )
{
pFrm = pTmp;
break;
}
}
pFrm = pFrm->FindNextCnt();
} while ( pFrm && pLay->IsAnLower( pFrm ) );
}
if ( pFrm && pFrm->IsInTab() && pLay->IsAnLower( pFrm ) )
{
do
{
// We allow mouse drag of table borders within nested tables,
// but disallow hotspot selection of nested tables.
if ( bMouseMoveRowCols )
{
// find the next cell frame
while ( pFrm && !pFrm->IsCellFrm() )
pFrm = pFrm->GetUpper();
}
else
{
// find the most upper cell frame:
while ( pFrm &&
( !pFrm->IsCellFrm() ||
!pFrm->GetUpper()->GetUpper()->IsTabFrm() ||
pFrm->GetUpper()->GetUpper()->GetUpper()->IsInTab() ) )
pFrm = pFrm->GetUpper();
}
if ( pFrm ) // Note: this condition should be the same like the while condition!!!
{
// #i32329# Enhanced table selection
// used for hotspot selection of tab/cols/rows
if ( !bMouseMoveRowCols )
{
OSL_ENSURE( pbCol && pbRow, "pbCol or pbRow missing" );
if ( bCloseToRow || bCloseToCol )
{
*pbRow = bCloseToRow;
*pbCol = bCloseToCol;
pRet = pFrm;
break;
}
}
else
{
// used for mouse move of columns/rows
const SwTabFrm* pTabFrm = pFrm->FindTabFrm();
SwRect aTabRect = pTabFrm->Prt();
aTabRect.Pos() += pTabFrm->Frm().Pos();
SWRECTFN( pTabFrm )
const SwTwips nTabTop = (aTabRect.*fnRect->fnGetTop)();
const SwTwips nMouseTop = bVert ? rPt.X() : rPt.Y();
// Do not allow to drag upper table border:
if ( !::IsSame( nTabTop, nMouseTop ) )
{
if ( ::IsSame( pFrm->Frm().Left(), rPt.X() ) ||
::IsSame( pFrm->Frm().Right(),rPt.X() ) )
{
if ( pbRow ) *pbRow = false;
pRet = pFrm;
break;
}
if ( ::IsSame( pFrm->Frm().Top(), rPt.Y() ) ||
::IsSame( pFrm->Frm().Bottom(),rPt.Y() ) )
{
if ( pbRow ) *pbRow = true;
pRet = pFrm;
break;
}
}
}
pFrm = pFrm->GetUpper();
}
} while ( pFrm );
}
// robust:
OSL_ENSURE( !pRet || pRet->IsCellFrm(), "lcl_FindFrm() is supposed to find a cell frame!" );
return pRet && pRet->IsCellFrm() ? static_cast<const SwCellFrm*>(pRet) : 0;
}
//
// pbCol = 0 => Used for moving table rows/cols with mouse
// pbCol != 0 => Used for selecting table/rows/cols
//
#define ENHANCED_TABLE_SELECTION_FUZZY 10
const SwFrm* SwFEShell::GetBox( const Point &rPt, bool* pbRow, bool* pbCol ) const
{
const SwPageFrm *pPage = (SwPageFrm*)GetLayout()->Lower();
Window* pOutWin = GetWin();
SwTwips nFuzzy = COLFUZZY;
if( pOutWin )
{
// #i32329# Enhanced table selection
SwTwips nSize = pbCol ? ENHANCED_TABLE_SELECTION_FUZZY : RULER_MOUSE_MARGINWIDTH;
Size aTmp( nSize, nSize );
aTmp = pOutWin->PixelToLogic( aTmp );
nFuzzy = aTmp.Width();
}
while ( pPage && !pPage->Frm().IsNear( rPt, nFuzzy ) )
pPage = (SwPageFrm*)pPage->GetNext();
const SwCellFrm *pFrm = 0;
if ( pPage )
{
//Per GetCrsrOfst oder GetCntntPos koennen wir hier die Box leider
//nicht suchen. Das wuerde zu einem Performance-Zusammenbruch bei
//Dokumenten mit vielen Absaetzen/Tabellen auf einer Seite fuehren
//(BrowseMode!)
//Erst die Flys checken.
if ( pPage->GetSortedObjs() )
{
for ( sal_uInt16 i = 0; !pFrm && i < pPage->GetSortedObjs()->Count(); ++i )
{
SwAnchoredObject* pObj = (*pPage->GetSortedObjs())[i];
if ( pObj->ISA(SwFlyFrm) )
{
pFrm = lcl_FindFrm( static_cast<SwFlyFrm*>(pObj),
rPt, nFuzzy, pbRow, pbCol );
}
}
}
const SwLayoutFrm *pLay = (SwLayoutFrm*)pPage->Lower();
while ( pLay && !pFrm )
{
pFrm = lcl_FindFrm( pLay, rPt, nFuzzy, pbRow, pbCol );
pLay = (SwLayoutFrm*)pLay->GetNext();
}
}
return pFrm;
}
/* Helper function*/
/* calculated the distance between Point rC and Line Segment (rA, rB) */
double lcl_DistancePoint2Segment( const Point& rA, const Point& rB, const Point& rC )
{
double nRet = 0;
const basegfx::B2DVector aBC( rC.X() - rB.X(), rC.Y() - rB.Y() );
const basegfx::B2DVector aAB( rB.X() - rA.X(), rB.Y() - rA.Y() );
const double nDot1 = aBC.scalar( aAB );
if ( nDot1 > 0 ) // check outside case 1
nRet = aBC.getLength();
else
{
const basegfx::B2DVector aAC( rC.X() - rA.X(), rC.Y() - rA.Y() );
const basegfx::B2DVector aBA( rA.X() - rB.X(), rA.Y() - rB.Y() );
const double nDot2 = aAC.scalar( aBA );
if ( nDot2 > 0 ) // check outside case 2
nRet = aAC.getLength();
else
{
const double nDiv = aAB.getLength();
nRet = nDiv ? aAB.cross( aAC ) / nDiv : 0;
}
}
return Abs(nRet);
}
/* Helper function*/
Point lcl_ProjectOntoClosestTableFrm( const SwTabFrm& rTab, const Point& rPoint, bool bRowDrag )
{
Point aRet( rPoint );
const SwTabFrm* pCurrentTab = &rTab;
const bool bVert = pCurrentTab->IsVertical();
const bool bRTL = pCurrentTab->IsRightToLeft();
// Western Layout:
// bRowDrag = true => compare to left border of table
// bRowDrag = false => compare to top border of table
// Asian Layout:
// bRowDrag = true => compare to right border of table
// bRowDrag = false => compare to top border of table
// RTL Layout:
// bRowDrag = true => compare to right border of table
// bRowDrag = false => compare to top border of table
bool bLeft = false;
bool bRight = false;
if ( bRowDrag )
{
if ( bVert || bRTL )
bRight = true;
else
bLeft = true;
}
// used to find the minimal distance
double nMin = -1;
Point aMin1;
Point aMin2;
Point aS1;
Point aS2;
while ( pCurrentTab )
{
SwRect aTabRect( pCurrentTab->Prt() );
aTabRect += pCurrentTab->Frm().Pos();
if ( bLeft )
{
// distance to left table border
aS1 = aTabRect.TopLeft();
aS2 = aTabRect.BottomLeft();
}
else if ( bRight )
{
// distance to right table border
aS1 = aTabRect.TopRight();
aS2 = aTabRect.BottomRight();
}
else //if ( bTop )
{
// distance to top table border
aS1 = aTabRect.TopLeft();
aS2 = aTabRect.TopRight();
}
const double nDist = lcl_DistancePoint2Segment( aS1, aS2, rPoint );
if ( nDist < nMin || -1 == nMin )
{
aMin1 = aS1;
aMin2 = aS2;
nMin = nDist;
}
pCurrentTab = pCurrentTab->GetFollow();
}
// project onto closest line:
if ( bLeft || bRight )
{
aRet.X() = aMin1.X();
if ( aRet.Y() > aMin2.Y() )
aRet.Y() = aMin2.Y();
else if ( aRet.Y() < aMin1.Y() )
aRet.Y() = aMin1.Y();
}
else
{
aRet.Y() = aMin1.Y();
if ( aRet.X() > aMin2.X() )
aRet.X() = aMin2.X();
else if ( aRet.X() < aMin1.X() )
aRet.X() = aMin1.X();
}
return aRet;
}
// #i32329# Enhanced table selection
bool SwFEShell::SelTblRowCol( const Point& rPt, const Point* pEnd, bool bRowDrag )
{
bool bRet = false;
Point aEndPt;
if ( pEnd )
aEndPt = *pEnd;
SwPosition* ppPos[2] = { 0, 0 };
Point paPt [2] = { rPt, aEndPt };
bool pbRow[2] = { 0, 0 };
bool pbCol[2] = { 0, 0 };
// pEnd is set during dragging.
for ( sal_uInt16 i = 0; i < ( pEnd ? 2 : 1 ); ++i )
{
const SwCellFrm* pFrm =
static_cast<const SwCellFrm*>(GetBox( paPt[i], &pbRow[i], &pbCol[i] ) );
if( pFrm )
{
while( pFrm->Lower() && pFrm->Lower()->IsRowFrm() )
pFrm = static_cast<const SwCellFrm*>( static_cast<const SwLayoutFrm*>( pFrm->Lower() )->Lower() );
if( pFrm && pFrm->GetTabBox()->GetSttNd() &&
pFrm->GetTabBox()->GetSttNd()->IsInProtectSect() )
pFrm = 0;
}
if ( pFrm )
{
const SwCntntFrm* pCntnt = ::GetCellCntnt( *pFrm );
if ( pCntnt && pCntnt->IsTxtFrm() )
{
ppPos[i] = new SwPosition( *pCntnt->GetNode() );
ppPos[i]->nContent.Assign( const_cast<SwCntntNode*>(pCntnt->GetNode()), 0 );
// paPt[i] will not be used any longer, now we use it to store
// a position inside the content frame
paPt[i] = pCntnt->Frm().Center();
}
}
// no calculation of end frame if start frame has not been found.
if ( 1 == i || !ppPos[0] || !pEnd )
break;
// find 'closest' table frame to pEnd:
const SwTabFrm* pCurrentTab = pFrm->FindTabFrm();
if ( pCurrentTab->IsFollow() )
pCurrentTab = pCurrentTab->FindMaster( true );
const Point aProjection = lcl_ProjectOntoClosestTableFrm( *pCurrentTab, *pEnd, bRowDrag );
paPt[1] = aProjection;
}
if ( ppPos[0] )
{
SwShellCrsr* pCrsr = _GetCrsr();
SwCrsrSaveState aSaveState( *pCrsr );
SwPosition aOldPos( *pCrsr->GetPoint() );
pCrsr->DeleteMark();
*pCrsr->GetPoint() = *ppPos[0];
pCrsr->GetPtPos() = paPt[0];
if ( !pCrsr->IsInProtectTable( sal_False, sal_True ) )
{
bool bNewSelection = true;
if ( ppPos[1] )
{
if ( ppPos[1]->nNode.GetNode().StartOfSectionNode() !=
aOldPos.nNode.GetNode().StartOfSectionNode() )
{
pCrsr->SetMark();
SwCrsrSaveState aSaveState2( *pCrsr );
*pCrsr->GetPoint() = *ppPos[1];
pCrsr->GetPtPos() = paPt[1];
if ( pCrsr->IsInProtectTable( sal_False, sal_False ) )
{
pCrsr->RestoreSavePos();
bNewSelection = false;
}
}
else
{
pCrsr->RestoreSavePos();
bNewSelection = false;
}
}
if ( bNewSelection )
{
// #i35543# SelTblRowCol should remove any existing
// table cursor:
if ( IsTableMode() )
TblCrsrToCursor();
if ( pbRow[0] && pbCol[0] )
bRet = SwCrsrShell::SelTbl();
else if ( pbRow[0] )
bRet = SwCrsrShell::_SelTblRowOrCol( true, true );
else if ( pbCol[0] )
bRet = SwCrsrShell::_SelTblRowOrCol( false, true );
}
else
bRet = true;
}
delete ppPos[0];
delete ppPos[1];
}
return bRet;
}
/*************************************************************************
|*
|* SwFEShell::WhichMouseTabCol()
|*
|*************************************************************************/
sal_uInt8 SwFEShell::WhichMouseTabCol( const Point &rPt ) const
{
sal_uInt8 nRet = SW_TABCOL_NONE;
bool bRow = false;
bool bCol = false;
bool bSelect = false;
// First try: Do we get the row/col move cursor?
SwCellFrm* pFrm = (SwCellFrm*)GetBox( rPt, &bRow, 0 );
if ( !pFrm )
{
// Second try: Do we get the row/col/tab selection cursor?
pFrm = (SwCellFrm*)GetBox( rPt, &bRow, &bCol );
bSelect = true;
}
if( pFrm )
{
while( pFrm->Lower() && pFrm->Lower()->IsRowFrm() )
pFrm = (SwCellFrm*)((SwLayoutFrm*)pFrm->Lower())->Lower();
if( pFrm && pFrm->GetTabBox()->GetSttNd() &&
pFrm->GetTabBox()->GetSttNd()->IsInProtectSect() )
pFrm = 0;
}
if( pFrm )
{
if ( !bSelect )
{
if ( pFrm->IsVertical() )
nRet = bRow ? SW_TABCOL_VERT : SW_TABROW_VERT;
else
nRet = bRow ? SW_TABROW_HORI : SW_TABCOL_HORI;
}
else
{
const SwTabFrm* pTabFrm = pFrm->FindTabFrm();
if ( pTabFrm->IsVertical() )
{
if ( bRow && bCol )
{
nRet = SW_TABSEL_VERT;
}
else if ( bRow )
{
nRet = SW_TABROWSEL_VERT;
}
else if ( bCol )
{
nRet = SW_TABCOLSEL_VERT;
}
}
else
{
if ( bRow && bCol )
{
nRet = pTabFrm->IsRightToLeft() ?
SW_TABSEL_HORI_RTL :
SW_TABSEL_HORI;
}
else if ( bRow )
{
nRet = pTabFrm->IsRightToLeft() ?
SW_TABROWSEL_HORI_RTL :
SW_TABROWSEL_HORI;
}
else if ( bCol )
{
nRet = SW_TABCOLSEL_HORI;
}
}
}
}
return nRet;
}
// -> #i23726#
SwTxtNode * SwFEShell::GetNumRuleNodeAtPos( const Point &rPt)
{
SwTxtNode * pResult = NULL;
SwContentAtPos aCntntAtPos
(SwContentAtPos::SW_NUMLABEL);
if( GetContentAtPos(rPt, aCntntAtPos) && aCntntAtPos.aFnd.pNode)
pResult = aCntntAtPos.aFnd.pNode->GetTxtNode();
return pResult;
}
sal_Bool SwFEShell::IsNumLabel( const Point &rPt, int nMaxOffset )
{
sal_Bool bResult = sal_False;
SwContentAtPos aCntntAtPos
(SwContentAtPos::SW_NUMLABEL);
if( GetContentAtPos(rPt, aCntntAtPos))
{
if ((nMaxOffset >= 0 && aCntntAtPos.nDist <= nMaxOffset) ||
(nMaxOffset < 0))
bResult = sal_True;
}
return bResult;
}
// <- #i23726#
// #i42921#
bool SwFEShell::IsVerticalModeAtNdAndPos( const SwTxtNode& _rTxtNode,
const Point& _rDocPos ) const
{
bool bRet( false );
const short nTextDir =
_rTxtNode.GetTextDirection( SwPosition(_rTxtNode), &_rDocPos );
switch ( nTextDir )
{
case -1:
case FRMDIR_HORI_RIGHT_TOP:
case FRMDIR_HORI_LEFT_TOP:
{
bRet = false;
}
break;
case FRMDIR_VERT_TOP_LEFT:
case FRMDIR_VERT_TOP_RIGHT:
{
bRet = true;
}
break;
}
return bRet;
}
/*************************************************************************
|*
|* SwFEShell::GetMouseTabCols()
|*
|*************************************************************************/
void SwFEShell::GetMouseTabCols( SwTabCols &rToFill, const Point &rPt ) const
{
const SwFrm *pBox = GetBox( rPt );
if ( pBox )
_GetTabCols( rToFill, pBox );
}
void SwFEShell::SetMouseTabCols( const SwTabCols &rNew, sal_Bool bCurRowOnly,
const Point &rPt )
{
const SwFrm *pBox = GetBox( rPt );
if( pBox )
{
SET_CURR_SHELL( this );
StartAllAction();
GetDoc()->SetTabCols( rNew, bCurRowOnly, 0, (SwCellFrm*)pBox );
EndAllActionAndCall();
}
}
/*************************************************************************
|*
|* SwFEShell::GetMouseColNum(), GetMouseTabColNum()
|*
|*************************************************************************/
sal_uInt16 SwFEShell::GetCurMouseColNum( const Point &rPt,
SwGetCurColNumPara* pPara ) const
{
return _GetCurColNum( GetBox( rPt ), pPara );
}
sal_uInt16 SwFEShell::GetCurMouseTabColNum( const Point &rPt ) const
{
//!!!GetCurTabColNum() mitpflegen!!!!
sal_uInt16 nRet = 0;
const SwFrm *pFrm = GetBox( rPt );
OSL_ENSURE( pFrm, "Table not found" );
if( pFrm )
{
const long nX = pFrm->Frm().Left();
//TabCols besorgen, den nur ueber diese erreichen wir die Position.
SwTabCols aTabCols;
GetMouseTabCols( aTabCols, rPt );
const long nLeft = aTabCols.GetLeftMin();
if ( !::IsSame( nX, nLeft + aTabCols.GetLeft() ) )
{
for ( sal_uInt16 i = 0; i < aTabCols.Count(); ++i )
if ( ::IsSame( nX, nLeft + aTabCols[i] ) )
{
nRet = i + 1;
break;
}
}
}
return nRet;
}
void ClearFEShellTabCols()
{
DELETEZ( pLastCols );
DELETEZ( pLastRows );
}
/*************************************************************************
|*
|* SwFEShell::GetTblAttr(), SetTblAttr()
|*
|*************************************************************************/
void SwFEShell::GetTblAttr( SfxItemSet &rSet ) const
{
SwFrm *pFrm = GetCurrFrm();
if( pFrm && pFrm->IsInTab() )
rSet.Put( pFrm->ImplFindTabFrm()->GetFmt()->GetAttrSet() );
}
void SwFEShell::SetTblAttr( const SfxItemSet &rNew )
{
SwFrm *pFrm = GetCurrFrm();
if( pFrm && pFrm->IsInTab() )
{
SET_CURR_SHELL( this );
StartAllAction();
SwTabFrm *pTab = pFrm->FindTabFrm();
pTab->GetTable()->SetHTMLTableLayout( 0 );
GetDoc()->SetAttr( rNew, *pTab->GetFmt() );
GetDoc()->SetModified();
EndAllActionAndCall();
}
}
/** move cursor within a table into previous/next row (same column)
* @param pShell cursor shell whose cursor is to be moved
* @param bUp true: move up, false: move down
* @returns true if successful
*/
bool lcl_GoTableRow( SwCrsrShell* pShell, bool bUp )
{
OSL_ENSURE( pShell != NULL, "need shell" );
bool bRet = false;
SwPaM* pPam = pShell->GetCrsr();
const SwStartNode* pTableBox = pPam->GetNode()->FindTableBoxStartNode();
OSL_ENSURE( pTableBox != NULL, "I'm living in a box... NOT!" );
// move cursor to start node of table box
pPam->GetPoint()->nNode = pTableBox->GetIndex();
pPam->GetPoint()->nContent.Assign( NULL, 0 );
GoInCntnt( *pPam, fnMoveForward );
// go to beginning end of table box
SwPosSection fnPosSect = bUp ? fnSectionStart : fnSectionEnd;
pShell->MoveSection( fnSectionCurr, fnPosSect );
// and go up/down into next content
bRet = bUp ? pShell->Up() : pShell->Down();
return bRet;
}
// aender eine Zellenbreite/-Hoehe/Spaltenbreite/Zeilenhoehe
sal_Bool SwFEShell::SetColRowWidthHeight( sal_uInt16 eType, sal_uInt16 nDiff )
{
SwFrm *pFrm = GetCurrFrm();
if( !pFrm || !pFrm->IsInTab() )
return sal_False;
if( nsTblChgWidthHeightType::WH_FLAG_INSDEL & eType &&
pFrm->ImplFindTabFrm()->GetTable()->ISA( SwDDETable ))
{
ErrorHandler::HandleError( ERR_TBLDDECHG_ERROR,
ERRCODE_MSG_INFO | ERRCODE_BUTTON_DEF_OK );
return sal_False;
}
SET_CURR_SHELL( this );
StartAllAction();
do {
pFrm = pFrm->GetUpper();
} while( !pFrm->IsCellFrm() );
SwTabFrm *pTab = pFrm->ImplFindTabFrm();
// sollte die Tabelle noch auf relativen Werten (USHRT_MAX) stehen
// dann muss es jetzt auf absolute umgerechnet werden.
const SwFmtFrmSize& rTblFrmSz = pTab->GetFmt()->GetFrmSize();
SWRECTFN( pTab )
long nPrtWidth = (pTab->Prt().*fnRect->fnGetWidth)();
if( TBLVAR_CHGABS == pTab->GetTable()->GetTblChgMode() &&
( eType & nsTblChgWidthHeightType::WH_COL_LEFT || eType & nsTblChgWidthHeightType::WH_COL_RIGHT ) &&
text::HoriOrientation::NONE == pTab->GetFmt()->GetHoriOrient().GetHoriOrient() &&
nPrtWidth != rTblFrmSz.GetWidth() )
{
SwFmtFrmSize aSz( rTblFrmSz );
aSz.SetWidth( pTab->Prt().Width() );
pTab->GetFmt()->SetFmtAttr( aSz );
}
if( (eType & (nsTblChgWidthHeightType::WH_FLAG_BIGGER | nsTblChgWidthHeightType::WH_FLAG_INSDEL)) ==
(nsTblChgWidthHeightType::WH_FLAG_BIGGER | nsTblChgWidthHeightType::WH_FLAG_INSDEL) )
{
nDiff = sal_uInt16((pFrm->Frm().*fnRect->fnGetWidth)());
// we must move the cursor outside the current cell before
// deleting the cells.
TblChgWidthHeightType eTmp =
static_cast<TblChgWidthHeightType>( eType & 0xfff );
switch( eTmp )
{
case nsTblChgWidthHeightType::WH_ROW_TOP:
lcl_GoTableRow( this, true );
break;
case nsTblChgWidthHeightType::WH_ROW_BOTTOM:
lcl_GoTableRow( this, false );
break;
case nsTblChgWidthHeightType::WH_COL_LEFT:
GoPrevCell();
break;
case nsTblChgWidthHeightType::WH_COL_RIGHT:
GoNextCell();
break;
default:
break;
}
}
SwTwips nLogDiff = nDiff;
nLogDiff *= pTab->GetFmt()->GetFrmSize().GetWidth();
nLogDiff /= nPrtWidth;
/** The cells are destroyed in here */
sal_Bool bRet = GetDoc()->SetColRowWidthHeight(
*(SwTableBox*)((SwCellFrm*)pFrm)->GetTabBox(),
eType, nDiff, nLogDiff );
delete pLastCols, pLastCols = 0;
EndAllActionAndCall();
if( bRet && (eType & (nsTblChgWidthHeightType::WH_FLAG_BIGGER | nsTblChgWidthHeightType::WH_FLAG_INSDEL)) == nsTblChgWidthHeightType::WH_FLAG_INSDEL )
{
switch(eType & ~(nsTblChgWidthHeightType::WH_FLAG_BIGGER | nsTblChgWidthHeightType::WH_FLAG_INSDEL))
{
case nsTblChgWidthHeightType::WH_CELL_LEFT:
case nsTblChgWidthHeightType::WH_COL_LEFT:
GoPrevCell();
break;
case nsTblChgWidthHeightType::WH_CELL_RIGHT:
case nsTblChgWidthHeightType::WH_COL_RIGHT:
GoNextCell();
break;
case nsTblChgWidthHeightType::WH_CELL_TOP:
case nsTblChgWidthHeightType::WH_ROW_TOP:
lcl_GoTableRow( this, true );
break;
case nsTblChgWidthHeightType::WH_CELL_BOTTOM:
case nsTblChgWidthHeightType::WH_ROW_BOTTOM:
lcl_GoTableRow( this, false );
break;
}
}
return bRet;
}
sal_Bool lcl_IsFormulaSelBoxes( const SwTable& rTbl, const SwTblBoxFormula& rFml,
SwCellFrms& rCells )
{
SwTblBoxFormula aTmp( rFml );
SwSelBoxes aBoxes;
for( sal_uInt16 nSelBoxes = aTmp.GetBoxesOfFormula( rTbl,aBoxes ); nSelBoxes; )
{
SwTableBox* pBox = aBoxes[ --nSelBoxes ];
sal_uInt16 i;
for( i = 0; i < rCells.Count(); ++i )
if( rCells[ i ]->GetTabBox() == pBox )
break; // gefunden
if( i == rCells.Count() )
return sal_False;
}
return sal_True;
}
// erfrage die Formel fuer die Autosumme
sal_Bool SwFEShell::GetAutoSum( String& rFml ) const
{
SwFrm *pFrm = GetCurrFrm();
SwTabFrm *pTab = pFrm ? pFrm->ImplFindTabFrm() : 0;
if( !pTab )
return sal_False;
rFml = String::CreateFromAscii( sCalc_Sum );
SwCellFrms aCells;
if( ::GetAutoSumSel( *this, aCells ))
{
sal_uInt16 nW = 0, nInsPos = 0;
for( sal_uInt16 n = aCells.Count(); n; )
{
SwCellFrm* pCFrm = aCells[ --n ];
sal_uInt16 nBoxW = pCFrm->GetTabBox()->IsFormulaOrValueBox();
if( !nBoxW )
break;
if( !nW )
{
if( USHRT_MAX == nBoxW )
continue; // leere am Anfang ueberspringen
rFml += '(';
nInsPos = rFml.Len();
// Formeln nur wenn diese Boxen enthalten
if( RES_BOXATR_FORMULA == nBoxW &&
!::lcl_IsFormulaSelBoxes( *pTab->GetTable(), pCFrm->
GetTabBox()->GetFrmFmt()->GetTblBoxFormula(), aCells))
{
nW = RES_BOXATR_VALUE;
// alle vorhierigen Leere wieder mit aufnehmen !
for( sal_uInt16 i = aCells.Count(); n+1 < i; )
{
String sTmp( String::CreateFromAscii(
RTL_CONSTASCII_STRINGPARAM( "|<" )) );
sTmp += aCells[ --i ]->GetTabBox()->GetName();
sTmp += '>';
rFml.Insert( sTmp, nInsPos );
}
}
else
nW = nBoxW;
}
else if( RES_BOXATR_VALUE == nW )
{
// values werden gesucht, Value/Formel/Text gefunden -> aufn.
if( RES_BOXATR_FORMULA == nBoxW &&
::lcl_IsFormulaSelBoxes( *pTab->GetTable(), pCFrm->
GetTabBox()->GetFrmFmt()->GetTblBoxFormula(), aCells ))
break;
else if( USHRT_MAX != nBoxW )
rFml.Insert( cListDelim, nInsPos );
else
break;
}
else if( RES_BOXATR_FORMULA == nW )
{
// bei Formeln nur weiter suchen, wenn die akt. Formel auf
// alle Boxen verweist, die sich in der Selektion befinden
if( RES_BOXATR_FORMULA == nBoxW )
{
if( !::lcl_IsFormulaSelBoxes( *pTab->GetTable(), pCFrm->
GetTabBox()->GetFrmFmt()->GetTblBoxFormula(), aCells ))
{
// dann noch mal von vorne und nur die Values!
nW = RES_BOXATR_VALUE;
rFml.Erase( nInsPos );
// alle vorhierigen Leere wieder mit aufnehmen !
for( sal_uInt16 i = aCells.Count(); n+1 < i; )
{
String sTmp( String::CreateFromAscii(
RTL_CONSTASCII_STRINGPARAM( "|<" )) );
sTmp += aCells[ --i ]->GetTabBox()->GetName();
sTmp += '>';
rFml.Insert( sTmp, nInsPos );
}
}
else
rFml.Insert( cListDelim, nInsPos );
}
else if( USHRT_MAX == nBoxW )
break;
else
continue; // diese Boxen ignorieren
}
else
// alles andere beendet die Schleife
// evt. Texte noch zu lassen??
break;
String sTmp( '<' );
sTmp += pCFrm->GetTabBox()->GetName();
sTmp += '>';
rFml.Insert( sTmp, nInsPos );
}
if( nW )
{
rFml += ')';
}
}
return sal_True;
}
sal_Bool SwFEShell::IsTableRightToLeft() const
{
SwFrm *pFrm = GetCurrFrm();
if( !pFrm || !pFrm->IsInTab() )
return sal_False;
return pFrm->ImplFindTabFrm()->IsRightToLeft();
}
sal_Bool SwFEShell::IsMouseTableRightToLeft(const Point &rPt) const
{
SwFrm *pFrm = (SwFrm *)GetBox( rPt );
const SwTabFrm* pTabFrm = pFrm ? pFrm->ImplFindTabFrm() : 0;
OSL_ENSURE( pTabFrm, "Table not found" );
return pTabFrm ? pTabFrm->IsRightToLeft() : sal_False;
}
sal_Bool SwFEShell::IsTableVertical() const
{
SwFrm *pFrm = GetCurrFrm();
if( !pFrm || !pFrm->IsInTab() )
return sal_False;
return pFrm->ImplFindTabFrm()->IsVertical();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|