summaryrefslogtreecommitdiff
path: root/sw/source/core/txtnode/ndtxt.cxx
blob: 56d5eb9d3c7c879a00d8e4d27f88e5025ca08294 (plain)
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
/*************************************************************************
 *
 *  $RCSfile: ndtxt.cxx,v $
 *
 *  $Revision: 1.13 $
 *
 *  last change: $Author: hr $ $Date: 2003-03-27 15:41:16 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library 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 for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifdef PRECOMPILED
#include "core_pch.hxx"
#endif

#pragma hdrstop

#include <hintids.hxx>

#ifndef _COM_SUN_STAR_I18N_SCRIPTTYPE_HDL_
#include <com/sun/star/i18n/ScriptType.hdl>
#endif
#ifndef _DRAFTS_COM_SUN_STAR_I18N_XINPUTSEQUENCECHECKER_HPP_
#include <drafts/com/sun/star/i18n/InputSequenceCheckMode.hpp>
#endif
#ifndef _SVX_FONTITEM_HXX //autogen
#include <svx/fontitem.hxx>
#endif
#ifndef _SVX_BRKITEM_HXX //autogen
#include <svx/brkitem.hxx>
#endif
#ifndef _SVX_ESCPITEM_HXX //autogen
#include <svx/escpitem.hxx>
#endif
#ifndef _SVX_LRSPITEM_HXX //autogen
#include <svx/lrspitem.hxx>
#endif
#ifndef SVTOOLS_URIHELPER_HXX
#include <svtools/urihelper.hxx>
#endif
#ifndef _SVTOOLS_LANGUAGEOPTIONS_HXX
#include <svtools/languageoptions.hxx>
#endif

#ifndef _TXTFLD_HXX //autogen
#include <txtfld.hxx>
#endif
#ifndef _TXTINET_HXX //autogen
#include <txtinet.hxx>
#endif
#ifndef _FMTINFMT_HXX //autogen
#include <fmtinfmt.hxx>
#endif
#ifndef _FMTPDSC_HXX //autogen
#include <fmtpdsc.hxx>
#endif
#ifndef _TXTATR_HXX //autogen
#include <txtatr.hxx>
#endif
#ifndef _FMTHBSH_HXX //autogen
#include <fmthbsh.hxx>
#endif
#ifndef _FMTRFMRK_HXX //autogen
#include <fmtrfmrk.hxx>
#endif
#ifndef _TXTTXMRK_HXX //autogen
#include <txttxmrk.hxx>
#endif
#ifndef _FCHRFMT_HXX //autogen
#include <fchrfmt.hxx>
#endif
#ifndef _TXTFTN_HXX //autogen
#include <txtftn.hxx>
#endif
#ifndef _FMTFLCNT_HXX //autogen
#include <fmtflcnt.hxx>
#endif
#ifndef _FMTFLD_HXX //autogen
#include <fmtfld.hxx>
#endif
#ifndef _FRMATR_HXX
#include <frmatr.hxx>
#endif
#ifndef _CHARATR_HXX
#include <charatr.hxx>
#endif
#ifndef _FTNIDX_HXX //autogen
#include <ftnidx.hxx>
#endif
#ifndef _FTNINFO_HXX //autogen
#include <ftninfo.hxx>
#endif
#ifndef _FMTFTN_HXX //autogen
#include <fmtftn.hxx>
#endif
#ifndef _CHARFMT_HXX //autogen
#include <charfmt.hxx>
#endif
#ifndef _NDTXT_HXX
#include <ndtxt.hxx>
#endif
#ifndef _DOC_HXX
#include <doc.hxx>
#endif
#ifndef _DOCARY_HXX
#include <docary.hxx>
#endif
#ifndef _PAM_HXX
#include <pam.hxx>                  // fuer SwPosition
#endif
#ifndef _FLDBAS_HXX
#include <fldbas.hxx>
#endif
#ifndef _ERRHDL_HXX
#include <errhdl.hxx>
#endif
#ifndef _FMTCOL_HXX
#include <fmtcol.hxx>
#endif
#ifndef _PARATR_HXX
#include <paratr.hxx>
#endif
#ifndef _TXTFRM_HXX
#include <txtfrm.hxx>
#endif
#ifndef _FTNFRM_HXX
#include <ftnfrm.hxx>
#endif
#ifndef _FTNBOSS_HXX
#include <ftnboss.hxx>
#endif
#ifndef _ROOTFRM_HXX
#include <rootfrm.hxx>
#endif
#ifndef _HINTS_HXX
#include <hints.hxx>                // fuer SwFmtChg in ChgTxtColl
#endif
#ifndef _PAGEDESC_HXX
#include <pagedesc.hxx>             // fuer SwPageDesc
#endif
#ifndef _EXPFLD_HXX
#include <expfld.hxx>               // fuer SwTblField
#endif
#ifndef _SECTION_HXX
#include <section.hxx>              // fuer SwSection
#endif
#ifndef _MVSAVE_HXX
#include <mvsave.hxx>
#endif
#ifndef _SWCACHE_HXX
#include <swcache.hxx>
#endif
#ifndef _WRONG_HXX
#include <wrong.hxx>                // fuer die WrongList des OnlineSpellings
#endif
#ifndef _DCONTACT_HXX
#include <dcontact.hxx>
#endif
#ifndef _REDLINE_HXX
#include <redline.hxx>
#endif
#ifndef _DOCTXM_HXX
#include <doctxm.hxx>
#endif
#ifndef _BOOKMRK_HXX
#include <bookmrk.hxx>
#endif
#ifndef _BREAKIT_HXX
#include <breakit.hxx>
#endif
#ifndef _CHECKIT_HXX
#include <checkit.hxx>
#endif


SV_DECL_PTRARR( TmpHints, SwTxtAttr*, 0, 4 )

TYPEINIT1( SwTxtNode, SwCntntNode )

SV_DECL_PTRARR(SwpHts,SwTxtAttr*,1,1)

// Leider ist das SwpHints nicht ganz wasserdicht:
// Jeder darf an den Hints rumfummeln, ohne die Sortierreihenfolge
// und Verkettung sicherstellen zu muessen.
#ifndef PRODUCT
#define CHECK_SWPHINTS(pNd)  { if( pNd->GetpSwpHints() && \
                                   !pNd->GetDoc()->IsInReading() ) \
                                  pNd->GetpSwpHints()->Check(); }
#else
#define CHECK_SWPHINTS(pNd)
#endif

SwTxtNode *SwNodes::MakeTxtNode( const SwNodeIndex & rWhere,
                                 SwTxtFmtColl *pColl,
                                 SwAttrSet* pAutoAttr )
{
    ASSERT( pColl, "Collectionpointer ist 0." );

    SwTxtNode *pNode = new SwTxtNode( rWhere, pColl, pAutoAttr );

    SwNodeIndex aIdx( *pNode );

    if( pColl && NO_NUMBERING != pColl->GetOutlineLevel() && IsDocNodes() )
        UpdateOutlineNode( *pNode, NO_NUMBERING, pColl->GetOutlineLevel() );

    //Wenn es noch kein Layout gibt oder in einer versteckten Section
    // stehen, brauchen wir uns um das MakeFrms nicht bemuehen.
    const SwSectionNode* pSectNd;
    if( !GetDoc()->GetRootFrm() ||
        ( 0 != (pSectNd = pNode->FindSectionNode()) &&
            pSectNd->GetSection().IsHiddenFlag() ))
        return pNode;

    SwNodeIndex aTmp( rWhere );
    do {
        // max. 2 Durchlaeufe:
        // 1. den Nachfolger nehmen
        // 2. den Vorgaenger

        SwNode *pNd;
        switch( ( pNd = (*this)[aTmp] )->GetNodeType() )
        {
        case ND_TABLENODE:
            ((SwTableNode*)pNd)->MakeFrms( aIdx );
            return pNode;

        case ND_SECTIONNODE:
            if( ((SwSectionNode*)pNd)->GetSection().IsHidden() ||
                ((SwSectionNode*)pNd)->IsCntntHidden() )
            {
                SwNodeIndex aTmpIdx( *pNode );
                pNd = FindPrvNxtFrmNode( aTmpIdx, pNode );
                if( !pNd )
                    return pNode;
                aTmp = *pNd;
                break;
            }
            ((SwSectionNode*)pNd)->MakeFrms( aIdx );
            return pNode;

        case ND_TEXTNODE:
        case ND_GRFNODE:
        case ND_OLENODE:
            ((SwCntntNode*)pNd)->MakeFrms( *pNode );
            return pNode;

        case ND_ENDNODE:
            if( pNd->FindStartNode()->IsSectionNode() &&
                aTmp.GetIndex() < rWhere.GetIndex() )
            {
                if( pNd->FindStartNode()->GetSectionNode()->GetSection().IsHiddenFlag())
                {
                    if( !GoPrevSection( &aTmp, TRUE, FALSE ) ||
                        aTmp.GetNode().FindTableNode() !=
                            pNode->FindTableNode() )
                        return pNode;       // schade, das wars
                }
                else
                    aTmp = *pNd->FindStartNode();
                break;
            }
            else if( pNd->FindStartNode()->IsTableNode() &&
                    aTmp.GetIndex() < rWhere.GetIndex() )
            {
                // wir stehen hinter einem TabellenNode
                aTmp = *pNd->FindStartNode();
                break;
            }
            // kein break !!!
        default:
            if( rWhere == aTmp )
                aTmp -= 2;
            else
                return pNode;
            break;
        }
    } while( TRUE );
}



// --------------------
// SwTxtNode
// --------------------

SwTxtNode::SwTxtNode( const SwNodeIndex &rWhere,
                      SwTxtFmtColl *pTxtColl,
                      SwAttrSet* pAutoAttr )
    : SwCntntNode( rWhere, ND_TEXTNODE, pTxtColl ),
      pSwpHints( 0 ), pWrong( 0 ), pNdNum( 0 ), pNdOutl( 0 )
{
    // soll eine Harte-Attributierung gesetzt werden?
    if( pAutoAttr )
        SwCntntNode::SetAttr( *pAutoAttr );

    const SfxPoolItem* pItem;
    if( GetNodes().IsDocNodes() &&
        SFX_ITEM_SET == GetSwAttrSet().GetItemState( RES_PARATR_NUMRULE,
        TRUE, &pItem ) && ((SwNumRuleItem*)pItem)->GetValue().Len() )
    {
        pNdNum = new SwNodeNum( 0 );
        SwNumRule* pRule = GetDoc()->FindNumRulePtr(
                                    ((SwNumRuleItem*)pItem)->GetValue() );
        if( pRule )
            pRule->SetInvalidRule( TRUE );
    }
}

SwTxtNode::~SwTxtNode()
{
    // delete loescht nur die Pointer, nicht die Arrayelemente!
    if( pSwpHints )
    {
        // damit Attribute die ihren Inhalt entfernen nicht doppelt
        // geloescht werden.
        SwpHints* pTmpHints = pSwpHints;
        pSwpHints = 0;

        for( register USHORT j = pTmpHints->Count(); j; )
            // erst muss das Attribut aus dem Array entfernt werden,
            // denn sonst wuerde es sich selbst loeschen (Felder) !!!!
            DestroyAttr( pTmpHints->GetHt( --j ) );

        delete pTmpHints;
    }
    delete pWrong;
    // Achtung. im Dtor von SwCntntNode kann DelFrms gerufen werden, wo
    // ggf. pWrong nochmal deletet wird, deshalb diese Zuweisung
    pWrong = NULL; // hier nicht wegoptimieren!

    delete pNdNum, pNdNum = 0;      // ggfs. wird in der BasisKlasse noch
    delete pNdOutl, pNdOutl = 0;    // darauf zugegriffen??
}

SwCntntFrm *SwTxtNode::MakeFrm()
{
    SwCntntFrm *pFrm = new SwTxtFrm(this);
    return pFrm;
}

xub_StrLen SwTxtNode::Len() const
{
    return aText.Len();
}

/*---------------------------------------------------------------------------
 * lcl_ChangeFtnRef
 *  After a split node, it's necessary to actualize the ref-pointer of the
 *  ftnfrms.
 * --------------------------------------------------------------------------*/

void lcl_ChangeFtnRef( SwTxtNode &rNode )
{
    SwpHints *pSwpHints = rNode.GetpSwpHints();
    if( pSwpHints && rNode.GetDoc()->GetRootFrm() )
    {
        SwTxtAttr* pHt;
        SwCntntFrm* pFrm = NULL;
        // OD 07.11.2002 #104840# - local variable to remember first footnote
        // of node <rNode> in order to invalidate position of its first content.
        // Thus, in its <MakeAll()> it will checked its position relative to its reference.
        SwFtnFrm* pFirstFtnOfNode = 0;
        for( register USHORT j = pSwpHints->Count(); j; )
        {
            if( RES_TXTATR_FTN == (pHt = pSwpHints->GetHt(--j))->Which() )
            {
                if( !pFrm )
                {
                    SwClientIter aNew( rNode );
                    pFrm = (SwCntntFrm*)aNew.First( TYPE(SwCntntFrm) );
//JP 11.07.00: the assert's shows incorrect an error when nodes are converted
//              to a table. Then no layout exist!
//                  ASSERT( pFrm, "lcl_ChangeFtnRef: No TxtFrm" );
//                  ASSERT( pFrm && !aNew.Next(),"lcl_ChangeFtnRef: Doublefault");
                    if( !pFrm )
                        return;
                }
                SwTxtFtn *pAttr = (SwTxtFtn*)pHt;
                ASSERT( pAttr->GetStartNode(), "FtnAtr ohne StartNode." );
                SwNodeIndex aIdx( *pAttr->GetStartNode(), 1 );
                SwCntntNode *pNd = aIdx.GetNode().GetCntntNode();
                if ( !pNd )
                    pNd = pFrm->GetAttrSet()->GetDoc()->
                            GetNodes().GoNextSection( &aIdx, TRUE, FALSE );
                if ( !pNd )
                    continue;
                SwClientIter aIter( *pNd );
                SwCntntFrm* pCntnt = (SwCntntFrm*)aIter.First(TYPE(SwCntntFrm));
                if( pCntnt )
                {
                    ASSERT( pCntnt->FindRootFrm() == pFrm->FindRootFrm(),
                            "lcl_ChangeFtnRef: Layout double?" );
                    SwFtnFrm *pFtn = pCntnt->FindFtnFrm();
                    if( pFtn && pFtn->GetAttr() == pAttr )
                    {
                        while( pFtn->GetMaster() )
                            pFtn = pFtn->GetMaster();
                        // OD 07.11.2002 #104840# - remember footnote frame
                        pFirstFtnOfNode = pFtn;
                        while ( pFtn )
                        {
                            pFtn->SetRef( pFrm );
                            pFtn = pFtn->GetFollow();
                            ((SwTxtFrm*)pFrm)->SetFtn( TRUE );
                        }
                    }
#ifndef PRODUCT
                    while( 0 != (pCntnt = (SwCntntFrm*)aIter.Next()) )
                    {
                        SwFtnFrm *pFtn = pCntnt->FindFtnFrm();
                        ASSERT( !pFtn || pFtn->GetRef() == pFrm,
                                "lcl_ChangeFtnRef: Who's that guy?" );
                    }
#endif
                }
            }
        } // end of for-loop on <SwpHints>
        // OD 08.11.2002 #104840# - invalidate
        if ( pFirstFtnOfNode )
        {
            SwCntntFrm* pCntnt = pFirstFtnOfNode->ContainsCntnt();
            if ( pCntnt )
            {
                pCntnt->_InvalidatePos();
            }
        }
    }
}

SwCntntNode *SwTxtNode::SplitNode( const SwPosition &rPos )
{
    // lege den Node "vor" mir an
    register xub_StrLen nSplitPos = rPos.nContent.GetIndex(),
                    nTxtLen = aText.Len();
    SwTxtNode* pNode = _MakeNewTxtNode( rPos.nNode, FALSE, nSplitPos==nTxtLen );

    if( GetDepends() && aText.Len() && (nTxtLen / 2) < nSplitPos )
    {
// JP 25.04.95: Optimierung fuer SplitNode:
//              Wird am Ende vom Node gesplittet, dann verschiebe die
//              Frames vom akt. auf den neuen und erzeuge fuer den akt.
//              neue. Dadurch entfaellt das neu aufbauen vom Layout.

        LockModify();   // Benachrichtigungen abschalten

        // werden FlyFrames mit verschoben, so muessen diese nicht ihre
        // Frames zerstoeren. Im SwTxtFly::SetAnchor wird es abgefragt!
        if( pSwpHints )
        {
            if( !pNode->pSwpHints )
                pNode->pSwpHints = new SwpHints;
            pNode->pSwpHints->bInSplitNode = TRUE;
        }

        //Ersten Teil des Inhalts in den neuen Node uebertragen und
        //im alten Node loeschen.
        SwIndex aIdx( this );
        Cut( pNode, aIdx, nSplitPos );

        if( GetWrong() )
            pNode->SetWrong( GetWrong()->SplitList( nSplitPos ) );

        SetWrongDirty( TRUE );

        if( pNode->pSwpHints )
        {
            if ( pNode->pSwpHints->CanBeDeleted() )
            {
                delete pNode->pSwpHints;
                pNode->pSwpHints = 0;
            }
            else
                pNode->pSwpHints->bInSplitNode = FALSE;

            // alle zeichengebundenen Rahmen, die im neuen Absatz laden
            // muessen aus den alten Frame entfernt werden:
            // JP 01.10.96: alle leeren und nicht zu expandierenden
            //              Attribute loeschen
            if( pSwpHints )
            {
                SwTxtAttr* pHt;
                xub_StrLen* pEnd;
                for( register USHORT j = pSwpHints->Count(); j; )
                    if( RES_TXTATR_FLYCNT ==
                        ( pHt = pSwpHints->GetHt( --j ) )->Which() )
                        pHt->GetFlyCnt().GetFrmFmt()->DelFrms();
                    else if( pHt->DontExpand() && 0 != ( pEnd = pHt->GetEnd() )
                            && *pHt->GetStart() == *pEnd )
                    {
                        // loeschen!
                        pSwpHints->DeleteAtPos( j );
                        DestroyAttr( pHt );
                    }
            }

        }

        SwClientIter aIter( *this );
        SwClient* pLast = aIter.GoStart();
        if( pLast )
            do
            {   SwCntntFrm *pFrm = PTR_CAST( SwCntntFrm, pLast );
                if ( pFrm )
                {
                    pNode->Add( pFrm );
                    if( pFrm->IsTxtFrm() && !pFrm->IsFollow() &&
                        ((SwTxtFrm*)pFrm)->GetOfst() )
                        ((SwTxtFrm*)pFrm)->SetOfst( 0 );
                }
            } while( 0 != ( pLast = aIter++ ));

        if ( IsInCache() )
        {
            SwFrm::GetCache().Delete( this );
            SetInCache( FALSE );
        }

        UnlockModify(); // Benachrichtigungen wieder freischalten

        const SwRootFrm *pRootFrm;
        // If there is an accessible layout we must call modify even
        // with length zero, because we have to notify about the changed
        // text node.
        if( nTxtLen != nSplitPos
#ifdef ACCESSIBLE_LAYOUT
                ||
            ( (pRootFrm = pNode->GetDoc()->GetRootFrm()) != 0 &&
               pRootFrm->IsAnyShellAccessible() )
#endif
              )

        {
            // dann sage den Frames noch, das am Ende etwas "geloescht" wurde
            if( 1 == nTxtLen - nSplitPos )
            {
                SwDelChr aHint( nSplitPos );
                pNode->SwModify::Modify( 0, &aHint );
            }
            else
            {
                SwDelTxt aHint( nSplitPos, nTxtLen - nSplitPos );
                pNode->SwModify::Modify( 0, &aHint );
            }
        }
        if( pSwpHints )
            MoveTxtAttr_To_AttrSet();
        pNode->MakeFrms( *this );       // neue Frames anlegen.
        lcl_ChangeFtnRef( *this );
    }
    else
    {
        SwWrongList *pList = GetWrong();
        pWrong = NULL;

        SetWrongDirty( TRUE );

        SwIndex aIdx( this );
        Cut( pNode, aIdx, rPos.nContent.GetIndex() );

        // JP 01.10.96: alle leeren und nicht zu expandierenden
        //              Attribute loeschen
        if( pSwpHints )
        {
            SwTxtAttr* pHt;
            xub_StrLen* pEnd;
            for( register USHORT j = pSwpHints->Count(); j; )
                if( ( pHt = pSwpHints->GetHt( --j ) )->DontExpand() &&
                    0 != ( pEnd = pHt->GetEnd() ) && *pHt->GetStart() == *pEnd )
                {
                    // loeschen!
                    pSwpHints->DeleteAtPos( j );
                    DestroyAttr( pHt );
                }
            MoveTxtAttr_To_AttrSet();
        }

        if( pList )
        {
            pNode->SetWrong( pList->SplitList( nSplitPos ) );
            pWrong = pList;
        }

        if ( GetDepends() )
            MakeFrms( *pNode );     // neue Frames anlegen.
        lcl_ChangeFtnRef( *pNode );
    }

    {
        //Hint fuer Pagedesc versenden. Das mueste eigntlich das Layout im
        //Paste der Frames selbst erledigen, aber das fuehrt dann wiederum
        //zu weiteren Folgefehlern, die mit Laufzeitkosten geloest werden
        //muesten. #56977# #55001# #56135#
        const SfxPoolItem *pItem;
        if( GetDepends() && SFX_ITEM_SET == pNode->GetSwAttrSet().
            GetItemState( RES_PAGEDESC, TRUE, &pItem ) )
            pNode->Modify( (SfxPoolItem*)pItem, (SfxPoolItem*)pItem );
    }
    return pNode;
}

void SwTxtNode::MoveTxtAttr_To_AttrSet()
{
    ASSERT( pSwpHints, "MoveTxtAttr_To_AttrSet without SwpHints?" );
    for( USHORT i = 0; pSwpHints && i < pSwpHints->Count(); ++i )
    {
        SwTxtAttr *pHt = pSwpHints->GetHt(i);

        if( *pHt->GetStart() )
            break;

        const xub_StrLen* pHtEndIdx = pHt->GetEnd();

        if( !pHtEndIdx )
            continue;

        const USHORT nWhich = pHt->Which();

        if( *pHtEndIdx < aText.Len() || pHt->IsCharFmtAttr() )
            break;

        if( !pHt->IsDontMoveAttr() &&
            SwCntntNode::SetAttr( pHt->GetAttr() ) )
        {
            pSwpHints->DeleteAtPos(i);
            DestroyAttr( pHt );
            --i;
        }
    }

}

SwCntntNode *SwTxtNode::JoinNext()
{
    SwNodes& rNds = GetNodes();
    SwNodeIndex aIdx( *this );
    if( SwCntntNode::CanJoinNext( &aIdx ) )
    {
        SwDoc* pDoc = rNds.GetDoc();
        SvULongs aBkmkArr( 15, 15 );
        _SaveCntntIdx( pDoc, aIdx.GetIndex(), USHRT_MAX, aBkmkArr, SAVEFLY );
        SwTxtNode *pTxtNode = aIdx.GetNode().GetTxtNode();
        xub_StrLen nOldLen = aText.Len();
        SwWrongList *pList = GetWrong();
        if( pList )
        {
            pList->JoinList( pTxtNode->GetWrong(), nOldLen );
            SetWrongDirty( TRUE );
            pWrong = NULL;
        }
        else
        {
            pList = pTxtNode->GetWrong();
            if( pList )
            {
                pList->Move( 0, nOldLen );
                SetWrongDirty( TRUE );
                pTxtNode->pWrong = NULL;
            }
        }
        { // wg. SwIndex
            pTxtNode->Cut( this, SwIndex(pTxtNode), pTxtNode->Len() );
        }
        // verschiebe noch alle Bookmarks/TOXMarks
        if( aBkmkArr.Count() )
            _RestoreCntntIdx( pDoc, aBkmkArr, GetIndex(), nOldLen );

        if( pTxtNode->HasAnyIndex() )
        {
            // alle Crsr/StkCrsr/UnoCrsr aus dem Loeschbereich verschieben
            pDoc->CorrAbs( aIdx, SwPosition( *this ), nOldLen, TRUE );
        }
        rNds.Delete(aIdx);
        pWrong = pList;
        InvalidateNumRule();
    }
    else
        ASSERT( FALSE, "kein TxtNode." );

    return this;
}

SwCntntNode *SwTxtNode::JoinPrev()
{
    SwNodes& rNds = GetNodes();
    SwNodeIndex aIdx( *this );
    if( SwCntntNode::CanJoinPrev( &aIdx ) )
    {
        SwDoc* pDoc = rNds.GetDoc();
        SvULongs aBkmkArr( 15, 15 );
        _SaveCntntIdx( pDoc, aIdx.GetIndex(), USHRT_MAX, aBkmkArr, SAVEFLY );
        SwTxtNode *pTxtNode = aIdx.GetNode().GetTxtNode();
        xub_StrLen nLen = pTxtNode->Len();
        SwWrongList *pList = pTxtNode->GetWrong();
        if( pList )
        {
            pList->JoinList( GetWrong(), Len() );
            SetWrongDirty( TRUE );
            pTxtNode->pWrong = NULL;
            SetWrong( NULL );
        }
        else
        {
            pList = GetWrong();
            if( pList )
            {
                pList->Move( 0, nLen );
                SetWrongDirty( TRUE );
                pWrong = NULL;
            }
        }
        { // wg. SwIndex
            pTxtNode->Cut( this, SwIndex( this ), SwIndex(pTxtNode), nLen );
        }
        // verschiebe noch alle Bookmarks/TOXMarks
        if( aBkmkArr.Count() )
            _RestoreCntntIdx( pDoc, aBkmkArr, GetIndex() );

        if( pTxtNode->HasAnyIndex() )
        {
            // alle Crsr/StkCrsr/UnoCrsr aus dem Loeschbereich verschieben
            pDoc->CorrAbs( aIdx, SwPosition( *this ), nLen, TRUE );
        }
        rNds.Delete(aIdx);
        pWrong = pList;
        InvalidateNumRule();
    }
    else
        ASSERT( FALSE, "kein TxtNode." );

    return this;
}

// erzeugt einen AttrSet mit Bereichen fuer Frame-/Para/Char-Attributen
void SwTxtNode::NewAttrSet( SwAttrPool& rPool )
{
    ASSERT( !pAttrSet, "AttrSet ist doch gesetzt" );
    pAttrSet = new SwAttrSet( rPool, aTxtNodeSetRange );
//FEATURE::CONDCOLL
//  pAttrSet->SetParent( &GetFmtColl()->GetAttrSet() );
    pAttrSet->SetParent( &GetAnyFmtColl().GetAttrSet() );
//FEATURE::CONDCOLL
}


// change the URL in the attribut - if it is a valid URL!
void lcl_CheckURLChanged( const SwFmtINetFmt& rURLAttr, const String& rText,
                            xub_StrLen nStt, xub_StrLen nEnd )
{
    if( nStt < nEnd )
    {
        xub_StrLen nS = nStt, nE = nEnd;
        String sNew( URIHelper::FindFirstURLInText( rText, nS, nE,
                                                    GetAppCharClass() ));
        if( sNew.Len() && nS == nStt && nE == nEnd )
        {
            // it is an valid URL, so set it to the URL Object
            ((SwFmtINetFmt&)rURLAttr).SetValue( rText.Copy( nS, nE - nS ));
        }
    }
}

// Ueberladen der virtuellen Update-Methode von SwIndexReg. Dadurch
// benoetigen die Text-Attribute nur xub_StrLen statt SwIndizies!
void SwTxtNode::Update( const SwIndex & aPos, xub_StrLen nLen,
                        BOOL bNegativ )
{
    SetAutoCompleteWordDirty( TRUE );

    TmpHints* pCollector = NULL;
    if( pSwpHints )
    {
        xub_StrLen nPos = aPos.GetIndex();
        xub_StrLen* pIdx;
        SwTxtAttr* pHt;
        if( bNegativ )
        {
            xub_StrLen nMax = nPos + nLen;
            for( USHORT n = 0; n < pSwpHints->Count(); ++n )
            {
                BOOL bCheckURL = FALSE, bSttBefore = FALSE;
                pHt = pSwpHints->GetHt(n);
                pIdx = pHt->GetStart();
                if( *pIdx >= nPos )
                {
                    if( *pIdx > nMax )
                         *pIdx -= nLen;
                    else
                    {
                        if( *pIdx < nMax )
                             bCheckURL = TRUE;
                         *pIdx = nPos;
                    }
                }
                else
                    bSttBefore = TRUE;

                if( 0 == (pIdx = pHt->GetEnd()) )
                    continue;

                if( *pIdx >= nPos )
                {
                    if( *pIdx > nMax )
                    {
                        *pIdx -= nLen;
                        if( bSttBefore )
                            bCheckURL = TRUE;
                    }
                    else if( *pIdx != nPos )
                    {
                        *pIdx = nPos;
                        if( bSttBefore )
                            bCheckURL = TRUE;
                    }
                }

                if( bCheckURL && RES_TXTATR_INETFMT == pHt->Which() )
                {
                    // reset the URL in the attribut - if it is a valid URL!
                    lcl_CheckURLChanged( pHt->GetINetFmt(), aText,
                                        *pHt->GetStart(), *pHt->GetEnd() );
                }

//JP 01.10.96: fuers SplitNode sollte das Flag nicht geloescht werden!
//              pHt->SetDontExpand( FALSE );
            }
            // AMA: Durch das Loeschen koennen Attribute gleiche Start-
            //      und/oder Endwerte erhalten, die vorher echt ungleich
            //      waren. Dadurch kann die Sortierung durcheinander geraten,
            //      die bei gleichen Start/Endwerten den Pointer selbst
            //      vergleicht, also ClearDummies ...
            pSwpHints->ClearDummies( *this );
            if ( !pSwpHints->Merge( *this ) )
                ((SwpHintsArr*)pSwpHints)->Resort();
        }
        else
        {
            xub_StrLen* pEnd;
            BOOL bNoExp = FALSE;
            BOOL bResort = FALSE;
            const USHORT coArrSz = RES_TXTATR_WITHEND_END - RES_CHRATR_BEGIN +
                                ( RES_UNKNOWNATR_END - RES_UNKNOWNATR_BEGIN );

            BOOL aDontExp[ coArrSz ];
            memset( &aDontExp, 0, coArrSz * sizeof(BOOL) );

            for( USHORT n = 0; n < pSwpHints->Count(); ++n )
            {
                BOOL bCheckURL = FALSE;
                pHt = pSwpHints->GetHt(n);
                pIdx = pHt->GetStart();
                if( *pIdx >= nPos )
                {
                    *pIdx += nLen;
                    if( 0 != ( pEnd = pHt->GetEnd() ) )
                        *pEnd += nLen;
                }
                else if( 0 != ( pEnd = pHt->GetEnd() ) && *pEnd >= nPos )
                {
                    if( *pEnd > nPos || IsIgnoreDontExpand() )
                    {
                        bCheckURL = TRUE;
                        *pEnd += nLen;
                    }
                    else
                    {
                        USHORT nWhPos, nWhich = pHt->Which();

                        if( RES_CHRATR_BEGIN <= nWhich &&
                            nWhich < RES_TXTATR_WITHEND_END )
                             nWhPos = nWhich - RES_CHRATR_BEGIN;
                        else if( RES_UNKNOWNATR_BEGIN <= nWhich &&
                                nWhich < RES_UNKNOWNATR_END )
                            nWhPos = nWhich - RES_UNKNOWNATR_BEGIN +
                                ( RES_TXTATR_WITHEND_END - RES_CHRATR_BEGIN );
                        else
                            continue;

                        if( aDontExp[ nWhPos ] )
                            continue;

                        if( pHt->DontExpand() )
                        {
                            pHt->SetDontExpand( FALSE );
                            bResort = TRUE;
                            if( pHt->IsCharFmtAttr() )
                            {
                                bNoExp = TRUE;
                                aDontExp[ RES_TXTATR_CHARFMT -RES_CHRATR_BEGIN ]
                                    = TRUE;
                                aDontExp[ RES_TXTATR_INETFMT -RES_CHRATR_BEGIN ]
                                    = TRUE;
                            }
                            else
                                aDontExp[ nWhPos ] = TRUE;
                        }
                        else if( bNoExp )
                        {
                             if( !pCollector )
                                pCollector = new TmpHints;
                             USHORT nCollCnt = pCollector->Count();
                             for( USHORT i = 0; i < nCollCnt; ++i )
                             {
                                SwTxtAttr *pTmp = (*pCollector)[ i ];
                                if( nWhich == pTmp->Which() )
                                {
                                    pCollector->Remove( i );
                                    delete pTmp;
                                    break;
                                }
                             }
                             SwTxtAttr *pTmp = MakeTxtAttr( pHt->GetAttr(),
                                                nPos, nPos + nLen );
                             pCollector->C40_INSERT( SwTxtAttr, pTmp, pCollector->Count() );
                        }
                        else
                        {
                            *pEnd += nLen;
                            bCheckURL = TRUE;
                        }
                    }
                }

                if( bCheckURL && RES_TXTATR_INETFMT == pHt->Which() )
                {
                    // reset the URL in the attribut - if it is a valid URL!
                    lcl_CheckURLChanged( pHt->GetINetFmt(), aText,
                                        *pHt->GetStart(), *pHt->GetEnd() );
                }
            }
            if( bResort )
                ((SwpHintsArr*)pSwpHints)->Resort();
        }
    }

    SwIndexReg aTmpIdxReg;
    if( !bNegativ )
    {
        SwIndex* pIdx;
        const SwRedlineTbl& rTbl = GetDoc()->GetRedlineTbl();
        if( rTbl.Count() )
            for( USHORT i = 0; i < rTbl.Count(); ++i )
            {
                SwRedline* pRedl = rTbl[ i ];
                if( pRedl->HasMark() )
                {
                    SwPosition* pEnd = pRedl->End();
                    if( this == &pEnd->nNode.GetNode() &&
                        *pRedl->GetPoint() != *pRedl->GetMark() &&
                        aPos.GetIndex() ==
                            (pIdx = &pEnd->nContent)->GetIndex() )
                        pIdx->Assign( &aTmpIdxReg, pIdx->GetIndex() );
                }
                else if( this == &pRedl->GetPoint()->nNode.GetNode() &&
                        aPos.GetIndex() == (pIdx = &pRedl->GetPoint()->
                            nContent)->GetIndex() )
                {
                    pIdx->Assign( &aTmpIdxReg, pIdx->GetIndex() );
                    if( &pRedl->GetBound( TRUE ) == pRedl->GetPoint() )
                    {
                        pRedl->GetBound( FALSE ) = pRedl->GetBound( TRUE );
                        pIdx = &pRedl->GetBound( FALSE ).nContent;
                    }
                    else
                    {
                        pRedl->GetBound( TRUE ) = pRedl->GetBound( FALSE );
                        pIdx = &pRedl->GetBound( TRUE ).nContent;
                    }
                    pIdx->Assign( &aTmpIdxReg, pIdx->GetIndex() );
                }
            }

        const SwBookmarks& rBkmk = GetDoc()->GetBookmarks();
        if( rBkmk.Count() )
            for( USHORT i = 0; i < rBkmk.Count(); ++i )
            {
                SwBookmark* pBkmk = rBkmk[ i ];
                if( (this == &pBkmk->GetPos().nNode.GetNode() &&
                     aPos.GetIndex() == (pIdx = (SwIndex*)&pBkmk->GetPos().
                            nContent)->GetIndex() ) ||
                    ( pBkmk->GetOtherPos() &&
                      this == &pBkmk->GetOtherPos()->nNode.GetNode() &&
                      aPos.GetIndex() == (pIdx = (SwIndex*)&pBkmk->
                              GetOtherPos()->nContent)->GetIndex() ) )
                        pIdx->Assign( &aTmpIdxReg, pIdx->GetIndex() );
            }
    }
    SwIndexReg::Update( aPos, nLen, bNegativ );
    if( pCollector )
    {
        USHORT nCount = pCollector->Count();
        for( USHORT i = 0; i < nCount; ++i )
            pSwpHints->Insert( (*pCollector)[ i ], *this, FALSE );
        delete pCollector;
    }

    aTmpIdxReg.MoveTo( *this );
}

SwFmtColl* SwTxtNode::ChgFmtColl( SwFmtColl *pNewColl )
{
    ASSERT( pNewColl,"ChgFmtColl: Collectionpointer ist 0." );
    ASSERT( HAS_BASE( SwTxtFmtColl, pNewColl ),
                "ChgFmtColl: ist kein Text-Collectionpointer." );

    SwTxtFmtColl *pOldColl = GetTxtColl();
    if( pNewColl != pOldColl )
        SwCntntNode::ChgFmtColl( pNewColl );
    // nur wenn im normalen Nodes-Array
    if( GetNodes().IsDocNodes() )
        _ChgTxtCollUpdateNum( pOldColl, (SwTxtFmtColl*)pNewColl );
    return  pOldColl;
}

void SwTxtNode::_ChgTxtCollUpdateNum( const SwTxtFmtColl *pOldColl,
                                        const SwTxtFmtColl *pNewColl)
{
    SwDoc* pDoc = GetDoc();
    ASSERT( pDoc, "Kein Doc?" );
    // erfrage die OutlineLevel und update gegebenenfalls das Nodes-Array,
    // falls sich die Level geaendert haben !
    const BYTE nOldLevel = pOldColl ? pOldColl->GetOutlineLevel():NO_NUMBERING;
    const BYTE nNewLevel = pNewColl ? pNewColl->GetOutlineLevel():NO_NUMBERING;

    SwNodes& rNds = GetNodes();
    if( nOldLevel != nNewLevel )
    {
        delete pNdOutl, pNdOutl = 0;
        // Numerierung aufheben, falls sie aus der Vorlage kommt
        // und nicht nicht aus der neuen
        if( NO_NUMBERING != nNewLevel && pNdNum && ( !GetpSwAttrSet() ||
            SFX_ITEM_SET != GetpSwAttrSet()->GetItemState(
                RES_PARATR_NUMRULE, FALSE )) &&
            (!pNewColl || SFX_ITEM_SET != pNewColl->GetItemState(
                RES_PARATR_NUMRULE )) )
            delete pNdNum, pNdNum = 0;
        if( rNds.IsDocNodes() )
            rNds.UpdateOutlineNode( *this, nOldLevel, nNewLevel );
    }

    // Update beim Level 0 noch die Fussnoten !!
    if( (!nNewLevel || !nOldLevel) && pDoc->GetFtnIdxs().Count() &&
        FTNNUM_CHAPTER == pDoc->GetFtnInfo().eNum &&
        rNds.IsDocNodes() )
    {
        SwNodeIndex aTmpIndex( rNds, GetIndex());

        pDoc->GetFtnIdxs().UpdateFtn( aTmpIndex);
    }

//FEATURE::CONDCOLL
    if( /*pOldColl != pNewColl && pNewColl && */
        RES_CONDTXTFMTCOLL == pNewColl->Which() )
    {
        // Erfrage die akt. Condition des TextNodes:
        ChkCondColl();
    }
//FEATURE::CONDCOLL
}

// Wenn man sich genau am Ende einer Text- bzw. INetvorlage befindet,
// bekommt diese das DontExpand-Flag verpasst

BOOL SwTxtNode::DontExpandFmt( const SwIndex& rIdx, BOOL bFlag,
                                BOOL bFmtToTxtAttributes )
{
    const xub_StrLen nIdx = rIdx.GetIndex();
    if( bFmtToTxtAttributes && nIdx == aText.Len() )
        FmtToTxtAttr( this );

    BOOL bRet = FALSE;
    if( pSwpHints )
    {
        const USHORT nEndCnt = pSwpHints->GetEndCount();
        USHORT nPos = nEndCnt;
        while( nPos )
        {
            SwTxtAttr *pTmp = pSwpHints->GetEnd( --nPos );
            xub_StrLen *pEnd = pTmp->GetEnd();
            if( !pEnd || *pEnd > nIdx )
                continue;
            if( nIdx != *pEnd )
                nPos = 0;
            else if( bFlag != pTmp->DontExpand() && !pTmp->IsLockExpandFlag()
                     && *pEnd > *pTmp->GetStart())
            {
                bRet = TRUE;
                pSwpHints->NoteInHistory( pTmp );
                pTmp->SetDontExpand( bFlag );
            }
        }
    }
    return bRet;
}


// gebe das vorgegebene Attribut, welches an der TextPosition (rIdx)
// gesetzt ist, zurueck. Gibt es keines, returne 0-Pointer.
// (gesetzt heisst, je nach bExpand ?
//                                    Start < rIdx <= End
//                                  : Start <= rIdx < End )

SwTxtAttr* SwTxtNode::GetTxtAttr( const SwIndex& rIdx, USHORT nWhichHt,
                                  BOOL bExpand ) const
{
    const SwTxtAttr* pRet = 0;
    const SwTxtAttr* pHt = 0;
    const xub_StrLen *pEndIdx = 0;
    const xub_StrLen nIdx = rIdx.GetIndex();
    const USHORT  nSize = pSwpHints ? pSwpHints->Count() : 0;

    for( USHORT i = 0; i < nSize; ++i )
    {
        // ist der Attribut-Anfang schon groesser als der Idx ?
        if( nIdx < *((pHt = (*pSwpHints)[i])->GetStart()) )
            break;          // beenden, kein gueltiges Attribut

        // ist es das gewuenschte Attribut ?
        if( pHt->Which() != nWhichHt )
            continue;       // nein, weiter

        pEndIdx = pHt->GetEnd();
        // liegt innerhalb des Bereiches ??
        if( !pEndIdx )
        {
            if( *pHt->GetStart() == nIdx )
            {
                pRet = pHt;
                break;
            }
        }
        else if( *pHt->GetStart() <= nIdx && nIdx <= *pEndIdx )
        {
            // Wenn bExpand gesetzt ist, wird das Verhalten bei Eingabe
            // simuliert, d.h. der Start wuede verschoben, das Ende expandiert,
            if( bExpand )
            {
                if( *pHt->GetStart() < nIdx )
                    pRet = pHt;
            }
            else
            {
                if( nIdx < *pEndIdx )
                    pRet = pHt;     // den am dichtesten liegenden
            }
        }
    }
    return (SwTxtAttr*)pRet;        // kein gueltiges Attribut gefunden !!
}

/*************************************************************************
 *                          CopyHint()
 *************************************************************************/

SwCharFmt* lcl_FindCharFmt( const SwCharFmts* pCharFmts, const XubString& rName )
{
    if( rName.Len() )
    {
        SwCharFmt* pFmt;
        USHORT nArrLen = pCharFmts->Count();
        for( USHORT i = 1; i < nArrLen; i++ )
        {
            pFmt = (*pCharFmts)[ i ];
            if( pFmt->GetName().CompareTo( rName ) == COMPARE_EQUAL )
                return pFmt;
        }
    }
    return NULL;
}

void lcl_CopyHint( const USHORT nWhich, const SwTxtAttr *pHt,
                    SwTxtAttr *pNewHt, SwDoc* pOtherDoc, SwTxtNode *pDest )
{
    ASSERT( nWhich == pHt->Which(), "Falsche Hint-Id" );
    switch( nWhich )
    {
        // Wenn wir es mit einem Fussnoten-Attribut zu tun haben,
        // muessen wir natuerlich auch den Fussnotenbereich kopieren.
        case RES_TXTATR_FTN :
            ((SwTxtFtn*)pHt)->CopyFtn( (SwTxtFtn*)pNewHt );
            break;

        // Beim Kopieren von Feldern in andere Dokumente
        // muessen die Felder bei ihren neuen Feldtypen angemeldet werden.

        // TabellenFormel muessen relativ kopiert werden.
        case RES_TXTATR_FIELD :
            {
                const SwFmtFld& rFld = pHt->GetFld();
                if( pOtherDoc )
                    ((SwTxtFld*)pHt)->CopyFld( (SwTxtFld*)pNewHt );

                // Tabellenformel ??
                if( RES_TABLEFLD == rFld.GetFld()->GetTyp()->Which()
                    && ((SwTblField*)rFld.GetFld())->IsIntrnlName() )
                {
                    // wandel die interne in eine externe Formel um
                    const SwTableNode* pDstTblNd = ((SwTxtFld*)pHt)->
                                            GetTxtNode().FindTableNode();
                    if( pDstTblNd )
                    {
                        SwTblField* pTblFld = (SwTblField*)
                                                pNewHt->GetFld().GetFld();
                        pTblFld->PtrToBoxNm( &pDstTblNd->GetTable() );
                    }
                }
            }
            break;

        case RES_TXTATR_TOXMARK :
            if( pOtherDoc && pDest && pDest->GetpSwpHints()
                && USHRT_MAX != pDest->GetpSwpHints()->GetPos( pNewHt ) )
                // Beim Kopieren von TOXMarks(Client) in andere Dokumente
                // muss der Verzeichnis (Modify) ausgetauscht werden
                ((SwTxtTOXMark*)pNewHt)->CopyTOXMark( pOtherDoc );
            break;

        case RES_TXTATR_CHARFMT :
            // Wenn wir es mit einer Zeichenvorlage zu tun haben,
            // muessen wir natuerlich auch die Formate kopieren.
            if( pDest && pDest->GetpSwpHints()
                && USHRT_MAX != pDest->GetpSwpHints()->GetPos( pNewHt ) )
            {
                SwCharFmt* pFmt = (SwCharFmt*)pHt->GetCharFmt().GetCharFmt();

                if( pFmt && pOtherDoc )
                    pFmt = pOtherDoc->CopyCharFmt( *pFmt );
                ((SwFmtCharFmt&)pNewHt->GetCharFmt()).SetCharFmt( pFmt );
            }
            break;
        case RES_TXTATR_INETFMT :
            // Wenn wir es mit benutzerdefinierten INet-Zeichenvorlagen
            // zu tun haben, muessen wir natuerlich auch die Formate kopieren.
            if( pOtherDoc && pDest && pDest->GetpSwpHints()
                && USHRT_MAX != pDest->GetpSwpHints()->GetPos( pNewHt ) )
            {
                const SwDoc* pDoc;
                if( 0!=( pDoc = ((SwTxtINetFmt*)pHt)->GetTxtNode().GetDoc() ) )
                {
                    const SwCharFmts* pCharFmts = pDoc->GetCharFmts();
                    const SwFmtINetFmt& rFmt = pHt->GetINetFmt();
                    SwCharFmt* pFmt;
                    pFmt = lcl_FindCharFmt( pCharFmts, rFmt.GetINetFmt() );
                    if( pFmt )
                        pOtherDoc->CopyCharFmt( *pFmt );
                    pFmt = lcl_FindCharFmt( pCharFmts, rFmt.GetVisitedFmt() );
                    if( pFmt )
                        pOtherDoc->CopyCharFmt( *pFmt );
                }
            }
            //JP 24.04.98: Bug 49753 - ein TextNode muss am Attribut
            //              gesetzt sein, damit die Vorlagen erzeugt
            //              werden koenne
            if( !((SwTxtINetFmt*)pNewHt)->GetpTxtNode() )
                ((SwTxtINetFmt*)pNewHt)->ChgTxtNode( pDest );

            //JP 22.10.97: Bug 44875 - Verbindung zum Format herstellen
            ((SwTxtINetFmt*)pNewHt)->GetCharFmt();
            break;
    }
}

/*************************************************************************
|*  SwTxtNode::CopyAttr()
|*  Beschreibung    kopiert Attribute an der Position nStart in pDest.
|*  BP 7.6.93:      Es werden mit Absicht nur die Attribute _mit_ EndIdx
|*                  kopiert! CopyAttr wird vornehmlich dann gerufen,
|*                  wenn Attribute fuer einen Node mit leerem String
|*                  gesetzt werden sollen.
*************************************************************************/

void SwTxtNode::CopyAttr( SwTxtNode *pDest, const xub_StrLen nTxtStartIdx,
                          const xub_StrLen nOldPos )
{
    if( pSwpHints )        // keine Attribute, keine Kekse
    {
        const xub_StrLen *pEndIdx = 0;
        const SwTxtAttr *pHt = 0;
        SwTxtAttr *pNewHt = 0;
        xub_StrLen nAttrStartIdx = 0;
        USHORT nWhich;

        SwDoc* pOtherDoc = pDest->GetDoc();
        if( pOtherDoc == GetDoc() )
            pOtherDoc = 0;

        for( USHORT i = 0; i < pSwpHints->Count(); i++ )
        {
            pHt = (*pSwpHints)[i];
            if( nTxtStartIdx < ( nAttrStartIdx = *pHt->GetStart() ) )
                break;      // ueber das Textende, da nLen == 0

            pEndIdx = pHt->GetEnd();
            if( pEndIdx )
            {
                if( ( *pEndIdx > nTxtStartIdx ||
                      ( *pEndIdx == nTxtStartIdx &&
                        nAttrStartIdx == nTxtStartIdx ) ) )
                {
                    if( RES_TXTATR_REFMARK != ( nWhich = pHt->Which()) )
                    {
                        // Attribut liegt im Bereich, also kopieren
                        if( 0 != ( pNewHt = pDest->Insert( pHt->GetAttr(),
                                                nOldPos, nOldPos ) ) )
                            lcl_CopyHint( nWhich, pHt, pNewHt, pOtherDoc, pDest );
                    }
                    else if( !pOtherDoc ? GetDoc()->IsCopyIsMove()
                                        : 0 == pOtherDoc->GetRefMark(
                                        pHt->GetRefMark().GetRefName() ) )
                        pDest->Insert( pHt->GetAttr(), nOldPos, nOldPos );
                }
            }
        }
    }

    if( this != pDest )
    {
        // Frames benachrichtigen, sonst verschwinden die Ftn-Nummern
        SwUpdateAttr aHint( nOldPos, nOldPos, 0 );
        pDest->Modify( 0, &aHint );
    }
}

/*************************************************************************
|*  SwTxtNode::Copy()
|*  Beschreibung        kopiert Zeichen und Attibute in pDest,
|*                      wird angehaengt
*************************************************************************/

void SwTxtNode::Copy( SwTxtNode *pDest, const SwIndex &rStart, xub_StrLen nLen )
{
    SwIndex aIdx( pDest, pDest->aText.Len() );
    Copy( pDest, aIdx, rStart, nLen );
}

void SwTxtNode::Copy( SwTxtNode *pDest, const SwIndex &rDestStart,
                      const SwIndex &rStart, xub_StrLen nLen)
{
    xub_StrLen nTxtStartIdx = rStart.GetIndex();
    xub_StrLen nDestStart = rDestStart.GetIndex();      // alte Pos merken

    if( !nLen )
    {
        // wurde keine Laenge angegeben, dann Kopiere die Attribute
        // an der Position rStart.
        CopyAttr( pDest, nTxtStartIdx, nDestStart );

        // harte Absatz umspannende Attribute kopieren
        if( GetpSwAttrSet() )
        {
            // alle, oder nur die CharAttribute ?
            if( nDestStart || pDest->GetpSwAttrSet() ||
                nLen != pDest->GetTxt().Len() )
            {
                SfxItemSet aCharSet( pDest->GetDoc()->GetAttrPool(),
                                    RES_CHRATR_BEGIN, RES_CHRATR_END-1,
                                    RES_TXTATR_CHARFMT, RES_TXTATR_CHARFMT,
                                    RES_TXTATR_INETFMT, RES_TXTATR_INETFMT,
                                    RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1,
                                    0 );
                aCharSet.Put( *GetpSwAttrSet() );
                if( aCharSet.Count() )
                    pDest->SetAttr( aCharSet, nDestStart, nDestStart );
            }
            else
                GetpSwAttrSet()->CopyToModify( *pDest );
        }

        return;
    }

    // 1. Text kopieren
    xub_StrLen i = pDest->aText.Len() - nDestStart;
    //JP 15.02.96: Bug 25537 - Attributbehandlung am Ende fehlt! Darum
    //              ueber die InsertMethode den Text einfuegen und nicht
    //              selbst direkt
    pDest->Insert( aText.Copy( nTxtStartIdx, nLen ), rDestStart,
                                                    INS_EMPTYEXPAND );

    // um reale Groesse Updaten !
    nLen = pDest->aText.Len() - nDestStart - i;
    if( !nLen )                                 // String nicht gewachsen ??
        return;

    i = 0;
    const xub_StrLen *pEndIdx = 0;
    xub_StrLen nAttrStartIdx = 0;
    const SwTxtAttr *pHt = 0;
    SwTxtAttr *pNewHt = 0;

    SwDoc* pOtherDoc = pDest->GetDoc();
    if( pOtherDoc == GetDoc() )
        pOtherDoc = 0;

    // harte Absatz umspannende Attribute kopieren
    if( GetpSwAttrSet() )
    {
        // alle, oder nur die CharAttribute ?
        if( nDestStart || pDest->GetpSwAttrSet() ||
            nLen != pDest->GetTxt().Len() )
        {
            SfxItemSet aCharSet( pDest->GetDoc()->GetAttrPool(),
                                RES_CHRATR_BEGIN, RES_CHRATR_END-1,
                                RES_TXTATR_CHARFMT, RES_TXTATR_CHARFMT,
                                RES_TXTATR_INETFMT, RES_TXTATR_INETFMT,
                                RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1,
                                0 );
            aCharSet.Put( *GetpSwAttrSet() );
            if( aCharSet.Count() )
                pDest->SetAttr( aCharSet, nDestStart, nDestStart + nLen );
        }
        else
            GetpSwAttrSet()->CopyToModify( *pDest );
    }


    const BOOL bUndoNodes = !pOtherDoc && GetDoc()->GetUndoNds() == &GetNodes();

    // Ende erst jetzt holen, weil beim Kopieren in sich selbst der
    // Start-Index und alle Attribute vorher aktualisiert werden.
    nTxtStartIdx = rStart.GetIndex();
    xub_StrLen nEnd = nTxtStartIdx + nLen;

    // 2. Attribute kopieren
    // durch das Attribute-Array, bis der Anfang des Geltungsbereiches
    // des Attributs hinter dem zu kopierenden Bereich liegt
    USHORT nWhich, nSize = pSwpHints ? pSwpHints->Count() : 0;
    xub_StrLen nAttrStt, nAttrEnd;

    // wird in sich selbst kopiert, dann kann beim Einfuegen ein
    // Attribut geloescht werden. Darum erst ins Tmp-Array kopieren und
    // dann erst ins eigene uebertragen.
    SwpHts aArr( 5 );

    // Del-Array fuer alle RefMarks ohne Ausdehnung
    SwpHts aRefMrkArr;

        //Achtung: kann ungueltig sein!!
    while( ( i < nSize ) &&
           ((nAttrStartIdx = *(*pSwpHints)[i]->GetStart()) < nEnd) )
    {
        pHt = (*pSwpHints)[i];
        pNewHt = 0;
        pEndIdx = pHt->GetEnd();
        nWhich = pHt->Which();

        // JP 26.04.94: REFMARK's werden nie kopiert. Hat das Refmark aber
        //              keinen Bereich umspannt, so steht im Text ein 255
        //              dieses muss entfernt werden. Trick: erst kopieren,
        //              erkennen und sammeln, nach dem kopieren Loeschen.
        //              Nimmt sein Zeichen mit ins Grab !!
        // JP 14.08.95: Duerfen RefMarks gemovt werden?
        int bCopyRefMark = RES_TXTATR_REFMARK == nWhich && ( bUndoNodes ||
                           (!pOtherDoc ? GetDoc()->IsCopyIsMove()
                                      : 0 == pOtherDoc->GetRefMark(
                                        pHt->GetRefMark().GetRefName() )));

        if( pEndIdx && RES_TXTATR_REFMARK == nWhich && !bCopyRefMark )
        {
            ++i;
            continue;
        }

        if( nAttrStartIdx < nTxtStartIdx )
        {
            // Anfang liegt vor dem Bereich
            if( pEndIdx && ( nAttrEnd = *pEndIdx ) > nTxtStartIdx )
            {
                // Attribut mit einem Bereich
                // und das Ende des Attribut liegt im Bereich
                nAttrStt = nDestStart;
                nAttrEnd = nAttrEnd > nEnd
                            ? rDestStart.GetIndex()
                            : nDestStart + nAttrEnd - nTxtStartIdx;
            }
            else
            {
                ++i;
                continue;
            }
        }
        else
        {
            // der Anfang liegt innerhalb des Bereiches
            nAttrStt = nDestStart + ( nAttrStartIdx - nTxtStartIdx );
            if( pEndIdx )
                nAttrEnd = *pEndIdx > nEnd
                            ? rDestStart.GetIndex()
                            : nDestStart + ( *pEndIdx - nTxtStartIdx );
            else
                nAttrEnd = nAttrStt;
        }

        if( pDest == this )
        {
            // die Daten kopieren
            pNewHt = MakeTxtAttr( pHt->GetAttr(), nAttrStt, nAttrEnd );

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//JP 23.04.95:  erstmal so gesondert hier behandeln. Am Besten ist es
//              aber im CopyFtn wenn die pDestFtn keinen StartNode hat,
//              sich diesen dann anlegt.
//              Aber so kurz vor der BETA besser nicht anfassen.
            if( RES_TXTATR_FTN == nWhich )
            {
                SwTxtFtn* pFtn = (SwTxtFtn*)pNewHt;
                pFtn->ChgTxtNode( this );
                pFtn->MakeNewTextSection( GetNodes() );
                lcl_CopyHint( nWhich, pHt, pFtn, 0, 0 );
                pFtn->ChgTxtNode( 0 );
            }
            else
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            {
                lcl_CopyHint( nWhich, pHt, pNewHt, 0, pDest );
            }
            aArr.C40_INSERT( SwTxtAttr, pNewHt, aArr.Count() );
        }
        else
        {
            pNewHt = pDest->Insert( pHt->GetAttr(), nAttrStt,
                                    nAttrEnd, SETATTR_NOTXTATRCHR );
            if( pNewHt )
                lcl_CopyHint( nWhich, pHt, pNewHt, pOtherDoc, pDest );
            else if( !pEndIdx )
            {
                // Attribut wurde nicht kopiert, hat seinen Inhalt mitgenommen!
                // Damit der rest aber korrekt kopiert werden kann, muss das
                // Zeichen wieder an der Position stehen. Darum hier ein
                // "Dummy-TextAttribut" einfuegen, wird am Ende wieder entfernt!
                pNewHt = pDest->Insert( SwFmtHardBlank( 0xB7 ), nAttrStt, 0
                                        /*???, INS_NOHINTEXPAND*/ );
                aRefMrkArr.C40_INSERT( SwTxtAttr, pNewHt, aRefMrkArr.Count() );
            }
        }

        if( RES_TXTATR_REFMARK == nWhich && !pEndIdx && !bCopyRefMark )
        {
            aRefMrkArr.C40_INSERT( SwTxtAttr, pNewHt, aRefMrkArr.Count() );
        }

        ++i;
    }

    // nur falls im Array Attribute stehen (kann nur beim Kopieren
    // sich selbst passieren!!)
    for( i = 0; i < aArr.Count(); ++i )
        Insert( aArr[ i ], SETATTR_NOTXTATRCHR );

    if( pDest->GetpSwpHints() )
        for( i = 0; i < aRefMrkArr.Count(); ++i )
        {
            pNewHt = aRefMrkArr[i];
            if( pNewHt->GetEnd() )
            {
                pDest->GetpSwpHints()->Delete( pNewHt );
                pDest->DestroyAttr( pNewHt );
            }
            else
            {
                const SwIndex aIdx( pDest, *pNewHt->GetStart() );
                pDest->Erase( aIdx, 1 );
            }
        }

    CHECK_SWPHINTS(this);
}


/*
 * Rudimentaeres Editieren, damit die SwDoc-Insert-Methoden
 * funktionieren.
 */

SwTxtNode& SwTxtNode::Insert( const XubString   &rStr,
                              const SwIndex &rIdx, const USHORT nMode )
{
    ASSERT( rIdx <= aText.Len(), "Array ueberindiziert." );
    ASSERT( (ULONG)aText.Len() + (ULONG)rStr.Len() <= STRING_LEN,
            "STRING_LEN ueberschritten." );

    xub_StrLen aPos = rIdx.GetIndex();
    xub_StrLen nLen = aText.Len() - aPos;

    // sequence input checking
    sal_Bool bInputChecked = sal_False;

    // We check only buffers which contain less than MAX_SEQUENCE_CHECK_LEN
    // characters. This is for performance reasons, because a "copy and paste"
    // can give us a really big input string.
    SvtLanguageOptions aLangOptions;
    if ( aLangOptions.IsCTLFontEnabled() &&
         aLangOptions.IsCTLSequenceChecking() && aPos &&
         rStr.Len() < MAX_SEQUENCE_CHECK_LEN && pBreakIt->xBreak.is() &&
         ::com::sun::star::i18n::ScriptType::COMPLEX ==
         pBreakIt->xBreak->getScriptType( rStr, 0 ) )
    {
        // generate new sequence input checker if not already done
        if ( ! pCheckIt )
            pCheckIt = new SwCheckIt;

        if ( pCheckIt->xCheck.is() )
        {
            xub_StrLen nI = 0;
            xub_StrLen nTmpPos = aPos;
            xub_Unicode cChar;

            while ( nI < rStr.Len() )
            {
                cChar = rStr.GetChar( nI++ );
                if ( pCheckIt->xCheck->checkInputSequence(
                        aText, nTmpPos - 1, cChar,
                        ::drafts::com::sun::star::i18n::InputSequenceCheckMode::BASIC ) )
                {
                    // character can be inserted
                    aText.Insert( cChar, nTmpPos++ );
                }
            }
            bInputChecked = sal_True;
        }
    }

    if ( ! bInputChecked )
        aText.Insert( rStr, aPos );

    nLen = aText.Len() - aPos - nLen;
    if( !nLen )                         // String nicht gewachsen ??
        return *this;
    Update( rIdx, nLen );       // um reale Groesse Updaten !

    // analog zu Insert(char) in txtedt.cxx:
    // 1) bei bHintExp leere Hints an rIdx.GetIndex suchen und aufspannen
    // 2) bei bHintExp == FALSE mitgezogene Feldattribute zuruecksetzen

    register USHORT i;

    if( pSwpHints )
    {
       for( i = 0; i < pSwpHints->Count() &&
                rIdx >= *(*pSwpHints)[i]->GetStart(); ++i )
        {
            SwTxtAttr *pHt = pSwpHints->GetHt( i );
            xub_StrLen* pEndIdx = pHt->GetEnd();
            if( !pEndIdx )
                continue;

            if( rIdx == *pEndIdx )
            {
                if( nMode & INS_NOHINTEXPAND || pHt->DontExpand() )
                {
                    // bei leeren Attributen auch Start veraendern
                    if( rIdx == *pHt->GetStart() )
                        *pHt->GetStart() -= nLen;
                    *pEndIdx -= nLen;
                }
                    // leere Hints an rIdx.GetIndex ?
                else if( nMode & INS_EMPTYEXPAND &&
                        *pEndIdx == *pHt->GetStart() )
                {
                    *pHt->GetStart() -= nLen;

                    // 8484: Symbol von 0-4, Roman von 4-6,
                    //       neuer Hint: Roman 4-4

                    // - while ... die Vorgaenger ueberpruefen:
                    // wenn gleiches Ende und gleicher Which
                    // => das Ende des gefundenen zuruecksetzen
                    const USHORT nWhich = pHt->Which();
                    SwTxtAttr *pFound;
                    xub_StrLen *pFoundEnd;
                    for( USHORT j = 0; j < i; ++j )
                        if( 0 != (pFound = pSwpHints->GetHt( j )) &&
                            nWhich == pFound->Which() &&
                            0 != ( pFoundEnd = pFound->GetEnd() ) &&
                            rIdx == *pFoundEnd )
                        {
                            *pFoundEnd -= nLen;
                            const USHORT nAktHtLen = pSwpHints->Count();
                            pSwpHints->DeleteAtPos(j);
                            Insert( pFound, SETATTR_NOHINTADJUST );
                            // AMA: Sicher ist sicher, falls pFound weiter hinten
                            // einsortiert wurde, koennte sonst die neue Position
                            // j vergessen werden!
                            if ( j ) --j;
                            // falls Attribute zusammengefasst werden, steht
                            // der "Index" ins Array falsch !
                            i -= nAktHtLen - pSwpHints->Count();
                            // Insert und Delete ?
                        }

                    // ist unser Attribut ueberhaupt noch vorhanden ?
                    if( pHt == pSwpHints->GetHt( i ) )
                    {
                        const USHORT nAktLen = pSwpHints->Count();
                        pSwpHints->DeleteAtPos(i);
                        Insert( pHt, SETATTR_NOHINTADJUST );
                        if( nAktLen > pSwpHints->Count() && i )
                            --i;
                    }
                    continue;
                }
                else
                    continue;
                pSwpHints->DeleteAtPos(i);
                Insert( pHt, SETATTR_NOHINTADJUST );
            }
            if ( !(nMode & INS_NOHINTEXPAND) &&
                 rIdx == nLen && *pHt->GetStart() == rIdx.GetIndex() &&
                 !pHt->IsDontExpandStartAttr() )
            {
                // Kein Feld, am Absatzanfang, HintExpand
                pSwpHints->DeleteAtPos(i);
                *pHt->GetStart() -= nLen;
                Insert( pHt, SETATTR_NOHINTADJUST );
            }
        }
        if ( pSwpHints->CanBeDeleted() )
            DELETEZ( pSwpHints );
    }

    if ( GetDepends() )
    {
        SwInsTxt aHint( aPos, nLen );
        SwModify::Modify( 0, &aHint );
    }

    CHECK_SWPHINTS(this);
    return *this;
}

/*************************************************************************
|*
|*  SwTxtNode::Cut()
|*
|*  Beschreibung        text.doc
|*  Ersterstellung      VB 20.03.91
|*  Letzte Aenderung    JP 11.08.94
|*
*************************************************************************/

void SwTxtNode::Cut( SwTxtNode *pDest, const SwIndex &rStart, xub_StrLen nLen )
{
    if(pDest)
    {
        SwIndex aDestStt( pDest, pDest->GetTxt().Len() );
        _Cut( pDest, aDestStt, rStart, nLen, FALSE );
    }
    else
        Erase( rStart, nLen );
}


void SwTxtNode::_Cut( SwTxtNode *pDest, const SwIndex& rDestStart,
                     const SwIndex &rStart, xub_StrLen nLen, BOOL bUpdate )
{
    if(!pDest)
    {
        Erase( rStart, nLen );
        return;
    }

    // nicht im Dokument verschieben ?
    if( GetDoc() != pDest->GetDoc() )
    {
        Copy( pDest, rDestStart, rStart, nLen);
        Erase(rStart,nLen);
        return;
    }

    if( !nLen )
    {
        // wurde keine Laenge angegeben, dann Kopiere die Attribute
        // an der Position rStart.
        CopyAttr( pDest, rStart.GetIndex(), rDestStart.GetIndex() );
        return;
    }

    xub_StrLen nTxtStartIdx = rStart.GetIndex();
    xub_StrLen nDestStart = rDestStart.GetIndex();      // alte Pos merken
    xub_StrLen nInitSize = pDest->aText.Len();

    xub_StrLen *pEndIdx = 0;
    xub_StrLen nAttrStartIdx = 0;
    SwTxtAttr *pHt = 0;
    SwTxtAttr *pNewHt = 0;

    // wird in sich selbst verschoben, muss es gesondert behandelt werden !!
    if( pDest == this )
    {
        aText.Insert( aText, nTxtStartIdx, nLen, nDestStart );
        aText.Erase( nTxtStartIdx + (nDestStart<nTxtStartIdx ? nLen : 0), nLen );

        xub_StrLen nEnd = rStart.GetIndex() + nLen;
        USHORT n;

        // dann suche mal alle Attribute zusammen, die im verschobenen
        // Bereich liegen. Diese werden in das extra Array verschoben,
        // damit sich die Indizies beim Updaten nicht veraendern !!!
        SwIndexReg aTmpRegArr;
        SwpHts aArr( 5 );

        // 2. Attribute verschieben
        // durch das Attribute-Array, bis der Anfang des Geltungsbereiches
        // des Attributs hinter dem zu verschiebenden Bereich liegt
        USHORT nAttrCnt = 0, nWhich;
        while(  pSwpHints && nAttrCnt < pSwpHints->Count() &&
                (nAttrStartIdx = *(pHt = pSwpHints->GetHt(nAttrCnt))->
                                    GetStart()) < nEnd )
        {
            pNewHt = 0;
            pEndIdx = pHt->GetEnd();

            if(nAttrStartIdx < nTxtStartIdx)
            {
                // Anfang liegt vor dem Bereich
                if( RES_TXTATR_REFMARK != ( nWhich = pHt->Which() ) &&
                    pEndIdx && *pEndIdx > nTxtStartIdx )
                {
                    // Attribut mit einem Bereich
                    // und das Ende des Attribut liegt im Bereich
                    pNewHt = MakeTxtAttr( pHt->GetAttr(), 0,
                                        *pEndIdx > nEnd
                                            ? nLen
                                            : *pEndIdx - nTxtStartIdx );
                }
            }
            else
            {
                // der Anfang liegt vollstaendig im Bereich
                if( !pEndIdx || *pEndIdx < nEnd )
                {
                    // Attribut verschieben
                    pSwpHints->Delete( pHt );
                    // die Start/End Indicies neu setzen
                    *pHt->GetStart() = nAttrStartIdx - nTxtStartIdx;
                    if( pEndIdx )
                        *pHt->GetEnd() = *pEndIdx - nTxtStartIdx;
                    aArr.C40_INSERT( SwTxtAttr, pHt, aArr.Count() );
                    continue;           // while-Schleife weiter, ohne ++ !
                }
                    // das Ende liegt dahinter
                else if( RES_TXTATR_REFMARK != ( nWhich = pHt->Which() ))
                {
                    pNewHt = MakeTxtAttr( pHt->GetAttr(),
                            nAttrStartIdx - nTxtStartIdx,
                            !pEndIdx ? 0
                                     : ( *pEndIdx > nEnd
                                            ? nLen
                                            : *pEndIdx - nTxtStartIdx ));
                }
            }
            if( pNewHt )
            {
                // die Daten kopieren
                lcl_CopyHint( nWhich, pHt, pNewHt, 0, this );
                aArr.C40_INSERT( SwTxtAttr, pNewHt, aArr.Count() );
            }
            ++nAttrCnt;
        }

        if( bUpdate )
            // Update aller Indizies
            Update( rDestStart, nLen );
#ifdef CUTNOEXPAND
        else
            // wird am Ende eingefuegt, nur die Attribut-Indizies verschieben
            if( 0 < nLen && 0 < nInitSize && pSwpHints )
            {
                // siehe nach, ob an der Einfuegeposition das Ende eines
                // Attributes stand. Ist es kein Feld, muss es expandiert werden !!!
                for( n = 0; n < pSwpHints->Count(); n++ )
                {
                    pHt = pSwpHints->GetHt(n);
                    if( 0 != ( pEndIdx = pHt->GetEnd() ) &&
                        *pEndIdx == nInitSize )
                        *pEndIdx += nLen;
                }
            }
#endif
        CHECK_SWPHINTS(this);

        Update( rStart, nLen, TRUE );

        CHECK_SWPHINTS(this);

        // dann setze die kopierten/geloeschten Attribute in den Node
        if( nDestStart <= nTxtStartIdx )
            nTxtStartIdx += nLen;
        else
            nDestStart -= nLen;

        for( n = 0; n < aArr.Count(); ++n )
        {
            pNewHt = aArr[n];
            *pNewHt->GetStart() = nDestStart + *pNewHt->GetStart();
            if( 0 != ( pEndIdx = pNewHt->GetEnd() ))
                *pEndIdx = nDestStart + *pEndIdx;
            Insert( pNewHt, SETATTR_NOTXTATRCHR );
        }
    }
    else
    {
        xub_StrLen i = nInitSize - nDestStart;
        pDest->aText.Insert( aText, nTxtStartIdx, nLen, nDestStart );
        aText.Erase( nTxtStartIdx, nLen );
        nLen = pDest->aText.Len() - nDestStart - i;  // um reale Groesse Updaten !
        if( !nLen )                 // String nicht gewachsen ??
            return;

        i = 0;

        if( bUpdate )
            // Update aller Indizies
            pDest->Update( rDestStart, nLen);
#ifdef CUTNOEXPAND
        else
            // wird am Ende eingefuegt, nur die Attribut-Indizies verschieben
            if( 0 < nLen && 0 < nInitSize && pDest->pSwpHints )
            {
                // siehe nach, ob an der Einfuegeposition das Ende eines
                // Attributes stand. Ist es kein Feld, muss es expandiert werden !!!
                for( USHORT n = 0; n < pDest->pSwpHints->Count(); n++ )
                {
                    pHt = pDest->pSwpHints->GetHt(n);
                    if( 0 != ( pEndIdx = pHt->GetEnd() ) &&
                        *pEndIdx == nInitSize )
                        *pEndIdx += nLen;
                }
            }
#endif
        CHECK_SWPHINTS(pDest);

        USHORT nEnd = rStart.GetIndex() + nLen;
        SwDoc* pOtherDoc = pDest->GetDoc();
        if( pOtherDoc == GetDoc() )
            pOtherDoc = 0;
        const BOOL bUndoNodes = !pOtherDoc && GetDoc()->GetUndoNds() == &GetNodes();

        // harte Absatz umspannende Attribute kopieren
        if( GetpSwAttrSet() )
        {
            // alle, oder nur die CharAttribute ?
            if( nInitSize || pDest->GetpSwAttrSet() ||
                nLen != pDest->GetTxt().Len() )
            {
                SfxItemSet aCharSet( pDest->GetDoc()->GetAttrPool(),
                                    RES_CHRATR_BEGIN, RES_CHRATR_END-1,
                                    RES_TXTATR_CHARFMT, RES_TXTATR_CHARFMT,
                                    RES_TXTATR_INETFMT, RES_TXTATR_INETFMT,
                                    RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1,
                                    0 );
                aCharSet.Put( *GetpSwAttrSet() );
                if( aCharSet.Count() )
                    pDest->SetAttr( aCharSet, nDestStart, nDestStart + nLen );
            }
            else
                GetpSwAttrSet()->CopyToModify( *pDest );
        }

        // 2. Attribute verschieben
        // durch das Attribute-Array, bis der Anfang des Geltungsbereiches
        // des Attributs hinter dem zu verschiebenden Bereich liegt
        USHORT nAttrCnt = 0, nWhich;
        while( pSwpHints && nAttrCnt < pSwpHints->Count() &&
                ( (nAttrStartIdx = *(pHt = pSwpHints->GetHt(nAttrCnt))->
                                    GetStart()) < nEnd ) )
        {
            pNewHt = 0;
            pEndIdx = pHt->GetEnd();

            if(nAttrStartIdx < nTxtStartIdx)
            {
                // Anfang liegt vor dem Bereich
                if( ( RES_TXTATR_REFMARK != ( nWhich = pHt->Which() )
                    || bUndoNodes ) && pEndIdx && *pEndIdx > nTxtStartIdx )
                {
                    // Attribut mit einem Bereich
                    // und das Ende des Attribut liegt im Bereich
                    pNewHt = pDest->MakeTxtAttr( pHt->GetAttr(), nDestStart,
                                        nDestStart + (
                                        *pEndIdx > nEnd
                                            ? nLen
                                            : *pEndIdx - nTxtStartIdx ) );
                }
            }
            else
            {
                // der Anfang liegt vollstaendig im Bereich
                nWhich = pHt->Which();
                if( !pEndIdx || *pEndIdx < nEnd ||
                    ( !pOtherDoc && !bUndoNodes && RES_TXTATR_REFMARK
                        == nWhich ) )
                {
                    // Attribut verschieben
                    pSwpHints->Delete( pHt );
                    // die Start/End Indicies neu setzen
                    *pHt->GetStart() =
                            nDestStart + (nAttrStartIdx - nTxtStartIdx);
                    if( pEndIdx )
                        *pHt->GetEnd() = nDestStart + (
                                        *pEndIdx > nEnd
                                            ? nLen
                                            : *pEndIdx - nTxtStartIdx );
                    pDest->Insert( pHt, SETATTR_NOTXTATRCHR | SETATTR_DONTREPLACE );
                    continue;           // while-Schleife weiter, ohne ++ !
                }
                    // das Ende liegt dahinter
                else if( RES_TXTATR_REFMARK != nWhich || bUndoNodes )
                {
                    pNewHt = MakeTxtAttr( pHt->GetAttr(),
                            nDestStart + (nAttrStartIdx - nTxtStartIdx),
                            !pEndIdx ? 0
                                     : nDestStart + ( *pEndIdx > nEnd
                                            ? nLen
                                            : *pEndIdx - nTxtStartIdx ));
                }
            }
            if ( pNewHt )
            {
                if( pDest->Insert( pNewHt, SETATTR_NOTXTATRCHR | SETATTR_DONTREPLACE ))
                    lcl_CopyHint( nWhich, pHt, pNewHt, pOtherDoc, pDest );
            }
            ++nAttrCnt;
        }
        // sollten jetzt noch leere Attribute rumstehen, dann haben diese
        // eine hoehere Praezedenz. Also herausholen und das Array updaten.
        // Die dabei entstehenden leeren Hints werden von den gesicherten
        // "uebergeplaettet".   (Bug: 6977)
        if( pSwpHints && nAttrCnt < pSwpHints->Count() )
        {
            SwpHts aArr( 5 );
            for( ; nAttrCnt < pSwpHints->Count() &&
                    nEnd == *(pHt = pSwpHints->GetHt(nAttrCnt))->GetStart();
                   ++nAttrCnt )
            {
                if( 0 != ( pEndIdx = pHt->GetEnd() ) && *pEndIdx == nEnd )
                {
                    aArr.C40_INSERT( SwTxtAttr, pHt, aArr.Count() );
                    pSwpHints->Delete( pHt );
                    --nAttrCnt;
                }
            }
            Update( rStart, nLen, TRUE );

            for( nAttrCnt = 0; nAttrCnt < aArr.Count(); ++nAttrCnt )
            {
                pHt = aArr[ nAttrCnt ];
                *pHt->GetStart() = *pHt->GetEnd() = rStart.GetIndex();
                Insert( pHt );
            }
        }
        else
            Update( rStart, nLen, TRUE );

        CHECK_SWPHINTS(this);
    }

    if( pSwpHints && pSwpHints->CanBeDeleted() )
        DELETEZ( pSwpHints );

    // Frames benachrichtigen;
    SwInsTxt aInsHint( nDestStart, nLen );
    pDest->SwCntntNode::Modify( 0, &aInsHint );
    SwDelTxt aDelHint( nTxtStartIdx, nLen );
    SwCntntNode::Modify( 0, &aDelHint );
}


SwTxtNode& SwTxtNode::Erase(const SwIndex &rIdx, xub_StrLen nCount,
                            const USHORT nMode )
{
    ASSERT( rIdx <= aText.Len(), "Array ueberindiziert." );

    const xub_StrLen nCnt = STRING_LEN == nCount
                      ? aText.Len() - rIdx.GetIndex() : nCount;
    aText.Erase( rIdx.GetIndex(), nCnt );

    /* GCAttr(); alle leeren weggwerfen ist zu brutal.
     * Es duerfen nur die wegggeworfen werden,
     * die im Bereich liegen und nicht am Ende des Bereiches liegen
     */

    // Abfrage auf pSwpHints weil TextFelder und FlyFrames Text loeschen
    // (Rekursion)!!
    for( USHORT i = 0; pSwpHints && i < pSwpHints->Count(); ++i )
    {
        SwTxtAttr *pHt = pSwpHints->GetHt(i);

        const xub_StrLen nHtStt = *pHt->GetStart();

        if( nHtStt < rIdx.GetIndex() )
            continue;

        // TextFelder und FlyFrames loeschen Text (Rekursion)!!
        const xub_StrLen nEndIdx = rIdx.GetIndex() + nCnt;
        if( nHtStt > nEndIdx )
            // die Hints sind nach Ende sortiert, also ist Start
            // vom Hint groesser als EndIdx dann Abbrechen
            break;

        const xub_StrLen* pHtEndIdx = pHt->GetEnd();
        const USHORT nWhich = pHt->Which();

        if( !pHtEndIdx )
        {
            // TxtHints ohne EndIndex werden natuerlich auch geloescht:
            if( RES_TXTATR_BEGIN <= nWhich && RES_TXTATR_END > nWhich &&
                nHtStt >= rIdx.GetIndex() && nHtStt < nEndIdx )
            {
                pSwpHints->DeleteAtPos(i);
                // Damit im Dtor der TxtAttr ohne End die CH_TXTATR nicht
                // geloescht werden...
                *(pHt->GetStart()) = USHRT_MAX;
                DestroyAttr( pHt );
                --i;
            }
            continue;
        }

        if( *pHtEndIdx >= nEndIdx && !(
            !(INS_EMPTYEXPAND & nMode) && *pHtEndIdx == nEndIdx &&
            (nWhich == RES_TXTATR_TOXMARK || nWhich == RES_TXTATR_REFMARK)) )
            continue;

        pSwpHints->DeleteAtPos(i);
        DestroyAttr( pHt );
        --i;
    }

    if ( pSwpHints && pSwpHints->CanBeDeleted() )
        DELETEZ( pSwpHints );

    Update( rIdx, nCnt, TRUE );

    if( 1 == nCnt )
    {
        SwDelChr aHint( rIdx.GetIndex() );
        SwModify::Modify( 0, &aHint );
    }
    else
    {
        SwDelTxt aHint( rIdx.GetIndex(), nCnt );
        SwModify::Modify( 0, &aHint );
    }

    CHECK_SWPHINTS(this);
    return *this;
}

/***********************************************************************
#*  Class       :   SwTxtNode
#*  Methode     :   GCAttr
#*
#*  Beschreibung
#*                  text.doc
#*
#*  Datum       :   MS 28.11.90
#*  Update      :   VB 24.07.91
#***********************************************************************/

void SwTxtNode::GCAttr()
{
    if ( !pSwpHints )
        return;

    const SwTxtAttr *pHt = 0;
    const xub_StrLen *pEndIdx = 0;
    BOOL   bChanged = FALSE;
    USHORT nMin = aText.Len(),
           nMax = 0;
    BOOL bAll = nMin != 0; // Bei leeren Absaetzen werden nur die
                           // INet-Formate entfernt.

    for ( USHORT i = 0; pSwpHints && i < pSwpHints->Count(); ++i )
    {
        pHt = (*pSwpHints)[i];

        // wenn Ende und Start gleich sind --> loeschen
        pEndIdx = pHt->GetEnd();
        if( pEndIdx && (*pEndIdx == *pHt->GetStart())
            && ( bAll || pHt->Which() == RES_TXTATR_INETFMT ) )
        {
            bChanged = TRUE;
            nMin = Min( nMin, *pHt->GetStart() );
            nMax = Max( nMax, *pHt->GetEnd() );
            DestroyAttr( pSwpHints->Cut(i) );
            --i;
        }
        else
            ((SwTxtAttr*)pHt)->SetDontExpand( FALSE );
    }
    if ( pSwpHints && pSwpHints->CanBeDeleted() )
        DELETEZ( pSwpHints );

    if(bChanged)
    {
        //TxtFrm's reagieren auf aHint, andere auf aNew
        SwUpdateAttr aHint( nMin, nMax, 0 );
        SwModify::Modify( 0, &aHint );
        SwFmtChg aNew( GetTxtColl() );
        SwModify::Modify( 0, &aNew );
    }
}

const SwNodeNum* SwTxtNode::UpdateNum( const SwNodeNum& rNum )
{
    if( NO_NUMBERING == rNum.GetLevel() )       // kein Nummerierung mehr ?
    {
        if( !pNdNum )
            return 0;
        delete pNdNum, pNdNum = 0;
    }
    else
    {
        if( !pNdNum )
            pNdNum = new SwNodeNum( rNum );
        else if( !( *pNdNum == rNum ))
            *pNdNum = rNum;
    }
    NumRuleChgd();
    return pNdNum;
}

const SwNumRule* SwTxtNode::GetNumRule() const
{
    const SwNumRule* pRet = 0;
    const SfxPoolItem* pItem = GetNoCondAttr( RES_PARATR_NUMRULE, TRUE );
    if( pItem && ((SwNumRuleItem*)pItem)->GetValue().Len() )
        pRet = GetDoc()->FindNumRulePtr( ((SwNumRuleItem*)pItem)->GetValue() );
    return pRet;
}

void SwTxtNode::NumRuleChgd()
{
#ifndef NUM_RELSPACE

    // 6969: Aktualisierung der NumPortions auch bei leeren Zeilen!
    SwInsTxt aHint( 0, 0 );
    SwModify::Modify( 0, &aHint );

#else

    if( IsInCache() )
    {
        SwFrm::GetCache().Delete( this );
        SetInCache( FALSE );
    }
    SetInSwFntCache( FALSE );

    SvxLRSpaceItem& rLR = (SvxLRSpaceItem&)GetSwAttrSet().GetLRSpace();
    SwModify::Modify( &rLR, &rLR );

#endif
}

const SwNodeNum* SwTxtNode::UpdateOutlineNum( const SwNodeNum& rNum )
{
    if( NO_NUMBERING == rNum.GetLevel() )       // kein Nummerierung mehr ?
    {
        if( !pNdOutl )
            return 0;
        delete pNdOutl, pNdOutl = 0;
    }
    else
    {
        if( !pNdOutl )
            pNdOutl = new SwNodeNum( rNum );
        else if( !( *pNdOutl == rNum ))
            *pNdOutl = rNum;
    }

    // 6969: Aktualisierung der NumPortions auch bei leeren Zeilen!
    NumRuleChgd();
    return pNdOutl;
}

SwTxtNode* SwTxtNode::_MakeNewTxtNode( const SwNodeIndex& rPos, BOOL bNext,
                                        BOOL bChgFollow )
{
    /* hartes PageBreak/PageDesc/ColumnBreak aus AUTO-Set ignorieren */
    SwAttrSet* pNewAttrSet = 0;
    if( GetpSwAttrSet() )
    {
        pNewAttrSet = new SwAttrSet( *GetpSwAttrSet() );
        SwAttrSet* pTmpSet = GetpSwAttrSet();

        if( bNext )     // der naechste erbt keine Breaks!
            pTmpSet = pNewAttrSet;

        // PageBreaks/PageDesc/ColBreak rausschmeissen.
        BOOL bRemoveFromCache = 0 != pTmpSet->ClearItem( RES_PAGEDESC );
        if( SFX_ITEM_SET == pTmpSet->GetItemState( RES_BREAK, FALSE ) )
        {
            pTmpSet->ClearItem( RES_BREAK );
            bRemoveFromCache = TRUE;
        }
        if( !bNext && bRemoveFromCache && IsInCache() )
        {
            SwFrm::GetCache().Delete( this );
            SetInCache( FALSE );
        }
    }
    SwNodes& rNds = GetNodes();

    SwTxtFmtColl* pColl = GetTxtColl();

    SwTxtNode *pNode = new SwTxtNode( rPos, pColl, pNewAttrSet );

    if( pNewAttrSet )
        delete pNewAttrSet;

    const SwNumRule* pRule = GetNumRule();
    if( pRule && rNds.IsDocNodes() )
    {
        // ist am Node eine Nummerierung gesetzt und wird dieser vor dem
        // alten eingefuegt, so kopiere die Nummer
        if( !bNext && pNdNum && NO_NUMBERING != pNdNum->GetLevel() )
        {
            if( pNode->pNdNum )
                *pNode->pNdNum = *pNdNum;
            else
                pNode->pNdNum = new SwNodeNum( *pNdNum );

            // SetValue immer auf default zurueck setzem
            pNdNum->SetSetValue( USHRT_MAX );
            if( pNdNum->IsStart() )
            {
                pNdNum->SetStart( FALSE );
                pNode->pNdNum->SetStart( TRUE );
            }

            // Ein SplitNode erzeugt !!immer!! einen neuen Level, NO_NUM
            // kann nur ueber eine entsprechende Methode erzeugt werden !!
            if( NO_NUMLEVEL & pNdNum->GetLevel() )
            {
                pNdNum->SetLevel( pNdNum->GetLevel() & ~NO_NUMLEVEL );
#ifndef NUM_RELSPACE
                SetNumLSpace( TRUE );
#endif
            }
        }
        rNds.GetDoc()->UpdateNumRule( pRule->GetName(), pNode->GetIndex() );
    }

    // jetzt kann es sein, das durch die Nummerierung dem neuen Node eine
    // Vorlage aus dem Pool zugewiesen wurde. Dann darf diese nicht
    // nochmal uebergeplaettet werden !!
    if( pColl != pNode->GetTxtColl() ||
        ( bChgFollow && pColl != GetTxtColl() ))
        return pNode;       // mehr duerfte nicht gemacht werden oder ????

    pNode->_ChgTxtCollUpdateNum( 0, pColl ); // fuer Nummerierung/Gliederung
    if( bNext || !bChgFollow )
        return pNode;

    SwTxtFmtColl *pNextColl = &pColl->GetNextTxtFmtColl();
    ChgFmtColl( pNextColl );

    return pNode;
}

SwCntntNode* SwTxtNode::AppendNode( const SwPosition & rPos )
{
    // Position hinter dem eingefuegt wird
    SwNodeIndex aIdx( rPos.nNode, 1 );
    SwTxtNode* pNew = _MakeNewTxtNode( aIdx, TRUE );
    if( GetDepends() )
        MakeFrms( *pNew );
    return pNew;
}

/*************************************************************************
 *                      SwTxtNode::GetTxtAttr
 *
 * Diese Methode liefert nur Textattribute auf der Position nIdx
 * zurueck, die kein EndIdx besitzen und denselben Which besitzen.
 * Ueblicherweise steht an dieser Position ein CH_TXTATR.
 * Bei RES_TXTATR_END entfaellt die Pruefung auf den Which-Wert.
 *************************************************************************/

SwTxtAttr *SwTxtNode::GetTxtAttr( const xub_StrLen nIdx,
                                  const USHORT nWhichHt ) const
{
    if( pSwpHints )
    {
        for( USHORT i = 0; i < pSwpHints->Count(); ++i )
        {
            SwTxtAttr *pPos = pSwpHints->GetHt(i);
            const xub_StrLen nStart = *pPos->GetStart();
            if( nIdx < nStart )
                return 0;
            if( nIdx == nStart && !pPos->GetEnd() )
            {
                if( RES_TXTATR_END == nWhichHt || nWhichHt == pPos->Which() )
                    return pPos;
                else
                    return 0;
            }
        }
    }
    return 0;
}

/*************************************************************************
 *                      SwTxtNode::GetExpandTxt
 *************************************************************************/
// Felder werden expandiert:

XubString SwTxtNode::GetNumString() const
{
    const SwNodeNum* pNum;
    const SwNumRule* pRule;
    if( (( 0 != ( pNum = GetNum() ) &&
            0 != ( pRule = GetNumRule() )) ||
            ( 0 != ( pNum = GetOutlineNum() ) &&
            0 != ( pRule = GetDoc()->GetOutlineNumRule() ) ) ) &&
        pNum->GetLevel() < MAXLEVEL &&
        pRule->Get( pNum->GetLevel() ).IsTxtFmt() )
        return pRule->MakeNumString( *pNum );
    return aEmptyStr;
}

long SwTxtNode::GetLeftMarginWithNum( BOOL bTxtLeft ) const
{
    long nOffset;
    const SwNodeNum* pNum;
    const SwNumRule* pRule;
    if( (( 0 != ( pNum = GetNum() ) &&
            0 != ( pRule = GetNumRule() )) ||
            ( 0 != ( pNum = GetOutlineNum() ) &&
            0 != ( pRule = GetDoc()->GetOutlineNumRule() ) ) ) &&
            pNum->GetLevel() < NO_NUM )
    {
        const SwNumFmt& rFmt = pRule->Get( GetRealLevel( pNum->GetLevel() ) );
        nOffset = rFmt.GetAbsLSpace();

        if( !bTxtLeft )
        {
            if( 0 > rFmt.GetFirstLineOffset() &&
                nOffset > -rFmt.GetFirstLineOffset() )
                nOffset += rFmt.GetFirstLineOffset();
            else
                nOffset = 0;
        }

        if( pRule->IsAbsSpaces() )
            nOffset -= GetSwAttrSet().GetLRSpace().GetLeft();
    }
    else
        nOffset = 0;
    return nOffset;
}

BOOL SwTxtNode::GetFirstLineOfsWithNum( short& rFLOffset ) const
{
    const SwNodeNum* pNum;
    const SwNumRule* pRule;
    if( (( 0 != ( pNum = GetNum() ) &&
            0 != ( pRule = GetNumRule() )) ||
            ( 0 != ( pNum = GetOutlineNum() ) &&
            0 != ( pRule = GetDoc()->GetOutlineNumRule() ) ) ) &&
            pNum->GetLevel() < NO_NUM )
    {
        if( NO_NUMLEVEL & pNum->GetLevel() )
            rFLOffset = 0;
        else
            rFLOffset = pRule->Get( pNum->GetLevel() ).GetFirstLineOffset();
        return TRUE;
    }
    rFLOffset = GetSwAttrSet().GetLRSpace().GetTxtFirstLineOfst();
    return FALSE;
}

void SwTxtNode::Replace0xFF( XubString& rTxt, xub_StrLen& rTxtStt,
                            xub_StrLen nEndPos, BOOL bExpandFlds ) const
{
    if( GetpSwpHints() )
    {
        sal_Unicode cSrchChr = CH_TXTATR_BREAKWORD;
        for( int nSrchIter = 0; 2 > nSrchIter; ++nSrchIter,
                                cSrchChr = CH_TXTATR_INWORD )
        {
            xub_StrLen nPos = rTxt.Search( cSrchChr );
            while( STRING_NOTFOUND != nPos && nPos < nEndPos )
            {
                const SwTxtAttr* pAttr = GetTxtAttr( rTxtStt + nPos );
                if( pAttr )
                {
                    switch( pAttr->Which() )
                    {
                    case RES_TXTATR_FIELD:
                        rTxt.Erase( nPos, 1 );
                        if( bExpandFlds )
                        {
                            const XubString aExpand( ((SwTxtFld*)pAttr)->GetFld().
                                                    GetFld()->Expand() );
                            rTxt.Insert( aExpand, nPos );
                            nPos += aExpand.Len();
                            nEndPos += aExpand.Len();
                            rTxtStt -= aExpand.Len();
                        }
                        ++rTxtStt;
                        break;
                    case RES_TXTATR_HARDBLANK:
                        rTxt.SetChar( nPos, ((SwTxtHardBlank*)pAttr)->GetChar() );
                        ++nPos;
                        ++nEndPos;
                        break;
                    case RES_TXTATR_FTN:
                        rTxt.Erase( nPos, 1 );
                        if( bExpandFlds )
                        {
                            const SwFmtFtn& rFtn = pAttr->GetFtn();
                            XubString sExpand;
                            if( rFtn.GetNumStr().Len() )
                                sExpand = rFtn.GetNumStr();
                            else if( rFtn.IsEndNote() )
                                sExpand = GetDoc()->GetEndNoteInfo().aFmt.
                                                GetNumStr( rFtn.GetNumber() );
                            else
                                sExpand = GetDoc()->GetFtnInfo().aFmt.
                                                GetNumStr( rFtn.GetNumber() );
                            rTxt.Insert( sExpand, nPos );
                            nPos += sExpand.Len();
                            nEndPos += sExpand.Len();
                            rTxtStt -= sExpand.Len();
                        }
                        ++rTxtStt;
                        break;
                    default:
                        rTxt.Erase( nPos, 1 );
                        ++rTxtStt;
                    }
                }
                else
                    ++nPos, ++nEndPos;
                nPos = rTxt.Search( cSrchChr, nPos );
            }
        }
    }
}

XubString SwTxtNode::GetExpandTxt( const xub_StrLen nIdx, const xub_StrLen nLen,
                                const BOOL bWithNum  ) const
{
    XubString aTxt( GetTxt().Copy( nIdx, nLen ) );
    xub_StrLen nTxtStt = nIdx;
    Replace0xFF( aTxt, nTxtStt, aTxt.Len(), TRUE );

    if( bWithNum )
        aTxt.Insert( GetNumString(), 0 );

    return aTxt;
}

BOOL SwTxtNode::GetExpandTxt( SwTxtNode& rDestNd, const SwIndex* pDestIdx,
                        xub_StrLen nIdx, xub_StrLen nLen, BOOL bWithNum,
                        BOOL bWithFtn ) const
{
    if( &rDestNd == this )
        return FALSE;

    SwIndex aDestIdx( &rDestNd, rDestNd.GetTxt().Len() );
    if( pDestIdx )
        aDestIdx = *pDestIdx;
    xub_StrLen nDestStt = aDestIdx.GetIndex();

    // Text einfuegen
    rDestNd.Insert( GetTxt().Copy( nIdx, nLen ), aDestIdx );
    nLen = aDestIdx.GetIndex() - nDestStt;

    // alle FontAttribute mit CHARSET Symbol in dem Bereich setzen
    if( pSwpHints )
    {
        xub_StrLen nInsPos = nDestStt - nIdx;
        for( USHORT i = 0; i < pSwpHints->Count(); i++ )
        {
            const SwTxtAttr* pHt = (*pSwpHints)[i];
            xub_StrLen nAttrStartIdx;
            USHORT nWhich = pHt->Which();
            if( nIdx + nLen <= ( nAttrStartIdx = *pHt->GetStart() ) )
                break;      // ueber das Textende

            const SvxFontItem* pFont;
            const xub_StrLen *pEndIdx = pHt->GetEnd();
            if( pEndIdx && *pEndIdx > nIdx && (
                ( RES_CHRATR_FONT == nWhich &&
                  RTL_TEXTENCODING_SYMBOL == (pFont = &pHt->GetFont())->GetCharSet() ) ||
                ( RES_TXTATR_CHARFMT == nWhich &&
                  RTL_TEXTENCODING_SYMBOL == (pFont = &pHt->GetCharFmt().
                      GetCharFmt()->GetFont())->GetCharSet() )))
            {
                // Attribut liegt im Bereich, also kopieren
                rDestNd.Insert( *pFont, nInsPos + nAttrStartIdx,
                                        nInsPos + *pEndIdx );
            }
            else if( !pEndIdx && nAttrStartIdx >= nIdx )
            {
                aDestIdx = nInsPos + nAttrStartIdx;
                switch( nWhich )
                {
                case RES_TXTATR_FIELD:
                    {
                        const XubString aExpand( ((SwTxtFld*)pHt)->GetFld().GetFld()->Expand() );
                        if( aExpand.Len() )
                        {
                            aDestIdx++;     // dahinter einfuegen;
                            rDestNd.Insert( aExpand, aDestIdx );
                            aDestIdx = nInsPos + nAttrStartIdx;
                            nInsPos += aExpand.Len();
                        }
                        rDestNd.Erase( aDestIdx, 1 );
                        --nInsPos;
                    }
                    break;

                case RES_TXTATR_HARDBLANK:
                    rDestNd.aText.SetChar( nInsPos + nAttrStartIdx,
                                ((SwTxtHardBlank*)pHt)->GetChar() );
                    break;

                case RES_TXTATR_FTN:
                    {
                        if ( bWithFtn )
                        {
                            const SwFmtFtn& rFtn = pHt->GetFtn();
                            XubString sExpand;
                            if( rFtn.GetNumStr().Len() )
                                sExpand = rFtn.GetNumStr();
                            else if( rFtn.IsEndNote() )
                                sExpand = GetDoc()->GetEndNoteInfo().aFmt.
                                                GetNumStr( rFtn.GetNumber() );
                            else
                                sExpand = GetDoc()->GetFtnInfo().aFmt.
                                                GetNumStr( rFtn.GetNumber() );
                            if( sExpand.Len() )
                            {
                                aDestIdx++;     // dahinter einfuegen;
                                rDestNd.Insert( SvxEscapementItem(
                                        SVX_ESCAPEMENT_SUPERSCRIPT ),
                                        aDestIdx.GetIndex(),
                                        aDestIdx.GetIndex() );
                                rDestNd.Insert( sExpand, aDestIdx, INS_EMPTYEXPAND );
                                aDestIdx = nInsPos + nAttrStartIdx;
                                nInsPos += sExpand.Len();
                            }
                        }
                        rDestNd.Erase( aDestIdx, 1 );
                        --nInsPos;
                    }
                    break;

                default:
                    rDestNd.Erase( aDestIdx, 1 );
                    --nInsPos;
                }
            }
        }
    }

    if( bWithNum )
    {
        aDestIdx = nDestStt;
        rDestNd.Insert( GetNumString(), aDestIdx );
    }
    return TRUE;
}


XubString SwTxtNode::GetRedlineTxt( xub_StrLen nIdx, xub_StrLen nLen,
                                BOOL bExpandFlds, BOOL bWithNum ) const
{
    SvUShorts aRedlArr;
    const SwDoc* pDoc = GetDoc();
    USHORT nRedlPos = pDoc->GetRedlinePos( *this, REDLINE_DELETE );
    if( USHRT_MAX != nRedlPos )
    {
        // es existiert fuer den Node irgendein Redline-Delete-Object
        const ULONG nNdIdx = GetIndex();
        for( ; nRedlPos < pDoc->GetRedlineTbl().Count() ; ++nRedlPos )
        {
            const SwRedline* pTmp = pDoc->GetRedlineTbl()[ nRedlPos ];
            if( REDLINE_DELETE == pTmp->GetType() )
            {
                const SwPosition *pRStt = pTmp->Start(), *pREnd = pTmp->End();
                if( pRStt->nNode < nNdIdx )
                {
                    if( pREnd->nNode > nNdIdx )
                        // Absatz ist komplett geloescht
                        return aEmptyStr;
                    else if( pREnd->nNode == nNdIdx )
                    {
                        // von 0 bis nContent ist alles geloescht
                        aRedlArr.Insert( xub_StrLen(0), aRedlArr.Count() );
                        aRedlArr.Insert( pREnd->nContent.GetIndex(), aRedlArr.Count() );
                    }
                }
                else if( pRStt->nNode == nNdIdx )
                {
                    aRedlArr.Insert( pRStt->nContent.GetIndex(), aRedlArr.Count() );
                    if( pREnd->nNode == nNdIdx )
                        aRedlArr.Insert( pREnd->nContent.GetIndex(), aRedlArr.Count() );
                    else
                    {
                        aRedlArr.Insert( GetTxt().Len(), aRedlArr.Count() );
                        break;      // mehr kann nicht kommen
                    }
                }
                else
                    break;      // mehr kann nicht kommen
            }
        }
    }

    XubString aTxt( GetTxt().Copy( nIdx, nLen ) );

    xub_StrLen nTxtStt = nIdx, nIdxEnd = nIdx + aTxt.Len();
    for( USHORT n = 0; n < aRedlArr.Count(); n += 2 )
    {
        xub_StrLen nStt = aRedlArr[ n ], nEnd = aRedlArr[ n+1 ];
        if( ( nIdx <= nStt && nStt <= nIdxEnd ) ||
            ( nIdx <= nEnd && nEnd <= nIdxEnd ))
        {
            if( nStt < nIdx ) nStt = nIdx;
            if( nIdxEnd < nEnd ) nEnd = nIdxEnd;
            xub_StrLen nDelCnt = nEnd - nStt;
            aTxt.Erase( nStt - nTxtStt, nDelCnt );
            Replace0xFF( aTxt, nTxtStt, nStt - nTxtStt, bExpandFlds );
            nTxtStt += nDelCnt;
        }
        else if( nStt >= nIdxEnd )
            break;
    }
    Replace0xFF( aTxt, nTxtStt, aTxt.Len(), bExpandFlds );

    if( bWithNum )
        aTxt.Insert( GetNumString(), 0 );
    return aTxt;
}

/*************************************************************************
 *                      SwTxtNode::GetExpandTxt
 *************************************************************************/
// Felder werden expandiert:

void SwTxtNode::Replace( const SwIndex& rStart, xub_Unicode cCh )
{

    ASSERT( rStart.GetIndex() < aText.Len(), "ausserhalb des Strings" );
    SwTxtAttr* pHt;
    if( ( CH_TXTATR_BREAKWORD == aText.GetChar( rStart.GetIndex() ) ||
          CH_TXTATR_INWORD == aText.GetChar( rStart.GetIndex() )) &&
        0 != ( pHt = GetTxtAttr( rStart.GetIndex() ) ))
    {
        Delete( pHt );
        aText.Insert( cCh, rStart.GetIndex() );
    }
    else
        aText.SetChar( rStart.GetIndex(), cCh );

    SwDelTxt aDelHint( rStart.GetIndex(), 1 );
    SwModify::Modify( 0, &aDelHint );

    SwInsTxt aHint( rStart.GetIndex(), 1 );
    SwModify::Modify( 0, &aHint );
}


void SwTxtNode::Replace( const SwIndex& rStart, xub_StrLen nLen,
                            const XubString& rText )
{
    ASSERT( rStart.GetIndex() < aText.Len() &&
            rStart.GetIndex() + nLen <= aText.Len(),
            "ausserhalb des Strings" );
    SwTxtAttr* pHt;
    xub_StrLen nStart = rStart.GetIndex();
    xub_StrLen nEnde = nStart + nLen;
    xub_StrLen nDelLen = nLen;
    for( xub_StrLen nPos = nStart; nPos < nEnde; ++nPos )
        if( ( CH_TXTATR_BREAKWORD == aText.GetChar( nPos ) ||
              CH_TXTATR_INWORD == aText.GetChar( nPos )) &&
            0 != ( pHt = GetTxtAttr( nPos ) ))
        {
            Delete( pHt );
            --nEnde;
            --nLen;
        }

    BOOL bOldExpFlg = IsIgnoreDontExpand();
    SetIgnoreDontExpand( TRUE );

    if( nLen && rText.Len() )
    {
        // dann das 1. Zeichen ersetzen den Rest loschen und einfuegen
        // Dadurch wird die Attributierung des 1. Zeichen expandiert!
        aText.SetChar( nStart, rText.GetChar( 0 ) );

        ((SwIndex&)rStart)++;
        aText.Erase( rStart.GetIndex(), nLen - 1 );
        Update( rStart, nLen - 1, TRUE );

        XubString aTmpTxt( rText ); aTmpTxt.Erase( 0, 1 );
        aText.Insert( aTmpTxt, rStart.GetIndex() );
        Update( rStart, aTmpTxt.Len(), FALSE );
    }
    else
    {
        aText.Erase( nStart, nLen );
        Update( rStart, nLen, TRUE );

        aText.Insert( rText, nStart );
        Update( rStart, rText.Len(), FALSE );
    }
    SetIgnoreDontExpand( bOldExpFlg );
    SwDelTxt aDelHint( nStart, nDelLen );
    SwModify::Modify( 0, &aDelHint );

    SwInsTxt aHint( nStart, rText.Len() );
    SwModify::Modify( 0, &aHint );
}

void SwTxtNode::Modify( SfxPoolItem* pOldValue, SfxPoolItem* pNewValue )
{
    // Bug 24616/24617:
    //      Modify ueberladen, damit beim Loeschen von Vorlagen diese
    //      wieder richtig verwaltet werden (Outline-Numerierung!!)
    //  Bug25481:
    //      bei Nodes im Undo nie _ChgTxtCollUpdateNum rufen.
    if( pOldValue && pNewValue && RES_FMT_CHG == pOldValue->Which() &&
        pRegisteredIn == ((SwFmtChg*)pNewValue)->pChangedFmt &&
        GetNodes().IsDocNodes() )
        _ChgTxtCollUpdateNum(
                        (SwTxtFmtColl*)((SwFmtChg*)pOldValue)->pChangedFmt,
                        (SwTxtFmtColl*)((SwFmtChg*)pNewValue)->pChangedFmt );

    SwCntntNode::Modify( pOldValue, pNewValue );
}