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 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include "hintids.hxx"
#include <vcl/svapp.hxx>
#include <vcl/wrkwin.hxx>
#include <editeng/boxitem.hxx>
#include <editeng/brshitem.hxx>
#include <editeng/adjitem.hxx>
#include <editeng/fhgtitem.hxx>
#include <editeng/ulspitem.hxx>
#include <editeng/lrspitem.hxx>
#include <editeng/brkitem.hxx>
#include <editeng/spltitem.hxx>
#include <svtools/htmltokn.h>
#include <svtools/htmlkywd.hxx>
#include <svl/urihelper.hxx>
#include <fmtornt.hxx>
#include <frmfmt.hxx>
#include <fmtfsize.hxx>
#include <fmtsrnd.hxx>
#include <fmtpdsc.hxx>
#include <fmtcntnt.hxx>
#include <fmtanchr.hxx>
#include <fmtlsplt.hxx>
#include "frmatr.hxx"
#include "pam.hxx"
#include "doc.hxx"
#include "ndtxt.hxx"
#include "shellio.hxx"
#include "poolfmt.hxx"
#include "swtable.hxx"
#include "cellatr.hxx"
#include "htmltbl.hxx"
#include "swtblfmt.hxx"
#include "htmlnum.hxx"
#include "swhtml.hxx"
#include "swcss1.hxx"
#include <numrule.hxx>
#define NETSCAPE_DFLT_BORDER 1
#define NETSCAPE_DFLT_CELLPADDING 1
#define NETSCAPE_DFLT_CELLSPACING 2
//#define FIX56334
using ::editeng::SvxBorderLine;
using namespace ::com::sun::star;
static HTMLOptionEnum aHTMLTblVAlignTable[] =
{
{ OOO_STRING_SVTOOLS_HTML_VA_top, text::VertOrientation::NONE },
{ OOO_STRING_SVTOOLS_HTML_VA_middle, text::VertOrientation::CENTER },
{ OOO_STRING_SVTOOLS_HTML_VA_bottom, text::VertOrientation::BOTTOM },
{ 0, 0 }
};
// table tags options
struct HTMLTableOptions
{
sal_uInt16 nCols;
sal_uInt16 nWidth;
sal_uInt16 nHeight;
sal_uInt16 nCellPadding;
sal_uInt16 nCellSpacing;
sal_uInt16 nBorder;
sal_uInt16 nHSpace;
sal_uInt16 nVSpace;
SvxAdjust eAdjust;
sal_Int16 eVertOri;
HTMLTableFrame eFrame;
HTMLTableRules eRules;
sal_Bool bPrcWidth : 1;
sal_Bool bTableAdjust : 1;
sal_Bool bBGColor : 1;
Color aBorderColor;
Color aBGColor;
String aBGImage, aStyle, aId, aClass, aDir;
HTMLTableOptions( const HTMLOptions& rOptions, SvxAdjust eParentAdjust );
};
class _HTMLTableContext
{
SwHTMLNumRuleInfo aNumRuleInfo; // Numbering valid before the table
SwTableNode *pTblNd; // table node
SwFrmFmt *pFrmFmt; // der Fly frame::Frame, containing the table
SwPosition *pPos; // position behind the table
sal_uInt16 nContextStAttrMin;
sal_uInt16 nContextStMin;
sal_Bool bRestartPRE : 1;
sal_Bool bRestartXMP : 1;
sal_Bool bRestartListing : 1;
public:
_HTMLAttrTable aAttrTab; // attributes
_HTMLTableContext( SwPosition *pPs, sal_uInt16 nCntxtStMin,
sal_uInt16 nCntxtStAttrMin ) :
pTblNd( 0 ),
pFrmFmt( 0 ),
pPos( pPs ),
nContextStAttrMin( nCntxtStAttrMin ),
nContextStMin( nCntxtStMin ),
bRestartPRE( sal_False ),
bRestartXMP( sal_False ),
bRestartListing( sal_False )
{
memset( &aAttrTab, 0, sizeof( _HTMLAttrTable ));
}
~_HTMLTableContext();
void SetNumInfo( const SwHTMLNumRuleInfo& rInf ) { aNumRuleInfo.Set(rInf); }
const SwHTMLNumRuleInfo& GetNumInfo() const { return aNumRuleInfo; };
void SavePREListingXMP( SwHTMLParser& rParser );
void RestorePREListingXMP( SwHTMLParser& rParser );
SwPosition *GetPos() const { return pPos; }
void SetTableNode( SwTableNode *pNd ) { pTblNd = pNd; }
SwTableNode *GetTableNode() const { return pTblNd; }
void SetFrmFmt( SwFrmFmt *pFmt ) { pFrmFmt = pFmt; }
SwFrmFmt *GetFrmFmt() const { return pFrmFmt; }
sal_uInt16 GetContextStMin() const { return nContextStMin; }
sal_uInt16 GetContextStAttrMin() const { return nContextStAttrMin; }
};
// Cell content is a linked list with SwStartNodes and
// HTMLTables.
class HTMLTableCnts
{
HTMLTableCnts *pNext; // next content
// Only one of the next two pointers must be set!
const SwStartNode *pStartNode; // a paragraph
HTMLTable *pTable; // a table
SwHTMLTableLayoutCnts* pLayoutInfo;
sal_Bool bNoBreak;
void InitCtor();
public:
HTMLTableCnts( const SwStartNode* pStNd );
HTMLTableCnts( HTMLTable* pTab );
~HTMLTableCnts(); // only allowed in ~HTMLTableCell
// Determine SwStartNode and HTMLTable respectively
const SwStartNode *GetStartNode() const { return pStartNode; }
const HTMLTable *GetTable() const { return pTable; }
HTMLTable *GetTable() { return pTable; }
// Add a new node at the end of the list
void Add( HTMLTableCnts* pNewCnts );
// Determine next node
const HTMLTableCnts *Next() const { return pNext; }
HTMLTableCnts *Next() { return pNext; }
inline void SetTableBox( SwTableBox *pBox );
void SetNoBreak() { bNoBreak = sal_True; }
SwHTMLTableLayoutCnts *CreateLayoutInfo();
};
// Cell of a HTML table
class HTMLTableCell
{
// !!!ATTENTION!!!!! For each new pointer the SetProtected
// method (and the dtor) has to be executed.
HTMLTableCnts *pContents; // cell content
SvxBrushItem *pBGBrush; // cell background
// !!!ATTENTION!!!!!
::boost::shared_ptr<SvxBoxItem> m_pBoxItem;
sal_uInt32 nNumFmt;
sal_uInt16 nRowSpan; // cell ROWSPAN
sal_uInt16 nColSpan; // cell COLSPAN
sal_uInt16 nWidth; // cell WIDTH
double nValue;
sal_Int16 eVertOri; // vertical alignment of the cell
sal_Bool bProtected : 1; // cell must not filled
sal_Bool bRelWidth : 1; // nWidth is given in %
sal_Bool bHasNumFmt : 1;
sal_Bool bHasValue : 1;
sal_Bool bNoWrap : 1;
sal_Bool mbCovered : 1;
public:
HTMLTableCell(); // new cells always empty
~HTMLTableCell(); // only allowed in ~HTMLTableRow
// Fill a not empty cell
void Set( HTMLTableCnts *pCnts, sal_uInt16 nRSpan, sal_uInt16 nCSpan,
sal_Int16 eVertOri, SvxBrushItem *pBGBrush,
::boost::shared_ptr<SvxBoxItem> const pBoxItem,
sal_Bool bHasNumFmt, sal_uInt32 nNumFmt,
sal_Bool bHasValue, double nValue, sal_Bool bNoWrap, sal_Bool bCovered );
// Protect an empty 1x1 cell
void SetProtected();
// Set/Get cell content
void SetContents( HTMLTableCnts *pCnts ) { pContents = pCnts; }
const HTMLTableCnts *GetContents() const { return pContents; }
HTMLTableCnts *GetContents() { return pContents; }
// Set/Get cell ROWSPAN/COLSPAN
void SetRowSpan( sal_uInt16 nRSpan ) { nRowSpan = nRSpan; }
sal_uInt16 GetRowSpan() const { return nRowSpan; }
void SetColSpan( sal_uInt16 nCSpan ) { nColSpan = nCSpan; }
sal_uInt16 GetColSpan() const { return nColSpan; }
inline void SetWidth( sal_uInt16 nWidth, sal_Bool bRelWidth );
const SvxBrushItem *GetBGBrush() const { return pBGBrush; }
::boost::shared_ptr<SvxBoxItem> GetBoxItem() const { return m_pBoxItem; }
inline sal_Bool GetNumFmt( sal_uInt32& rNumFmt ) const;
inline sal_Bool GetValue( double& rValue ) const;
sal_Int16 GetVertOri() const { return eVertOri; }
// Is the cell filled or protected ?
sal_Bool IsUsed() const { return pContents!=0 || bProtected; }
SwHTMLTableLayoutCell *CreateLayoutInfo();
sal_Bool IsCovered() const { return mbCovered; }
};
// Row of a HTML table
typedef HTMLTableCell* HTMLTableCellPtr;
SV_DECL_PTRARR_DEL(HTMLTableCells,HTMLTableCellPtr,5,5)
class HTMLTableRow
{
HTMLTableCells *pCells; // cells of the row
sal_Bool bIsEndOfGroup : 1;
sal_Bool bSplitable : 1;
sal_uInt16 nHeight; // options of <TR>/<TD>
sal_uInt16 nEmptyRows; // number of empty rows are following
SvxAdjust eAdjust;
sal_Int16 eVertOri;
SvxBrushItem *pBGBrush; // background of cell from STYLE
public:
sal_Bool bBottomBorder; // Is there a line after the row?
HTMLTableRow( sal_uInt16 nCells=0 ); // cells of the row are empty
~HTMLTableRow();
inline void SetHeight( sal_uInt16 nHeight );
sal_uInt16 GetHeight() const { return nHeight; }
inline HTMLTableCell *GetCell( sal_uInt16 nCell ) const;
inline const HTMLTableCells *GetCells() const { return pCells; }
inline void SetAdjust( SvxAdjust eAdj ) { eAdjust = eAdj; }
inline SvxAdjust GetAdjust() const { return eAdjust; }
inline void SetVertOri( sal_Int16 eV) { eVertOri = eV; }
inline sal_Int16 GetVertOri() const { return eVertOri; }
void SetBGBrush( SvxBrushItem *pBrush ) { pBGBrush = pBrush; }
const SvxBrushItem *GetBGBrush() const { return pBGBrush; }
inline void SetEndOfGroup() { bIsEndOfGroup = sal_True; }
inline sal_Bool IsEndOfGroup() const { return bIsEndOfGroup; }
void IncEmptyRows() { nEmptyRows++; }
sal_uInt16 GetEmptyRows() const { return nEmptyRows; }
// Expand row by adding empty cells
void Expand( sal_uInt16 nCells, sal_Bool bOneCell=sal_False );
// Shrink row by deleting empty cells
void Shrink( sal_uInt16 nCells );
void SetSplitable( sal_Bool bSet ) { bSplitable = bSet; }
sal_Bool IsSplitable() const { return bSplitable; }
};
// Column of a HTML table
class HTMLTableColumn
{
sal_Bool bIsEndOfGroup;
sal_uInt16 nWidth; // options of <COL>
sal_Bool bRelWidth;
SvxAdjust eAdjust;
sal_Int16 eVertOri;
SwFrmFmt *aFrmFmts[6];
inline sal_uInt16 GetFrmFmtIdx( sal_Bool bBorderLine,
sal_Int16 eVertOri ) const;
public:
sal_Bool bLeftBorder; // is there a line before the column
HTMLTableColumn();
inline void SetWidth( sal_uInt16 nWidth, sal_Bool bRelWidth);
inline void SetAdjust( SvxAdjust eAdj ) { eAdjust = eAdj; }
inline SvxAdjust GetAdjust() const { return eAdjust; }
inline void SetVertOri( sal_Int16 eV) { eVertOri = eV; }
inline sal_Int16 GetVertOri() const { return eVertOri; }
inline void SetEndOfGroup() { bIsEndOfGroup = sal_True; }
inline sal_Bool IsEndOfGroup() const { return bIsEndOfGroup; }
inline void SetFrmFmt( SwFrmFmt *pFmt, sal_Bool bBorderLine,
sal_Int16 eVertOri );
inline SwFrmFmt *GetFrmFmt( sal_Bool bBorderLine,
sal_Int16 eVertOri ) const;
SwHTMLTableLayoutColumn *CreateLayoutInfo();
};
// HTML table
typedef HTMLTableRow* HTMLTableRowPtr;
SV_DECL_PTRARR_DEL(HTMLTableRows,HTMLTableRowPtr,5,5)
typedef HTMLTableColumn* HTMLTableColumnPtr;
SV_DECL_PTRARR_DEL(HTMLTableColumns,HTMLTableColumnPtr,5,5)
SV_DECL_PTRARR(SdrObjects,SdrObject *,1,1)
class HTMLTable
{
String aId;
String aStyle;
String aClass;
String aDir;
SdrObjects *pResizeDrawObjs;// SDR objects
std::vector<sal_uInt16> *pDrawObjPrcWidths; // column of draw object and its rel. width
HTMLTableRows *pRows; // table rows
HTMLTableColumns *pColumns; // table columns
sal_uInt16 nRows; // number of rows
sal_uInt16 nCols; // number of columns
sal_uInt16 nFilledCols; // number of filled columns
sal_uInt16 nCurRow; // aktuelle Zeile
sal_uInt16 nCurCol; // aktuelle Spalte
sal_uInt16 nLeftMargin; // Abstand zum linken Rand (aus Absatz)
sal_uInt16 nRightMargin; // Abstand zum rechten Rand (aus Absatz)
sal_uInt16 nCellPadding; // Abstand Umrandung zum Text
sal_uInt16 nCellSpacing; // Abstand zwischen zwei Zellen
sal_uInt16 nHSpace;
sal_uInt16 nVSpace;
sal_uInt16 nBoxes; // Wievele Boxen enthaelt die Tabelle
const SwStartNode *pPrevStNd; // der Table-Node oder der Start-Node
// der vorhergehenden Section
const SwTable *pSwTable; // die SW-Tabelle (nur auf dem Top-Level)
SwTableBox *pBox1; // die TableBox, die beim Erstellen
// der Top-Level-Tabelle angelegt wird
SwTableBoxFmt *pBoxFmt; // das frame::Frame-Format einer SwTableBox
SwTableLineFmt *pLineFmt; // das frame::Frame-Format einer SwTableLine
SwTableLineFmt *pLineFrmFmtNoHeight;
SvxBrushItem *pBGBrush; // Hintergrund der Tabelle
SvxBrushItem *pInhBGBrush; // "geerbter" Hintergrund der Tabelle
const SwStartNode *pCaptionStartNode; // Start-Node der Tabellen-Ueberschrift
SvxBorderLine aTopBorderLine; // die Linie fuer die Umrandung
SvxBorderLine aBottomBorderLine;// die Linie fuer die Umrandung
SvxBorderLine aLeftBorderLine; // die Linie fuer die Umrandung
SvxBorderLine aRightBorderLine; // die Linie fuer die Umrandung
SvxBorderLine aBorderLine; // die Linie fuer die Umrandung
SvxBorderLine aInhLeftBorderLine; // die Linie fuer die Umrandung
SvxBorderLine aInhRightBorderLine; // die Linie fuer die Umrandung
sal_Bool bTopBorder; // besitzt die Tabelle oben eine Linie
sal_Bool bRightBorder; // besitzt die Tabelle rechts eine Linie
sal_Bool bTopAlwd; // duerfen die Raender gesetzt werden?
sal_Bool bRightAlwd;
sal_Bool bFillerTopBorder; // bekommt eine linke/rechter Filler-
sal_Bool bFillerBottomBorder; // Zelle eine obere/untere Umrandung?
sal_Bool bInhLeftBorder;
sal_Bool bInhRightBorder;
sal_Bool bBordersSet; // die Umrandung wurde bereits gesetzt
sal_Bool bForceFrame;
sal_Bool bTableAdjustOfTag; // stammt nTableAdjust aus <TABLE>?
sal_uInt32 nHeadlineRepeat; // repeating rows
sal_Bool bIsParentHead;
sal_Bool bHasParentSection;
sal_Bool bMakeTopSubTable;
sal_Bool bHasToFly;
sal_Bool bFixedCols;
sal_Bool bColSpec; // Gab es COL(GROUP)-Elemente?
sal_Bool bPrcWidth; // Breite ist eine %-Angabe
SwHTMLParser *pParser; // der aktuelle Parser
HTMLTable *pTopTable; // die Tabelle auf dem Top-Level
HTMLTableCnts *pParentContents;
_HTMLTableContext *pContext; // der Kontext der Tabelle
SwHTMLTableLayout *pLayoutInfo;
// die folgenden Parameter stammen aus der dem <TABLE>-Tag
sal_uInt16 nWidth; // die Breite der Tabelle
sal_uInt16 nHeight; // absolute Hoehe der Tabelle
SvxAdjust eTableAdjust; // drawing::Alignment der Tabelle
sal_Int16 eVertOri; // Default vertikale Ausr. der Zellen
sal_uInt16 nBorder; // Breite der auesseren Umrandung
HTMLTableFrame eFrame; // Rahmen um die Tabelle
HTMLTableRules eRules; // Ramhen in der Tabelle
sal_Bool bTopCaption; // Ueberschrift ueber der Tabelle
void InitCtor( const HTMLTableOptions *pOptions );
// Korigieren des Row-Spans fuer alle Zellen oberhalb der
// angegeben Zelle und der Zelle selbst, fuer die den anegebenen
// Inhalt besitzen. Die angegeben Zelle bekommt den Row-Span 1
void FixRowSpan( sal_uInt16 nRow, sal_uInt16 nCol, const HTMLTableCnts *pCnts );
// Schuetzen der angegeben Zelle und den darunterliegenden
void ProtectRowSpan( sal_uInt16 nRow, sal_uInt16 nCol, sal_uInt16 nRowSpan );
// Suchen des SwStartNodes der logisch vorhergehenden Box
// bei nRow==nCell==USHRT_MAX wird der allerletzte Start-Node
// der Tabelle zurueckgegeben
const SwStartNode* GetPrevBoxStartNode( sal_uInt16 nRow, sal_uInt16 nCell ) const;
sal_uInt16 GetTopCellSpace( sal_uInt16 nRow, sal_uInt16 nRowSpan,
sal_Bool bSwBorders=sal_True ) const;
sal_uInt16 GetBottomCellSpace( sal_uInt16 nRow, sal_uInt16 nRowSpan,
sal_Bool bSwBorders=sal_True ) const;
// Anpassen des frame::Frame-Formates einer Box
void FixFrameFmt( SwTableBox *pBox, sal_uInt16 nRow, sal_uInt16 nCol,
sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
sal_Bool bFirstPara=sal_True, sal_Bool bLastPara=sal_True ) const;
void FixFillerFrameFmt( SwTableBox *pBox, sal_Bool bRight ) const;
// den Inhalt (Lines/Boxen) eine Tabelle erstellen
void _MakeTable( SwTableBox *pUpper=0 );
// Anlegen einer neuen SwTableBox, die einen SwStartNode enthaelt
SwTableBox *NewTableBox( const SwStartNode *pStNd,
SwTableLine *pUpper ) const;
// Erstellen einer SwTableLine aus den Zellen des Rechtecks
// (nTopRow/nLeftCol) inklusive bis (nBottomRow/nRightRow) exklusive
SwTableLine *MakeTableLine( SwTableBox *pUpper,
sal_uInt16 nTopRow, sal_uInt16 nLeftCol,
sal_uInt16 nBottomRow, sal_uInt16 nRightCol );
// Erstellen einer SwTableBox aus dem Inhalt einer Zelle
SwTableBox *MakeTableBox( SwTableLine *pUpper,
HTMLTableCnts *pCnts,
sal_uInt16 nTopRow, sal_uInt16 nLeftCol,
sal_uInt16 nBootomRow, sal_uInt16 nRightCol );
// der Autolayout-Algorithmus
// Setzen der Umrandung anhand der Vorgaben der Parent-Tabelle
void InheritBorders( const HTMLTable *pParent,
sal_uInt16 nRow, sal_uInt16 nCol,
sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
sal_Bool bFirstPara, sal_Bool bLastPara );
// Linke und rechte Umrandung der umgebenen Tabelle erben
void InheritVertBorders( const HTMLTable *pParent,
sal_uInt16 nCol, sal_uInt16 nColSpan );
// Setzen der Umrandung anhand der Benutzervorgaben
void SetBorders();
// wurde die Umrandung der Tabelle schon gesetzt
sal_Bool BordersSet() const { return bBordersSet; }
const SvxBrushItem *GetBGBrush() const { return pBGBrush; }
const SvxBrushItem *GetInhBGBrush() const { return pInhBGBrush; }
sal_uInt16 GetBorderWidth( const SvxBorderLine& rBLine,
sal_Bool bWithDistance=sal_False ) const;
public:
sal_Bool bFirstCell; // wurde schon eine Zelle angelegt?
HTMLTable( SwHTMLParser* pPars, HTMLTable *pTopTab,
sal_Bool bParHead, sal_Bool bHasParentSec,
sal_Bool bTopTbl, sal_Bool bHasToFly,
const HTMLTableOptions *pOptions );
~HTMLTable();
// Ermitteln einer Zelle
inline HTMLTableCell *GetCell( sal_uInt16 nRow, sal_uInt16 nCell ) const;
// Ueberschrift setzen/ermitteln
inline void SetCaption( const SwStartNode *pStNd, sal_Bool bTop );
const SwStartNode *GetCaptionStartNode() const { return pCaptionStartNode; }
sal_Bool IsTopCaption() const { return bTopCaption; }
SvxAdjust GetTableAdjust( sal_Bool bAny ) const
{
return (bTableAdjustOfTag || bAny) ? eTableAdjust : SVX_ADJUST_END;
}
sal_Int16 GetVertOri() const { return eVertOri; }
sal_uInt16 GetHSpace() const { return nHSpace; }
sal_uInt16 GetVSpace() const { return nVSpace; }
sal_Bool HasPrcWidth() const { return bPrcWidth; }
sal_uInt8 GetPrcWidth() const { return bPrcWidth ? (sal_uInt8)nWidth : 0; }
sal_uInt16 GetMinWidth() const
{
sal_uInt32 nMin = pLayoutInfo->GetMin();
return nMin < USHRT_MAX ? (sal_uInt16)nMin : USHRT_MAX;
}
// von Zeilen oder Spalten geerbtes drawing::Alignment holen
SvxAdjust GetInheritedAdjust() const;
sal_Int16 GetInheritedVertOri() const;
// Einfuegen einer Zelle an der aktuellen Position
void InsertCell( HTMLTableCnts *pCnts, sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
sal_uInt16 nWidth, sal_Bool bRelWidth, sal_uInt16 nHeight,
sal_Int16 eVertOri, SvxBrushItem *pBGBrush,
boost::shared_ptr<SvxBoxItem> const pBoxItem,
sal_Bool bHasNumFmt, sal_uInt32 nNumFmt,
sal_Bool bHasValue, double nValue, sal_Bool bNoWrap );
// Start/Ende einer neuen Zeile bekanntgeben
void OpenRow( SvxAdjust eAdjust, sal_Int16 eVertOri,
SvxBrushItem *pBGBrush );
void CloseRow( sal_Bool bEmpty );
// Ende einer neuen Section bekanntgeben
inline void CloseSection( sal_Bool bHead );
// Ende einer Spalten-Gruppe bekanntgeben
inline void CloseColGroup( sal_uInt16 nSpan, sal_uInt16 nWidth, sal_Bool bRelWidth,
SvxAdjust eAdjust, sal_Int16 eVertOri );
// Einfuegen einer Spalte
void InsertCol( sal_uInt16 nSpan, sal_uInt16 nWidth, sal_Bool bRelWidth,
SvxAdjust eAdjust, sal_Int16 eVertOri );
// Beenden einer Tab-Definition (MUSS fuer ALLE Tabs aufgerufen werden)
void CloseTable();
// SwTable konstruieren (inkl. der Child-Tabellen)
void MakeTable( SwTableBox *pUpper, sal_uInt16 nAbsAvail,
sal_uInt16 nRelAvail=0, sal_uInt16 nAbsLeftSpace=0,
sal_uInt16 nAbsRightSpace=0, sal_uInt16 nInhAbsSpace=0 );
inline sal_Bool IsNewDoc() const { return pParser->IsNewDoc(); }
void SetHasParentSection( sal_Bool bSet ) { bHasParentSection = bSet; }
sal_Bool HasParentSection() const { return bHasParentSection; }
void SetParentContents( HTMLTableCnts *pCnts ) { pParentContents = pCnts; }
HTMLTableCnts *GetParentContents() const { return pParentContents; }
void MakeParentContents();
sal_Bool GetIsParentHeader() const { return bIsParentHead; }
sal_Bool IsMakeTopSubTable() const { return bMakeTopSubTable; }
void SetHasToFly() { bHasToFly=sal_True; }
sal_Bool HasToFly() const { return bHasToFly; }
void SetTable( const SwStartNode *pStNd, _HTMLTableContext *pCntxt,
sal_uInt16 nLeft, sal_uInt16 nRight,
const SwTable *pSwTab=0, sal_Bool bFrcFrame=sal_False );
_HTMLTableContext *GetContext() const { return pContext; }
SwHTMLTableLayout *CreateLayoutInfo();
sal_Bool HasColTags() const { return bColSpec; }
sal_uInt16 IncGrfsThatResize() { return pSwTable ? ((SwTable *)pSwTable)->IncGrfsThatResize() : 0; }
void RegisterDrawObject( SdrObject *pObj, sal_uInt8 nPrcWidth );
const SwTable *GetSwTable() const { return pSwTable; }
void SetBGBrush( const SvxBrushItem& rBrush ) { delete pBGBrush; pBGBrush = new SvxBrushItem( rBrush ); }
const String& GetId() const { return aId; }
const String& GetClass() const { return aClass; }
const String& GetStyle() const { return aStyle; }
const String& GetDirection() const { return aDir; }
void IncBoxCount() { nBoxes++; }
sal_Bool IsOverflowing() const { return nBoxes > 64000; }
};
SV_IMPL_PTRARR(HTMLTableCells,HTMLTableCellPtr)
SV_IMPL_PTRARR(HTMLTableRows,HTMLTableRowPtr)
SV_IMPL_PTRARR(HTMLTableColumns,HTMLTableColumnPtr)
void HTMLTableCnts::InitCtor()
{
pNext = 0;
pLayoutInfo = 0;
bNoBreak = sal_False;
}
HTMLTableCnts::HTMLTableCnts( const SwStartNode* pStNd ):
pStartNode(pStNd), pTable(0)
{
InitCtor();
}
HTMLTableCnts::HTMLTableCnts( HTMLTable* pTab ):
pStartNode(0), pTable(pTab)
{
InitCtor();
}
HTMLTableCnts::~HTMLTableCnts()
{
delete pTable; // die Tabellen brauchen wir nicht mehr
delete pNext;
}
void HTMLTableCnts::Add( HTMLTableCnts* pNewCnts )
{
HTMLTableCnts *pCnts = this;
while( pCnts->pNext )
pCnts = pCnts->pNext;
pCnts->pNext = pNewCnts;
}
inline void HTMLTableCnts::SetTableBox( SwTableBox *pBox )
{
OSL_ENSURE( pLayoutInfo, "Da sit noch keine Layout-Info" );
if( pLayoutInfo )
pLayoutInfo->SetTableBox( pBox );
}
SwHTMLTableLayoutCnts *HTMLTableCnts::CreateLayoutInfo()
{
if( !pLayoutInfo )
{
SwHTMLTableLayoutCnts *pNextInfo = pNext ? pNext->CreateLayoutInfo() : 0;
SwHTMLTableLayout *pTableInfo = pTable ? pTable->CreateLayoutInfo() : 0;
pLayoutInfo = new SwHTMLTableLayoutCnts( pStartNode, pTableInfo,
bNoBreak, pNextInfo );
}
return pLayoutInfo;
}
HTMLTableCell::HTMLTableCell():
pContents(0),
pBGBrush(0),
nNumFmt(0),
nRowSpan(1),
nColSpan(1),
nWidth( 0 ),
nValue(0),
eVertOri( text::VertOrientation::NONE ),
bProtected(sal_False),
bRelWidth( sal_False ),
bHasNumFmt(sal_False),
bHasValue(sal_False),
bNoWrap(sal_False),
mbCovered(sal_False)
{}
HTMLTableCell::~HTMLTableCell()
{
// der Inhalt ist in mehrere Zellen eingetragen, darf aber nur einmal
// geloescht werden
if( 1==nRowSpan && 1==nColSpan )
{
delete pContents;
delete pBGBrush;
}
}
void HTMLTableCell::Set( HTMLTableCnts *pCnts, sal_uInt16 nRSpan, sal_uInt16 nCSpan,
sal_Int16 eVert, SvxBrushItem *pBrush,
::boost::shared_ptr<SvxBoxItem> const pBoxItem,
sal_Bool bHasNF, sal_uInt32 nNF, sal_Bool bHasV, double nVal,
sal_Bool bNWrap, sal_Bool bCovered )
{
pContents = pCnts;
nRowSpan = nRSpan;
nColSpan = nCSpan;
bProtected = sal_False;
eVertOri = eVert;
pBGBrush = pBrush;
m_pBoxItem = pBoxItem;
bHasNumFmt = bHasNF;
bHasValue = bHasV;
nNumFmt = nNF;
nValue = nVal;
bNoWrap = bNWrap;
mbCovered = bCovered;
}
inline void HTMLTableCell::SetWidth( sal_uInt16 nWdth, sal_Bool bRelWdth )
{
nWidth = nWdth;
bRelWidth = bRelWdth;
}
void HTMLTableCell::SetProtected()
{
// Die Inhalte dieser Zelle mussen nich irgenwo anders verankert
// sein, weil sie nicht geloescht werden!!!
// Inhalt loeschen
pContents = 0;
// Hintergrundfarbe kopieren.
if( pBGBrush )
pBGBrush = new SvxBrushItem( *pBGBrush );
nRowSpan = 1;
nColSpan = 1;
bProtected = sal_True;
}
inline sal_Bool HTMLTableCell::GetNumFmt( sal_uInt32& rNumFmt ) const
{
rNumFmt = nNumFmt;
return bHasNumFmt;
}
inline sal_Bool HTMLTableCell::GetValue( double& rValue ) const
{
rValue = nValue;
return bHasValue;
}
SwHTMLTableLayoutCell *HTMLTableCell::CreateLayoutInfo()
{
SwHTMLTableLayoutCnts *pCntInfo = pContents ? pContents->CreateLayoutInfo() : 0;
return new SwHTMLTableLayoutCell( pCntInfo, nRowSpan, nColSpan, nWidth,
bRelWidth, bNoWrap );
}
HTMLTableRow::HTMLTableRow( sal_uInt16 nCells ):
pCells(new HTMLTableCells),
bIsEndOfGroup(sal_False),
bSplitable( sal_False ),
nHeight(0),
nEmptyRows(0),
eAdjust(SVX_ADJUST_END),
eVertOri(text::VertOrientation::TOP),
pBGBrush(0),
bBottomBorder(sal_False)
{
for( sal_uInt16 i=0; i<nCells; i++ )
{
pCells->Insert( new HTMLTableCell, pCells->Count() );
}
OSL_ENSURE( nCells==pCells->Count(),
"Zellenzahl in neuer HTML-Tabellenzeile stimmt nicht" );
}
HTMLTableRow::~HTMLTableRow()
{
delete pCells;
delete pBGBrush;
}
inline void HTMLTableRow::SetHeight( sal_uInt16 nHght )
{
if( nHght > nHeight )
nHeight = nHght;
}
inline HTMLTableCell *HTMLTableRow::GetCell( sal_uInt16 nCell ) const
{
OSL_ENSURE( nCell<pCells->Count(),
"ungueltiger Zellen-Index in HTML-Tabellenzeile" );
return (*pCells)[nCell];
}
void HTMLTableRow::Expand( sal_uInt16 nCells, sal_Bool bOneCell )
{
// die Zeile wird mit einer einzigen Zelle aufgefuellt, wenn
// bOneCell gesetzt ist. Das geht, nur fuer Zeilen, in die keine
// Zellen mehr eingefuegt werden!
sal_uInt16 nColSpan = nCells-pCells->Count();
for( sal_uInt16 i=pCells->Count(); i<nCells; i++ )
{
HTMLTableCell *pCell = new HTMLTableCell;
if( bOneCell )
pCell->SetColSpan( nColSpan );
pCells->Insert( pCell, pCells->Count() );
nColSpan--;
}
OSL_ENSURE( nCells==pCells->Count(),
"Zellenzahl in expandierter HTML-Tabellenzeile stimmt nicht" );
}
void HTMLTableRow::Shrink( sal_uInt16 nCells )
{
OSL_ENSURE( nCells < pCells->Count(), "Anzahl Zellen falsch" );
#if OSL_DEBUG_LEVEL > 0
sal_uInt16 nEnd = pCells->Count();
#endif
// The colspan of empty cells at the end has to be fixed to the new
// number of cells.
sal_uInt16 i=nCells;
while( i )
{
HTMLTableCell *pCell = (*pCells)[--i];
if( !pCell->GetContents() )
{
#if OSL_DEBUG_LEVEL > 0
OSL_ENSURE( pCell->GetColSpan() == nEnd - i,
"invalid col span for empty cell at row end" );
#endif
pCell->SetColSpan( nCells-i);
}
else
break;
}
#if OSL_DEBUG_LEVEL > 0
for( i=nCells; i<nEnd; i++ )
{
HTMLTableCell *pCell = (*pCells)[i];
OSL_ENSURE( pCell->GetRowSpan() == 1,
"RowSpan von zu loesender Zelle ist falsch" );
OSL_ENSURE( pCell->GetColSpan() == nEnd - i,
"ColSpan von zu loesender Zelle ist falsch" );
OSL_ENSURE( !pCell->GetContents(), "Zu loeschende Zelle hat Inhalt" );
}
#endif
pCells->DeleteAndDestroy( nCells, pCells->Count()-nCells );
}
HTMLTableColumn::HTMLTableColumn():
bIsEndOfGroup(sal_False),
nWidth(0), bRelWidth(sal_False),
eAdjust(SVX_ADJUST_END), eVertOri(text::VertOrientation::TOP),
bLeftBorder(sal_False)
{
for( sal_uInt16 i=0; i<6; i++ )
aFrmFmts[i] = 0;
}
inline void HTMLTableColumn::SetWidth( sal_uInt16 nWdth, sal_Bool bRelWdth )
{
if( bRelWidth==bRelWdth )
{
if( nWdth > nWidth )
nWidth = nWdth;
}
else
nWidth = nWdth;
bRelWidth = bRelWdth;
}
inline SwHTMLTableLayoutColumn *HTMLTableColumn::CreateLayoutInfo()
{
return new SwHTMLTableLayoutColumn( nWidth, bRelWidth, bLeftBorder );
}
inline sal_uInt16 HTMLTableColumn::GetFrmFmtIdx( sal_Bool bBorderLine,
sal_Int16 eVertOrient ) const
{
OSL_ENSURE( text::VertOrientation::TOP != eVertOrient, "Top ist nicht erlaubt" );
sal_uInt16 n = bBorderLine ? 3 : 0;
switch( eVertOrient )
{
case text::VertOrientation::CENTER: n+=1; break;
case text::VertOrientation::BOTTOM: n+=2; break;
default:
;
}
return n;
}
inline void HTMLTableColumn::SetFrmFmt( SwFrmFmt *pFmt, sal_Bool bBorderLine,
sal_Int16 eVertOrient )
{
aFrmFmts[GetFrmFmtIdx(bBorderLine,eVertOrient)] = pFmt;
}
inline SwFrmFmt *HTMLTableColumn::GetFrmFmt( sal_Bool bBorderLine,
sal_Int16 eVertOrient ) const
{
return aFrmFmts[GetFrmFmtIdx(bBorderLine,eVertOrient)];
}
void HTMLTable::InitCtor( const HTMLTableOptions *pOptions )
{
pResizeDrawObjs = 0;
pDrawObjPrcWidths = 0;
pRows = new HTMLTableRows;
pColumns = new HTMLTableColumns;
nRows = 0;
nCurRow = 0; nCurCol = 0;
pBox1 = 0;
pBoxFmt = 0; pLineFmt = 0;
pLineFrmFmtNoHeight = 0;
pInhBGBrush = 0;
pPrevStNd = 0;
pSwTable = 0;
bTopBorder = sal_False; bRightBorder = sal_False;
bTopAlwd = sal_True; bRightAlwd = sal_True;
bFillerTopBorder = sal_False; bFillerBottomBorder = sal_False;
bInhLeftBorder = sal_False; bInhRightBorder = sal_False;
bBordersSet = sal_False;
bForceFrame = sal_False;
nHeadlineRepeat = 0;
nLeftMargin = 0;
nRightMargin = 0;
const Color& rBorderColor = pOptions->aBorderColor;
long nBorderOpt = (long)pOptions->nBorder;
long nPWidth = nBorderOpt==USHRT_MAX ? NETSCAPE_DFLT_BORDER
: nBorderOpt;
long nPHeight = nBorderOpt==USHRT_MAX ? 0 : nBorderOpt;
SvxCSS1Parser::PixelToTwip( nPWidth, nPHeight );
// nBorder gibt die Breite der Umrandung an, wie sie in die
// Breitenberechnung in Netscape einfliesst. Wenn pOption->nBorder
// == USHRT_MAX, wurde keine BORDER-Option angegeben. Trotzdem fliesst
// eine 1 Pixel breite Umrandung in die Breitenberechnung mit ein.
nBorder = (sal_uInt16)nPWidth;
if( nBorderOpt==USHRT_MAX )
nPWidth = 0;
// HACK: ein Pixel-breite Linien sollen zur Haarlinie werden, wenn
// wir mit doppelter Umrandung arbeiten
if( pOptions->nCellSpacing!=0 && nBorderOpt==1 )
{
nPWidth = 1;
nPHeight = 1;
}
if ( pOptions->nCellSpacing != 0 )
aTopBorderLine.SetStyle( ::editeng::DOUBLE );
aTopBorderLine.SetWidth( nPHeight );
aTopBorderLine.SetColor( rBorderColor );
aBottomBorderLine = aTopBorderLine;
if( nPWidth == nPHeight )
{
aLeftBorderLine = aTopBorderLine;
}
else
{
if ( pOptions->nCellSpacing != 0 )
aLeftBorderLine.SetStyle( ::editeng::DOUBLE );
aLeftBorderLine.SetWidth( nPWidth );
aLeftBorderLine.SetColor( rBorderColor );
}
aRightBorderLine = aLeftBorderLine;
if( pOptions->nCellSpacing != 0 )
{
aBorderLine.SetStyle( ::editeng::DOUBLE );
aBorderLine.SetWidth( DEF_LINE_WIDTH_0 );
}
else
{
aBorderLine.SetWidth( DEF_LINE_WIDTH_0 );
}
aBorderLine.SetColor( rBorderColor );
if( nCellPadding )
{
if( nCellPadding==USHRT_MAX )
nCellPadding = MIN_BORDER_DIST; // default
else
{
nCellPadding = pParser->ToTwips( nCellPadding );
if( nCellPadding<MIN_BORDER_DIST )
nCellPadding = MIN_BORDER_DIST;
}
}
if( nCellSpacing )
{
if( nCellSpacing==USHRT_MAX )
nCellSpacing = NETSCAPE_DFLT_CELLSPACING;
nCellSpacing = pParser->ToTwips( nCellSpacing );
}
nPWidth = pOptions->nHSpace;
nPHeight = pOptions->nVSpace;
SvxCSS1Parser::PixelToTwip( nPWidth, nPHeight );
nHSpace = (sal_uInt16)nPWidth;
nVSpace = (sal_uInt16)nPHeight;
bColSpec = sal_False;
pBGBrush = pParser->CreateBrushItem(
pOptions->bBGColor ? &(pOptions->aBGColor) : 0,
pOptions->aBGImage, aEmptyStr, aEmptyStr, aEmptyStr );
pContext = 0;
pParentContents = 0;
aId = pOptions->aId;
aClass = pOptions->aClass;
aStyle = pOptions->aStyle;
aDir = pOptions->aDir;
}
HTMLTable::HTMLTable( SwHTMLParser* pPars, HTMLTable *pTopTab,
sal_Bool bParHead,
sal_Bool bHasParentSec, sal_Bool bTopTbl, sal_Bool bHasToFlw,
const HTMLTableOptions *pOptions ) :
nCols( pOptions->nCols ),
nFilledCols( 0 ),
nCellPadding( pOptions->nCellPadding ),
nCellSpacing( pOptions->nCellSpacing ),
nBoxes( 1 ),
pCaptionStartNode( 0 ),
bTableAdjustOfTag( pTopTab ? sal_False : pOptions->bTableAdjust ),
bIsParentHead( bParHead ),
bHasParentSection( bHasParentSec ),
bMakeTopSubTable( bTopTbl ),
bHasToFly( bHasToFlw ),
bFixedCols( pOptions->nCols>0 ),
bPrcWidth( pOptions->bPrcWidth ),
pParser( pPars ),
pTopTable( pTopTab ? pTopTab : this ),
pLayoutInfo( 0 ),
nWidth( pOptions->nWidth ),
nHeight( pTopTab ? 0 : pOptions->nHeight ),
eTableAdjust( pOptions->eAdjust ),
eVertOri( pOptions->eVertOri ),
eFrame( pOptions->eFrame ),
eRules( pOptions->eRules ),
bTopCaption( sal_False ),
bFirstCell( !pTopTab )
{
InitCtor( pOptions );
for( sal_uInt16 i=0; i<nCols; i++ )
pColumns->Insert( new HTMLTableColumn, pColumns->Count() );
}
HTMLTable::~HTMLTable()
{
delete pResizeDrawObjs;
delete pDrawObjPrcWidths;
delete pRows;
delete pColumns;
delete pBGBrush;
delete pInhBGBrush;
delete pContext;
// pLayoutInfo wurde entweder bereits geloescht oder muss aber es
// in den Besitz der SwTable uebergegangen.
}
SwHTMLTableLayout *HTMLTable::CreateLayoutInfo()
{
sal_uInt16 nW = bPrcWidth ? nWidth : pParser->ToTwips( nWidth );
sal_uInt16 nBorderWidth = GetBorderWidth( aBorderLine, sal_True );
sal_uInt16 nLeftBorderWidth =
((*pColumns)[0])->bLeftBorder ? GetBorderWidth( aLeftBorderLine, sal_True ) : 0;
sal_uInt16 nRightBorderWidth =
bRightBorder ? GetBorderWidth( aRightBorderLine, sal_True ) : 0;
sal_uInt16 nInhLeftBorderWidth = 0;
sal_uInt16 nInhRightBorderWidth = 0;
pLayoutInfo = new SwHTMLTableLayout(
pSwTable,
nRows, nCols, bFixedCols, bColSpec,
nW, bPrcWidth, nBorder, nCellPadding,
nCellSpacing, eTableAdjust,
nLeftMargin, nRightMargin,
nBorderWidth, nLeftBorderWidth, nRightBorderWidth,
nInhLeftBorderWidth, nInhRightBorderWidth );
sal_Bool bExportable = sal_True;
sal_uInt16 i;
for( i=0; i<nRows; i++ )
{
HTMLTableRow *pRow = (*pRows)[i];
for( sal_uInt16 j=0; j<nCols; j++ )
{
SwHTMLTableLayoutCell *pLayoutCell =
pRow->GetCell(j)->CreateLayoutInfo();
pLayoutInfo->SetCell( pLayoutCell, i, j );
if( bExportable )
{
SwHTMLTableLayoutCnts *pLayoutCnts =
pLayoutCell->GetContents();
bExportable = !pLayoutCnts ||
( pLayoutCnts->GetStartNode() &&
!pLayoutCnts->GetNext() );
}
}
}
pLayoutInfo->SetExportable( bExportable );
for( i=0; i<nCols; i++ )
pLayoutInfo->SetColumn( ((*pColumns)[i])->CreateLayoutInfo(), i );
return pLayoutInfo;
}
inline void HTMLTable::SetCaption( const SwStartNode *pStNd, sal_Bool bTop )
{
pCaptionStartNode = pStNd;
bTopCaption = bTop;
}
void HTMLTable::FixRowSpan( sal_uInt16 nRow, sal_uInt16 nCol,
const HTMLTableCnts *pCnts )
{
sal_uInt16 nRowSpan=1;
HTMLTableCell *pCell;
while( ( pCell=GetCell(nRow,nCol), pCell->GetContents()==pCnts ) )
{
pCell->SetRowSpan( nRowSpan );
if( pLayoutInfo )
pLayoutInfo->GetCell(nRow,nCol)->SetRowSpan( nRowSpan );
if( !nRow ) break;
nRowSpan++; nRow--;
}
}
void HTMLTable::ProtectRowSpan( sal_uInt16 nRow, sal_uInt16 nCol, sal_uInt16 nRowSpan )
{
for( sal_uInt16 i=0; i<nRowSpan; i++ )
{
GetCell(nRow+i,nCol)->SetProtected();
if( pLayoutInfo )
pLayoutInfo->GetCell(nRow+i,nCol)->SetProtected();
}
}
// Suchen des SwStartNodes der letzten belegten Vorgaengerbox
const SwStartNode* HTMLTable::GetPrevBoxStartNode( sal_uInt16 nRow, sal_uInt16 nCol ) const
{
const HTMLTableCnts *pPrevCnts = 0;
if( 0==nRow )
{
// immer die Vorgaenger-Zelle
if( nCol>0 )
pPrevCnts = GetCell( 0, nCol-1 )->GetContents();
else
return pPrevStNd;
}
else if( USHRT_MAX==nRow && USHRT_MAX==nCol )
// der Contents der letzten Zelle
pPrevCnts = GetCell( nRows-1, nCols-1 )->GetContents();
else
{
sal_uInt16 i;
HTMLTableRow *pPrevRow = (*pRows)[nRow-1];
// evtl. eine Zelle in der aktuellen Zeile
i = nCol;
while( i )
{
i--;
if( 1 == pPrevRow->GetCell(i)->GetRowSpan() )
{
pPrevCnts = GetCell(nRow,i)->GetContents();
break;
}
}
// sonst die letzte gefuellte Zelle der Zeile davor suchen
if( !pPrevCnts )
{
i = nCols;
while( !pPrevCnts && i )
{
i--;
pPrevCnts = pPrevRow->GetCell(i)->GetContents();
}
}
}
OSL_ENSURE( pPrevCnts, "keine gefuellte Vorgaenger-Zelle gefunden" );
if( !pPrevCnts )
{
pPrevCnts = GetCell(0,0)->GetContents();
if( !pPrevCnts )
return pPrevStNd;
}
while( pPrevCnts->Next() )
pPrevCnts = pPrevCnts->Next();
return ( pPrevCnts->GetStartNode() ? pPrevCnts->GetStartNode()
: pPrevCnts->GetTable()->GetPrevBoxStartNode( USHRT_MAX, USHRT_MAX ) );
}
static sal_Bool IsBoxEmpty( const SwTableBox *pBox )
{
const SwStartNode *pSttNd = pBox->GetSttNd();
if( pSttNd &&
pSttNd->GetIndex() + 2 == pSttNd->EndOfSectionIndex() )
{
const SwCntntNode *pCNd =
pSttNd->GetNodes()[pSttNd->GetIndex()+1]->GetCntntNode();
if( pCNd && !pCNd->Len() )
return sal_True;
}
return sal_False;
}
sal_uInt16 HTMLTable::GetTopCellSpace( sal_uInt16 nRow, sal_uInt16 nRowSpan,
sal_Bool bSwBorders ) const
{
sal_uInt16 nSpace = nCellPadding;
if( nRow == 0 )
{
nSpace += nBorder + nCellSpacing;
if( bSwBorders )
{
sal_uInt16 nTopBorderWidth =
GetBorderWidth( aTopBorderLine, sal_True );
if( nSpace < nTopBorderWidth )
nSpace = nTopBorderWidth;
}
}
else if( bSwBorders && ((*pRows)[nRow+nRowSpan-1])->bBottomBorder &&
nSpace < MIN_BORDER_DIST )
{
OSL_ENSURE( !nCellPadding, "GetTopCellSpace: CELLPADDING!=0" );
// Wenn die Gegenueberliegende Seite umrandet ist muessen
// wir zumindest den minimalen Abstand zum Inhalt
// beruecksichtigen. (Koennte man zusaetzlich auch an
// nCellPadding festmachen.)
nSpace = MIN_BORDER_DIST;
}
return nSpace;
}
sal_uInt16 HTMLTable::GetBottomCellSpace( sal_uInt16 nRow, sal_uInt16 nRowSpan,
sal_Bool bSwBorders ) const
{
sal_uInt16 nSpace = nCellSpacing + nCellPadding;
if( nRow+nRowSpan == nRows )
{
nSpace = nSpace + nBorder;
if( bSwBorders )
{
sal_uInt16 nBottomBorderWidth =
GetBorderWidth( aBottomBorderLine, sal_True );
if( nSpace < nBottomBorderWidth )
nSpace = nBottomBorderWidth;
}
}
else if( bSwBorders )
{
if( ((*pRows)[nRow+nRowSpan+1])->bBottomBorder )
{
sal_uInt16 nBorderWidth = GetBorderWidth( aBorderLine, sal_True );
if( nSpace < nBorderWidth )
nSpace = nBorderWidth;
}
else if( nRow==0 && bTopBorder && nSpace < MIN_BORDER_DIST )
{
OSL_ENSURE( GetBorderWidth( aTopBorderLine, sal_True ) > 0,
"GetBottomCellSpace: |aTopLine| == 0" );
OSL_ENSURE( !nCellPadding, "GetBottomCellSpace: CELLPADDING!=0" );
// Wenn die Gegenueberliegende Seite umrandet ist muessen
// wir zumindest den minimalen Abstand zum Inhalt
// beruecksichtigen. (Koennte man zusaetzlich auch an
// nCellPadding festmachen.)
nSpace = MIN_BORDER_DIST;
}
}
return nSpace;
}
void HTMLTable::FixFrameFmt( SwTableBox *pBox,
sal_uInt16 nRow, sal_uInt16 nCol,
sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
sal_Bool bFirstPara, sal_Bool bLastPara ) const
{
SwFrmFmt *pFrmFmt = 0; // frame::Frame-Format
sal_Int16 eVOri = text::VertOrientation::NONE;
const SvxBrushItem *pBGBrushItem = 0; // Hintergrund
boost::shared_ptr<SvxBoxItem> pBoxItem;
sal_Bool bTopLine = sal_False, bBottomLine = sal_False, bLastBottomLine = sal_False;
sal_Bool bReUsable = sal_False; // Format nochmals verwendbar?
sal_uInt16 nEmptyRows = 0;
sal_Bool bHasNumFmt = sal_False;
sal_Bool bHasValue = sal_False;
sal_uInt32 nNumFmt = 0;
double nValue = 0.0;
HTMLTableColumn *pColumn = (*pColumns)[nCol];
if( pBox->GetSttNd() )
{
// die Hintergrundfarbe/-grafik bestimmen
const HTMLTableCell *pCell = GetCell( nRow, nCol );
pBoxItem = pCell->GetBoxItem();
pBGBrushItem = pCell->GetBGBrush();
if( !pBGBrushItem )
{
// Wenn die Zelle ueber mehrere Zeilen geht muss ein evtl.
// an der Zeile gesetzter Hintergrund an die Zelle uebernommen
// werden.
#ifndef FIX56334
// Wenn es sich um eine Tabelle in der Tabelle handelt und
// die Zelle ueber die gesamte Heoehe der Tabelle geht muss
// ebenfalls der Hintergrund der Zeile uebernommen werden, weil
// die Line von der GC (zu Recht) wegoptimiert wird.
if( nRowSpan > 1 || (this != pTopTable && nRowSpan==nRows) )
#else
if( nRowSpan > 1 )
#endif
{
pBGBrushItem = ((*pRows)[nRow])->GetBGBrush();
if( !pBGBrushItem && this != pTopTable )
{
pBGBrushItem = GetBGBrush();
if( !pBGBrushItem )
pBGBrushItem = GetInhBGBrush();
}
}
}
bTopLine = 0==nRow && bTopBorder && bFirstPara;
if( ((*pRows)[nRow+nRowSpan-1])->bBottomBorder && bLastPara )
{
nEmptyRows = ((*pRows)[nRow+nRowSpan-1])->GetEmptyRows();
if( nRow+nRowSpan == nRows )
bLastBottomLine = sal_True;
else
bBottomLine = sal_True;
}
eVOri = pCell->GetVertOri();
bHasNumFmt = pCell->GetNumFmt( nNumFmt );
if( bHasNumFmt )
bHasValue = pCell->GetValue( nValue );
if( nColSpan==1 && !bTopLine && !bLastBottomLine && !nEmptyRows &&
!pBGBrushItem && !bHasNumFmt && !pBoxItem)
{
pFrmFmt = pColumn->GetFrmFmt( bBottomLine, eVOri );
bReUsable = !pFrmFmt;
}
}
if( !pFrmFmt )
{
pFrmFmt = pBox->ClaimFrmFmt();
// die Breite der Box berechnen
SwTwips nFrmWidth = (SwTwips)pLayoutInfo->GetColumn(nCol)
->GetRelColWidth();
for( sal_uInt16 i=1; i<nColSpan; i++ )
nFrmWidth += (SwTwips)pLayoutInfo->GetColumn(nCol+i)
->GetRelColWidth();
// die Umrandung nur an Edit-Boxen setzen (bei der oberen und unteren
// Umrandung muss beruecks. werden, ob es sich um den ersten oder
// letzen Absatz der Zelle handelt)
if( pBox->GetSttNd() )
{
sal_Bool bSet = (nCellPadding > 0);
SvxBoxItem aBoxItem( RES_BOX );
long nInnerFrmWidth = nFrmWidth;
if( bTopLine )
{
aBoxItem.SetLine( &aTopBorderLine, BOX_LINE_TOP );
bSet = sal_True;
}
if( bLastBottomLine )
{
aBoxItem.SetLine( &aBottomBorderLine, BOX_LINE_BOTTOM );
bSet = sal_True;
}
else if( bBottomLine )
{
if( nEmptyRows && !aBorderLine.GetInWidth() )
{
// Leere Zeilen koennen zur Zeit nur dann ueber
// dicke Linien simuliert werden, wenn die Linie
// einfach ist.
SvxBorderLine aThickBorderLine( aBorderLine );
sal_uInt16 nBorderWidth = aBorderLine.GetOutWidth();
nBorderWidth *= (nEmptyRows + 1);
aThickBorderLine.SetStyle( ::editeng::SOLID );
aThickBorderLine.SetWidth( nBorderWidth );
aBoxItem.SetLine( &aThickBorderLine, BOX_LINE_BOTTOM );
}
else
{
aBoxItem.SetLine( &aBorderLine, BOX_LINE_BOTTOM );
}
bSet = sal_True;
}
if( ((*pColumns)[nCol])->bLeftBorder )
{
const SvxBorderLine& rBorderLine =
0==nCol ? aLeftBorderLine : aBorderLine;
aBoxItem.SetLine( &rBorderLine, BOX_LINE_LEFT );
nInnerFrmWidth -= GetBorderWidth( rBorderLine );
bSet = sal_True;
}
if( nCol+nColSpan == nCols && bRightBorder )
{
aBoxItem.SetLine( &aRightBorderLine, BOX_LINE_RIGHT );
nInnerFrmWidth -= GetBorderWidth( aRightBorderLine );
bSet = sal_True;
}
if (pBoxItem)
{
pFrmFmt->SetFmtAttr( *pBoxItem );
}
else if (bSet)
{
// BorderDist nicht mehr Bestandteil einer Zelle mit fixer Breite
sal_uInt16 nBDist = static_cast< sal_uInt16 >(
(2*nCellPadding <= nInnerFrmWidth) ? nCellPadding
: (nInnerFrmWidth / 2) );
// wir setzen das Item nur, wenn es eine Umrandung gibt
// oder eine sheet::Border-Distanz vorgegeben ist. Fehlt letztere,
// dann gibt es eine Umrandung, und wir muessen die Distanz
// setzen
aBoxItem.SetDistance( nBDist ? nBDist : MIN_BORDER_DIST );
pFrmFmt->SetFmtAttr( aBoxItem );
}
else
pFrmFmt->ResetFmtAttr( RES_BOX );
if( pBGBrushItem )
{
pFrmFmt->SetFmtAttr( *pBGBrushItem );
}
else
pFrmFmt->ResetFmtAttr( RES_BACKGROUND );
// Format nur setzten, wenn es auch einen Value gibt oder die Box leer ist.
if( bHasNumFmt && (bHasValue || IsBoxEmpty(pBox)) )
{
sal_Bool bLock = pFrmFmt->GetDoc()->GetNumberFormatter()
->IsTextFormat( nNumFmt );
SfxItemSet aItemSet( *pFrmFmt->GetAttrSet().GetPool(),
RES_BOXATR_FORMAT, RES_BOXATR_VALUE );
SvxAdjust eAdjust = SVX_ADJUST_END;
SwCntntNode *pCNd = 0;
if( !bLock )
{
const SwStartNode *pSttNd = pBox->GetSttNd();
pCNd = pSttNd->GetNodes()[pSttNd->GetIndex()+1]
->GetCntntNode();
const SfxPoolItem *pItem;
if( pCNd && pCNd->HasSwAttrSet() &&
SFX_ITEM_SET==pCNd->GetpSwAttrSet()->GetItemState(
RES_PARATR_ADJUST, sal_False, &pItem ) )
{
eAdjust = ((const SvxAdjustItem *)pItem)
->GetAdjust();
}
}
aItemSet.Put( SwTblBoxNumFormat(nNumFmt) );
if( bHasValue )
aItemSet.Put( SwTblBoxValue(nValue) );
if( bLock )
pFrmFmt->LockModify();
pFrmFmt->SetFmtAttr( aItemSet );
if( bLock )
pFrmFmt->UnlockModify();
else if( pCNd && SVX_ADJUST_END != eAdjust )
{
SvxAdjustItem aAdjItem( eAdjust, RES_PARATR_ADJUST );
pCNd->SetAttr( aAdjItem );
}
}
else
pFrmFmt->ResetFmtAttr( RES_BOXATR_FORMAT );
OSL_ENSURE( eVOri != text::VertOrientation::TOP, "text::VertOrientation::TOP ist nicht erlaubt!" );
if( text::VertOrientation::NONE != eVOri )
{
pFrmFmt->SetFmtAttr( SwFmtVertOrient( 0, eVOri ) );
}
else
pFrmFmt->ResetFmtAttr( RES_VERT_ORIENT );
if( bReUsable )
pColumn->SetFrmFmt( pFrmFmt, bBottomLine, eVOri );
}
else
{
pFrmFmt->ResetFmtAttr( RES_BOX );
pFrmFmt->ResetFmtAttr( RES_BACKGROUND );
pFrmFmt->ResetFmtAttr( RES_VERT_ORIENT );
pFrmFmt->ResetFmtAttr( RES_BOXATR_FORMAT );
}
}
else
{
OSL_ENSURE( pBox->GetSttNd() ||
SFX_ITEM_SET!=pFrmFmt->GetAttrSet().GetItemState(
RES_VERT_ORIENT, sal_False ),
"Box ohne Inhalt hat vertikale Ausrichtung" );
pBox->ChgFrmFmt( (SwTableBoxFmt*)pFrmFmt );
}
}
void HTMLTable::FixFillerFrameFmt( SwTableBox *pBox, sal_Bool bRight ) const
{
SwFrmFmt *pFrmFmt = pBox->ClaimFrmFmt();
if( bFillerTopBorder || bFillerBottomBorder ||
(!bRight && bInhLeftBorder) || (bRight && bInhRightBorder) )
{
SvxBoxItem aBoxItem( RES_BOX );
if( bFillerTopBorder )
aBoxItem.SetLine( &aTopBorderLine, BOX_LINE_TOP );
if( bFillerBottomBorder )
aBoxItem.SetLine( &aBottomBorderLine, BOX_LINE_BOTTOM );
if( !bRight && bInhLeftBorder )
aBoxItem.SetLine( &aInhLeftBorderLine, BOX_LINE_LEFT );
if( bRight && bInhRightBorder )
aBoxItem.SetLine( &aInhRightBorderLine, BOX_LINE_RIGHT );
aBoxItem.SetDistance( MIN_BORDER_DIST );
pFrmFmt->SetFmtAttr( aBoxItem );
}
else
{
pFrmFmt->ResetFmtAttr( RES_BOX );
}
if( GetInhBGBrush() )
pFrmFmt->SetFmtAttr( *GetInhBGBrush() );
else
pFrmFmt->ResetFmtAttr( RES_BACKGROUND );
pFrmFmt->ResetFmtAttr( RES_VERT_ORIENT );
pFrmFmt->ResetFmtAttr( RES_BOXATR_FORMAT );
}
SwTableBox *HTMLTable::NewTableBox( const SwStartNode *pStNd,
SwTableLine *pUpper ) const
{
SwTableBox *pBox;
if( pTopTable->pBox1 &&
pTopTable->pBox1->GetSttNd() == pStNd )
{
// wenn der StartNode dem StartNode der initial angelegten Box
// entspricht nehmen wir diese Box
pBox = pTopTable->pBox1;
pBox->SetUpper( pUpper );
pTopTable->pBox1 = 0;
}
else
pBox = new SwTableBox( pBoxFmt, *pStNd, pUpper );
return pBox;
}
static void ResetLineFrmFmtAttrs( SwFrmFmt *pFrmFmt )
{
pFrmFmt->ResetFmtAttr( RES_FRM_SIZE );
pFrmFmt->ResetFmtAttr( RES_BACKGROUND );
OSL_ENSURE( SFX_ITEM_SET!=pFrmFmt->GetAttrSet().GetItemState(
RES_VERT_ORIENT, sal_False ),
"Zeile hat vertikale Ausrichtung" );
}
// !!! kann noch vereinfacht werden
SwTableLine *HTMLTable::MakeTableLine( SwTableBox *pUpper,
sal_uInt16 nTopRow, sal_uInt16 nLeftCol,
sal_uInt16 nBottomRow, sal_uInt16 nRightCol )
{
SwTableLine *pLine;
if( this==pTopTable && !pUpper && 0==nTopRow )
pLine = (pSwTable->GetTabLines())[0];
else
pLine = new SwTableLine( pLineFrmFmtNoHeight ? pLineFrmFmtNoHeight
: pLineFmt,
0, pUpper );
HTMLTableRow *pTopRow = (*pRows)[nTopRow];
sal_uInt16 nRowHeight = pTopRow->GetHeight();
const SvxBrushItem *pBGBrushItem = 0;
#ifndef FIX56334
if( this == pTopTable || nTopRow>0 || nBottomRow<nRows )
{
// An der Line eine Frabe zu setzen macht keinen Sinn, wenn sie
// die auesserste und gleichzeitig einzige Zeile einer Tabelle in
// der Tabelle ist.
#endif
pBGBrushItem = pTopRow->GetBGBrush();
if( !pBGBrushItem && this != pTopTable )
{
// Ein an einer Tabellen in der Tabelle gesetzter Hintergrund
// wird an den Rows gesetzt. Das gilt auch fuer den Hintergrund
// der Zelle, in dem die Tabelle vorkommt.
pBGBrushItem = GetBGBrush();
if( !pBGBrushItem )
pBGBrushItem = GetInhBGBrush();
}
#ifndef FIX56334
}
#endif
if( nTopRow==nBottomRow-1 && (nRowHeight || pBGBrushItem) )
{
SwTableLineFmt *pFrmFmt = (SwTableLineFmt*)pLine->ClaimFrmFmt();
ResetLineFrmFmtAttrs( pFrmFmt );
if( nRowHeight )
{
// Tabellenhoehe einstellen. Da es sich um eine
// Mindesthoehe handelt, kann sie genauso wie in
// Netscape berechnet werden, also ohne Beruecksichtigung
// der tatsaechlichen Umrandungsbreite.
nRowHeight += GetTopCellSpace( nTopRow, 1, sal_False ) +
GetBottomCellSpace( nTopRow, 1, sal_False );
pFrmFmt->SetFmtAttr( SwFmtFrmSize( ATT_MIN_SIZE, 0, nRowHeight ) );
}
if( pBGBrushItem )
{
pFrmFmt->SetFmtAttr( *pBGBrushItem );
}
}
else if( !pLineFrmFmtNoHeight )
{
// sonst muessen wir die Hoehe aus dem Attribut entfernen
// und koennen uns das Format merken
pLineFrmFmtNoHeight = (SwTableLineFmt*)pLine->ClaimFrmFmt();
ResetLineFrmFmtAttrs( pLineFrmFmtNoHeight );
}
SwTableBoxes& rBoxes = pLine->GetTabBoxes();
sal_uInt16 nStartCol = nLeftCol;
while( nStartCol<nRightCol )
{
sal_uInt16 nCol = nStartCol;
sal_uInt16 nSplitCol = nRightCol;
sal_Bool bSplitted = sal_False;
while( !bSplitted )
{
OSL_ENSURE( nCol < nRightCol, "Zu weit gelaufen" );
HTMLTableCell *pCell = GetCell(nTopRow,nCol);
const sal_Bool bSplit = 1 == pCell->GetColSpan();
OSL_ENSURE((nCol != nRightCol-1) || bSplit, "Split-Flag wrong");
if( bSplit )
{
SwTableBox* pBox = 0;
HTMLTableCell *pCell2 = GetCell( nTopRow, nStartCol );
if( pCell2->GetColSpan() == (nCol+1-nStartCol) )
{
// Die HTML-Tabellen-Zellen bilden genau eine Box.
// Dann muss hinter der Box gesplittet werden
nSplitCol = nCol + 1;
long nBoxRowSpan = pCell2->GetRowSpan();
if ( !pCell2->GetContents() || pCell2->IsCovered() )
{
if ( pCell2->IsCovered() )
nBoxRowSpan = -1 * nBoxRowSpan;
const SwStartNode* pPrevStartNd =
GetPrevBoxStartNode( nTopRow, nStartCol );
HTMLTableCnts *pCnts = new HTMLTableCnts(
pParser->InsertTableSection(pPrevStartNd) );
SwHTMLTableLayoutCnts *pCntsLayoutInfo =
pCnts->CreateLayoutInfo();
pCell2->SetContents( pCnts );
SwHTMLTableLayoutCell *pCurrCell = pLayoutInfo->GetCell( nTopRow, nStartCol );
pCurrCell->SetContents( pCntsLayoutInfo );
if( nBoxRowSpan < 0 )
pCurrCell->SetRowSpan( 0 );
// ggf. COLSPAN beachten
for( sal_uInt16 j=nStartCol+1; j<nSplitCol; j++ )
{
GetCell(nTopRow,j)->SetContents( pCnts );
pLayoutInfo->GetCell( nTopRow, j )
->SetContents( pCntsLayoutInfo );
}
}
pBox = MakeTableBox( pLine, pCell2->GetContents(),
nTopRow, nStartCol,
nBottomRow, nSplitCol );
if ( 1 != nBoxRowSpan )
pBox->setRowSpan( nBoxRowSpan );
bSplitted = sal_True;
}
OSL_ENSURE( pBox, "Colspan trouble" );
if( pBox )
rBoxes.C40_INSERT( SwTableBox, pBox, rBoxes.Count() );
}
nCol++;
}
nStartCol = nSplitCol;
}
return pLine;
}
SwTableBox *HTMLTable::MakeTableBox( SwTableLine *pUpper,
HTMLTableCnts *pCnts,
sal_uInt16 nTopRow, sal_uInt16 nLeftCol,
sal_uInt16 nBottomRow, sal_uInt16 nRightCol )
{
SwTableBox *pBox;
sal_uInt16 nColSpan = nRightCol - nLeftCol;
sal_uInt16 nRowSpan = nBottomRow - nTopRow;
if( !pCnts->Next() )
{
// nur eine Inhalts-Section
if( pCnts->GetStartNode() )
{
// und die ist keine Tabelle
pBox = NewTableBox( pCnts->GetStartNode(), pUpper );
pCnts->SetTableBox( pBox );
}
else
{
pCnts->GetTable()->InheritVertBorders( this, nLeftCol,
nRightCol-nLeftCol );
// und die ist eine Tabelle: dann bauen wir eine neue
// Box und fuegen die Zeilen der Tabelle in die Zeilen
// der Box ein
pBox = new SwTableBox( pBoxFmt, 0, pUpper );
sal_uInt16 nAbs, nRel;
pLayoutInfo->GetAvail( nLeftCol, nColSpan, nAbs, nRel );
sal_uInt16 nLSpace = pLayoutInfo->GetLeftCellSpace( nLeftCol, nColSpan );
sal_uInt16 nRSpace = pLayoutInfo->GetRightCellSpace( nLeftCol, nColSpan );
sal_uInt16 nInhSpace = pLayoutInfo->GetInhCellSpace( nLeftCol, nColSpan );
pCnts->GetTable()->MakeTable( pBox, nAbs, nRel, nLSpace, nRSpace,
nInhSpace );
}
}
else
{
// mehrere Inhalts Sections: dann brauchen wir eine Box mit Zeilen
pBox = new SwTableBox( pBoxFmt, 0, pUpper );
SwTableLines& rLines = pBox->GetTabLines();
sal_Bool bFirstPara = sal_True;
while( pCnts )
{
if( pCnts->GetStartNode() )
{
// normale Absaetze werden zu einer Box in einer Zeile
SwTableLine *pLine =
new SwTableLine( pLineFrmFmtNoHeight ? pLineFrmFmtNoHeight
: pLineFmt, 0, pBox );
if( !pLineFrmFmtNoHeight )
{
// Wenn es noch kein Line-Format ohne Hoehe gibt, koennen
// wir uns dieses her als soleches merken
pLineFrmFmtNoHeight = (SwTableLineFmt*)pLine->ClaimFrmFmt();
ResetLineFrmFmtAttrs( pLineFrmFmtNoHeight );
}
SwTableBox* pCntBox = NewTableBox( pCnts->GetStartNode(),
pLine );
pCnts->SetTableBox( pCntBox );
FixFrameFmt( pCntBox, nTopRow, nLeftCol, nRowSpan, nColSpan,
bFirstPara, 0==pCnts->Next() );
pLine->GetTabBoxes().C40_INSERT( SwTableBox, pCntBox,
pLine->GetTabBoxes().Count() );
rLines.C40_INSERT( SwTableLine, pLine, rLines.Count() );
}
else
{
pCnts->GetTable()->InheritVertBorders( this, nLeftCol,
nRightCol-nLeftCol );
// Tabellen werden direkt eingetragen
sal_uInt16 nAbs, nRel;
pLayoutInfo->GetAvail( nLeftCol, nColSpan, nAbs, nRel );
sal_uInt16 nLSpace = pLayoutInfo->GetLeftCellSpace( nLeftCol,
nColSpan );
sal_uInt16 nRSpace = pLayoutInfo->GetRightCellSpace( nLeftCol,
nColSpan );
sal_uInt16 nInhSpace = pLayoutInfo->GetInhCellSpace( nLeftCol, nColSpan );
pCnts->GetTable()->MakeTable( pBox, nAbs, nRel, nLSpace,
nRSpace, nInhSpace );
}
pCnts = pCnts->Next();
bFirstPara = sal_False;
}
}
FixFrameFmt( pBox, nTopRow, nLeftCol, nRowSpan, nColSpan );
return pBox;
}
void HTMLTable::InheritBorders( const HTMLTable *pParent,
sal_uInt16 nRow, sal_uInt16 nCol,
sal_uInt16 nRowSpan, sal_uInt16 /*nColSpan*/,
sal_Bool bFirstPara, sal_Bool bLastPara )
{
OSL_ENSURE( nRows>0 && nCols>0 && nCurRow==nRows,
"Wurde CloseTable nicht aufgerufen?" );
// Die Child-Tabelle muss einen Rahmen bekommen, wenn die umgebende
// Zelle einen Rand an der betreffenden Seite besitzt.
// Der obere bzw. untere Rand wird nur gesetzt, wenn die Tabelle
// ale erster bzw. letzter Absatz in der Zelle vorkommt. Ansonsten
// Fuer den linken/rechten Rand kann noch nicht entschieden werden,
// ob eine Umrandung der Tabelle noetig/moeglich ist, weil das davon
// abhaengt, ob "Filler"-Zellen eingefuegt werden. Hier werden deshalb
// erstmal nur Informationen gesammelt
//
if( 0==nRow && pParent->bTopBorder && bFirstPara )
{
bTopBorder = sal_True;
bFillerTopBorder = sal_True; // auch Filler bekommt eine Umrandung
aTopBorderLine = pParent->aTopBorderLine;
}
if( ((*pParent->pRows)[nRow+nRowSpan-1])->bBottomBorder && bLastPara )
{
((*pRows)[nRows-1])->bBottomBorder = sal_True;
bFillerBottomBorder = sal_True; // auch Filler bekommt eine Umrandung
aBottomBorderLine =
nRow+nRowSpan==pParent->nRows ? pParent->aBottomBorderLine
: pParent->aBorderLine;
}
// Die Child Tabelle darf keinen oberen oder linken Rahmen bekommen,
// wenn der bereits durch die umgebende Tabelle gesetzt ist.
// Sie darf jedoch immer einen oberen Rand bekommen, wenn die Tabelle
// nicht der erste Absatz in der Zelle ist.
bTopAlwd = ( !bFirstPara || (pParent->bTopAlwd &&
(0==nRow || !((*pParent->pRows)[nRow-1])->bBottomBorder)) );
// die Child-Tabelle muss die Farbe der Zelle erben, in der sie
// vorkommt, wenn sie keine eigene besitzt
const SvxBrushItem *pInhBG = pParent->GetCell(nRow,nCol)->GetBGBrush();
if( !pInhBG && pParent != pTopTable &&
pParent->GetCell(nRow,nCol)->GetRowSpan() == pParent->nRows )
{
// die ganze umgebende Tabelle ist eine Tabelle in der Tabelle
// und besteht nur aus einer Line, die bei der GC (zu Recht)
// wegoptimiert wird. Deshalb muss der Hintergrund der Line in
// diese Tabelle uebernommen werden.
pInhBG = ((*pParent->pRows)[nRow])->GetBGBrush();
if( !pInhBG )
pInhBG = pParent->GetBGBrush();
if( !pInhBG )
pInhBG = pParent->GetInhBGBrush();
}
if( pInhBG )
pInhBGBrush = new SvxBrushItem( *pInhBG );
}
void HTMLTable::InheritVertBorders( const HTMLTable *pParent,
sal_uInt16 nCol, sal_uInt16 nColSpan )
{
sal_uInt16 nInhLeftBorderWidth = 0;
sal_uInt16 nInhRightBorderWidth = 0;
if( nCol+nColSpan==pParent->nCols && pParent->bRightBorder )
{
bInhRightBorder = sal_True; // erstmal nur merken
aInhRightBorderLine = pParent->aRightBorderLine;
nInhRightBorderWidth =
GetBorderWidth( aInhRightBorderLine, sal_True ) + MIN_BORDER_DIST;
}
if( ((*pParent->pColumns)[nCol])->bLeftBorder )
{
bInhLeftBorder = sal_True; // erstmal nur merken
aInhLeftBorderLine = 0==nCol ? pParent->aLeftBorderLine
: pParent->aBorderLine;
nInhLeftBorderWidth =
GetBorderWidth( aInhLeftBorderLine, sal_True ) + MIN_BORDER_DIST;
}
if( !bInhLeftBorder && (bFillerTopBorder || bFillerBottomBorder) )
nInhLeftBorderWidth = 2 * MIN_BORDER_DIST;
if( !bInhRightBorder && (bFillerTopBorder || bFillerBottomBorder) )
nInhRightBorderWidth = 2 * MIN_BORDER_DIST;
pLayoutInfo->SetInhBorderWidths( nInhLeftBorderWidth,
nInhRightBorderWidth );
bRightAlwd = ( pParent->bRightAlwd &&
(nCol+nColSpan==pParent->nCols ||
!((*pParent->pColumns)[nCol+nColSpan])->bLeftBorder) );
}
void HTMLTable::SetBorders()
{
sal_uInt16 i;
for( i=1; i<nCols; i++ )
if( HTML_TR_ALL==eRules || HTML_TR_COLS==eRules ||
((HTML_TR_ROWS==eRules || HTML_TR_GROUPS==eRules) &&
((*pColumns)[i-1])->IsEndOfGroup()) )
((*pColumns)[i])->bLeftBorder = sal_True;
for( i=0; i<nRows-1; i++ )
if( HTML_TR_ALL==eRules || HTML_TR_ROWS==eRules ||
((HTML_TR_COLS==eRules || HTML_TR_GROUPS==eRules) &&
((*pRows)[i])->IsEndOfGroup()) )
((*pRows)[i])->bBottomBorder = sal_True;
if( bTopAlwd && (HTML_TF_ABOVE==eFrame || HTML_TF_HSIDES==eFrame ||
HTML_TF_BOX==eFrame) )
bTopBorder = sal_True;
if( HTML_TF_BELOW==eFrame || HTML_TF_HSIDES==eFrame ||
HTML_TF_BOX==eFrame )
((*pRows)[nRows-1])->bBottomBorder = sal_True;
if( (HTML_TF_RHS==eFrame || HTML_TF_VSIDES==eFrame ||
HTML_TF_BOX==eFrame) )
bRightBorder = sal_True;
if( HTML_TF_LHS==eFrame || HTML_TF_VSIDES==eFrame || HTML_TF_BOX==eFrame )
((*pColumns)[0])->bLeftBorder = sal_True;
for( i=0; i<nRows; i++ )
{
HTMLTableRow *pRow = (*pRows)[i];
for( sal_uInt16 j=0; j<nCols; j++ )
{
HTMLTableCell *pCell = pRow->GetCell(j);
if( pCell->GetContents() )
{
HTMLTableCnts *pCnts = pCell->GetContents();
sal_Bool bFirstPara = sal_True;
while( pCnts )
{
HTMLTable *pTable = pCnts->GetTable();
if( pTable && !pTable->BordersSet() )
{
pTable->InheritBorders( this, i, j,
pCell->GetRowSpan(),
pCell->GetColSpan(),
bFirstPara,
0==pCnts->Next() );
pTable->SetBorders();
}
bFirstPara = sal_False;
pCnts = pCnts->Next();
}
}
}
}
bBordersSet = sal_True;
}
sal_uInt16 HTMLTable::GetBorderWidth( const SvxBorderLine& rBLine,
sal_Bool bWithDistance ) const
{
sal_uInt16 nBorderWidth = rBLine.GetOutWidth() + rBLine.GetInWidth() +
rBLine.GetDistance();
if( bWithDistance )
{
if( nCellPadding )
nBorderWidth = nBorderWidth + nCellPadding;
else if( nBorderWidth )
nBorderWidth = nBorderWidth + MIN_BORDER_DIST;
}
return nBorderWidth;
}
inline HTMLTableCell *HTMLTable::GetCell( sal_uInt16 nRow,
sal_uInt16 nCell ) const
{
OSL_ENSURE( nRow<pRows->Count(),
"ungueltiger Zeilen-Index in HTML-Tabelle" );
return ((*pRows)[nRow])->GetCell( nCell );
}
SvxAdjust HTMLTable::GetInheritedAdjust() const
{
SvxAdjust eAdjust = (nCurCol<nCols ? ((*pColumns)[nCurCol])->GetAdjust()
: SVX_ADJUST_END );
if( SVX_ADJUST_END==eAdjust )
eAdjust = ((*pRows)[nCurRow])->GetAdjust();
return eAdjust;
}
sal_Int16 HTMLTable::GetInheritedVertOri() const
{
// text::VertOrientation::TOP ist der default!
sal_Int16 eVOri = ((*pRows)[nCurRow])->GetVertOri();
if( text::VertOrientation::TOP==eVOri && nCurCol<nCols )
eVOri = ((*pColumns)[nCurCol])->GetVertOri();
if( text::VertOrientation::TOP==eVOri )
eVOri = eVertOri;
OSL_ENSURE( eVertOri != text::VertOrientation::TOP, "text::VertOrientation::TOP ist nicht erlaubt!" );
return eVOri;
}
void HTMLTable::InsertCell( HTMLTableCnts *pCnts,
sal_uInt16 nRowSpan, sal_uInt16 nColSpan,
sal_uInt16 nCellWidth, sal_Bool bRelWidth, sal_uInt16 nCellHeight,
sal_Int16 eVertOrient, SvxBrushItem *pBGBrushItem,
boost::shared_ptr<SvxBoxItem> const pBoxItem,
sal_Bool bHasNumFmt, sal_uInt32 nNumFmt,
sal_Bool bHasValue, double nValue, sal_Bool bNoWrap )
{
if( !nRowSpan || (sal_uInt32)nCurRow + nRowSpan > USHRT_MAX )
nRowSpan = 1;
if( !nColSpan || (sal_uInt32)nCurCol + nColSpan > USHRT_MAX )
nColSpan = 1;
sal_uInt16 nColsReq = nCurCol + nColSpan; // benoetigte Spalten
sal_uInt16 nRowsReq = nCurRow + nRowSpan; // benoetigte Zeilen
sal_uInt16 i, j;
// falls wir mehr Spalten benoetigen als wir zur Zeit haben,
// muessen wir in allen Zeilen noch Zellen hinzufuegen
if( nCols < nColsReq )
{
for( i=nCols; i<nColsReq; i++ )
pColumns->Insert( new HTMLTableColumn, pColumns->Count() );
for( i=0; i<nRows; i++ )
((*pRows)[i])->Expand( nColsReq, i<nCurRow );
nCols = nColsReq;
OSL_ENSURE( pColumns->Count()==nCols,
"Anzahl der Spalten nach Expandieren stimmt nicht" );
}
if( nColsReq > nFilledCols )
nFilledCols = nColsReq;
// falls wir mehr Zeilen benoetigen als wir zur Zeit haben,
// muessen wir noch neue Zeilen hinzufuegen
if( nRows < nRowsReq )
{
for( i=nRows; i<nRowsReq; i++ )
pRows->Insert( new HTMLTableRow(nCols), pRows->Count() );
nRows = nRowsReq;
OSL_ENSURE( nRows==pRows->Count(), "Zeilenzahl in Insert stimmt nicht" );
}
// Testen, ob eine Ueberschneidung vorliegt und diese
// gegebenfalls beseitigen
sal_uInt16 nSpanedCols = 0;
if( nCurRow>0 )
{
HTMLTableRow *pCurRow = (*pRows)[nCurRow];
for( i=nCurCol; i<nColsReq; i++ )
{
HTMLTableCell *pCell = pCurRow->GetCell(i);
if( pCell->GetContents() )
{
// Der Inhalt reicht von einer weiter oben stehenden Zelle
// hier herein. Inhalt und Farbe der Zelle sind deshalb in
// jedem Fall noch dort verankert und koennen deshalb
// ueberschrieben werden bzw. von ProtectRowSpan geloescht
// (Inhalt) oder kopiert (Farbe) werden.
nSpanedCols = i + pCell->GetColSpan();
FixRowSpan( nCurRow-1, i, pCell->GetContents() );
if( pCell->GetRowSpan() > nRowSpan )
ProtectRowSpan( nRowsReq, i,
pCell->GetRowSpan()-nRowSpan );
}
}
for( i=nColsReq; i<nSpanedCols; i++ )
{
// Auch diese Inhalte sind in jedem Fall nich in der Zeile
// darueber verankert.
HTMLTableCell *pCell = pCurRow->GetCell(i);
FixRowSpan( nCurRow-1, i, pCell->GetContents() );
ProtectRowSpan( nCurRow, i, pCell->GetRowSpan() );
}
}
// Fill the cells
for( i=nColSpan; i>0; i-- )
{
for( j=nRowSpan; j>0; j-- )
{
const bool bCovered = i != nColSpan || j != nRowSpan;
GetCell( nRowsReq-j, nColsReq-i )
->Set( pCnts, j, i, eVertOrient, pBGBrushItem, pBoxItem,
bHasNumFmt, nNumFmt, bHasValue, nValue, bNoWrap, bCovered );
}
}
Size aTwipSz( bRelWidth ? 0 : nCellWidth, nCellHeight );
if( (aTwipSz.Width() || aTwipSz.Height()) && Application::GetDefaultDevice() )
{
aTwipSz = Application::GetDefaultDevice()
->PixelToLogic( aTwipSz, MapMode( MAP_TWIP ) );
}
// die Breite nur in die erste Zelle setzen!
if( nCellWidth )
{
sal_uInt16 nTmp = bRelWidth ? nCellWidth : (sal_uInt16)aTwipSz.Width();
GetCell( nCurRow, nCurCol )->SetWidth( nTmp, bRelWidth );
}
// Ausserdem noch die Hoehe merken
if( nCellHeight && 1==nRowSpan )
{
if( nCellHeight < MINLAY )
nCellHeight = MINLAY;
((*pRows)[nCurRow])->SetHeight( (sal_uInt16)aTwipSz.Height() );
}
// den Spaltenzaehler hinter die neuen Zellen setzen
nCurCol = nColsReq;
if( nSpanedCols > nCurCol )
nCurCol = nSpanedCols;
// und die naechste freie Zelle suchen
while( nCurCol<nCols && GetCell(nCurRow,nCurCol)->IsUsed() )
nCurCol++;
}
inline void HTMLTable::CloseSection( sal_Bool bHead )
{
// die vorhergende Section beenden, falls es schon eine Zeile gibt
OSL_ENSURE( nCurRow<=nRows, "ungeultige aktuelle Zeile" );
if( nCurRow>0 && nCurRow<=nRows )
((*pRows)[nCurRow-1])->SetEndOfGroup();
if( bHead )
nHeadlineRepeat = nCurRow;
}
void HTMLTable::OpenRow( SvxAdjust eAdjust, sal_Int16 eVertOrient,
SvxBrushItem *pBGBrushItem )
{
sal_uInt16 nRowsReq = nCurRow+1; // Anzahl benoetigter Zeilen;
// die naechste Zeile anlegen, falls sie nicht schon da ist
if( nRows<nRowsReq )
{
for( sal_uInt16 i=nRows; i<nRowsReq; i++ )
pRows->Insert( new HTMLTableRow(nCols), pRows->Count() );
nRows = nRowsReq;
OSL_ENSURE( nRows==pRows->Count(),
"Zeilenzahl in OpenRow stimmt nicht" );
}
HTMLTableRow *pCurRow = ((*pRows)[nCurRow]);
pCurRow->SetAdjust( eAdjust );
pCurRow->SetVertOri( eVertOrient );
if( pBGBrushItem )
((*pRows)[nCurRow])->SetBGBrush( pBGBrushItem );
// den Spaltenzaehler wieder an den Anfang setzen
nCurCol=0;
// und die naechste freie Zelle suchen
while( nCurCol<nCols && GetCell(nCurRow,nCurCol)->IsUsed() )
nCurCol++;
}
void HTMLTable::CloseRow( sal_Bool bEmpty )
{
OSL_ENSURE( nCurRow<nRows, "aktulle Zeile hinter dem Tabellenende" );
// leere Zellen bekommen einfach einen etwas dickeren unteren Rand!
if( bEmpty )
{
if( nCurRow > 0 )
((*pRows)[nCurRow-1])->IncEmptyRows();
return;
}
HTMLTableRow *pRow = (*pRows)[nCurRow];
// den COLSPAN aller leeren Zellen am Zeilenende so anpassen, dass
// eine Zelle daraus wird. Das kann man hier machen (und auf keinen
// Fall frueher), weill jetzt keine Zellen mehr in die Zeile eingefuegt
// werden.
sal_uInt16 i=nCols;
while( i )
{
HTMLTableCell *pCell = pRow->GetCell(--i);
if( !pCell->GetContents() )
{
sal_uInt16 nColSpan = nCols-i;
if( nColSpan > 1 )
pCell->SetColSpan( nColSpan );
}
else
break;
}
nCurRow++;
}
inline void HTMLTable::CloseColGroup( sal_uInt16 nSpan, sal_uInt16 _nWidth,
sal_Bool bRelWidth, SvxAdjust eAdjust,
sal_Int16 eVertOrient )
{
if( nSpan )
InsertCol( nSpan, _nWidth, bRelWidth, eAdjust, eVertOrient );
OSL_ENSURE( nCurCol<=nCols, "ungueltige Spalte" );
if( nCurCol>0 && nCurCol<=nCols )
((*pColumns)[nCurCol-1])->SetEndOfGroup();
}
void HTMLTable::InsertCol( sal_uInt16 nSpan, sal_uInt16 nColWidth, sal_Bool bRelWidth,
SvxAdjust eAdjust, sal_Int16 eVertOrient )
{
// #i35143# - no columns, if rows already exist.
if ( nRows > 0 )
return;
sal_uInt16 i;
if( !nSpan )
nSpan = 1;
sal_uInt16 nColsReq = nCurCol + nSpan; // benoetigte Spalten
if( nCols < nColsReq )
{
for( i=nCols; i<nColsReq; i++ )
pColumns->Insert( new HTMLTableColumn, pColumns->Count() );
nCols = nColsReq;
}
Size aTwipSz( bRelWidth ? 0 : nColWidth, 0 );
if( aTwipSz.Width() && Application::GetDefaultDevice() )
{
aTwipSz = Application::GetDefaultDevice()
->PixelToLogic( aTwipSz, MapMode( MAP_TWIP ) );
}
for( i=nCurCol; i<nColsReq; i++ )
{
HTMLTableColumn *pCol = (*pColumns)[i];
sal_uInt16 nTmp = bRelWidth ? nColWidth : (sal_uInt16)aTwipSz.Width();
pCol->SetWidth( nTmp, bRelWidth );
pCol->SetAdjust( eAdjust );
pCol->SetVertOri( eVertOrient );
}
bColSpec = sal_True;
nCurCol = nColsReq;
}
void HTMLTable::CloseTable()
{
sal_uInt16 i;
// Die Anzahl der Tabellenzeilen richtet sich nur nach den
// <TR>-Elementen (d.h. nach nCurRow). Durch ROWSPAN aufgespannte
// Zeilen hinter Zeile nCurRow muessen wir deshalb loeschen
// und vor allem aber den ROWSPAN in den darueberliegenden Zeilen
// anpassen.
if( nRows>nCurRow )
{
HTMLTableRow *pPrevRow = (*pRows)[nCurRow-1];
HTMLTableCell *pCell;
for( i=0; i<nCols; i++ )
if( ( (pCell=(pPrevRow->GetCell(i))), (pCell->GetRowSpan()) > 1 ) )
{
FixRowSpan( nCurRow-1, i, pCell->GetContents() );
ProtectRowSpan( nCurRow, i, (*pRows)[nCurRow]->GetCell(i)->GetRowSpan() );
}
for( i=nRows-1; i>=nCurRow; i-- )
pRows->DeleteAndDestroy(i);
nRows = nCurRow;
}
// falls die Tabelle keine Spalte hat, muessen wir eine hinzufuegen
if( 0==nCols )
{
pColumns->Insert( new HTMLTableColumn, pColumns->Count() );
for( i=0; i<nRows; i++ )
((*pRows)[i])->Expand(1);
nCols = 1;
nFilledCols = 1;
}
// falls die Tabelle keine Zeile hat, muessen wir eine hinzufuegen
if( 0==nRows )
{
pRows->Insert( new HTMLTableRow(nCols), pRows->Count() );
nRows = 1;
nCurRow = 1;
}
if( nFilledCols < nCols )
{
pColumns->DeleteAndDestroy( nFilledCols, nCols-nFilledCols );
for( i=0; i<nRows; i++ )
((*pRows)[i])->Shrink( nFilledCols );
nCols = nFilledCols;
}
}
void HTMLTable::_MakeTable( SwTableBox *pBox )
{
SwTableLines& rLines = (pBox ? pBox->GetTabLines()
: ((SwTable *)pSwTable)->GetTabLines() );
// jetzt geht's richtig los ...
for( sal_uInt16 i=0; i<nRows; i++ )
{
SwTableLine *pLine = MakeTableLine( pBox, i, 0, i+1, nCols );
if( pBox || i > 0 )
rLines.C40_INSERT( SwTableLine, pLine, rLines.Count() );
}
}
/* Wie werden Tabellen ausgerichtet?
erste Zeile: ohne Absatz-Einzuege
zweite Zeile: mit Absatz-Einzuegen
ALIGN= LEFT RIGHT CENTER -
-------------------------------------------------------------------------
xxx bei Tabellen mit WIDTH=nn% ist die Prozent-Angabe von Bedeutung:
xxx nn = 100 text::HoriOrientation::FULL text::HoriOrientation::FULL text::HoriOrientation::FULL text::HoriOrientation::FULL %
xxx text::HoriOrientation::NONE text::HoriOrientation::NONE text::HoriOrientation::NONE % text::HoriOrientation::NONE %
xxx nn < 100 Rahmen F Rahmen F text::HoriOrientation::CENTER % text::HoriOrientation::LEFT %
xxx Rahmen F Rahmen F text::HoriOrientation::CENTER % text::HoriOrientation::NONE %
bei Tabellen mit WIDTH=nn% ist die Prozent-Angabe von Bedeutung:
nn = 100 text::HoriOrientation::LEFT text::HoriOrientation::RIGHT text::HoriOrientation::CENTER % text::HoriOrientation::LEFT %
text::HoriOrientation::LEFT_AND text::HoriOrientation::RIGHT text::HoriOrientation::CENTER % text::HoriOrientation::LEFT_AND %
nn < 100 Rahmen F Rahmen F text::HoriOrientation::CENTER % text::HoriOrientation::LEFT %
Rahmen F Rahmen F text::HoriOrientation::CENTER % text::HoriOrientation::NONE %
sonst die berechnete Breite w
w = avail* text::HoriOrientation::LEFT text::HoriOrientation::RIGHT text::HoriOrientation::CENTER text::HoriOrientation::LEFT
HORI_LEDT_AND text::HoriOrientation::RIGHT text::HoriOrientation::CENTER text::HoriOrientation::LEFT_AND
w < avail Rahmen L Rahmen L text::HoriOrientation::CENTER text::HoriOrientation::LEFT
Rahmen L Rahmen L text::HoriOrientation::CENTER text::HoriOrientation::NONE
xxx *) wenn fuer die Tabelle keine Groesse angegeben wurde, wird immer
xxx text::HoriOrientation::FULL genommen
*/
void HTMLTable::MakeTable( SwTableBox *pBox, sal_uInt16 nAbsAvail,
sal_uInt16 nRelAvail, sal_uInt16 nAbsLeftSpace,
sal_uInt16 nAbsRightSpace, sal_uInt16 nInhAbsSpace )
{
OSL_ENSURE( nRows>0 && nCols>0 && nCurRow==nRows,
"Wurde CloseTable nicht aufgerufen?" );
OSL_ENSURE( (pLayoutInfo==0) == (this==pTopTable),
"Top-Tabelle hat keine Layout-Info oder umgekehrt" );
if( this==pTopTable )
{
// Umrandung der Tabelle und aller in ihr enthaltenen berechnen
SetBorders();
// Schritt 1: Die benoetigten Layout-Strukturen werden angelegt
// (inklusive Tabellen in Tabellen).
CreateLayoutInfo();
// Schritt 2: Die minimalen und maximalen Spaltenbreiten werden
// berechnet (inklusive Tabellen in Tabellen). Da wir noch keine
// Boxen haben, arabeiten wir noch auf den Start-Nodes.
pLayoutInfo->AutoLayoutPass1();
}
// Schritt 3: Die tatsaechlichen Spaltenbreiten dieser Tabelle werden
// berechnet (nicht von Tabellen in Tabellen). Dies muss jetzt schon
// sein, damit wir entscheiden koennen ob Filler-Zellen benoetigt werden
// oder nicht (deshalb war auch Pass1 schon noetig).
pLayoutInfo->AutoLayoutPass2( nAbsAvail, nRelAvail, nAbsLeftSpace,
nAbsRightSpace, nInhAbsSpace );
if( this!=pTopTable )
{
// die linke und rechte Umrandung der Tabelle kann jetzt entgueltig
// festgelegt werden
if( pLayoutInfo->GetRelRightFill() == 0 )
{
if( !bRightBorder )
{
// linke Umrandung von auesserer Tabelle uebernehmen
if( bInhRightBorder )
{
bRightBorder = sal_True;
aRightBorderLine = aInhRightBorderLine;
}
}
else
{
// Umrandung nur setzen, wenn es erlaubt ist
bRightBorder = bRightAlwd;
}
}
if( pLayoutInfo->GetRelLeftFill() == 0 &&
!((*pColumns)[0])->bLeftBorder &&
bInhLeftBorder )
{
// ggf. rechte Umrandung von auesserer Tabelle uebernehmen
((*pColumns)[0])->bLeftBorder = sal_True;
aLeftBorderLine = aInhLeftBorderLine;
}
}
// Fuer die Top-Table muss die Ausrichtung gesetzt werden
if( this==pTopTable )
{
sal_Int16 eHoriOri;
if( bForceFrame )
{
// Die Tabelle soll in einen Rahmen und ist auch schmaler
// als der verfuegbare Platz und nicht 100% breit.
// Dann kommt sie in einen Rahmen
eHoriOri = bPrcWidth ? text::HoriOrientation::FULL : text::HoriOrientation::LEFT;
}
else switch( eTableAdjust )
{
// Die Tabelle passt entweder auf die Seite, soll aber in keinen
// Rahmen oder sie ist Breiter als die Seite und soll deshalb
// in keinen Rahmen
case SVX_ADJUST_RIGHT:
// in rechtsbuendigen Tabellen kann nicht auf den rechten
// Rand Ruecksicht genommen werden
eHoriOri = text::HoriOrientation::RIGHT;
break;
case SVX_ADJUST_CENTER:
// zentrierte Tabellen nehmen keine Ruecksicht auf Raender!
eHoriOri = text::HoriOrientation::CENTER;
break;
case SVX_ADJUST_LEFT:
default:
// linksbuendige Tabellen nehmen nur auf den linken Rand
// Ruecksicht
eHoriOri = nLeftMargin ? text::HoriOrientation::LEFT_AND_WIDTH : text::HoriOrientation::LEFT;
break;
}
// das Tabellenform holen und anpassen
SwFrmFmt *pFrmFmt = pSwTable->GetFrmFmt();
pFrmFmt->SetFmtAttr( SwFmtHoriOrient(0,eHoriOri) );
if( text::HoriOrientation::LEFT_AND_WIDTH==eHoriOri )
{
OSL_ENSURE( nLeftMargin || nRightMargin,
"Da gibt's wohl noch Reste von relativen Breiten" );
// The right margin will be ignored anyway.
SvxLRSpaceItem aLRItem( pSwTable->GetFrmFmt()->GetLRSpace() );
aLRItem.SetLeft( nLeftMargin );
aLRItem.SetRight( nRightMargin );
pFrmFmt->SetFmtAttr( aLRItem );
}
if( bPrcWidth && text::HoriOrientation::FULL!=eHoriOri )
{
pFrmFmt->LockModify();
SwFmtFrmSize aFrmSize( pFrmFmt->GetFrmSize() );
aFrmSize.SetWidthPercent( (sal_uInt8)nWidth );
pFrmFmt->SetFmtAttr( aFrmSize );
pFrmFmt->UnlockModify();
}
}
// die Default Line- und Box-Formate holen
if( this==pTopTable )
{
// die erste Box merken und aus der ersten Zeile ausketten
SwTableLine *pLine1 = (pSwTable->GetTabLines())[0];
pBox1 = (pLine1->GetTabBoxes())[0];
pLine1->GetTabBoxes().Remove(0);
pLineFmt = (SwTableLineFmt*)pLine1->GetFrmFmt();
pBoxFmt = (SwTableBoxFmt*)pBox1->GetFrmFmt();
}
else
{
pLineFmt = (SwTableLineFmt*)pTopTable->pLineFmt;
pBoxFmt = (SwTableBoxFmt*)pTopTable->pBoxFmt;
}
// ggf. muessen fuer Tabellen in Tabellen "Filler"-Zellen eingefuegt
// werden
if( this != pTopTable &&
( pLayoutInfo->GetRelLeftFill() > 0 ||
pLayoutInfo->GetRelRightFill() > 0 ) )
{
OSL_ENSURE( pBox, "kein TableBox fuer Tabelle in Tabelle" );
SwTableLines& rLines = pBox->GetTabLines();
// dazu brauchen wir erstmal ein eine neue Table-Line in der Box
SwTableLine *pLine =
new SwTableLine( pLineFrmFmtNoHeight ? pLineFrmFmtNoHeight
: pLineFmt, 0, pBox );
rLines.C40_INSERT( SwTableLine, pLine, rLines.Count() );
// Sicherstellen, dass wie ein Format ohne Hoehe erwischt haben
if( !pLineFrmFmtNoHeight )
{
// sonst muessen wir die Hoehe aus dem Attribut entfernen
// und koennen uns das Format merken
pLineFrmFmtNoHeight = (SwTableLineFmt*)pLine->ClaimFrmFmt();
ResetLineFrmFmtAttrs( pLineFrmFmtNoHeight );
}
SwTableBoxes& rBoxes = pLine->GetTabBoxes();
SwTableBox *pNewBox;
// ggf. links eine Zelle einfuegen
if( pLayoutInfo->GetRelLeftFill() > 0 )
{
// pPrevStNd ist der Vorgaenger-Start-Node der Tabelle. Den
// "Filler"-Node fuegen wir einfach dahinter ein ...
pPrevStNd = pParser->InsertTableSection( pPrevStNd );
pNewBox = NewTableBox( pPrevStNd, pLine );
rBoxes.C40_INSERT( SwTableBox, pNewBox, rBoxes.Count() );
FixFillerFrameFmt( pNewBox, sal_False );
pLayoutInfo->SetLeftFillerBox( pNewBox );
}
// jetzt die Tabelle bearbeiten
pNewBox = new SwTableBox( pBoxFmt, 0, pLine );
rBoxes.C40_INSERT( SwTableBox, pNewBox, rBoxes.Count() );
SwFrmFmt *pFrmFmt = pNewBox->ClaimFrmFmt();
pFrmFmt->ResetFmtAttr( RES_BOX );
pFrmFmt->ResetFmtAttr( RES_BACKGROUND );
pFrmFmt->ResetFmtAttr( RES_VERT_ORIENT );
pFrmFmt->ResetFmtAttr( RES_BOXATR_FORMAT );
_MakeTable( pNewBox );
// und noch ggf. rechts eine Zelle einfuegen
if( pLayoutInfo->GetRelRightFill() > 0 )
{
const SwStartNode *pStNd =
GetPrevBoxStartNode( USHRT_MAX, USHRT_MAX );
pStNd = pParser->InsertTableSection( pStNd );
pNewBox = NewTableBox( pStNd, pLine );
rBoxes.C40_INSERT( SwTableBox, pNewBox, rBoxes.Count() );
FixFillerFrameFmt( pNewBox, sal_True );
pLayoutInfo->SetRightFillerBox( pNewBox );
}
}
else
{
_MakeTable( pBox );
}
// zum Schluss fuehren wir noch eine Garbage-Collection fuer die
// Top-Level-Tabelle durch
if( this==pTopTable )
{
if( 1==nRows && nHeight && 1==pSwTable->GetTabLines().Count() )
{
// Hoehe einer einzeiligen Tabelle als Mindesthoehe der
// Zeile setzen. (War mal fixe Hoehe, aber das gibt manchmal
// Probleme (fix #34972#) und ist auch nicht Netscape 4.0
// konform
nHeight = pParser->ToTwips( nHeight );
if( nHeight < MINLAY )
nHeight = MINLAY;
(pSwTable->GetTabLines())[0]->ClaimFrmFmt();
(pSwTable->GetTabLines())[0]->GetFrmFmt()
->SetFmtAttr( SwFmtFrmSize( ATT_MIN_SIZE, 0, nHeight ) );
}
if( GetBGBrush() )
pSwTable->GetFrmFmt()->SetFmtAttr( *GetBGBrush() );
((SwTable *)pSwTable)->SetRowsToRepeat( static_cast< sal_uInt16 >(nHeadlineRepeat) );
((SwTable *)pSwTable)->GCLines();
sal_Bool bIsInFlyFrame = pContext && pContext->GetFrmFmt();
if( bIsInFlyFrame && !nWidth )
{
SvxAdjust eTblAdjust = GetTableAdjust(sal_False);
if( eTblAdjust != SVX_ADJUST_LEFT &&
eTblAdjust != SVX_ADJUST_RIGHT )
{
// Wenn eine Tabelle ohne Breitenangabe nicht links oder
// rechts umflossen werden soll, dann stacken wir sie
// in einem Rahmen mit 100%-Breite, damit ihre Groesse
// angepasst wird. Der Rahmen darf nicht angepasst werden.
OSL_ENSURE( HasToFly(), "Warum ist die Tabelle in einem Rahmen?" );
sal_uInt32 nMin = pLayoutInfo->GetMin();
if( nMin > USHRT_MAX )
nMin = USHRT_MAX;
SwFmtFrmSize aFlyFrmSize( ATT_VAR_SIZE, (SwTwips)nMin, MINLAY );
aFlyFrmSize.SetWidthPercent( 100 );
pContext->GetFrmFmt()->SetFmtAttr( aFlyFrmSize );
bIsInFlyFrame = sal_False;
}
else
{
// Links und rechts ausgerichtete Tabellen ohne Breite
// duerfen leider nicht in der Breite angepasst werden, denn
// sie wuerden nur schrumpfen aber nie wachsen.
pLayoutInfo->SetMustNotRecalc( sal_True );
if( pContext->GetFrmFmt()->GetAnchor().GetCntntAnchor()
->nNode.GetNode().FindTableNode() )
{
sal_uInt32 nMax = pLayoutInfo->GetMax();
if( nMax > USHRT_MAX )
nMax = USHRT_MAX;
SwFmtFrmSize aFlyFrmSize( ATT_VAR_SIZE, (SwTwips)nMax, MINLAY );
pContext->GetFrmFmt()->SetFmtAttr( aFlyFrmSize );
bIsInFlyFrame = sal_False;
}
else
{
pLayoutInfo->SetMustNotResize( sal_True );
}
}
}
pLayoutInfo->SetMayBeInFlyFrame( bIsInFlyFrame );
// Nur Tabellen mit relativer Breite oder ohne Breite muessen
// angepasst werden.
pLayoutInfo->SetMustResize( bPrcWidth || !nWidth );
pLayoutInfo->SetWidths();
((SwTable *)pSwTable)->SetHTMLTableLayout( pLayoutInfo );
if( pResizeDrawObjs )
{
sal_uInt16 nCount = pResizeDrawObjs->Count();
for( sal_uInt16 i=0; i<nCount; i++ )
{
SdrObject *pObj = (*pResizeDrawObjs)[i];
sal_uInt16 nRow = (*pDrawObjPrcWidths)[3*i];
sal_uInt16 nCol = (*pDrawObjPrcWidths)[3*i+1];
sal_uInt8 nPrcWidth = (sal_uInt8)(*pDrawObjPrcWidths)[3*i+2];
SwHTMLTableLayoutCell *pLayoutCell =
pLayoutInfo->GetCell( nRow, nCol );
sal_uInt16 nColSpan = pLayoutCell->GetColSpan();
sal_uInt16 nWidth2, nDummy;
pLayoutInfo->GetAvail( nCol, nColSpan, nWidth2, nDummy );
nWidth2 = nWidth2 - pLayoutInfo->GetLeftCellSpace( nCol, nColSpan );
nWidth2 = nWidth2 - pLayoutInfo->GetRightCellSpace( nCol, nColSpan );
nWidth2 = static_cast< sal_uInt16 >(((long)nWidth * nPrcWidth) / 100);
pParser->ResizeDrawObject( pObj, nWidth2 );
}
}
}
}
void HTMLTable::SetTable( const SwStartNode *pStNd, _HTMLTableContext *pCntxt,
sal_uInt16 nLeft, sal_uInt16 nRight,
const SwTable *pSwTab, sal_Bool bFrcFrame )
{
pPrevStNd = pStNd;
pSwTable = pSwTab;
pContext = pCntxt;
nLeftMargin = nLeft;
nRightMargin = nRight;
bForceFrame = bFrcFrame;
}
void HTMLTable::RegisterDrawObject( SdrObject *pObj, sal_uInt8 nPrcWidth )
{
if( !pResizeDrawObjs )
pResizeDrawObjs = new SdrObjects;
pResizeDrawObjs->C40_INSERT( SdrObject, pObj, pResizeDrawObjs->Count() );
if( !pDrawObjPrcWidths )
pDrawObjPrcWidths = new std::vector<sal_uInt16>;
pDrawObjPrcWidths->push_back( nCurRow );
pDrawObjPrcWidths->push_back( nCurCol );
pDrawObjPrcWidths->push_back( (sal_uInt16)nPrcWidth );
}
void HTMLTable::MakeParentContents()
{
if( !GetContext() && !HasParentSection() )
{
SetParentContents(
pParser->InsertTableContents( GetIsParentHeader() ) );
SetHasParentSection( sal_True );
}
}
_HTMLTableContext::~_HTMLTableContext()
{
delete pPos;
}
void _HTMLTableContext::SavePREListingXMP( SwHTMLParser& rParser )
{
bRestartPRE = rParser.IsReadPRE();
bRestartXMP = rParser.IsReadXMP();
bRestartListing = rParser.IsReadListing();
rParser.FinishPREListingXMP();
}
void _HTMLTableContext::RestorePREListingXMP( SwHTMLParser& rParser )
{
rParser.FinishPREListingXMP();
if( bRestartPRE )
rParser.StartPRE();
if( bRestartXMP )
rParser.StartXMP();
if( bRestartListing )
rParser.StartListing();
}
const SwStartNode *SwHTMLParser::InsertTableSection
( const SwStartNode *pPrevStNd )
{
OSL_ENSURE( pPrevStNd, "Start-Node ist NULL" );
pCSS1Parser->SetTDTagStyles();
SwTxtFmtColl *pColl = pCSS1Parser->GetTxtCollFromPool( RES_POOLCOLL_TABLE );
const SwStartNode *pStNd;
if( pTable && pTable->bFirstCell )
{
SwNode *const pNd = & pPam->GetPoint()->nNode.GetNode();
pNd->GetTxtNode()->ChgFmtColl( pColl );
pStNd = pNd->FindTableBoxStartNode();
pTable->bFirstCell = sal_False;
}
else
{
const SwNode* pNd;
if( pPrevStNd->IsTableNode() )
pNd = pPrevStNd;
else
pNd = pPrevStNd->EndOfSectionNode();
SwNodeIndex nIdx( *pNd, 1 );
pStNd = pDoc->GetNodes().MakeTextSection( nIdx, SwTableBoxStartNode,
pColl );
pTable->IncBoxCount();
}
SwCntntNode *pCNd = pDoc->GetNodes()[pStNd->GetIndex()+1] ->GetCntntNode();
SvxFontHeightItem aFontHeight( 40, 100, RES_CHRATR_FONTSIZE );
pCNd->SetAttr( aFontHeight );
aFontHeight.SetWhich( RES_CHRATR_CJK_FONTSIZE );
pCNd->SetAttr( aFontHeight );
aFontHeight.SetWhich( RES_CHRATR_CTL_FONTSIZE );
pCNd->SetAttr( aFontHeight );
return pStNd;
}
const SwStartNode *SwHTMLParser::InsertTableSection( sal_uInt16 nPoolId )
{
switch( nPoolId )
{
case RES_POOLCOLL_TABLE_HDLN:
pCSS1Parser->SetTHTagStyles();
break;
case RES_POOLCOLL_TABLE:
pCSS1Parser->SetTDTagStyles();
break;
}
SwTxtFmtColl *pColl = pCSS1Parser->GetTxtCollFromPool( nPoolId );
SwNode *const pNd = & pPam->GetPoint()->nNode.GetNode();
const SwStartNode *pStNd;
if( pTable && pTable->bFirstCell )
{
pNd->GetTxtNode()->ChgFmtColl( pColl );
pTable->bFirstCell = sal_False;
pStNd = pNd->FindTableBoxStartNode();
}
else
{
SwTableNode *pTblNd = pNd->FindTableNode();
if( pTblNd->GetTable().GetHTMLTableLayout() )
{ // if there is already a HTMTableLayout, this table is already finished
// and we have to look for the right table in the environment
SwTableNode *pOutTbl = pTblNd;
do {
pTblNd = pOutTbl;
pOutTbl = pOutTbl->StartOfSectionNode()->FindTableNode();
} while( pOutTbl && pTblNd->GetTable().GetHTMLTableLayout() );
}
SwNodeIndex aIdx( *pTblNd->EndOfSectionNode() );
pStNd = pDoc->GetNodes().MakeTextSection( aIdx, SwTableBoxStartNode,
pColl );
pPam->GetPoint()->nNode = pStNd->GetIndex() + 1;
SwTxtNode *pTxtNd = pPam->GetPoint()->nNode.GetNode().GetTxtNode();
pPam->GetPoint()->nContent.Assign( pTxtNd, 0 );
pTable->IncBoxCount();
}
return pStNd;
}
SwStartNode *SwHTMLParser::InsertTempTableCaptionSection()
{
SwTxtFmtColl *pColl = pCSS1Parser->GetTxtCollFromPool( RES_POOLCOLL_TEXT );
SwNodeIndex& rIdx = pPam->GetPoint()->nNode;
rIdx = pDoc->GetNodes().GetEndOfExtras();
SwStartNode *pStNd = pDoc->GetNodes().MakeTextSection( rIdx,
SwNormalStartNode, pColl );
rIdx = pStNd->GetIndex() + 1;
pPam->GetPoint()->nContent.Assign( rIdx.GetNode().GetTxtNode(), 0 );
return pStNd;
}
xub_StrLen SwHTMLParser::StripTrailingLF()
{
xub_StrLen nStripped = 0;
xub_StrLen nLen = pPam->GetPoint()->nContent.GetIndex();
if( nLen )
{
SwTxtNode* pTxtNd = pPam->GetPoint()->nNode.GetNode().GetTxtNode();
// vorsicht, wenn Kommentare nicht uebrlesen werden!!!
if( pTxtNd )
{
xub_StrLen nPos = nLen;
xub_StrLen nLFCount = 0;
while( nPos && '\x0a' == (pTxtNd->GetTxt()).GetChar(--nPos) )
nLFCount++;
if( nLFCount )
{
if( nLFCount > 2 )
{
// Bei Netscape entspricht ein Absatz-Ende zwei LFs
// (mit einem kommt man in die naechste Zeile, das
// zweite erzeugt eine Leerzeile) Diesen Abstand
// erreichen wie aber schon mit dem unteren
// Absatz-Abstand. Wenn nach den <BR> ein neuer
// Absatz aufgemacht wird, wird das Maximum des Abstands,
// der sich aus den BR und dem P ergibt genommen.
// Deshalb muessen wir 2 bzw. alle bei weniger
// als zweien loeschen
nLFCount = 2;
}
nPos = nLen - nLFCount;
SwIndex nIdx( pTxtNd, nPos );
pTxtNd->EraseText( nIdx, nLFCount );
nStripped = nLFCount;
}
}
}
return nStripped;
}
SvxBrushItem* SwHTMLParser::CreateBrushItem( const Color *pColor,
const String& rImageURL,
const String& rStyle,
const String& rId,
const String& rClass )
{
SvxBrushItem *pBrushItem = 0;
if( rStyle.Len() || rId.Len() || rClass.Len() )
{
SfxItemSet aItemSet( pDoc->GetAttrPool(), RES_BACKGROUND,
RES_BACKGROUND );
SvxCSS1PropertyInfo aPropInfo;
if( rClass.Len() )
{
String aClass( rClass );
SwCSS1Parser::GetScriptFromClass( aClass );
const SvxCSS1MapEntry *pClass = pCSS1Parser->GetClass( aClass );
if( pClass )
aItemSet.Put( pClass->GetItemSet() );
}
if( rId.Len() )
{
const SvxCSS1MapEntry *pId = pCSS1Parser->GetId( rId );
if( pId )
aItemSet.Put( pId->GetItemSet() );
}
pCSS1Parser->ParseStyleOption( rStyle, aItemSet, aPropInfo );
const SfxPoolItem *pItem = 0;
if( SFX_ITEM_SET == aItemSet.GetItemState( RES_BACKGROUND, sal_False,
&pItem ) )
{
pBrushItem = new SvxBrushItem( *((const SvxBrushItem *)pItem) );
}
}
if( !pBrushItem && (pColor || rImageURL.Len()) )
{
pBrushItem = new SvxBrushItem(RES_BACKGROUND);
if( pColor )
pBrushItem->SetColor(*pColor);
if( rImageURL.Len() )
{
pBrushItem->SetGraphicLink( URIHelper::SmartRel2Abs( INetURLObject(sBaseURL), rImageURL, Link(), false) );
pBrushItem->SetGraphicPos( GPOS_TILED );
}
}
return pBrushItem;
}
class _SectionSaveStruct : public SwPendingStackData
{
sal_uInt16 nBaseFontStMinSave, nFontStMinSave, nFontStHeadStartSave;
sal_uInt16 nDefListDeepSave, nContextStMinSave, nContextStAttrMinSave;
public:
HTMLTable *pTable;
_SectionSaveStruct( SwHTMLParser& rParser );
virtual ~_SectionSaveStruct();
sal_uInt16 GetContextStAttrMin() const { return nContextStAttrMinSave; }
void Restore( SwHTMLParser& rParser );
};
_SectionSaveStruct::_SectionSaveStruct( SwHTMLParser& rParser ) :
nBaseFontStMinSave(0), nFontStMinSave(0), nFontStHeadStartSave(0),
nDefListDeepSave(0), nContextStMinSave(0), nContextStAttrMinSave(0),
pTable( 0 )
{
// Font-Stacks einfrieren
nBaseFontStMinSave = rParser.nBaseFontStMin;
rParser.nBaseFontStMin = rParser.aBaseFontStack.size();
nFontStMinSave = rParser.nFontStMin;
nFontStHeadStartSave = rParser.nFontStHeadStart;
rParser.nFontStMin = rParser.aFontStack.size();
// Kontext-Stack einfrieren
nContextStMinSave = rParser.nContextStMin;
nContextStAttrMinSave = rParser.nContextStAttrMin;
rParser.nContextStMin = rParser.aContexts.Count();
rParser.nContextStAttrMin = rParser.nContextStMin;
// und noch ein par Zaehler retten
nDefListDeepSave = rParser.nDefListDeep;
rParser.nDefListDeep = 0;
}
_SectionSaveStruct::~_SectionSaveStruct()
{}
void _SectionSaveStruct::Restore( SwHTMLParser& rParser )
{
// Font-Stacks wieder auftauen
sal_uInt16 nMin = rParser.nBaseFontStMin;
if( rParser.aBaseFontStack.size() > nMin )
rParser.aBaseFontStack.erase( rParser.aBaseFontStack.begin() + nMin,
rParser.aBaseFontStack.end() );
rParser.nBaseFontStMin = nBaseFontStMinSave;
nMin = rParser.nFontStMin;
if( rParser.aFontStack.size() > nMin )
rParser.aFontStack.erase( rParser.aFontStack.begin() + nMin,
rParser.aFontStack.end() );
rParser.nFontStMin = nFontStMinSave;
rParser.nFontStHeadStart = nFontStHeadStartSave;
// Der Kontext-Stack muss schon aufgeraeumt sein!
OSL_ENSURE( rParser.aContexts.Count() == rParser.nContextStMin &&
rParser.aContexts.Count() == rParser.nContextStAttrMin,
"Der Kontext-Stack wurde nicht aufgeraeumt" );
rParser.nContextStMin = nContextStMinSave;
rParser.nContextStAttrMin = nContextStAttrMinSave;
// und noch ein par Zaehler rekonstruieren
rParser.nDefListDeep = nDefListDeepSave;
// und ein par Flags zuruecksetzen
rParser.bNoParSpace = sal_False;
rParser.nOpenParaToken = 0;
if( rParser.aParaAttrs.Count() )
rParser.aParaAttrs.Remove( 0, rParser.aParaAttrs.Count() );
}
class _CellSaveStruct : public _SectionSaveStruct
{
String aStyle, aId, aClass, aLang, aDir;
String aBGImage;
Color aBGColor;
boost::shared_ptr<SvxBoxItem> m_pBoxItem;
HTMLTableCnts* pCnts; // Liste aller Inhalte
HTMLTableCnts* pCurrCnts; // der aktuelle Inhalt oder 0
SwNodeIndex *pNoBreakEndParaIdx;// Absatz-Index eines </NOBR>
double nValue;
sal_uInt32 nNumFmt;
sal_uInt16 nRowSpan, nColSpan, nWidth, nHeight;
xub_StrLen nNoBreakEndCntntPos; // Zeichen-Index eines </NOBR>
SvxAdjust eAdjust;
sal_Int16 eVertOri;
sal_Bool bHead : 1;
sal_Bool bPrcWidth : 1;
sal_Bool bHasNumFmt : 1;
sal_Bool bHasValue : 1;
sal_Bool bBGColor : 1;
sal_Bool bNoWrap : 1; // NOWRAP-Option
sal_Bool bNoBreak : 1; // NOBREAK-Tag
public:
_CellSaveStruct( SwHTMLParser& rParser, HTMLTable *pCurTable, sal_Bool bHd,
sal_Bool bReadOpt );
virtual ~_CellSaveStruct();
void AddContents( HTMLTableCnts *pNewCnts );
HTMLTableCnts *GetFirstContents() { return pCnts; }
void ClearIsInSection() { pCurrCnts = 0; }
sal_Bool IsInSection() const { return pCurrCnts!=0; }
HTMLTableCnts *GetCurrContents() const { return pCurrCnts; }
void InsertCell( SwHTMLParser& rParser, HTMLTable *pCurTable );
sal_Bool IsHeaderCell() const { return bHead; }
void StartNoBreak( const SwPosition& rPos );
void EndNoBreak( const SwPosition& rPos );
void CheckNoBreak( const SwPosition& rPos, SwDoc *pDoc );
};
_CellSaveStruct::_CellSaveStruct( SwHTMLParser& rParser, HTMLTable *pCurTable,
sal_Bool bHd, sal_Bool bReadOpt ) :
_SectionSaveStruct( rParser ),
pCnts( 0 ),
pCurrCnts( 0 ),
pNoBreakEndParaIdx( 0 ),
nValue( 0.0 ),
nNumFmt( 0 ),
nRowSpan( 1 ),
nColSpan( 1 ),
nWidth( 0 ),
nHeight( 0 ),
nNoBreakEndCntntPos( 0 ),
eAdjust( pCurTable->GetInheritedAdjust() ),
eVertOri( pCurTable->GetInheritedVertOri() ),
bHead( bHd ),
bPrcWidth( sal_False ),
bHasNumFmt( sal_False ),
bHasValue( sal_False ),
bBGColor( sal_False ),
bNoWrap( sal_False ),
bNoBreak( sal_False )
{
String aNumFmt, aValue;
if( bReadOpt )
{
const HTMLOptions& rOptions = rParser.GetOptions();
for (size_t i = rOptions.size(); i; )
{
const HTMLOption& rOption = rOptions[--i];
switch( rOption.GetToken() )
{
case HTML_O_ID:
aId = rOption.GetString();
break;
case HTML_O_COLSPAN:
nColSpan = (sal_uInt16)rOption.GetNumber();
break;
case HTML_O_ROWSPAN:
nRowSpan = (sal_uInt16)rOption.GetNumber();
break;
case HTML_O_ALIGN:
eAdjust = (SvxAdjust)rOption.GetEnum(
aHTMLPAlignTable, static_cast< sal_uInt16 >(eAdjust) );
break;
case HTML_O_VALIGN:
eVertOri = rOption.GetEnum(
aHTMLTblVAlignTable, eVertOri );
break;
case HTML_O_WIDTH:
nWidth = (sal_uInt16)rOption.GetNumber(); // nur fuer Netscape
bPrcWidth = (rOption.GetString().Search('%') != STRING_NOTFOUND);
if( bPrcWidth && nWidth>100 )
nWidth = 100;
break;
case HTML_O_HEIGHT:
nHeight = (sal_uInt16)rOption.GetNumber(); // nur fuer Netscape
if( rOption.GetString().Search('%') != STRING_NOTFOUND)
nHeight = 0; // keine %-Angaben beruecksichtigen
break;
case HTML_O_BGCOLOR:
// Leere BGCOLOR bei <TABLE>, <TR> und <TD>/<TH> wie Netscape
// ignorieren, bei allen anderen Tags *wirklich* nicht.
if( rOption.GetString().Len() )
{
rOption.GetColor( aBGColor );
bBGColor = sal_True;
}
break;
case HTML_O_BACKGROUND:
aBGImage = rOption.GetString();
break;
case HTML_O_STYLE:
aStyle = rOption.GetString();
break;
case HTML_O_CLASS:
aClass = rOption.GetString();
break;
case HTML_O_LANG:
aLang = rOption.GetString();
break;
case HTML_O_DIR:
aDir = rOption.GetString();
break;
case HTML_O_SDNUM:
aNumFmt = rOption.GetString();
bHasNumFmt = sal_True;
break;
case HTML_O_SDVAL:
bHasValue = sal_True;
aValue = rOption.GetString();
break;
case HTML_O_NOWRAP:
bNoWrap = sal_True;
break;
}
}
if( aId.Len() )
rParser.InsertBookmark( aId );
}
if( bHasNumFmt )
{
LanguageType eLang;
nValue = rParser.GetTableDataOptionsValNum(
nNumFmt, eLang, aValue, aNumFmt,
*rParser.pDoc->GetNumberFormatter() );
}
// einen neuen Kontext anlegen, aber das drawing::Alignment-Attribut
// nicht dort verankern, weil es noch ger keine Section gibt, in der
// es gibt.
sal_uInt16 nToken, nColl;
if( bHead )
{
nToken = HTML_TABLEHEADER_ON;
nColl = RES_POOLCOLL_TABLE_HDLN;
}
else
{
nToken = HTML_TABLEDATA_ON;
nColl = RES_POOLCOLL_TABLE;
}
_HTMLAttrContext *pCntxt = new _HTMLAttrContext( nToken, nColl, aEmptyStr, sal_True );
if( SVX_ADJUST_END != eAdjust )
rParser.InsertAttr( &rParser.aAttrTab.pAdjust, SvxAdjustItem(eAdjust, RES_PARATR_ADJUST),
pCntxt );
if( rParser.HasStyleOptions( aStyle, aId, aClass, &aLang, &aDir ) )
{
SfxItemSet aItemSet( rParser.pDoc->GetAttrPool(),
rParser.pCSS1Parser->GetWhichMap() );
SvxCSS1PropertyInfo aPropInfo;
if( rParser.ParseStyleOptions( aStyle, aId, aClass, aItemSet,
aPropInfo, &aLang, &aDir ) )
{
SfxPoolItem const* pItem;
if (SFX_ITEM_SET == aItemSet.GetItemState(RES_BOX, false, &pItem))
{ // fdo#41796: steal box item to set it in FixFrameFmt later!
m_pBoxItem.reset(dynamic_cast<SvxBoxItem *>(pItem->Clone()));
aItemSet.ClearItem(RES_BOX);
}
rParser.InsertAttrs( aItemSet, aPropInfo, pCntxt );
}
}
rParser.SplitPREListingXMP( pCntxt );
rParser.PushContext( pCntxt );
}
_CellSaveStruct::~_CellSaveStruct()
{
delete pNoBreakEndParaIdx;
}
void _CellSaveStruct::AddContents( HTMLTableCnts *pNewCnts )
{
if( pCnts )
pCnts->Add( pNewCnts );
else
pCnts = pNewCnts;
pCurrCnts = pNewCnts;
}
void _CellSaveStruct::InsertCell( SwHTMLParser& rParser,
HTMLTable *pCurTable )
{
#if OSL_DEBUG_LEVEL > 0
// Die Attribute muessen schon beim Auefrauemen des Kontext-Stacks
// entfernt worden sein, sonst ist etwas schiefgelaufen. Das
// Checken wir mal eben ...
// MIB 8.1.98: Wenn ausserhalb einer Zelle Attribute geoeffnet
// wurden stehen diese noch in der Attribut-Tabelle und werden erst
// ganz zum Schluss durch die CleanContext-Aufrufe in BuildTable
// geloescht. Damit es in diesem Fall keine Asserts gibt findet dann
// keine Ueberpruefung statt. Erkennen tut man diesen Fall an
// nContextStAttrMin: Der gemerkte Wert nContextStAttrMinSave ist der
// Wert, den nContextStAttrMin beim Start der Tabelle hatte. Und
// der aktuelle Wert von nContextStAttrMin entspricht der Anzahl der
// Kontexte, die beim Start der Zelle vorgefunden wurden. Sind beide
// Werte unterschiedlich, wurden ausserhalb der Zelle Kontexte
// angelegt und wir ueberpruefen nichts.
if( rParser.nContextStAttrMin == GetContextStAttrMin() )
{
_HTMLAttr** pTbl = (_HTMLAttr**)&rParser.aAttrTab;
for( sal_uInt16 nCnt = sizeof( _HTMLAttrTable ) / sizeof( _HTMLAttr* );
nCnt--; ++pTbl )
{
OSL_ENSURE( !*pTbl, "Die Attribut-Tabelle ist nicht leer" );
}
}
#endif
// jetzt muessen wir noch die Zelle an der aktuellen Position einfuegen
SvxBrushItem *pBrushItem =
rParser.CreateBrushItem( bBGColor ? &aBGColor : 0, aBGImage,
aStyle, aId, aClass );
pCurTable->InsertCell( pCnts, nRowSpan, nColSpan, nWidth,
bPrcWidth, nHeight, eVertOri, pBrushItem, m_pBoxItem,
bHasNumFmt, nNumFmt, bHasValue, nValue,
bNoWrap );
Restore( rParser );
}
void _CellSaveStruct::StartNoBreak( const SwPosition& rPos )
{
if( !pCnts ||
(!rPos.nContent.GetIndex() && pCurrCnts==pCnts &&
pCnts->GetStartNode() &&
pCnts->GetStartNode()->GetIndex() + 1 ==
rPos.nNode.GetIndex()) )
{
bNoBreak = sal_True;
}
}
void _CellSaveStruct::EndNoBreak( const SwPosition& rPos )
{
if( bNoBreak )
{
delete pNoBreakEndParaIdx;
pNoBreakEndParaIdx = new SwNodeIndex( rPos.nNode );
nNoBreakEndCntntPos = rPos.nContent.GetIndex();
bNoBreak = sal_False;
}
}
void _CellSaveStruct::CheckNoBreak( const SwPosition& rPos, SwDoc * /*pDoc*/ )
{
if( pCnts && pCurrCnts==pCnts )
{
if( bNoBreak )
{
// <NOBR> wurde nicht beendet
pCnts->SetNoBreak();
}
else if( pNoBreakEndParaIdx &&
pNoBreakEndParaIdx->GetIndex() == rPos.nNode.GetIndex() )
{
if( nNoBreakEndCntntPos == rPos.nContent.GetIndex() )
{
// <NOBR> wurde unmittelbar vor dem Zellen-Ende beendet
pCnts->SetNoBreak();
}
else if( nNoBreakEndCntntPos + 1 == rPos.nContent.GetIndex() )
{
SwTxtNode const*const pTxtNd(rPos.nNode.GetNode().GetTxtNode());
if( pTxtNd )
{
sal_Unicode cLast =
pTxtNd->GetTxt().GetChar(nNoBreakEndCntntPos);
if( ' '==cLast || '\x0a'==cLast )
{
// Zwischem dem </NOBR> und dem Zellen-Ende gibt es nur
// ein Blank oder einen Zeilenumbruch.
pCnts->SetNoBreak();
}
}
}
}
}
}
HTMLTableCnts *SwHTMLParser::InsertTableContents(
sal_Bool bHead )
{
// eine neue Section anlegen, der PaM steht dann darin
const SwStartNode *pStNd =
InsertTableSection( static_cast< sal_uInt16 >(bHead ? RES_POOLCOLL_TABLE_HDLN
: RES_POOLCOLL_TABLE) );
if( GetNumInfo().GetNumRule() )
{
// 1. Absatz auf nicht numeriert setzen
sal_uInt8 nLvl = GetNumInfo().GetLevel();
SetNodeNum( nLvl, false );
}
// Attributierungs-Anfang neu setzen
const SwNodeIndex& rSttPara = pPam->GetPoint()->nNode;
xub_StrLen nSttCnt = pPam->GetPoint()->nContent.GetIndex();
_HTMLAttr** pTbl = (_HTMLAttr**)&aAttrTab;
for( sal_uInt16 nCnt = sizeof( _HTMLAttrTable ) / sizeof( _HTMLAttr* );
nCnt--; ++pTbl )
{
_HTMLAttr *pAttr = *pTbl;
while( pAttr )
{
OSL_ENSURE( !pAttr->GetPrev(), "Attribut hat Previous-Liste" );
pAttr->nSttPara = rSttPara;
pAttr->nEndPara = rSttPara;
pAttr->nSttCntnt = nSttCnt;
pAttr->nEndCntnt = nSttCnt;
pAttr = pAttr->GetNext();
}
}
return new HTMLTableCnts( pStNd );
}
sal_uInt16 SwHTMLParser::IncGrfsThatResizeTable()
{
return pTable ? pTable->IncGrfsThatResize() : 0;
}
void SwHTMLParser::RegisterDrawObjectToTable( HTMLTable *pCurTable,
SdrObject *pObj, sal_uInt8 nPrcWidth )
{
pCurTable->RegisterDrawObject( pObj, nPrcWidth );
}
void SwHTMLParser::BuildTableCell( HTMLTable *pCurTable, sal_Bool bReadOptions,
sal_Bool bHead )
{
if( !IsParserWorking() && !pPendStack )
return;
_CellSaveStruct* pSaveStruct;
int nToken = 0;
sal_Bool bPending = sal_False;
if( pPendStack )
{
pSaveStruct = (_CellSaveStruct*)pPendStack->pData;
SwPendingStack* pTmp = pPendStack->pNext;
delete pPendStack;
pPendStack = pTmp;
nToken = pPendStack ? pPendStack->nToken : GetSaveToken();
bPending = SVPAR_ERROR == eState && pPendStack != 0;
SaveState( nToken );
}
else
{
// <TH> bzw. <TD> wurde bereits gelesen
if( pTable->IsOverflowing() )
{
SaveState( 0 );
return;
}
if( !pCurTable->GetContext() )
{
sal_Bool bTopTable = pTable==pCurTable;
// die Tabelle besitzt noch keinen Inhalt, d.h. die eigentliche
// Tabelle muss erst noch angelegt werden
static sal_uInt16 aWhichIds[] =
{
RES_PARATR_SPLIT, RES_PARATR_SPLIT,
RES_PAGEDESC, RES_PAGEDESC,
RES_BREAK, RES_BREAK,
RES_BACKGROUND, RES_BACKGROUND,
RES_KEEP, RES_KEEP,
RES_LAYOUT_SPLIT, RES_LAYOUT_SPLIT,
RES_FRAMEDIR, RES_FRAMEDIR,
0
};
SfxItemSet aItemSet( pDoc->GetAttrPool(), aWhichIds );
SvxCSS1PropertyInfo aPropInfo;
sal_Bool bStyleParsed = ParseStyleOptions( pCurTable->GetStyle(),
pCurTable->GetId(),
pCurTable->GetClass(),
aItemSet, aPropInfo,
0, &pCurTable->GetDirection() );
const SfxPoolItem *pItem = 0;
if( bStyleParsed )
{
if( SFX_ITEM_SET == aItemSet.GetItemState(
RES_BACKGROUND, sal_False, &pItem ) )
{
pCurTable->SetBGBrush( *(const SvxBrushItem *)pItem );
aItemSet.ClearItem( RES_BACKGROUND );
}
if( SFX_ITEM_SET == aItemSet.GetItemState(
RES_PARATR_SPLIT, sal_False, &pItem ) )
{
aItemSet.Put(
SwFmtLayoutSplit( ((const SvxFmtSplitItem *)pItem)
->GetValue() ) );
aItemSet.ClearItem( RES_PARATR_SPLIT );
}
}
// Den linken/rechten Absatzeinzug ermitteln
sal_uInt16 nLeftSpace = 0;
sal_uInt16 nRightSpace = 0;
short nIndent;
GetMarginsFromContextWithNumBul( nLeftSpace, nRightSpace, nIndent );
// die aktuelle Position an die wir irgendwann zurueckkehren
SwPosition *pSavePos = 0;
sal_Bool bForceFrame = sal_False;
sal_Bool bAppended = sal_False;
sal_Bool bParentLFStripped = sal_False;
if( bTopTable )
{
SvxAdjust eTblAdjust = pTable->GetTableAdjust(sal_False);
// Wenn die Tabelle links oder rechts ausgerivchtet ist,
// oder in einen Rahmen soll, dann kommt sie auch in einen
// solchen.
bForceFrame = eTblAdjust == SVX_ADJUST_LEFT ||
eTblAdjust == SVX_ADJUST_RIGHT ||
pCurTable->HasToFly();
// Entweder kommt die Tabelle in keinen Rahmen und befindet
// sich in keinem Rahmen (wird also durch Zellen simuliert),
// oder es gibt bereits Inhalt an der entsprechenden Stelle.
OSL_ENSURE( !bForceFrame || pCurTable->HasParentSection(),
"Tabelle im Rahmen hat keine Umgebung!" );
sal_Bool bAppend = sal_False;
if( bForceFrame )
{
// Wenn die Tabelle in einen Rahmen kommt, muss
// nur ein neuer Absatz aufgemacht werden, wenn
// der Absatz Rahmen ohne Umlauf enthaelt.
bAppend = HasCurrentParaFlys(sal_True);
}
else
{
// Sonst muss ein neuer Absatz aufgemacht werden,
// wenn der Absatz nicht leer ist, oder Rahmen
// oder text::Bookmarks enthaelt.
bAppend =
pPam->GetPoint()->nContent.GetIndex() ||
HasCurrentParaFlys() ||
HasCurrentParaBookmarks();
}
if( bAppend )
{
if( !pPam->GetPoint()->nContent.GetIndex() )
{
pDoc->SetTxtFmtColl( *pPam,
pCSS1Parser->GetTxtCollFromPool(RES_POOLCOLL_STANDARD) );
SvxFontHeightItem aFontHeight( 40, 100, RES_CHRATR_FONTSIZE );
_HTMLAttr* pTmp =
new _HTMLAttr( *pPam->GetPoint(), aFontHeight );
aSetAttrTab.Insert( pTmp, aSetAttrTab.Count() );
aFontHeight.SetWhich( RES_CHRATR_CJK_FONTSIZE );
pTmp = new _HTMLAttr( *pPam->GetPoint(), aFontHeight );
aSetAttrTab.Insert( pTmp, aSetAttrTab.Count() );
aFontHeight.SetWhich( RES_CHRATR_CTL_FONTSIZE );
pTmp = new _HTMLAttr( *pPam->GetPoint(), aFontHeight );
aSetAttrTab.Insert( pTmp, aSetAttrTab.Count() );
pTmp = new _HTMLAttr( *pPam->GetPoint(),
SvxULSpaceItem( 0, 0, RES_UL_SPACE ) );
aSetAttrTab.Insert( pTmp, 0 ); // ja, 0, weil schon
// vom Tabellenende vorher
// was gesetzt sein kann.
}
AppendTxtNode( AM_NOSPACE );
bAppended = sal_True;
}
else if( aParaAttrs.Count() )
{
if( !bForceFrame )
{
// Der Absatz wird gleich hinter die Tabelle
// verschoben. Deshalb entfernen wir alle harten
// Attribute des Absatzes
for( sal_uInt16 i=0; i<aParaAttrs.Count(); i++ )
aParaAttrs[i]->Invalidate();
}
aParaAttrs.Remove( 0, aParaAttrs.Count() );
}
pSavePos = new SwPosition( *pPam->GetPoint() );
}
else if( pCurTable->HasParentSection() )
{
bParentLFStripped = StripTrailingLF() > 0;
// Absaetze bzw. ueberschriften beeenden
nOpenParaToken = 0;
nFontStHeadStart = nFontStMin;
// die harten Attribute an diesem Absatz werden nie mehr ungueltig
if( aParaAttrs.Count() )
aParaAttrs.Remove( 0, aParaAttrs.Count() );
}
// einen Tabellen Kontext anlegen
_HTMLTableContext *pTCntxt =
new _HTMLTableContext( pSavePos, nContextStMin,
nContextStAttrMin );
// alle noch offenen Attribute beenden und hinter der Tabelle
// neu aufspannen
_HTMLAttrs *pPostIts = 0;
if( !bForceFrame && (bTopTable || pCurTable->HasParentSection()) )
{
SplitAttrTab( pTCntxt->aAttrTab, bTopTable );
// Wenn wir einen schon vorhandenen Absatz verwenden, duerfen
// in den keine PostIts eingefuegt werden, weil der Absatz
// ja hinter die Tabelle wandert. Sie werden deshalb in den
// ersten Absatz der Tabelle verschoben.
// Bei Tabellen in Tabellen duerfen ebenfalls keine PostIts
// in einen noch leeren Absatz eingefuegt werden, weil
// der sonat nicht geloescht wird.
if( (bTopTable && !bAppended) ||
(!bTopTable && !bParentLFStripped &&
!pPam->GetPoint()->nContent.GetIndex()) )
pPostIts = new _HTMLAttrs;
SetAttr( bTopTable, bTopTable, pPostIts );
}
else
{
SaveAttrTab( pTCntxt->aAttrTab );
if( bTopTable && !bAppended )
{
pPostIts = new _HTMLAttrs;
SetAttr( sal_True, sal_True, pPostIts );
}
}
bNoParSpace = sal_False;
// Aktuelle Numerierung retten und auschalten.
pTCntxt->SetNumInfo( GetNumInfo() );
GetNumInfo().Clear();
pTCntxt->SavePREListingXMP( *this );
if( bTopTable )
{
if( bForceFrame )
{
// Die Tabelle soll in einen Rahmen geschaufelt werden.
SfxItemSet aFrmSet( pDoc->GetAttrPool(),
RES_FRMATR_BEGIN, RES_FRMATR_END-1 );
if( !pCurTable->IsNewDoc() )
Reader::ResetFrmFmtAttrs( aFrmSet );
SwSurround eSurround = SURROUND_NONE;
sal_Int16 eHori;
switch( pCurTable->GetTableAdjust(sal_True) )
{
case SVX_ADJUST_RIGHT:
eHori = text::HoriOrientation::RIGHT;
eSurround = SURROUND_LEFT;
break;
case SVX_ADJUST_CENTER:
eHori = text::HoriOrientation::CENTER;
break;
case SVX_ADJUST_LEFT:
eSurround = SURROUND_RIGHT;
default:
eHori = text::HoriOrientation::LEFT;
break;
}
SetAnchorAndAdjustment( text::VertOrientation::NONE, eHori, aFrmSet,
sal_True );
aFrmSet.Put( SwFmtSurround(eSurround) );
SwFmtFrmSize aFrmSize( ATT_VAR_SIZE, 20*MM50, MINLAY );
aFrmSize.SetWidthPercent( 100 );
aFrmSet.Put( aFrmSize );
sal_uInt16 nSpace = pCurTable->GetHSpace();
if( nSpace )
aFrmSet.Put( SvxLRSpaceItem(nSpace,nSpace, 0, 0, RES_LR_SPACE) );
nSpace = pCurTable->GetVSpace();
if( nSpace )
aFrmSet.Put( SvxULSpaceItem(nSpace,nSpace, RES_UL_SPACE) );
RndStdIds eAnchorId = ((const SwFmtAnchor&)aFrmSet.
Get( RES_ANCHOR )).
GetAnchorId();
SwFrmFmt *pFrmFmt = pDoc->MakeFlySection(
eAnchorId, pPam->GetPoint(), &aFrmSet );
pTCntxt->SetFrmFmt( pFrmFmt );
const SwFmtCntnt& rFlyCntnt = pFrmFmt->GetCntnt();
pPam->GetPoint()->nNode = *rFlyCntnt.GetCntntIdx();
SwCntntNode *pCNd =
pDoc->GetNodes().GoNext( &(pPam->GetPoint()->nNode) );
pPam->GetPoint()->nContent.Assign( pCNd, 0 );
}
// eine SwTable mit einer Box anlegen und den PaM in den
// Inhalt der Box-Section bewegen (der Ausrichtungs-Parameter
// ist erstmal nur ein Dummy und wird spaeter noch richtig
// gesetzt)
OSL_ENSURE( !pPam->GetPoint()->nContent.GetIndex(),
"Der Absatz hinter der Tabelle ist nicht leer!" );
const SwTable* pSwTable = pDoc->InsertTable(
SwInsertTableOptions( tabopts::HEADLINE_NO_BORDER, 1 ),
*pPam->GetPoint(), 1, 1, text::HoriOrientation::LEFT );
if( bForceFrame )
{
SwNodeIndex aDstIdx( pPam->GetPoint()->nNode );
pPam->Move( fnMoveBackward );
pDoc->GetNodes().Delete( aDstIdx );
}
else
{
if( bStyleParsed )
{
pCSS1Parser->SetFmtBreak( aItemSet, aPropInfo );
pSwTable->GetFrmFmt()->SetFmtAttr( aItemSet );
}
pPam->Move( fnMoveBackward );
}
SwNode const*const pNd = & pPam->GetPoint()->nNode.GetNode();
if( !bAppended && !bForceFrame )
{
SwTxtNode *const pOldTxtNd =
pSavePos->nNode.GetNode().GetTxtNode();
OSL_ENSURE( pOldTxtNd, "Wieso stehen wir in keinem Txt-Node?" );
SwFrmFmt *pFrmFmt = pSwTable->GetFrmFmt();
const SfxPoolItem* pItem2;
if( SFX_ITEM_SET == pOldTxtNd->GetSwAttrSet()
.GetItemState( RES_PAGEDESC, sal_False, &pItem2 ) &&
((SwFmtPageDesc *)pItem2)->GetPageDesc() )
{
pFrmFmt->SetFmtAttr( *pItem2 );
pOldTxtNd->ResetAttr( RES_PAGEDESC );
}
if( SFX_ITEM_SET == pOldTxtNd->GetSwAttrSet()
.GetItemState( RES_BREAK, sal_True, &pItem2 ) )
{
switch( ((SvxFmtBreakItem *)pItem2)->GetBreak() )
{
case SVX_BREAK_PAGE_BEFORE:
case SVX_BREAK_PAGE_AFTER:
case SVX_BREAK_PAGE_BOTH:
pFrmFmt->SetFmtAttr( *pItem2 );
pOldTxtNd->ResetAttr( RES_BREAK );
default:
;
}
}
}
if( !bAppended && pPostIts )
{
// noch vorhandene PostIts in den ersten Absatz
// der Tabelle setzen
InsertAttrs( *pPostIts );
delete pPostIts;
pPostIts = 0;
}
pTCntxt->SetTableNode( (SwTableNode *)pNd->FindTableNode() );
pCurTable->SetTable( pTCntxt->GetTableNode(), pTCntxt,
nLeftSpace, nRightSpace,
pSwTable, bForceFrame );
OSL_ENSURE( !pPostIts, "ubenutzte PostIts" );
}
else
{
// noch offene Bereiche muessen noch entfernt werden
if( EndSections( bParentLFStripped ) )
bParentLFStripped = sal_False;
if( pCurTable->HasParentSection() )
{
// dannach entfernen wir ein ggf. zu viel vorhandenen
// leeren Absatz, aber nur, wenn er schon vor dem
// entfernen von LFs leer war
if( !bParentLFStripped )
StripTrailingPara();
if( pPostIts )
{
// noch vorhandene PostIts an das Ende des jetzt
// aktuellen Absatzes schieben
InsertAttrs( *pPostIts );
delete pPostIts;
pPostIts = 0;
}
}
SwNode const*const pNd = & pPam->GetPoint()->nNode.GetNode();
const SwStartNode *pStNd = (pTable->bFirstCell ? pNd->FindTableNode()
: pNd->FindTableBoxStartNode() );
pCurTable->SetTable( pStNd, pTCntxt, nLeftSpace, nRightSpace );
}
// Den Kontext-Stack einfrieren, denn es koennen auch mal
// irgendwo ausserhalb von Zellen Attribute gesetzt werden.
// Darf nicht frueher passieren, weil eventuell noch im
// Stack gesucht wird!!!
nContextStMin = aContexts.Count();
nContextStAttrMin = nContextStMin;
}
pSaveStruct = new _CellSaveStruct( *this, pCurTable, bHead,
bReadOptions );
// ist beim ersten GetNextToken schon pending, muss bei
// wiederaufsetzen auf jedenfall neu gelesen werden!
SaveState( 0 );
}
if( !nToken )
nToken = GetNextToken(); // Token nach <TABLE>
sal_Bool bDone = sal_False;
while( (IsParserWorking() && !bDone) || bPending )
{
SaveState( nToken );
nToken = FilterToken( nToken );
OSL_ENSURE( pPendStack || !bCallNextToken || pSaveStruct->IsInSection(),
"Wo ist die Section gebieben?" );
if( !pPendStack && bCallNextToken && pSaveStruct->IsInSection() )
{
// NextToken direkt aufrufen (z.B. um den Inhalt von
// Floating-Frames oder Applets zu ignorieren)
NextToken( nToken );
}
else switch( nToken )
{
case HTML_TABLEHEADER_ON:
case HTML_TABLEDATA_ON:
case HTML_TABLEROW_ON:
case HTML_TABLEROW_OFF:
case HTML_THEAD_ON:
case HTML_THEAD_OFF:
case HTML_TFOOT_ON:
case HTML_TFOOT_OFF:
case HTML_TBODY_ON:
case HTML_TBODY_OFF:
case HTML_TABLE_OFF:
SkipToken(-1);
case HTML_TABLEHEADER_OFF:
case HTML_TABLEDATA_OFF:
bDone = sal_True;
break;
case HTML_TABLE_ON:
{
sal_Bool bTopTable = sal_False;
sal_Bool bHasToFly = sal_False;
SvxAdjust eTabAdjust = SVX_ADJUST_END;
if( !pPendStack )
{
// nur wenn eine neue Tabelle aufgemacht wird, aber
// nicht wenn nach einem Pending in der Tabelle
// weitergelesen wird!
pSaveStruct->pTable = pTable;
// HACK: Eine Section fuer eine Tabelle anlegen, die
// in einen Rahmen kommt.
if( !pSaveStruct->IsInSection() )
{
// Diese Schleife muss vorwartes sein, weil die
// erste Option immer gewinnt.
sal_Bool bNeedsSection = sal_False;
const HTMLOptions& rHTMLOptions = GetOptions();
for (size_t i = 0; i < rHTMLOptions.size(); ++i)
{
const HTMLOption& rOption = rHTMLOptions[i];
if( HTML_O_ALIGN==rOption.GetToken() )
{
SvxAdjust eAdjust =
(SvxAdjust)rOption.GetEnum(
aHTMLPAlignTable, SVX_ADJUST_END );
bNeedsSection = SVX_ADJUST_LEFT == eAdjust ||
SVX_ADJUST_RIGHT == eAdjust;
break;
}
}
if( bNeedsSection )
{
pSaveStruct->AddContents(
InsertTableContents(bHead ) );
}
}
else
{
// Wenn wir mitlerweile in einem Rahmen stehen
// koennen wir erneut eine echte Tabelle aufmachen.
// Wir erkennen das daran, dass wir keinen
// Tabellen-Node mehr finden.
bTopTable = (0 ==
pPam->GetPoint()->nNode.GetNode().FindTableNode());
// Wenn im aktuellen Absatz Flys verankert sind,
// muss die neue Tabelle in einen Rahmen.
bHasToFly = HasCurrentParaFlys(sal_False,sal_True);
}
// in der Zelle kann sich ein Bereich befinden!
eTabAdjust = aAttrTab.pAdjust
? ((const SvxAdjustItem&)aAttrTab.pAdjust->GetItem()).
GetAdjust()
: SVX_ADJUST_END;
}
HTMLTable *pSubTable = BuildTable( eTabAdjust,
bHead,
pSaveStruct->IsInSection(),
bTopTable, bHasToFly );
if( SVPAR_PENDING != GetStatus() )
{
// nur wenn die Tabelle wirklich zu Ende ist!
if( pSubTable )
{
OSL_ENSURE( pSubTable->GetTableAdjust(sal_False)!= SVX_ADJUST_LEFT &&
pSubTable->GetTableAdjust(sal_False)!= SVX_ADJUST_RIGHT,
"links oder rechts ausgerichtete Tabellen gehoehren in Rahmen" );
HTMLTableCnts *pParentContents =
pSubTable->GetParentContents();
if( pParentContents )
{
OSL_ENSURE( !pSaveStruct->IsInSection(),
"Wo ist die Section geblieben" );
// Wenn jetzt keine Tabelle kommt haben wir eine
// Section
pSaveStruct->AddContents( pParentContents );
}
const SwStartNode *pCapStNd =
pSubTable->GetCaptionStartNode();
if( pSubTable->GetContext() )
{
OSL_ENSURE( !pSubTable->GetContext()->GetFrmFmt(),
"Tabelle steht im Rahmen" );
if( pCapStNd && pSubTable->IsTopCaption() )
{
pSaveStruct->AddContents(
new HTMLTableCnts(pCapStNd) );
}
pSaveStruct->AddContents(
new HTMLTableCnts(pSubTable) );
if( pCapStNd && !pSubTable->IsTopCaption() )
{
pSaveStruct->AddContents(
new HTMLTableCnts(pCapStNd) );
}
// Jetzt haben wir keine Section mehr
pSaveStruct->ClearIsInSection();
}
else if( pCapStNd )
{
// Da wir diese Sction nicht mehr loeschen
// koennen (sie koeente zur erster Box
// gehoeren), fuegen wir sie ein.
pSaveStruct->AddContents(
new HTMLTableCnts(pCapStNd) );
// Jetzt haben wir keine Section mehr
pSaveStruct->ClearIsInSection();
}
}
pTable = pSaveStruct->pTable;
}
}
break;
case HTML_NOBR_ON:
// HACK fuer MS: Steht das <NOBR> zu beginn der Zelle?
pSaveStruct->StartNoBreak( *pPam->GetPoint() );
break;
case HTML_NOBR_OFF:
pSaveStruct->EndNoBreak( *pPam->GetPoint() );
break;
case HTML_COMMENT:
// Mit Kommentar-Feldern werden Spaces nicht mehr geloescht
// ausserdem wollen wir fuer einen Kommentar keine neue Zelle
// anlegen !!!
NextToken( nToken );
break;
case HTML_MARQUEE_ON:
if( !pSaveStruct->IsInSection() )
{
// eine neue Section anlegen, der PaM steht dann darin
pSaveStruct->AddContents(
InsertTableContents( bHead ) );
}
bCallNextToken = sal_True;
NewMarquee( pCurTable );
break;
case HTML_TEXTTOKEN:
// keine Section fuer einen leeren String anlegen
if( !pSaveStruct->IsInSection() && 1==aToken.Len() &&
' '==aToken.GetChar(0) )
break;
default:
if( !pSaveStruct->IsInSection() )
{
// eine neue Section anlegen, der PaM steht dann darin
pSaveStruct->AddContents(
InsertTableContents( bHead ) );
}
if( IsParserWorking() || bPending )
NextToken( nToken );
break;
}
OSL_ENSURE( !bPending || !pPendStack,
"SwHTMLParser::BuildTableCell: Es gibt wieder einen Pend-Stack" );
bPending = sal_False;
if( IsParserWorking() )
SaveState( 0 );
if( !bDone )
nToken = GetNextToken();
}
if( SVPAR_PENDING == GetStatus() )
{
pPendStack = new SwPendingStack( bHead ? HTML_TABLEHEADER_ON
: HTML_TABLEDATA_ON, pPendStack );
pPendStack->pData = pSaveStruct;
return;
}
// Falls der Inhalt der Zelle leer war, muessen wir noch einen
// leeren Inhalt anlegen. Ausserdem legen wir einen leeren Inhalt
// an, wenn die Zelle mit einer Tabelle aufgehoert hat und keine
// COL-Tags hatte (sonst wurde sie wahrscheinlich von uns exportiert,
// und dann wollen wir natuerlich keinen zusaetzlichen Absatz haben).
if( !pSaveStruct->GetFirstContents() ||
(!pSaveStruct->IsInSection() && !pCurTable->HasColTags()) )
{
OSL_ENSURE( pSaveStruct->GetFirstContents() ||
!pSaveStruct->IsInSection(),
"Section oder nicht, das ist hier die Frage" );
const SwStartNode *pStNd =
InsertTableSection( static_cast< sal_uInt16 >(pSaveStruct->IsHeaderCell()
? RES_POOLCOLL_TABLE_HDLN
: RES_POOLCOLL_TABLE ));
const SwEndNode *pEndNd = pStNd->EndOfSectionNode();
SwCntntNode *pCNd = pDoc->GetNodes()[pEndNd->GetIndex()-1] ->GetCntntNode();
SvxFontHeightItem aFontHeight( 40, 100, RES_CHRATR_FONTSIZE );
pCNd->SetAttr( aFontHeight );
aFontHeight.SetWhich( RES_CHRATR_CJK_FONTSIZE );
pCNd->SetAttr( aFontHeight );
aFontHeight.SetWhich( RES_CHRATR_CTL_FONTSIZE );
pCNd->SetAttr( aFontHeight );
pSaveStruct->AddContents( new HTMLTableCnts(pStNd) );
pSaveStruct->ClearIsInSection();
}
if( pSaveStruct->IsInSection() )
{
pSaveStruct->CheckNoBreak( *pPam->GetPoint(), pDoc );
// Alle noch offenen Kontexte beenden. Wir nehmen hier
// AttrMin, weil nContxtStMin evtl. veraendert wurde.
// Da es durch EndContext wieder restauriert wird, geht das.
while( aContexts.Count() > nContextStAttrMin+1 )
{
_HTMLAttrContext *pCntxt = PopContext();
EndContext( pCntxt );
delete pCntxt;
}
// LFs am Absatz-Ende entfernen
if( StripTrailingLF()==0 && !pPam->GetPoint()->nContent.GetIndex() )
StripTrailingPara();
// falls fuer die Zelle eine Ausrichtung gesetzt wurde, muessen
// wir die beenden
_HTMLAttrContext *pCntxt = PopContext();
EndContext( pCntxt );
delete pCntxt;
}
else
{
// Alle noch offenen Kontexte beenden
while( aContexts.Count() > nContextStAttrMin )
{
_HTMLAttrContext *pCntxt = PopContext();
ClearContext( pCntxt );
delete pCntxt;
}
}
// auch eine Numerierung muss beendet werden
GetNumInfo().Clear();
SetAttr( sal_False );
pSaveStruct->InsertCell( *this, pCurTable );
// wir stehen jetzt (wahrschenlich) vor <TH>, <TD>, <TR> oder </TABLE>
delete pSaveStruct;
}
class _RowSaveStruct : public SwPendingStackData
{
public:
SvxAdjust eAdjust;
sal_Int16 eVertOri;
sal_Bool bHasCells;
_RowSaveStruct() :
eAdjust( SVX_ADJUST_END ), eVertOri( text::VertOrientation::TOP ), bHasCells( sal_False )
{}
};
void SwHTMLParser::BuildTableRow( HTMLTable *pCurTable, sal_Bool bReadOptions,
SvxAdjust eGrpAdjust,
sal_Int16 eGrpVertOri )
{
// <TR> wurde bereist gelesen
if( !IsParserWorking() && !pPendStack )
return;
int nToken = 0;
_RowSaveStruct* pSaveStruct;
sal_Bool bPending = sal_False;
if( pPendStack )
{
pSaveStruct = (_RowSaveStruct*)pPendStack->pData;
SwPendingStack* pTmp = pPendStack->pNext;
delete pPendStack;
pPendStack = pTmp;
nToken = pPendStack ? pPendStack->nToken : GetSaveToken();
bPending = SVPAR_ERROR == eState && pPendStack != 0;
SaveState( nToken );
}
else
{
SvxAdjust eAdjust = eGrpAdjust;
sal_Int16 eVertOri = eGrpVertOri;
Color aBGColor;
String aBGImage, aStyle, aId, aClass;
sal_Bool bBGColor = sal_False;
pSaveStruct = new _RowSaveStruct;
if( bReadOptions )
{
const HTMLOptions& rHTMLOptions = GetOptions();
for (size_t i = rHTMLOptions.size(); i; )
{
const HTMLOption& rOption = rHTMLOptions[--i];
switch( rOption.GetToken() )
{
case HTML_O_ID:
aId = rOption.GetString();
break;
case HTML_O_ALIGN:
eAdjust = (SvxAdjust)rOption.GetEnum(
aHTMLPAlignTable, static_cast< sal_uInt16 >(eAdjust) );
break;
case HTML_O_VALIGN:
eVertOri = rOption.GetEnum(
aHTMLTblVAlignTable, eVertOri );
break;
case HTML_O_BGCOLOR:
// Leere BGCOLOR bei <TABLE>, <TR> und <TD>/<TH> wie Netsc.
// ignorieren, bei allen anderen Tags *wirklich* nicht.
if( rOption.GetString().Len() )
{
rOption.GetColor( aBGColor );
bBGColor = sal_True;
}
break;
case HTML_O_BACKGROUND:
aBGImage = rOption.GetString();
break;
case HTML_O_STYLE:
aStyle = rOption.GetString();
break;
case HTML_O_CLASS:
aClass= rOption.GetString();
break;
}
}
}
if( aId.Len() )
InsertBookmark( aId );
SvxBrushItem *pBrushItem =
CreateBrushItem( bBGColor ? &aBGColor : 0, aBGImage, aStyle,
aId, aClass );
pCurTable->OpenRow( eAdjust, eVertOri, pBrushItem );
// ist beim ersten GetNextToken schon pending, muss bei
// wiederaufsetzen auf jedenfall neu gelesen werden!
SaveState( 0 );
}
if( !nToken )
nToken = GetNextToken(); // naechstes Token
sal_Bool bDone = sal_False;
while( (IsParserWorking() && !bDone) || bPending )
{
SaveState( nToken );
nToken = FilterToken( nToken );
OSL_ENSURE( pPendStack || !bCallNextToken ||
pCurTable->GetContext() || pCurTable->HasParentSection(),
"Wo ist die Section gebieben?" );
if( !pPendStack && bCallNextToken &&
(pCurTable->GetContext() || pCurTable->HasParentSection()) )
{
// NextToken direkt aufrufen (z.B. um den Inhalt von
// Floating-Frames oder Applets zu ignorieren)
NextToken( nToken );
}
else switch( nToken )
{
case HTML_TABLE_ON:
if( !pCurTable->GetContext() )
{
SkipToken( -1 );
bDone = sal_True;
}
break;
case HTML_TABLEROW_ON:
case HTML_THEAD_ON:
case HTML_THEAD_OFF:
case HTML_TBODY_ON:
case HTML_TBODY_OFF:
case HTML_TFOOT_ON:
case HTML_TFOOT_OFF:
case HTML_TABLE_OFF:
SkipToken( -1 );
case HTML_TABLEROW_OFF:
bDone = sal_True;
break;
case HTML_TABLEHEADER_ON:
case HTML_TABLEDATA_ON:
BuildTableCell( pCurTable, sal_True, HTML_TABLEHEADER_ON==nToken );
if( SVPAR_PENDING != GetStatus() )
{
pSaveStruct->bHasCells = sal_True;
bDone = pTable->IsOverflowing();
}
break;
case HTML_CAPTION_ON:
BuildTableCaption( pCurTable );
bDone = pTable->IsOverflowing();
break;
case HTML_CAPTION_OFF:
case HTML_TABLEHEADER_OFF:
case HTML_TABLEDATA_OFF:
case HTML_COLGROUP_ON:
case HTML_COLGROUP_OFF:
case HTML_COL_ON:
case HTML_COL_OFF:
// wo keine Zelle anfing kann auch keine aufhoehren, oder?
// und die ganzen anderen Tokens haben hier auch nicht zu
// suchen und machen nur die Tabelle kaputt
break;
case HTML_MULTICOL_ON:
// spaltige Rahmen koennen wir hier leider nicht einguegen
break;
case HTML_FORM_ON:
NewForm( sal_False ); // keinen neuen Absatz aufmachen!
break;
case HTML_FORM_OFF:
EndForm( sal_False ); // keinen neuen Absatz aufmachen!
break;
case HTML_COMMENT:
NextToken( nToken );
break;
case HTML_MAP_ON:
// eine Image-Map fuegt nichts ein, deshalb koennen wir sie
// problemlos auch ohne Zelle parsen
NextToken( nToken );
break;
case HTML_TEXTTOKEN:
if( (pCurTable->GetContext() ||
!pCurTable->HasParentSection()) &&
1==aToken.Len() && ' '==aToken.GetChar(0) )
break;
default:
pCurTable->MakeParentContents();
NextToken( nToken );
break;
}
OSL_ENSURE( !bPending || !pPendStack,
"SwHTMLParser::BuildTableRow: Es gibt wieder einen Pend-Stack" );
bPending = sal_False;
if( IsParserWorking() )
SaveState( 0 );
if( !bDone )
nToken = GetNextToken();
}
if( SVPAR_PENDING == GetStatus() )
{
pPendStack = new SwPendingStack( HTML_TABLEROW_ON, pPendStack );
pPendStack->pData = pSaveStruct;
}
else
{
pCurTable->CloseRow( !pSaveStruct->bHasCells );
delete pSaveStruct;
}
// wir stehen jetzt (wahrscheinlich) vor <TR> oder </TABLE>
}
void SwHTMLParser::BuildTableSection( HTMLTable *pCurTable,
sal_Bool bReadOptions,
sal_Bool bHead )
{
// <THEAD>, <TBODY> bzw. <TFOOT> wurde bereits gelesen
if( !IsParserWorking() && !pPendStack )
return;
int nToken = 0;
sal_Bool bPending = sal_False;
_RowSaveStruct* pSaveStruct;
if( pPendStack )
{
pSaveStruct = (_RowSaveStruct*)pPendStack->pData;
SwPendingStack* pTmp = pPendStack->pNext;
delete pPendStack;
pPendStack = pTmp;
nToken = pPendStack ? pPendStack->nToken : GetSaveToken();
bPending = SVPAR_ERROR == eState && pPendStack != 0;
SaveState( nToken );
}
else
{
pSaveStruct = new _RowSaveStruct;
if( bReadOptions )
{
const HTMLOptions& rHTMLOptions = GetOptions();
for (size_t i = rHTMLOptions.size(); i; )
{
const HTMLOption& rOption = rHTMLOptions[--i];
switch( rOption.GetToken() )
{
case HTML_O_ID:
InsertBookmark( rOption.GetString() );
break;
case HTML_O_ALIGN:
pSaveStruct->eAdjust =
(SvxAdjust)rOption.GetEnum( aHTMLPAlignTable,
static_cast< sal_uInt16 >(pSaveStruct->eAdjust) );
break;
case HTML_O_VALIGN:
pSaveStruct->eVertOri =
rOption.GetEnum( aHTMLTblVAlignTable,
pSaveStruct->eVertOri );
break;
}
}
}
// ist beim ersten GetNextToken schon pending, muss bei
// wiederaufsetzen auf jedenfall neu gelesen werden!
SaveState( 0 );
}
if( !nToken )
nToken = GetNextToken(); // naechstes Token
sal_Bool bDone = sal_False;
while( (IsParserWorking() && !bDone) || bPending )
{
SaveState( nToken );
nToken = FilterToken( nToken );
OSL_ENSURE( pPendStack || !bCallNextToken ||
pCurTable->GetContext() || pCurTable->HasParentSection(),
"Wo ist die Section gebieben?" );
if( !pPendStack && bCallNextToken &&
(pCurTable->GetContext() || pCurTable->HasParentSection()) )
{
// NextToken direkt aufrufen (z.B. um den Inhalt von
// Floating-Frames oder Applets zu ignorieren)
NextToken( nToken );
}
else switch( nToken )
{
case HTML_TABLE_ON:
if( !pCurTable->GetContext() )
{
SkipToken( -1 );
bDone = sal_True;
}
break;
case HTML_THEAD_ON:
case HTML_TFOOT_ON:
case HTML_TBODY_ON:
case HTML_TABLE_OFF:
SkipToken( -1 );
case HTML_THEAD_OFF:
case HTML_TBODY_OFF:
case HTML_TFOOT_OFF:
bDone = sal_True;
break;
case HTML_CAPTION_ON:
BuildTableCaption( pCurTable );
bDone = pTable->IsOverflowing();
break;
case HTML_CAPTION_OFF:
break;
case HTML_TABLEHEADER_ON:
case HTML_TABLEDATA_ON:
SkipToken( -1 );
BuildTableRow( pCurTable, sal_False, pSaveStruct->eAdjust,
pSaveStruct->eVertOri );
bDone = pTable->IsOverflowing();
break;
case HTML_TABLEROW_ON:
BuildTableRow( pCurTable, sal_True, pSaveStruct->eAdjust,
pSaveStruct->eVertOri );
bDone = pTable->IsOverflowing();
break;
case HTML_MULTICOL_ON:
// spaltige Rahmen koennen wir hier leider nicht einguegen
break;
case HTML_FORM_ON:
NewForm( sal_False ); // keinen neuen Absatz aufmachen!
break;
case HTML_FORM_OFF:
EndForm( sal_False ); // keinen neuen Absatz aufmachen!
break;
case HTML_TEXTTOKEN:
// Blank-Strings sind Folge von CR+LF und kein Text
if( (pCurTable->GetContext() ||
!pCurTable->HasParentSection()) &&
1==aToken.Len() && ' '==aToken.GetChar(0) )
break;
default:
pCurTable->MakeParentContents();
NextToken( nToken );
}
OSL_ENSURE( !bPending || !pPendStack,
"SwHTMLParser::BuildTableSection: Es gibt wieder einen Pend-Stack" );
bPending = sal_False;
if( IsParserWorking() )
SaveState( 0 );
if( !bDone )
nToken = GetNextToken();
}
if( SVPAR_PENDING == GetStatus() )
{
pPendStack = new SwPendingStack( bHead ? HTML_THEAD_ON
: HTML_TBODY_ON, pPendStack );
pPendStack->pData = pSaveStruct;
}
else
{
pCurTable->CloseSection( bHead );
delete pSaveStruct;
}
// now we stand (perhaps) in front of <TBODY>,... or </TABLE>
}
struct _TblColGrpSaveStruct : public SwPendingStackData
{
sal_uInt16 nColGrpSpan;
sal_uInt16 nColGrpWidth;
sal_Bool bRelColGrpWidth;
SvxAdjust eColGrpAdjust;
sal_Int16 eColGrpVertOri;
inline _TblColGrpSaveStruct();
inline void CloseColGroup( HTMLTable *pTable );
};
inline _TblColGrpSaveStruct::_TblColGrpSaveStruct() :
nColGrpSpan( 1 ), nColGrpWidth( 0 ),
bRelColGrpWidth( sal_False ), eColGrpAdjust( SVX_ADJUST_END ),
eColGrpVertOri( text::VertOrientation::TOP )
{}
inline void _TblColGrpSaveStruct::CloseColGroup( HTMLTable *pTable )
{
pTable->CloseColGroup( nColGrpSpan, nColGrpWidth,
bRelColGrpWidth, eColGrpAdjust, eColGrpVertOri );
}
void SwHTMLParser::BuildTableColGroup( HTMLTable *pCurTable,
sal_Bool bReadOptions )
{
// <COLGROUP> wurde bereits gelesen, wenn bReadOptions
if( !IsParserWorking() && !pPendStack )
return;
int nToken = 0;
sal_Bool bPending = sal_False;
_TblColGrpSaveStruct* pSaveStruct;
if( pPendStack )
{
pSaveStruct = (_TblColGrpSaveStruct*)pPendStack->pData;
SwPendingStack* pTmp = pPendStack->pNext;
delete pPendStack;
pPendStack = pTmp;
nToken = pPendStack ? pPendStack->nToken : GetSaveToken();
bPending = SVPAR_ERROR == eState && pPendStack != 0;
SaveState( nToken );
}
else
{
pSaveStruct = new _TblColGrpSaveStruct;
if( bReadOptions )
{
const HTMLOptions& rColGrpOptions = GetOptions();
for (size_t i = rColGrpOptions.size(); i; )
{
const HTMLOption& rOption = rColGrpOptions[--i];
switch( rOption.GetToken() )
{
case HTML_O_ID:
InsertBookmark( rOption.GetString() );
break;
case HTML_O_SPAN:
pSaveStruct->nColGrpSpan = (sal_uInt16)rOption.GetNumber();
break;
case HTML_O_WIDTH:
pSaveStruct->nColGrpWidth = (sal_uInt16)rOption.GetNumber();
pSaveStruct->bRelColGrpWidth =
(rOption.GetString().Search('*') != STRING_NOTFOUND);
break;
case HTML_O_ALIGN:
pSaveStruct->eColGrpAdjust =
(SvxAdjust)rOption.GetEnum( aHTMLPAlignTable,
static_cast< sal_uInt16 >(pSaveStruct->eColGrpAdjust) );
break;
case HTML_O_VALIGN:
pSaveStruct->eColGrpVertOri =
rOption.GetEnum( aHTMLTblVAlignTable,
pSaveStruct->eColGrpVertOri );
break;
}
}
}
// ist beim ersten GetNextToken schon pending, muss bei
// wiederaufsetzen auf jedenfall neu gelesen werden!
SaveState( 0 );
}
if( !nToken )
nToken = GetNextToken(); // naechstes Token
sal_Bool bDone = sal_False;
while( (IsParserWorking() && !bDone) || bPending )
{
SaveState( nToken );
nToken = FilterToken( nToken );
OSL_ENSURE( pPendStack || !bCallNextToken ||
pCurTable->GetContext() || pCurTable->HasParentSection(),
"Wo ist die Section gebieben?" );
if( !pPendStack && bCallNextToken &&
(pCurTable->GetContext() || pCurTable->HasParentSection()) )
{
// NextToken direkt aufrufen (z.B. um den Inhalt von
// Floating-Frames oder Applets zu ignorieren)
NextToken( nToken );
}
else switch( nToken )
{
case HTML_TABLE_ON:
if( !pCurTable->GetContext() )
{
SkipToken( -1 );
bDone = sal_True;
}
break;
case HTML_COLGROUP_ON:
case HTML_THEAD_ON:
case HTML_TFOOT_ON:
case HTML_TBODY_ON:
case HTML_TABLEROW_ON:
case HTML_TABLE_OFF:
SkipToken( -1 );
case HTML_COLGROUP_OFF:
bDone = sal_True;
break;
case HTML_COL_ON:
{
sal_uInt16 nColSpan = 1;
sal_uInt16 nColWidth = pSaveStruct->nColGrpWidth;
sal_Bool bRelColWidth = pSaveStruct->bRelColGrpWidth;
SvxAdjust eColAdjust = pSaveStruct->eColGrpAdjust;
sal_Int16 eColVertOri = pSaveStruct->eColGrpVertOri;
const HTMLOptions& rColOptions = GetOptions();
for (size_t i = rColOptions.size(); i; )
{
const HTMLOption& rOption = rColOptions[--i];
switch( rOption.GetToken() )
{
case HTML_O_ID:
InsertBookmark( rOption.GetString() );
break;
case HTML_O_SPAN:
nColSpan = (sal_uInt16)rOption.GetNumber();
break;
case HTML_O_WIDTH:
nColWidth = (sal_uInt16)rOption.GetNumber();
bRelColWidth =
(rOption.GetString().Search('*') != STRING_NOTFOUND);
break;
case HTML_O_ALIGN:
eColAdjust =
(SvxAdjust)rOption.GetEnum( aHTMLPAlignTable,
static_cast< sal_uInt16 >(eColAdjust) );
break;
case HTML_O_VALIGN:
eColVertOri =
rOption.GetEnum( aHTMLTblVAlignTable,
eColVertOri );
break;
}
}
pCurTable->InsertCol( nColSpan, nColWidth, bRelColWidth,
eColAdjust, eColVertOri );
// die Angaben in <COLGRP> sollen ignoriert werden, wenn
// <COL>-Elemente existieren
pSaveStruct->nColGrpSpan = 0;
}
break;
case HTML_COL_OFF:
break; // Ignorieren
case HTML_MULTICOL_ON:
// spaltige Rahmen koennen wir hier leider nicht einguegen
break;
case HTML_TEXTTOKEN:
if( (pCurTable->GetContext() ||
!pCurTable->HasParentSection()) &&
1==aToken.Len() && ' '==aToken.GetChar(0) )
break;
default:
pCurTable->MakeParentContents();
NextToken( nToken );
}
OSL_ENSURE( !bPending || !pPendStack,
"SwHTMLParser::BuildTableColGrp: Es gibt wieder einen Pend-Stack" );
bPending = sal_False;
if( IsParserWorking() )
SaveState( 0 );
if( !bDone )
nToken = GetNextToken();
}
if( SVPAR_PENDING == GetStatus() )
{
pPendStack = new SwPendingStack( HTML_COL_ON, pPendStack );
pPendStack->pData = pSaveStruct;
}
else
{
pSaveStruct->CloseColGroup( pCurTable );
delete pSaveStruct;
}
}
class _CaptionSaveStruct : public _SectionSaveStruct
{
SwPosition aSavePos;
SwHTMLNumRuleInfo aNumRuleInfo; // gueltige Numerierung
public:
_HTMLAttrTable aAttrTab; // und die Attribute
_CaptionSaveStruct( SwHTMLParser& rParser, const SwPosition& rPos ) :
_SectionSaveStruct( rParser ), aSavePos( rPos )
{
rParser.SaveAttrTab( aAttrTab );
// Die aktuelle Numerierung wurde gerettet und muss nur
// noch beendet werden.
aNumRuleInfo.Set( rParser.GetNumInfo() );
rParser.GetNumInfo().Clear();
}
const SwPosition& GetPos() const { return aSavePos; }
void RestoreAll( SwHTMLParser& rParser )
{
// Die alten Stack wiederherstellen
Restore( rParser );
// Die alte Attribut-Tabelle wiederherstellen
rParser.RestoreAttrTab( aAttrTab );
// Die alte Numerierung wieder aufspannen
rParser.GetNumInfo().Set( aNumRuleInfo );
}
virtual ~_CaptionSaveStruct();
};
_CaptionSaveStruct::~_CaptionSaveStruct()
{}
void SwHTMLParser::BuildTableCaption( HTMLTable *pCurTable )
{
// <CAPTION> wurde bereits gelesen
if( !IsParserWorking() && !pPendStack )
return;
int nToken = 0;
_CaptionSaveStruct* pSaveStruct;
if( pPendStack )
{
pSaveStruct = (_CaptionSaveStruct*)pPendStack->pData;
SwPendingStack* pTmp = pPendStack->pNext;
delete pPendStack;
pPendStack = pTmp;
nToken = pPendStack ? pPendStack->nToken : GetSaveToken();
OSL_ENSURE( !pPendStack, "Wo kommt hier ein Pending-Stack her?" );
SaveState( nToken );
}
else
{
if( pTable->IsOverflowing() )
{
SaveState( 0 );
return;
}
sal_Bool bTop = sal_True;
const HTMLOptions& rHTMLOptions = GetOptions();
for ( size_t i = rHTMLOptions.size(); i; )
{
const HTMLOption& rOption = rHTMLOptions[--i];
if( HTML_O_ALIGN == rOption.GetToken() )
{
if( rOption.GetString().EqualsIgnoreCaseAscii(OOO_STRING_SVTOOLS_HTML_VA_bottom))
bTop = sal_False;
}
}
// Alte PaM-Position retten.
pSaveStruct = new _CaptionSaveStruct( *this, *pPam->GetPoint() );
// Eine Text-Section im Icons-Bereich als Container fuer die
// Ueberschrift anlegen und PaM dort reinstellen.
const SwStartNode *pStNd;
if( pTable == pCurTable )
pStNd = InsertTempTableCaptionSection();
else
pStNd = InsertTableSection( RES_POOLCOLL_TEXT );
_HTMLAttrContext *pCntxt = new _HTMLAttrContext( HTML_CAPTION_ON );
// Tabellen-Ueberschriften sind immer zentriert.
NewAttr( &aAttrTab.pAdjust, SvxAdjustItem(SVX_ADJUST_CENTER, RES_PARATR_ADJUST) );
_HTMLAttrs &rAttrs = pCntxt->GetAttrs();
rAttrs.Insert( aAttrTab.pAdjust, rAttrs.Count() );
PushContext( pCntxt );
// StartNode der Section an der Tabelle merken.
pCurTable->SetCaption( pStNd, bTop );
// ist beim ersten GetNextToken schon pending, muss bei
// wiederaufsetzen auf jedenfall neu gelesen werden!
SaveState( 0 );
}
if( !nToken )
nToken = GetNextToken(); // naechstes Token
// </CAPTION> wird laut DTD benoetigt
sal_Bool bDone = sal_False;
while( IsParserWorking() && !bDone )
{
SaveState( nToken );
nToken = FilterToken( nToken );
switch( nToken )
{
case HTML_TABLE_ON:
if( !pPendStack )
{
pSaveStruct->pTable = pTable;
sal_Bool bHasToFly = pSaveStruct->pTable!=pCurTable;
BuildTable( pCurTable->GetTableAdjust( sal_True ),
sal_False, sal_True, sal_True, bHasToFly );
}
else
{
BuildTable( SVX_ADJUST_END );
}
if( SVPAR_PENDING != GetStatus() )
{
pTable = pSaveStruct->pTable;
}
break;
case HTML_TABLE_OFF:
case HTML_COLGROUP_ON:
case HTML_THEAD_ON:
case HTML_TFOOT_ON:
case HTML_TBODY_ON:
case HTML_TABLEROW_ON:
SkipToken( -1 );
bDone = sal_True;
break;
case HTML_CAPTION_OFF:
bDone = sal_True;
break;
default:
if( pPendStack )
{
SwPendingStack* pTmp = pPendStack->pNext;
delete pPendStack;
pPendStack = pTmp;
OSL_ENSURE( !pTmp, "weiter kann es nicht gehen!" );
}
if( IsParserWorking() )
NextToken( nToken );
break;
}
if( IsParserWorking() )
SaveState( 0 );
if( !bDone )
nToken = GetNextToken();
}
if( SVPAR_PENDING==GetStatus() )
{
pPendStack = new SwPendingStack( HTML_CAPTION_ON, pPendStack );
pPendStack->pData = pSaveStruct;
return;
}
// Alle noch offenen Kontexte beenden
while( aContexts.Count() > nContextStAttrMin+1 )
{
_HTMLAttrContext *pCntxt = PopContext();
EndContext( pCntxt );
delete pCntxt;
}
// LF am Absatz-Ende entfernen
sal_Bool bLFStripped = StripTrailingLF() > 0;
if( pTable==pCurTable )
{
// Beim spaeteren verschieben der Beschriftung vor oder hinter
// die Tabelle wird der letzte Absatz nicht mitverschoben.
// Deshalb muss sich am Ende der Section immer ein leerer
// Absatz befinden.
if( pPam->GetPoint()->nContent.GetIndex() || bLFStripped )
AppendTxtNode( AM_NOSPACE );
}
else
{
// LFs am Absatz-Ende entfernen
if( !pPam->GetPoint()->nContent.GetIndex() && !bLFStripped )
StripTrailingPara();
}
// falls fuer die Zelle eine Ausrichtung gesetzt wurde, muessen
// wir die beenden
_HTMLAttrContext *pCntxt = PopContext();
EndContext( pCntxt );
delete pCntxt;
SetAttr( sal_False );
// Stacks und Attribut-Tabelle wiederherstellen
pSaveStruct->RestoreAll( *this );
// PaM wiederherstellen.
*pPam->GetPoint() = pSaveStruct->GetPos();
delete pSaveStruct;
}
class _TblSaveStruct : public SwPendingStackData
{
public:
HTMLTable *pCurTable;
_TblSaveStruct( HTMLTable *pCurTbl ) :
pCurTable( pCurTbl )
{}
virtual ~_TblSaveStruct();
// Aufbau der Tabelle anstossen und die Tabelle ggf. in einen
// Rahmen packen. Wenn sal_True zurueckgegeben wird muss noch ein
// Absatz eingefuegt werden!
void MakeTable( sal_uInt16 nWidth, SwPosition& rPos, SwDoc *pDoc );
};
_TblSaveStruct::~_TblSaveStruct()
{}
void _TblSaveStruct::MakeTable( sal_uInt16 nWidth, SwPosition& rPos, SwDoc *pDoc )
{
pCurTable->MakeTable( 0, nWidth );
_HTMLTableContext *pTCntxt = pCurTable->GetContext();
OSL_ENSURE( pTCntxt, "Wo ist der Tabellen-Kontext" );
SwTableNode *pTblNd = pTCntxt->GetTableNode();
OSL_ENSURE( pTblNd, "Wo ist der Tabellen-Node" );
if( pDoc->GetCurrentViewShell() && pTblNd ) //swmod 071108//swmod 071225
{
// Existiert schon ein Layout, dann muss an dieser Tabelle die
// BoxFrames neu erzeugt werden.
if( pTCntxt->GetFrmFmt() )
{
pTCntxt->GetFrmFmt()->DelFrms();
pTblNd->DelFrms();
pTCntxt->GetFrmFmt()->MakeFrms();
}
else
{
pTblNd->DelFrms();
SwNodeIndex aIdx( *pTblNd->EndOfSectionNode(), 1 );
OSL_ENSURE( aIdx.GetIndex() <= pTCntxt->GetPos()->nNode.GetIndex(),
"unerwarteter Node fuer das Tabellen-Layout" );
pTblNd->MakeFrms( &aIdx );
}
}
rPos = *pTCntxt->GetPos();
}
HTMLTableOptions::HTMLTableOptions( const HTMLOptions& rOptions,
SvxAdjust eParentAdjust ) :
nCols( 0 ),
nWidth( 0 ), nHeight( 0 ),
nCellPadding( USHRT_MAX ), nCellSpacing( USHRT_MAX ),
nBorder( USHRT_MAX ),
nHSpace( 0 ), nVSpace( 0 ),
eAdjust( eParentAdjust ), eVertOri( text::VertOrientation::CENTER ),
eFrame( HTML_TF_VOID ), eRules( HTML_TR_NONE ),
bPrcWidth( sal_False ),
bTableAdjust( sal_False ),
bBGColor( sal_False ),
aBorderColor( COL_GRAY )
{
sal_Bool bBorderColor = sal_False;
sal_Bool bHasFrame = sal_False, bHasRules = sal_False;
for (size_t i = rOptions.size(); i; )
{
const HTMLOption& rOption = rOptions[--i];
switch( rOption.GetToken() )
{
case HTML_O_ID:
aId = rOption.GetString();
break;
case HTML_O_COLS:
nCols = (sal_uInt16)rOption.GetNumber();
break;
case HTML_O_WIDTH:
nWidth = (sal_uInt16)rOption.GetNumber();
bPrcWidth = (rOption.GetString().Search('%') != STRING_NOTFOUND);
if( bPrcWidth && nWidth>100 )
nWidth = 100;
break;
case HTML_O_HEIGHT:
nHeight = (sal_uInt16)rOption.GetNumber();
if( rOption.GetString().Search('%') != STRING_NOTFOUND )
nHeight = 0; // keine %-Anagben benutzen!!!
break;
case HTML_O_CELLPADDING:
nCellPadding = (sal_uInt16)rOption.GetNumber();
break;
case HTML_O_CELLSPACING:
nCellSpacing = (sal_uInt16)rOption.GetNumber();
break;
case HTML_O_ALIGN:
{
sal_uInt16 nAdjust = static_cast< sal_uInt16 >(eAdjust);
if( rOption.GetEnum( nAdjust, aHTMLPAlignTable ) )
{
eAdjust = (SvxAdjust)nAdjust;
bTableAdjust = sal_True;
}
}
break;
case HTML_O_VALIGN:
eVertOri = rOption.GetEnum( aHTMLTblVAlignTable, eVertOri );
break;
case HTML_O_BORDER:
// BORDER und BORDER=BORDER wie BORDER=1 behandeln
if( rOption.GetString().Len() &&
!rOption.GetString().EqualsIgnoreCaseAscii(OOO_STRING_SVTOOLS_HTML_O_border) )
nBorder = (sal_uInt16)rOption.GetNumber();
else
nBorder = 1;
if( !bHasFrame )
eFrame = ( nBorder ? HTML_TF_BOX : HTML_TF_VOID );
if( !bHasRules )
eRules = ( nBorder ? HTML_TR_ALL : HTML_TR_NONE );
break;
case HTML_O_FRAME:
eFrame = rOption.GetTableFrame();
bHasFrame = sal_True;
break;
case HTML_O_RULES:
eRules = rOption.GetTableRules();
bHasRules = sal_True;
break;
case HTML_O_BGCOLOR:
// Leere BGCOLOR bei <TABLE>, <TR> und <TD>/<TH> wie Netscape
// ignorieren, bei allen anderen Tags *wirklich* nicht.
if( rOption.GetString().Len() )
{
rOption.GetColor( aBGColor );
bBGColor = sal_True;
}
break;
case HTML_O_BACKGROUND:
aBGImage = rOption.GetString();
break;
case HTML_O_BORDERCOLOR:
rOption.GetColor( aBorderColor );
bBorderColor = sal_True;
break;
case HTML_O_BORDERCOLORDARK:
if( !bBorderColor )
rOption.GetColor( aBorderColor );
break;
case HTML_O_STYLE:
aStyle = rOption.GetString();
break;
case HTML_O_CLASS:
aClass = rOption.GetString();
break;
case HTML_O_DIR:
aDir = rOption.GetString();
break;
case HTML_O_HSPACE:
nHSpace = (sal_uInt16)rOption.GetNumber();
break;
case HTML_O_VSPACE:
nVSpace = (sal_uInt16)rOption.GetNumber();
break;
}
}
if( nCols && !nWidth )
{
nWidth = 100;
bPrcWidth = sal_True;
}
// Wenn BORDER=0 oder kein BORDER gegeben ist, daan darf es auch
// keine Umrandung geben
if( 0==nBorder || USHRT_MAX==nBorder )
{
eFrame = HTML_TF_VOID;
eRules = HTML_TR_NONE;
}
}
HTMLTable *SwHTMLParser::BuildTable( SvxAdjust eParentAdjust,
sal_Bool bIsParentHead,
sal_Bool bHasParentSection,
sal_Bool bMakeTopSubTable,
sal_Bool bHasToFly )
{
if( !IsParserWorking() && !pPendStack )
return 0;
int nToken = 0;
sal_Bool bPending = sal_False;
_TblSaveStruct* pSaveStruct;
if( pPendStack )
{
pSaveStruct = (_TblSaveStruct*)pPendStack->pData;
SwPendingStack* pTmp = pPendStack->pNext;
delete pPendStack;
pPendStack = pTmp;
nToken = pPendStack ? pPendStack->nToken : GetSaveToken();
bPending = SVPAR_ERROR == eState && pPendStack != 0;
SaveState( nToken );
}
else
{
pTable = 0;
HTMLTableOptions *pTblOptions =
new HTMLTableOptions( GetOptions(), eParentAdjust );
if( pTblOptions->aId.Len() )
InsertBookmark( pTblOptions->aId );
HTMLTable *pCurTable = new HTMLTable( this, pTable,
bIsParentHead,
bHasParentSection,
bMakeTopSubTable,
bHasToFly,
pTblOptions );
if( !pTable )
pTable = pCurTable;
pSaveStruct = new _TblSaveStruct( pCurTable );
delete pTblOptions;
// ist beim ersten GetNextToken schon pending, muss bei
// wiederaufsetzen auf jedenfall neu gelesen werden!
SaveState( 0 );
}
HTMLTable *pCurTable = pSaveStruct->pCurTable;
// </TABLE> wird laut DTD benoetigt
if( !nToken )
nToken = GetNextToken(); // naechstes Token
sal_Bool bDone = sal_False;
while( (IsParserWorking() && !bDone) || bPending )
{
SaveState( nToken );
nToken = FilterToken( nToken );
OSL_ENSURE( pPendStack || !bCallNextToken ||
pCurTable->GetContext() || pCurTable->HasParentSection(),
"Wo ist die Section gebieben?" );
if( !pPendStack && bCallNextToken &&
(pCurTable->GetContext() || pCurTable->HasParentSection()) )
{
// NextToken direkt aufrufen (z.B. um den Inhalt von
// Floating-Frames oder Applets zu ignorieren)
NextToken( nToken );
}
else switch( nToken )
{
case HTML_TABLE_ON:
if( !pCurTable->GetContext() )
{
// Wenn noch keine Tabelle eingefuegt wurde,
// die naechste Tabelle lesen
SkipToken( -1 );
bDone = sal_True;
}
break;
case HTML_TABLE_OFF:
bDone = sal_True;
break;
case HTML_CAPTION_ON:
BuildTableCaption( pCurTable );
bDone = pTable->IsOverflowing();
break;
case HTML_COL_ON:
SkipToken( -1 );
BuildTableColGroup( pCurTable, sal_False );
break;
case HTML_COLGROUP_ON:
BuildTableColGroup( pCurTable, sal_True );
break;
case HTML_TABLEROW_ON:
case HTML_TABLEHEADER_ON:
case HTML_TABLEDATA_ON:
SkipToken( -1 );
BuildTableSection( pCurTable, sal_False, sal_False );
bDone = pTable->IsOverflowing();
break;
case HTML_THEAD_ON:
case HTML_TFOOT_ON:
case HTML_TBODY_ON:
BuildTableSection( pCurTable, sal_True, HTML_THEAD_ON==nToken );
bDone = pTable->IsOverflowing();
break;
case HTML_MULTICOL_ON:
// spaltige Rahmen koennen wir hier leider nicht einguegen
break;
case HTML_FORM_ON:
NewForm( sal_False ); // keinen neuen Absatz aufmachen!
break;
case HTML_FORM_OFF:
EndForm( sal_False ); // keinen neuen Absatz aufmachen!
break;
case HTML_TEXTTOKEN:
// Blank-Strings sind u. U. eine Folge von CR+LF und kein Text
if( (pCurTable->GetContext() ||
!pCurTable->HasParentSection()) &&
1==aToken.Len() && ' '==aToken.GetChar(0) )
break;
default:
pCurTable->MakeParentContents();
NextToken( nToken );
break;
}
OSL_ENSURE( !bPending || !pPendStack,
"SwHTMLParser::BuildTable: Es gibt wieder einen Pend-Stack" );
bPending = sal_False;
if( IsParserWorking() )
SaveState( 0 );
if( !bDone )
nToken = GetNextToken();
}
if( SVPAR_PENDING == GetStatus() )
{
pPendStack = new SwPendingStack( HTML_TABLE_ON, pPendStack );
pPendStack->pData = pSaveStruct;
return 0;
}
_HTMLTableContext *pTCntxt = pCurTable->GetContext();
if( pTCntxt )
{
// Die Tabelle wurde auch angelegt
// Tabellen-Struktur anpassen
pCurTable->CloseTable();
// ausserhalb von Zellen begonnene Kontexte beenden
// muss vor(!) dem Umsetzten der Attribut Tabelle existieren,
// weil die aktuelle danach nicht mehr existiert
while( aContexts.Count() > nContextStAttrMin )
{
_HTMLAttrContext *pCntxt = PopContext();
ClearContext( pCntxt );
delete pCntxt;
}
nContextStMin = pTCntxt->GetContextStMin();
nContextStAttrMin = pTCntxt->GetContextStAttrMin();
if( pTable==pCurTable )
{
// Tabellen-Beschriftung setzen
const SwStartNode *pCapStNd = pTable->GetCaptionStartNode();
if( pCapStNd )
{
// Der letzte Absatz der Section wird nie mitkopiert. Deshalb
// muss die Section mindestens zwei Absaetze enthalten.
if( pCapStNd->EndOfSectionIndex() - pCapStNd->GetIndex() > 2 )
{
// Start-Node und letzten Absatz nicht mitkopieren.
SwNodeRange aSrcRg( *pCapStNd, 1,
*pCapStNd->EndOfSectionNode(), -1 );
sal_Bool bTop = pTable->IsTopCaption();
SwStartNode *pTblStNd = pTCntxt->GetTableNode();
OSL_ENSURE( pTblStNd, "Wo ist der Tabellen-Node" );
OSL_ENSURE( pTblStNd==pPam->GetNode()->FindTableNode(),
"Stehen wir in der falschen Tabelle?" );
SwNode* pNd;
if( bTop )
pNd = pTblStNd;
else
pNd = pTblStNd->EndOfSectionNode();
SwNodeIndex aDstIdx( *pNd, bTop ? 0 : 1 );
pDoc->MoveNodeRange( aSrcRg, aDstIdx,
IDocumentContentOperations::DOC_MOVEDEFAULT );
// Wenn die Caption vor der Tabelle eingefuegt wurde muss
// eine an der Tabelle gestzte Seitenvorlage noch in den
// ersten Absatz der Ueberschrift verschoben werden.
// Ausserdem muessen alle gemerkten Indizes, die auf den
// Tabellen-Node zeigen noch verschoben werden.
if( bTop )
{
MovePageDescAttrs( pTblStNd, aSrcRg.aStart.GetIndex(),
sal_False );
}
}
// Die Section wird jetzt nicht mehr gebraucht.
pPam->SetMark();
pPam->DeleteMark();
pDoc->DeleteSection( (SwStartNode *)pCapStNd );
pTable->SetCaption( 0, sal_False );
}
// SwTable aufbereiten
sal_uInt16 nBrowseWidth = (sal_uInt16)GetCurrentBrowseWidth();
pSaveStruct->MakeTable( nBrowseWidth, *pPam->GetPoint(), pDoc );
}
GetNumInfo().Set( pTCntxt->GetNumInfo() );
pTCntxt->RestorePREListingXMP( *this );
RestoreAttrTab( pTCntxt->aAttrTab );
if( pTable==pCurTable )
{
// oberen Absatz-Abstand einstellen
bUpperSpace = sal_True;
SetTxtCollAttrs();
nParaCnt = nParaCnt - Min(nParaCnt, pTCntxt->GetTableNode()->GetTable().GetTabSortBoxes().Count());
// ggfs. eine Tabelle anspringen
if( JUMPTO_TABLE == eJumpTo && pTable->GetSwTable() &&
pTable->GetSwTable()->GetFrmFmt()->GetName() == sJmpMark )
{
bChkJumpMark = sal_True;
eJumpTo = JUMPTO_NONE;
}
// Wenn Import abgebrochen wurde kein erneutes Show
// aufrufen, weil die ViewShell schon geloescht wurde!
// Genuegt nicht. Auch im ACCEPTING_STATE darf
// kein Show aufgerufen werden, weil sonst waehrend des
// Reschedules der Parser zerstoert wird, wenn noch ein
// DataAvailable-Link kommt. Deshalb: Nur im WORKING-State.
if( !nParaCnt && SVPAR_WORKING == GetStatus() )
Show();
}
}
else if( pTable==pCurTable )
{
// Es wurde gar keine Tabelle gelesen.
// Dann muss eine evtl gelesene Beschriftung noch geloescht werden.
const SwStartNode *pCapStNd = pCurTable->GetCaptionStartNode();
if( pCapStNd )
{
pPam->SetMark();
pPam->DeleteMark();
pDoc->DeleteSection( (SwStartNode *)pCapStNd );
pCurTable->SetCaption( 0, sal_False );
}
}
if( pTable == pCurTable )
{
delete pSaveStruct->pCurTable;
pSaveStruct->pCurTable = 0;
pTable = 0;
}
HTMLTable* pRetTbl = pSaveStruct->pCurTable;
delete pSaveStruct;
return pRetTbl;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|