1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/container/XIndexReplace.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/text/ChapterFormat.hpp>
#include <com/sun/star/text/ReferenceFieldPart.hpp>
#include <com/sun/star/text/BibliographyDataField.hpp>
#include <com/sun/star/text/XTextDocument.hpp>
#include <osl/mutex.hxx>
#include <vcl/svapp.hxx>
#include <editeng/unolingu.hxx>
#include <hints.hxx>
#include <cmdid.h>
#include <swtypes.hxx>
#include <shellres.hxx>
#include <viewsh.hxx>
#include <doc.hxx>
#include <docary.hxx>
#include <poolfmt.hxx>
#include <poolfmt.hrc>
#include <pagedesc.hxx>
#include <fmtcntnt.hxx>
#include <unomap.hxx>
#include <unotextrange.hxx>
#include <unotextcursor.hxx>
#include <unosection.hxx>
#include <doctxm.hxx>
#include <txttxmrk.hxx>
#include <unocrsr.hxx>
#include <unostyle.hxx>
#include <ndtxt.hxx>
#include <unoidx.hxx>
#include <docsh.hxx>
#include <chpfld.hxx>
#include <SwStyleNameMapper.hxx>
#include <unoevtlstnr.hxx>
#include <comphelper/servicehelper.hxx>
#include <comphelper/string.hxx>
using namespace ::com::sun::star;
using ::rtl::OUString;
static OUString
lcl_AnyToString(uno::Any const& rVal) throw (lang::IllegalArgumentException)
{
OUString sRet;
if(!(rVal >>= sRet))
{
throw lang::IllegalArgumentException();
}
return sRet;
}
static sal_Int16
lcl_AnyToInt16(uno::Any const& rVal) throw (lang::IllegalArgumentException)
{
sal_Int16 nRet = 0;
if(!(rVal >>= nRet))
{
throw lang::IllegalArgumentException();
}
return nRet;
}
static sal_Bool
lcl_AnyToBool(uno::Any const& rVal) throw (lang::IllegalArgumentException)
{
sal_Bool bRet = sal_False;
if(!(rVal >>= bRet))
{
throw lang::IllegalArgumentException();
}
return bRet;
}
static void
lcl_AnyToBitMask(uno::Any const& rValue,
sal_uInt16 & rBitMask, const sal_uInt16 nBit)
throw (lang::IllegalArgumentException)
{
rBitMask = lcl_AnyToBool(rValue)
? (rBitMask | nBit)
: (rBitMask & ~nBit);
}
static void
lcl_BitMaskToAny(uno::Any & o_rValue,
const sal_uInt16 nBitMask, const sal_uInt16 nBit)
{
const sal_Bool bRet = 0 != (nBitMask & nBit);
o_rValue <<= bRet;
}
static void
lcl_ReAssignTOXType(SwDoc* pDoc, SwTOXBase& rTOXBase, const OUString& rNewName)
{
const sal_uInt16 nUserCount = pDoc->GetTOXTypeCount( TOX_USER );
const SwTOXType* pNewType = 0;
for(sal_uInt16 nUser = 0; nUser < nUserCount; nUser++)
{
const SwTOXType* pType = pDoc->GetTOXType( TOX_USER, nUser );
if(pType->GetTypeName().Equals((String)rNewName))
{
pNewType = pType;
break;
}
}
if(!pNewType)
{
SwTOXType aNewType(TOX_USER, rNewName);
pNewType = pDoc->InsertTOXType( aNewType );
}
rTOXBase.RegisterToTOXType( *((SwTOXType*)pNewType) );
}
static const char cUserDefined[] = "User-Defined";
static const char cUserSuffix[] = " (user)";
#define USER_LEN 12
#define USER_AND_SUFFIXLEN 19
void lcl_ConvertTOUNameToProgrammaticName(OUString& rTmp)
{
ShellResource* pShellRes = ViewShell::GetShellRes();
if(rTmp.equals(pShellRes->aTOXUserName))
{
rTmp = OUString(C2U(cUserDefined));
}
// if the version is not English but the alternative index's name is
// "User-Defined" a " (user)" is appended
else if(rTmp.equalsAscii(cUserDefined))
{
rTmp += C2U(cUserSuffix);
}
}
static void
lcl_ConvertTOUNameToUserName(OUString& rTmp)
{
ShellResource* pShellRes = ViewShell::GetShellRes();
if(rTmp.equalsAscii(cUserDefined))
{
rTmp = pShellRes->aTOXUserName;
}
else if(!pShellRes->aTOXUserName.EqualsAscii(cUserDefined) &&
USER_AND_SUFFIXLEN == rTmp.getLength())
{
//make sure that in non-English versions the " (user)" suffix is removed
if (rTmp.matchAsciiL(cUserDefined, sizeof(cUserDefined)) &&
rTmp.matchAsciiL(cUserSuffix, sizeof(cUserSuffix), USER_LEN))
{
rTmp = C2U(cUserDefined);
}
}
}
typedef ::cppu::WeakImplHelper2
< lang::XServiceInfo
, container::XIndexReplace
> SwXDocumentIndexStyleAccess_Base;
class SwXDocumentIndex::StyleAccess_Impl
: public SwXDocumentIndexStyleAccess_Base
{
private:
/// can be destroyed threadsafely, so no UnoImplPtr here
::rtl::Reference<SwXDocumentIndex> m_xParent;
virtual ~StyleAccess_Impl();
public:
StyleAccess_Impl(SwXDocumentIndex& rParentIdx);
// XServiceInfo
virtual ::rtl::OUString SAL_CALL getImplementationName()
throw (uno::RuntimeException);
virtual sal_Bool SAL_CALL
supportsService(const ::rtl::OUString& rServiceName)
throw (uno::RuntimeException);
virtual uno::Sequence< ::rtl::OUString > SAL_CALL
getSupportedServiceNames() throw (uno::RuntimeException);
// XElementAccess
virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException);
virtual sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException);
// XIndexAccess
virtual sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException);
virtual uno::Any SAL_CALL getByIndex(sal_Int32 nIndex)
throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException,
uno::RuntimeException);
// XIndexReplace
virtual void SAL_CALL
replaceByIndex(sal_Int32 Index, const uno::Any& rElement)
throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException,
lang::WrappedTargetException, uno::RuntimeException);
};
typedef ::cppu::WeakImplHelper2
< lang::XServiceInfo
, container::XIndexReplace
> SwXDocumentIndexTokenAccess_Base;
class SwXDocumentIndex::TokenAccess_Impl
: public SwXDocumentIndexTokenAccess_Base
{
private:
/// can be destroyed threadsafely, so no UnoImplPtr here
::rtl::Reference<SwXDocumentIndex> m_xParent;
virtual ~TokenAccess_Impl();
public:
TokenAccess_Impl(SwXDocumentIndex& rParentIdx);
// XServiceInfo
virtual ::rtl::OUString SAL_CALL getImplementationName()
throw (uno::RuntimeException);
virtual sal_Bool SAL_CALL
supportsService(const ::rtl::OUString& rServiceName)
throw (uno::RuntimeException);
virtual uno::Sequence< ::rtl::OUString > SAL_CALL
getSupportedServiceNames() throw (uno::RuntimeException);
// XElementAccess
virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException);
virtual sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException);
// XIndexAccess
virtual sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException);
virtual uno::Any SAL_CALL getByIndex(sal_Int32 nIndex)
throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException,
uno::RuntimeException);
// XIndexReplace
virtual void SAL_CALL
replaceByIndex(sal_Int32 Index, const uno::Any& rElement)
throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException,
lang::WrappedTargetException, uno::RuntimeException);
};
/******************************************************************
* SwXDocumentIndex
******************************************************************/
class SwDocIndexDescriptorProperties_Impl
{
private:
::std::auto_ptr<SwTOXBase> m_pTOXBase;
OUString m_sUserTOXTypeName;
public:
SwDocIndexDescriptorProperties_Impl(SwTOXType const*const pType);
SwTOXBase & GetTOXBase() { return *m_pTOXBase; }
const OUString& GetTypeName() const { return m_sUserTOXTypeName; }
void SetTypeName(const OUString& rSet) { m_sUserTOXTypeName = rSet; }
};
SwDocIndexDescriptorProperties_Impl::SwDocIndexDescriptorProperties_Impl(
SwTOXType const*const pType)
{
SwForm aForm(pType->GetType());
m_pTOXBase.reset(new SwTOXBase(pType, aForm,
nsSwTOXElement::TOX_MARK, pType->GetTypeName()));
if(pType->GetType() == TOX_CONTENT || pType->GetType() == TOX_USER)
{
m_pTOXBase->SetLevel(MAXLEVEL);
}
m_sUserTOXTypeName = pType->GetTypeName();
}
static sal_uInt16
lcl_TypeToPropertyMap_Index(const TOXTypes eType)
{
switch (eType)
{
case TOX_INDEX: return PROPERTY_MAP_INDEX_IDX;
case TOX_CONTENT: return PROPERTY_MAP_INDEX_CNTNT;
case TOX_TABLES: return PROPERTY_MAP_INDEX_TABLES;
case TOX_ILLUSTRATIONS: return PROPERTY_MAP_INDEX_ILLUSTRATIONS;
case TOX_OBJECTS: return PROPERTY_MAP_INDEX_OBJECTS;
case TOX_AUTHORITIES: return PROPERTY_MAP_BIBLIOGRAPHY;
//case TOX_USER:
default:
return PROPERTY_MAP_INDEX_USER;
}
}
class SwXDocumentIndex::Impl
: public SwClient
{
public:
SfxItemPropertySet const& m_rPropSet;
const TOXTypes m_eTOXType;
SwEventListenerContainer m_ListenerContainer;
bool m_bIsDescriptor;
SwDoc * m_pDoc;
::std::auto_ptr<SwDocIndexDescriptorProperties_Impl> m_pProps;
uno::WeakReference<container::XIndexReplace> m_wStyleAccess;
uno::WeakReference<container::XIndexReplace> m_wTokenAccess;
Impl( SwXDocumentIndex & rThis,
SwDoc & rDoc,
const TOXTypes eType,
SwTOXBaseSection const*const pBaseSection)
: SwClient((pBaseSection) ? pBaseSection->GetFmt() : 0)
, m_rPropSet(
*aSwMapProvider.GetPropertySet(lcl_TypeToPropertyMap_Index(eType)))
, m_eTOXType(eType)
, m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis))
// #i111177# unxsols4 (Sun C++ 5.9 SunOS_sparc) may generate wrong code
, m_bIsDescriptor((0 == pBaseSection) ? true : false)
, m_pDoc(&rDoc)
, m_pProps((m_bIsDescriptor)
? new SwDocIndexDescriptorProperties_Impl(rDoc.GetTOXType(eType, 0))
: 0)
{
}
SwSectionFmt * GetSectionFmt() const {
return static_cast<SwSectionFmt *>(
const_cast<SwModify *>(GetRegisteredIn()));
}
SwTOXBase & GetTOXSectionOrThrow() const
{
SwSectionFmt *const pSectionFmt(GetSectionFmt());
SwTOXBase *const pTOXSection( (m_bIsDescriptor)
? &m_pProps->GetTOXBase()
: ((pSectionFmt)
? static_cast<SwTOXBaseSection*>(pSectionFmt->GetSection())
: 0));
if (!pTOXSection)
{
throw uno::RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM(
"SwXDocumentIndex: disposed or invalid")), 0);
}
return *pTOXSection;
}
sal_Int32 GetFormMax() const
{
SwTOXBase & rSection( GetTOXSectionOrThrow() );
return (m_bIsDescriptor)
? SwForm::GetFormMaxLevel(m_eTOXType)
: rSection.GetTOXForm().GetFormMax();
}
protected:
// SwClient
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew);
};
void SwXDocumentIndex::Impl::Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew)
{
ClientModify(this, pOld, pNew);
if (!GetRegisteredIn())
{
m_ListenerContainer.Disposing();
}
}
SwXDocumentIndex::SwXDocumentIndex(
SwTOXBaseSection const& rBaseSection, SwDoc & rDoc)
: m_pImpl( new SwXDocumentIndex::Impl( *this,
rDoc, rBaseSection.SwTOXBase::GetType(), & rBaseSection) )
{
}
SwXDocumentIndex::SwXDocumentIndex(const TOXTypes eType, SwDoc& rDoc)
: m_pImpl( new SwXDocumentIndex::Impl( *this, rDoc, eType, 0) )
{
}
SwXDocumentIndex::~SwXDocumentIndex()
{
}
uno::Reference<text::XDocumentIndex>
SwXDocumentIndex::CreateXDocumentIndex(
SwDoc & rDoc, SwTOXBaseSection const& rSection)
{
// re-use existing SwXDocumentIndex
// #i105557#: do not iterate over the registered clients: race condition
SwSectionFmt *const pFmt = rSection.GetFmt();
uno::Reference<text::XDocumentIndex> xIndex(pFmt->GetXObject(),
uno::UNO_QUERY);
if (!xIndex.is())
{
SwXDocumentIndex *const pIndex(new SwXDocumentIndex(rSection, rDoc));
xIndex.set(pIndex);
pFmt->SetXObject(uno::Reference<uno::XInterface>(xIndex));
}
return xIndex;
}
namespace
{
class theSwXDocumentIndexUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXDocumentIndexUnoTunnelId > {};
}
const uno::Sequence< sal_Int8 > & SwXDocumentIndex::getUnoTunnelId()
{
return theSwXDocumentIndexUnoTunnelId::get().getSeq();
}
sal_Int64 SAL_CALL
SwXDocumentIndex::getSomething(const uno::Sequence< sal_Int8 >& rId)
throw (uno::RuntimeException)
{
return ::sw::UnoTunnelImpl<SwXDocumentIndex>(rId, this);
}
OUString SAL_CALL
SwXDocumentIndex::getImplementationName() throw (uno::RuntimeException)
{
return C2U("SwXDocumentIndex");
}
sal_Bool SAL_CALL
SwXDocumentIndex::supportsService(const OUString& rServiceName)
throw (uno::RuntimeException)
{
SolarMutexGuard g;
return C2U("com.sun.star.text.BaseIndex") == rServiceName
|| ((TOX_INDEX == m_pImpl->m_eTOXType) && rServiceName == "com.sun.star.text.DocumentIndex")
|| ((TOX_CONTENT == m_pImpl->m_eTOXType) && rServiceName == "com.sun.star.text.ContentIndex")
|| ((TOX_USER == m_pImpl->m_eTOXType) && rServiceName == "com.sun.star.text.UserDefinedIndex")
|| ((TOX_ILLUSTRATIONS == m_pImpl->m_eTOXType) && rServiceName == "com.sun.star.text.IllustrationsIndex")
|| ((TOX_TABLES == m_pImpl->m_eTOXType) && rServiceName == "com.sun.star.text.TableIndex")
|| ((TOX_OBJECTS == m_pImpl->m_eTOXType) && rServiceName == "com.sun.star.text.ObjectIndex")
|| ((TOX_AUTHORITIES == m_pImpl->m_eTOXType) && rServiceName == "com.sun.star.text.Bibliography");
}
uno::Sequence< OUString > SAL_CALL
SwXDocumentIndex::getSupportedServiceNames() throw (uno::RuntimeException)
{
SolarMutexGuard g;
uno::Sequence< OUString > aRet(2);
OUString* pArray = aRet.getArray();
pArray[0] = C2U("com.sun.star.text.BaseIndex");
switch (m_pImpl->m_eTOXType)
{
case TOX_INDEX:
pArray[1] = C2U("com.sun.star.text.DocumentIndex");
break;
case TOX_CONTENT:
pArray[1] = C2U("com.sun.star.text.ContentIndex");
break;
case TOX_TABLES:
pArray[1] = C2U("com.sun.star.text.TableIndex");
break;
case TOX_ILLUSTRATIONS:
pArray[1] = C2U("com.sun.star.text.IllustrationsIndex");
break;
case TOX_OBJECTS:
pArray[1] = C2U("com.sun.star.text.ObjectIndex");
break;
case TOX_AUTHORITIES:
pArray[1] = C2U("com.sun.star.text.Bibliography");
break;
//case TOX_USER:
default:
pArray[1] = C2U("com.sun.star.text.UserDefinedIndex");
}
return aRet;
}
OUString SAL_CALL SwXDocumentIndex::getServiceName()
throw (uno::RuntimeException)
{
SolarMutexGuard g;
sal_uInt16 nObjectType = SW_SERVICE_TYPE_INDEX;
switch (m_pImpl->m_eTOXType)
{
// case TOX_INDEX: break;
case TOX_USER: nObjectType = SW_SERVICE_USER_INDEX;
break;
case TOX_CONTENT: nObjectType = SW_SERVICE_CONTENT_INDEX;
break;
case TOX_ILLUSTRATIONS: nObjectType = SW_SERVICE_INDEX_ILLUSTRATIONS;
break;
case TOX_OBJECTS: nObjectType = SW_SERVICE_INDEX_OBJECTS;
break;
case TOX_TABLES: nObjectType = SW_SERVICE_INDEX_TABLES;
break;
case TOX_AUTHORITIES: nObjectType = SW_SERVICE_INDEX_BIBLIOGRAPHY;
break;
default:
break;
}
return SwXServiceProvider::GetProviderName(nObjectType);
}
void SAL_CALL SwXDocumentIndex::update() throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
SwSectionFmt *const pFmt = m_pImpl->GetSectionFmt();
SwTOXBaseSection *const pTOXBase = (pFmt) ?
static_cast<SwTOXBaseSection*>(pFmt->GetSection()) : 0;
if(!pTOXBase)
{
throw uno::RuntimeException();
}
pTOXBase->Update();
// page numbers
pTOXBase->UpdatePageNum();
}
uno::Reference< beans::XPropertySetInfo > SAL_CALL
SwXDocumentIndex::getPropertySetInfo() throw (uno::RuntimeException)
{
SolarMutexGuard g;
const uno::Reference< beans::XPropertySetInfo > xRef =
m_pImpl->m_rPropSet.getPropertySetInfo();
return xRef;
}
void SAL_CALL
SwXDocumentIndex::setPropertyValue(
const OUString& rPropertyName, const uno::Any& rValue)
throw (beans::UnknownPropertyException, beans::PropertyVetoException,
lang::IllegalArgumentException, lang::WrappedTargetException,
uno::RuntimeException)
{
SolarMutexGuard aGuard;
SfxItemPropertySimpleEntry const*const pEntry =
m_pImpl->m_rPropSet.getPropertyMap().getByName(rPropertyName);
if (!pEntry)
{
throw beans::UnknownPropertyException(
OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
+ rPropertyName,
static_cast<cppu::OWeakObject *>(this));
}
if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
{
throw beans::PropertyVetoException(
OUString(RTL_CONSTASCII_USTRINGPARAM("Property is read-only: " ))
+ rPropertyName,
static_cast<cppu::OWeakObject *>(this));
}
SwSectionFmt *const pSectionFmt(m_pImpl->GetSectionFmt());
SwTOXBase & rTOXBase( m_pImpl->GetTOXSectionOrThrow() );
sal_uInt16 nCreate = rTOXBase.GetCreateType();
sal_uInt16 nTOIOptions = 0;
sal_uInt16 nOLEOptions = rTOXBase.GetOLEOptions();
const TOXTypes eTxBaseType = rTOXBase.GetTOXType()->GetType();
if (eTxBaseType == TOX_INDEX)
{
nTOIOptions = rTOXBase.GetOptions();
}
SwForm aForm(rTOXBase.GetTOXForm());
sal_Bool bForm = sal_False;
switch (pEntry->nWID)
{
case WID_IDX_TITLE:
{
OUString sNewName;
if (!(rValue >>= sNewName))
{
throw lang::IllegalArgumentException();
}
rTOXBase.SetTitle(sNewName);
}
break;
case WID_IDX_NAME:
{
OUString sNewName;
if (!(rValue >>= sNewName))
{
throw lang::IllegalArgumentException();
}
rTOXBase.SetTOXName(sNewName);
}
break;
case WID_USER_IDX_NAME:
{
OUString sNewName;
if (!(rValue >>= sNewName))
{
throw lang::IllegalArgumentException();
}
lcl_ConvertTOUNameToUserName(sNewName);
OSL_ENSURE(TOX_USER == eTxBaseType,
"tox type name can only be changed for user indexes");
if (pSectionFmt)
{
OUString sTmp = rTOXBase.GetTOXType()->GetTypeName();
if (sTmp != sNewName)
{
lcl_ReAssignTOXType(pSectionFmt->GetDoc(),
rTOXBase, sNewName);
}
}
else
{
m_pImpl->m_pProps->SetTypeName(sNewName);
}
}
break;
case WID_IDX_LOCALE:
{
lang::Locale aLocale;
if (!(rValue>>= aLocale))
{
throw lang::IllegalArgumentException();
}
rTOXBase.SetLanguage(SvxLocaleToLanguage(aLocale));
}
break;
case WID_IDX_SORT_ALGORITHM:
{
OUString sTmp;
if (!(rValue >>= sTmp))
{
throw lang::IllegalArgumentException();
}
rTOXBase.SetSortAlgorithm(sTmp);
}
break;
case WID_LEVEL:
{
rTOXBase.SetLevel(lcl_AnyToInt16(rValue));
}
break;
case WID_CREATE_FROM_MARKS:
lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_MARK);
break;
case WID_CREATE_FROM_OUTLINE:
lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_OUTLINELEVEL);
break;
// case WID_PARAGRAPH_STYLE_NAMES :OSL_FAIL("not implemented")
// break;
case WID_CREATE_FROM_CHAPTER:
rTOXBase.SetFromChapter(lcl_AnyToBool(rValue));
break;
case WID_CREATE_FROM_LABELS:
rTOXBase.SetFromObjectNames(! lcl_AnyToBool(rValue));
break;
case WID_PROTECTED:
{
sal_Bool bSet = lcl_AnyToBool(rValue);
rTOXBase.SetProtected(bSet);
if (pSectionFmt)
{
static_cast<SwTOXBaseSection &>(rTOXBase).SetProtect(bSet);
}
}
break;
case WID_USE_ALPHABETICAL_SEPARATORS:
lcl_AnyToBitMask(rValue, nTOIOptions,
nsSwTOIOptions::TOI_ALPHA_DELIMITTER);
break;
case WID_USE_KEY_AS_ENTRY:
lcl_AnyToBitMask(rValue, nTOIOptions,
nsSwTOIOptions::TOI_KEY_AS_ENTRY);
break;
case WID_USE_COMBINED_ENTRIES:
lcl_AnyToBitMask(rValue, nTOIOptions,
nsSwTOIOptions::TOI_SAME_ENTRY);
break;
case WID_IS_CASE_SENSITIVE:
lcl_AnyToBitMask(rValue, nTOIOptions,
nsSwTOIOptions::TOI_CASE_SENSITIVE);
break;
case WID_USE_P_P:
lcl_AnyToBitMask(rValue, nTOIOptions, nsSwTOIOptions::TOI_FF);
break;
case WID_USE_DASH:
lcl_AnyToBitMask(rValue, nTOIOptions, nsSwTOIOptions::TOI_DASH);
break;
case WID_USE_UPPER_CASE:
lcl_AnyToBitMask(rValue, nTOIOptions,
nsSwTOIOptions::TOI_INITIAL_CAPS);
break;
case WID_IS_COMMA_SEPARATED:
bForm = sal_True;
aForm.SetCommaSeparated(lcl_AnyToBool(rValue));
break;
case WID_LABEL_CATEGORY:
{
// convert file-format/API/external programmatic english name
// to internal UI name before usage
String aName( SwStyleNameMapper::GetSpecialExtraUIName(
lcl_AnyToString(rValue) ) );
rTOXBase.SetSequenceName( aName );
}
break;
case WID_LABEL_DISPLAY_TYPE:
{
const sal_Int16 nVal = lcl_AnyToInt16(rValue);
sal_uInt16 nSet = CAPTION_COMPLETE;
switch (nVal)
{
case text::ReferenceFieldPart::TEXT:
nSet = CAPTION_COMPLETE;
break;
case text::ReferenceFieldPart::CATEGORY_AND_NUMBER:
nSet = CAPTION_NUMBER;
break;
case text::ReferenceFieldPart::ONLY_CAPTION:
nSet = CAPTION_TEXT;
break;
default:
throw lang::IllegalArgumentException();
}
rTOXBase.SetCaptionDisplay(static_cast<SwCaptionDisplay>(nSet));
}
break;
case WID_USE_LEVEL_FROM_SOURCE:
rTOXBase.SetLevelFromChapter(lcl_AnyToBool(rValue));
break;
case WID_MAIN_ENTRY_CHARACTER_STYLE_NAME:
{
String aString;
SwStyleNameMapper::FillUIName(lcl_AnyToString(rValue),
aString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True);
rTOXBase.SetMainEntryCharStyle( aString );
}
break;
case WID_CREATE_FROM_TABLES:
lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_TABLE);
break;
case WID_CREATE_FROM_TEXT_FRAMES:
lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_FRAME);
break;
case WID_CREATE_FROM_GRAPHIC_OBJECTS:
lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_GRAPHIC);
break;
case WID_CREATE_FROM_EMBEDDED_OBJECTS:
lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_OLE);
break;
case WID_CREATE_FROM_STAR_MATH:
lcl_AnyToBitMask(rValue, nOLEOptions, nsSwTOOElements::TOO_MATH);
break;
case WID_CREATE_FROM_STAR_CHART:
lcl_AnyToBitMask(rValue, nOLEOptions, nsSwTOOElements::TOO_CHART);
break;
case WID_CREATE_FROM_STAR_CALC:
lcl_AnyToBitMask(rValue, nOLEOptions, nsSwTOOElements::TOO_CALC);
break;
case WID_CREATE_FROM_STAR_DRAW:
lcl_AnyToBitMask(rValue, nOLEOptions,
nsSwTOOElements::TOO_DRAW_IMPRESS);
break;
case WID_CREATE_FROM_OTHER_EMBEDDED_OBJECTS:
lcl_AnyToBitMask(rValue, nOLEOptions, nsSwTOOElements::TOO_OTHER);
break;
case WID_PARA_HEAD:
{
String aString;
SwStyleNameMapper::FillUIName( lcl_AnyToString(rValue),
aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True);
bForm = sal_True;
// Header is on Pos 0
aForm.SetTemplate( 0, aString );
}
break;
case WID_IS_RELATIVE_TABSTOPS:
bForm = sal_True;
aForm.SetRelTabPos(lcl_AnyToBool(rValue));
break;
case WID_PARA_SEP:
{
String aString;
bForm = sal_True;
SwStyleNameMapper::FillUIName( lcl_AnyToString(rValue),
aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True);
aForm.SetTemplate( 1, aString );
}
break;
case WID_CREATE_FROM_PARAGRAPH_STYLES:
lcl_AnyToBitMask(rValue, nCreate, nsSwTOXElement::TOX_TEMPLATE);
break;
case WID_PARA_LEV1:
case WID_PARA_LEV2:
case WID_PARA_LEV3:
case WID_PARA_LEV4:
case WID_PARA_LEV5:
case WID_PARA_LEV6:
case WID_PARA_LEV7:
case WID_PARA_LEV8:
case WID_PARA_LEV9:
case WID_PARA_LEV10:
{
bForm = sal_True;
// in sdbcx::Index Label 1 begins at Pos 2 otherwise at Pos 1
const sal_uInt16 nLPos = rTOXBase.GetType() == TOX_INDEX ? 2 : 1;
String aString;
SwStyleNameMapper::FillUIName( lcl_AnyToString(rValue),
aString, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True);
aForm.SetTemplate(nLPos + pEntry->nWID - WID_PARA_LEV1, aString );
}
break;
default:
//this is for items only
if (WID_PRIMARY_KEY > pEntry->nWID)
{
const SwAttrSet& rSet =
m_pImpl->m_pDoc->GetTOXBaseAttrSet(rTOXBase);
SfxItemSet aAttrSet(rSet);
m_pImpl->m_rPropSet.setPropertyValue(
rPropertyName, rValue, aAttrSet);
const SwSectionFmts& rSects = m_pImpl->m_pDoc->GetSections();
for (sal_uInt16 i = 0; i < rSects.Count(); i++)
{
const SwSectionFmt* pTmpFmt = rSects[ i ];
if (pTmpFmt == pSectionFmt)
{
SwSectionData tmpData(
static_cast<SwTOXBaseSection&>(rTOXBase));
m_pImpl->m_pDoc->UpdateSection(i, tmpData, & aAttrSet);
break;
}
}
}
}
rTOXBase.SetCreate(nCreate);
rTOXBase.SetOLEOptions(nOLEOptions);
if (rTOXBase.GetTOXType()->GetType() == TOX_INDEX)
{
rTOXBase.SetOptions(nTOIOptions);
}
if (bForm)
{
rTOXBase.SetTOXForm(aForm);
}
}
uno::Any SAL_CALL
SwXDocumentIndex::getPropertyValue(const OUString& rPropertyName)
throw (beans::UnknownPropertyException, lang::WrappedTargetException,
uno::RuntimeException)
{
SolarMutexGuard aGuard;
uno::Any aRet;
SfxItemPropertySimpleEntry const*const pEntry =
m_pImpl->m_rPropSet.getPropertyMap().getByName(rPropertyName);
if (!pEntry)
{
throw beans::UnknownPropertyException(
OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
+ rPropertyName,
static_cast< cppu::OWeakObject * >(this));
}
SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() );
SwTOXBase* pTOXBase = 0;
if (pSectionFmt)
{
pTOXBase = static_cast<SwTOXBaseSection*>(pSectionFmt->GetSection());
}
else if (m_pImpl->m_bIsDescriptor)
{
pTOXBase = &m_pImpl->m_pProps->GetTOXBase();
}
if(pTOXBase)
{
const sal_uInt16 nCreate = pTOXBase->GetCreateType();
const sal_uInt16 nOLEOptions = pTOXBase->GetOLEOptions();
const sal_uInt16 nTOIOptions =
(pTOXBase->GetTOXType()->GetType() == TOX_INDEX)
? pTOXBase->GetOptions()
: 0U;
const SwForm& rForm = pTOXBase->GetTOXForm();
switch(pEntry->nWID)
{
case WID_IDX_CONTENT_SECTION:
case WID_IDX_HEADER_SECTION :
if(WID_IDX_CONTENT_SECTION == pEntry->nWID)
{
const uno::Reference <text::XTextSection> xContentSect =
SwXTextSection::CreateXTextSection( pSectionFmt );
aRet <<= xContentSect;
}
else
{
SwSections aSectArr;
pSectionFmt->GetChildSections(aSectArr,
SORTSECT_NOT, sal_False);
for(sal_uInt16 i = 0; i < aSectArr.Count(); i++)
{
SwSection* pSect = aSectArr[i];
if(pSect->GetType() == TOX_HEADER_SECTION)
{
const uno::Reference <text::XTextSection> xHeader =
SwXTextSection::CreateXTextSection(
pSect->GetFmt() );
aRet <<= xHeader;
break;
}
}
}
break;
case WID_IDX_TITLE :
{
OUString uRet(pTOXBase->GetTitle());
aRet <<= uRet;
break;
}
case WID_IDX_NAME:
aRet <<= OUString(pTOXBase->GetTOXName());
break;
case WID_USER_IDX_NAME:
{
OUString sTmp;
if (!m_pImpl->m_bIsDescriptor)
{
sTmp = pTOXBase->GetTOXType()->GetTypeName();
}
else
{
sTmp = m_pImpl->m_pProps->GetTypeName();
}
//I18N
lcl_ConvertTOUNameToProgrammaticName(sTmp);
aRet <<= sTmp;
}
break;
case WID_IDX_LOCALE:
aRet <<= SvxCreateLocale(pTOXBase->GetLanguage());
break;
case WID_IDX_SORT_ALGORITHM:
aRet <<= OUString(pTOXBase->GetSortAlgorithm());
break;
case WID_LEVEL :
aRet <<= static_cast<sal_Int16>(pTOXBase->GetLevel());
break;
case WID_CREATE_FROM_MARKS:
lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_MARK);
break;
case WID_CREATE_FROM_OUTLINE:
lcl_BitMaskToAny(aRet, nCreate,
nsSwTOXElement::TOX_OUTLINELEVEL);
break;
case WID_CREATE_FROM_CHAPTER:
{
const sal_Bool bRet = pTOXBase->IsFromChapter();
aRet <<= bRet;
}
break;
case WID_CREATE_FROM_LABELS:
{
const sal_Bool bRet = ! pTOXBase->IsFromObjectNames();
aRet <<= bRet;
}
break;
case WID_PROTECTED:
{
const sal_Bool bRet = pTOXBase->IsProtected();
aRet <<= bRet;
}
break;
case WID_USE_ALPHABETICAL_SEPARATORS:
lcl_BitMaskToAny(aRet, nTOIOptions,
nsSwTOIOptions::TOI_ALPHA_DELIMITTER);
break;
case WID_USE_KEY_AS_ENTRY:
lcl_BitMaskToAny(aRet, nTOIOptions,
nsSwTOIOptions::TOI_KEY_AS_ENTRY);
break;
case WID_USE_COMBINED_ENTRIES:
lcl_BitMaskToAny(aRet, nTOIOptions,
nsSwTOIOptions::TOI_SAME_ENTRY);
break;
case WID_IS_CASE_SENSITIVE:
lcl_BitMaskToAny(aRet, nTOIOptions,
nsSwTOIOptions::TOI_CASE_SENSITIVE);
break;
case WID_USE_P_P:
lcl_BitMaskToAny(aRet, nTOIOptions, nsSwTOIOptions::TOI_FF);
break;
case WID_USE_DASH:
lcl_BitMaskToAny(aRet, nTOIOptions, nsSwTOIOptions::TOI_DASH);
break;
case WID_USE_UPPER_CASE:
lcl_BitMaskToAny(aRet, nTOIOptions,
nsSwTOIOptions::TOI_INITIAL_CAPS);
break;
case WID_IS_COMMA_SEPARATED:
{
const sal_Bool bRet = rForm.IsCommaSeparated();
aRet <<= bRet;
}
break;
case WID_LABEL_CATEGORY:
{
// convert internal UI name to
// file-format/API/external programmatic english name
// before usage
String aName( SwStyleNameMapper::GetSpecialExtraProgName(
pTOXBase->GetSequenceName() ) );
aRet <<= OUString( aName );
}
break;
case WID_LABEL_DISPLAY_TYPE:
{
sal_Int16 nSet = text::ReferenceFieldPart::TEXT;
switch (pTOXBase->GetCaptionDisplay())
{
case CAPTION_COMPLETE:
nSet = text::ReferenceFieldPart::TEXT;
break;
case CAPTION_NUMBER:
nSet = text::ReferenceFieldPart::CATEGORY_AND_NUMBER;
break;
case CAPTION_TEXT:
nSet = text::ReferenceFieldPart::ONLY_CAPTION;
break;
}
aRet <<= nSet;
}
break;
case WID_USE_LEVEL_FROM_SOURCE:
{
const sal_Bool bRet = pTOXBase->IsLevelFromChapter();
aRet <<= bRet;
}
break;
case WID_LEVEL_FORMAT:
{
uno::Reference< container::XIndexReplace > xTokenAccess(
m_pImpl->m_wTokenAccess);
if (!xTokenAccess.is())
{
xTokenAccess = new TokenAccess_Impl(*this);
m_pImpl->m_wTokenAccess = xTokenAccess;
}
aRet <<= xTokenAccess;
}
break;
case WID_LEVEL_PARAGRAPH_STYLES:
{
uno::Reference< container::XIndexReplace > xStyleAccess(
m_pImpl->m_wStyleAccess);
if (!xStyleAccess.is())
{
xStyleAccess = new StyleAccess_Impl(*this);
m_pImpl->m_wStyleAccess = xStyleAccess;
}
aRet <<= xStyleAccess;
}
break;
case WID_MAIN_ENTRY_CHARACTER_STYLE_NAME:
{
String aString;
SwStyleNameMapper::FillProgName(
pTOXBase->GetMainEntryCharStyle(),
aString,
nsSwGetPoolIdFromName::GET_POOLID_CHRFMT,
sal_True);
aRet <<= OUString( aString );
}
break;
case WID_CREATE_FROM_TABLES:
lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_TABLE);
break;
case WID_CREATE_FROM_TEXT_FRAMES:
lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_FRAME);
break;
case WID_CREATE_FROM_GRAPHIC_OBJECTS:
lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_GRAPHIC);
break;
case WID_CREATE_FROM_EMBEDDED_OBJECTS:
lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_OLE);
break;
case WID_CREATE_FROM_STAR_MATH:
lcl_BitMaskToAny(aRet, nOLEOptions, nsSwTOOElements::TOO_MATH);
break;
case WID_CREATE_FROM_STAR_CHART:
lcl_BitMaskToAny(aRet, nOLEOptions, nsSwTOOElements::TOO_CHART);
break;
case WID_CREATE_FROM_STAR_CALC:
lcl_BitMaskToAny(aRet, nOLEOptions, nsSwTOOElements::TOO_CALC);
break;
case WID_CREATE_FROM_STAR_DRAW:
lcl_BitMaskToAny(aRet, nOLEOptions,
nsSwTOOElements::TOO_DRAW_IMPRESS);
break;
case WID_CREATE_FROM_OTHER_EMBEDDED_OBJECTS:
lcl_BitMaskToAny(aRet, nOLEOptions, nsSwTOOElements::TOO_OTHER);
break;
case WID_CREATE_FROM_PARAGRAPH_STYLES:
lcl_BitMaskToAny(aRet, nCreate, nsSwTOXElement::TOX_TEMPLATE);
break;
case WID_PARA_HEAD:
{
//Header steht an Pos 0
String aString;
SwStyleNameMapper::FillProgName(rForm.GetTemplate( 0 ), aString,
nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True );
aRet <<= OUString( aString );
}
break;
case WID_PARA_SEP:
{
String aString;
SwStyleNameMapper::FillProgName(
rForm.GetTemplate( 1 ),
aString,
nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL,
sal_True);
aRet <<= OUString( aString );
}
break;
case WID_PARA_LEV1:
case WID_PARA_LEV2:
case WID_PARA_LEV3:
case WID_PARA_LEV4:
case WID_PARA_LEV5:
case WID_PARA_LEV6:
case WID_PARA_LEV7:
case WID_PARA_LEV8:
case WID_PARA_LEV9:
case WID_PARA_LEV10:
{
// in sdbcx::Index Label 1 begins at Pos 2 otherwise at Pos 1
sal_uInt16 nLPos = pTOXBase->GetType() == TOX_INDEX ? 2 : 1;
String aString;
SwStyleNameMapper::FillProgName(
rForm.GetTemplate(nLPos + pEntry->nWID - WID_PARA_LEV1),
aString,
nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL,
sal_True);
aRet <<= OUString( aString );
}
break;
case WID_IS_RELATIVE_TABSTOPS:
{
const sal_Bool bRet = rForm.IsRelTabPos();
aRet <<= bRet;
}
break;
case WID_INDEX_MARKS:
{
SwTOXMarks aMarks;
const SwTOXType* pType = pTOXBase->GetTOXType();
SwTOXMark::InsertTOXMarks( aMarks, *pType );
uno::Sequence< uno::Reference<text::XDocumentIndexMark> > aXMarks(aMarks.Count());
uno::Reference<text::XDocumentIndexMark>* pxMarks = aXMarks.getArray();
for(sal_uInt16 i = 0; i < aMarks.Count(); i++)
{
SwTOXMark* pMark = aMarks.GetObject(i);
pxMarks[i] = SwXDocumentIndexMark::CreateXDocumentIndexMark(
*m_pImpl->m_pDoc,
*const_cast<SwTOXType*>(pType), *pMark);
}
aRet <<= aXMarks;
}
break;
default:
//this is for items only
if(WID_PRIMARY_KEY > pEntry->nWID)
{
const SwAttrSet& rSet =
m_pImpl->m_pDoc->GetTOXBaseAttrSet(*pTOXBase);
aRet = m_pImpl->m_rPropSet.getPropertyValue(
rPropertyName, rSet);
}
}
}
return aRet;
}
void SAL_CALL
SwXDocumentIndex::addPropertyChangeListener(
const ::rtl::OUString& /*rPropertyName*/,
const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
throw (beans::UnknownPropertyException, lang::WrappedTargetException,
uno::RuntimeException)
{
OSL_FAIL("SwXDocumentIndex::addPropertyChangeListener(): not implemented");
}
void SAL_CALL
SwXDocumentIndex::removePropertyChangeListener(
const ::rtl::OUString& /*rPropertyName*/,
const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
throw (beans::UnknownPropertyException, lang::WrappedTargetException,
uno::RuntimeException)
{
OSL_FAIL("SwXDocumentIndex::removePropertyChangeListener(): not implemented");
}
void SAL_CALL
SwXDocumentIndex::addVetoableChangeListener(
const ::rtl::OUString& /*rPropertyName*/,
const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
throw (beans::UnknownPropertyException, lang::WrappedTargetException,
uno::RuntimeException)
{
OSL_FAIL("SwXDocumentIndex::addVetoableChangeListener(): not implemented");
}
void SAL_CALL
SwXDocumentIndex::removeVetoableChangeListener(
const ::rtl::OUString& /*rPropertyName*/,
const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
throw (beans::UnknownPropertyException, lang::WrappedTargetException,
uno::RuntimeException)
{
OSL_FAIL("SwXDocumentIndex::removeVetoableChangeListener(): not implemented");
}
void SAL_CALL
SwXDocumentIndex::attach(const uno::Reference< text::XTextRange > & xTextRange)
throw (lang::IllegalArgumentException, uno::RuntimeException)
{
SolarMutexGuard aGuard;
if (!m_pImpl->m_bIsDescriptor)
{
throw uno::RuntimeException();
}
const uno::Reference<XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
SwXTextRange *const pRange =
::sw::UnoTunnelGetImplementation<SwXTextRange>(xRangeTunnel);
OTextCursorHelper *const pCursor =
::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xRangeTunnel);
SwDoc *const pDoc =
(pRange) ? pRange->GetDoc() : ((pCursor) ? pCursor->GetDoc() : 0);
if (!pDoc)
{
throw lang::IllegalArgumentException();
}
SwUnoInternalPaM aPam(*pDoc);
//das muss jetzt sal_True liefern
::sw::XTextRangeToSwPaM(aPam, xTextRange);
const SwTOXBase* pOld = pDoc->GetCurTOX( *aPam.Start() );
if (pOld)
{
throw lang::IllegalArgumentException();
}
UnoActionContext aAction(pDoc);
if (aPam.HasMark())
{
pDoc->DeleteAndJoin(aPam);
}
SwTOXBase & rTOXBase = m_pImpl->m_pProps->GetTOXBase();
SwTOXType const*const pTOXType = rTOXBase.GetTOXType();
if ((TOX_USER == pTOXType->GetType()) &&
!m_pImpl->m_pProps->GetTypeName().equals(pTOXType->GetTypeName()))
{
lcl_ReAssignTOXType(pDoc, rTOXBase, m_pImpl->m_pProps->GetTypeName());
}
//TODO: apply Section attributes (columns and background)
SwTOXBaseSection const*const pTOX =
pDoc->InsertTableOf( *aPam.GetPoint(), rTOXBase, 0, sal_False );
pDoc->SetTOXBaseName(*pTOX, m_pImpl->m_pProps->GetTOXBase().GetTOXName());
// update page numbers
pTOX->GetFmt()->Add(m_pImpl.get());
pTOX->GetFmt()->SetXObject(static_cast< ::cppu::OWeakObject*>(this));
const_cast<SwTOXBaseSection*>(pTOX)->UpdatePageNum();
m_pImpl->m_pProps.reset();
m_pImpl->m_pDoc = pDoc;
m_pImpl->m_bIsDescriptor = sal_False;
}
uno::Reference< text::XTextRange > SAL_CALL
SwXDocumentIndex::getAnchor() throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() );
if (!pSectionFmt)
{
throw uno::RuntimeException();
}
uno::Reference< text::XTextRange > xRet;
SwNodeIndex const*const pIdx( pSectionFmt->GetCntnt().GetCntntIdx() );
if (pIdx && pIdx->GetNode().GetNodes().IsDocNodes())
{
SwPaM aPaM(*pIdx);
aPaM.Move( fnMoveForward, fnGoCntnt );
aPaM.SetMark();
aPaM.GetPoint()->nNode = *pIdx->GetNode().EndOfSectionNode();
aPaM.Move( fnMoveBackward, fnGoCntnt );
xRet = SwXTextRange::CreateXTextRange(*pSectionFmt->GetDoc(),
*aPaM.GetMark(), aPaM.GetPoint());
}
return xRet;
}
void lcl_RemoveChildSections(SwSectionFmt& rParentFmt)
{
SwSections aTmpArr;
SwDoc *const pDoc = rParentFmt.GetDoc();
const sal_uInt16 nCnt = rParentFmt.GetChildSections(aTmpArr, SORTSECT_POS);
if( nCnt )
{
for( sal_uInt16 n = 0; n < nCnt; ++n )
{
if( aTmpArr[n]->GetFmt()->IsInNodesArr() )
{
SwSectionFmt* pFmt = aTmpArr[n]->GetFmt();
lcl_RemoveChildSections(*pFmt);
pDoc->DelSectionFmt( pFmt );
}
}
}
}
void SAL_CALL SwXDocumentIndex::dispose() throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() );
if (pSectionFmt)
{
pSectionFmt->GetDoc()->DeleteTOX(
*static_cast<SwTOXBaseSection*>(pSectionFmt->GetSection()),
sal_True);
}
}
void SAL_CALL
SwXDocumentIndex::addEventListener(
const uno::Reference< lang::XEventListener > & xListener)
throw (uno::RuntimeException)
{
SolarMutexGuard g;
if (!m_pImpl->GetRegisteredIn())
{
throw uno::RuntimeException();
}
m_pImpl->m_ListenerContainer.AddListener(xListener);
}
void SAL_CALL
SwXDocumentIndex::removeEventListener(
const uno::Reference< lang::XEventListener > & xListener)
throw (uno::RuntimeException)
{
SolarMutexGuard g;
if (!m_pImpl->GetRegisteredIn() ||
!m_pImpl->m_ListenerContainer.RemoveListener(xListener))
{
throw uno::RuntimeException();
}
}
OUString SAL_CALL SwXDocumentIndex::getName() throw (uno::RuntimeException)
{
SolarMutexGuard g;
OUString uRet;
SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() );
if (m_pImpl->m_bIsDescriptor)
{
uRet = OUString(m_pImpl->m_pProps->GetTOXBase().GetTOXName());
}
else if(pSectionFmt)
{
uRet = OUString(pSectionFmt->GetSection()->GetSectionName());
}
else
{
throw uno::RuntimeException();
}
return uRet;
}
void SAL_CALL
SwXDocumentIndex::setName(const OUString& rName) throw (uno::RuntimeException)
{
SolarMutexGuard g;
if (rName.isEmpty())
{
throw uno::RuntimeException();
}
SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() );
if (m_pImpl->m_bIsDescriptor)
{
m_pImpl->m_pProps->GetTOXBase().SetTOXName(rName);
}
else if (pSectionFmt)
{
const bool bSuccess = pSectionFmt->GetDoc()->SetTOXBaseName(
*static_cast<SwTOXBaseSection*>(pSectionFmt->GetSection()), rName);
if (!bSuccess)
{
throw uno::RuntimeException();
}
}
else
{
throw uno::RuntimeException();
}
}
// MetadatableMixin
::sfx2::Metadatable* SwXDocumentIndex::GetCoreObject()
{
SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() );
return pSectionFmt;
}
uno::Reference<frame::XModel> SwXDocumentIndex::GetModel()
{
SwSectionFmt *const pSectionFmt( m_pImpl->GetSectionFmt() );
if (pSectionFmt)
{
SwDocShell const*const pShell( pSectionFmt->GetDoc()->GetDocShell() );
return (pShell) ? pShell->GetModel() : 0;
}
return 0;
}
/******************************************************************
* SwXDocumentIndexMark
******************************************************************/
static sal_uInt16
lcl_TypeToPropertyMap_Mark(const TOXTypes eType)
{
switch (eType)
{
case TOX_INDEX: return PROPERTY_MAP_INDEX_MARK;
case TOX_CONTENT: return PROPERTY_MAP_CNTIDX_MARK;
//case TOX_USER:
default:
return PROPERTY_MAP_USER_MARK;
}
}
class SwXDocumentIndexMark::Impl
: public SwClient
{
private:
bool m_bInReplaceMark;
public:
SfxItemPropertySet const& m_rPropSet;
const TOXTypes m_eTOXType;
SwEventListenerContainer m_ListenerContainer;
bool m_bIsDescriptor;
SwDepend m_TypeDepend;
const SwTOXMark * m_pTOXMark;
SwDoc * m_pDoc;
sal_Bool m_bMainEntry;
sal_uInt16 m_nLevel;
OUString m_sAltText;
OUString m_sPrimaryKey;
OUString m_sSecondaryKey;
OUString m_sTextReading;
OUString m_sPrimaryKeyReading;
OUString m_sSecondaryKeyReading;
OUString m_sUserIndexName;
Impl( SwXDocumentIndexMark & rThis,
SwDoc *const pDoc,
const enum TOXTypes eType,
SwTOXType *const pType, SwTOXMark const*const pMark)
: SwClient(const_cast<SwTOXMark*>(pMark))
, m_bInReplaceMark(false)
, m_rPropSet(
*aSwMapProvider.GetPropertySet(lcl_TypeToPropertyMap_Mark(eType)))
, m_eTOXType(eType)
, m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis))
// #i112513#: unxsols4 (Sun C++ 5.9 SunOS_sparc) generates wrong code for this
// , m_bIsDescriptor(0 == pMark)
, m_bIsDescriptor((0 == pMark) ? true : false)
, m_TypeDepend(this, pType)
, m_pTOXMark(pMark)
, m_pDoc(pDoc)
, m_bMainEntry(sal_False)
, m_nLevel(0)
{
}
SwTOXType * GetTOXType() const {
return static_cast<SwTOXType*>(
const_cast<SwModify *>(m_TypeDepend.GetRegisteredIn()));
}
void DeleteTOXMark()
{
m_pDoc->DeleteTOXMark(m_pTOXMark); // calls Invalidate() via Modify!
m_pTOXMark = 0;
}
void InsertTOXMark(SwTOXType & rTOXType, SwTOXMark & rMark, SwPaM & rPam,
SwXTextCursor const*const pTextCursor);
void ReplaceTOXMark(SwTOXType & rTOXType, SwTOXMark & rMark, SwPaM & rPam)
{
m_bInReplaceMark = true;
DeleteTOXMark();
m_bInReplaceMark = false;
try {
InsertTOXMark(rTOXType, rMark, rPam, 0);
} catch (...) {
OSL_FAIL("ReplaceTOXMark() failed!");
m_ListenerContainer.Disposing();
throw;
}
}
void Invalidate();
protected:
// SwClient
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew);
};
void SwXDocumentIndexMark::Impl::Invalidate()
{
if (GetRegisteredIn())
{
const_cast<SwModify*>(GetRegisteredIn())->Remove(this);
if (m_TypeDepend.GetRegisteredIn())
{
const_cast<SwModify*>(m_TypeDepend.GetRegisteredIn())->Remove(
&m_TypeDepend);
}
}
if (!m_bInReplaceMark) // #i109983# only dispose on delete, not on replace!
{
m_ListenerContainer.Disposing();
}
m_pDoc = 0;
m_pTOXMark = 0;
}
void SwXDocumentIndexMark::Impl::Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew)
{
ClientModify(this, pOld, pNew);
if (!GetRegisteredIn()) // removed => dispose
{
Invalidate();
}
}
SwXDocumentIndexMark::SwXDocumentIndexMark(const TOXTypes eToxType)
: m_pImpl( new SwXDocumentIndexMark::Impl(*this, 0, eToxType, 0, 0) )
{
}
SwXDocumentIndexMark::SwXDocumentIndexMark(SwDoc & rDoc,
SwTOXType & rType, SwTOXMark & rMark)
: m_pImpl( new SwXDocumentIndexMark::Impl(*this, &rDoc, rType.GetType(),
&rType, &rMark) )
{
}
SwXDocumentIndexMark::~SwXDocumentIndexMark()
{
}
uno::Reference<text::XDocumentIndexMark>
SwXDocumentIndexMark::CreateXDocumentIndexMark(
SwDoc & rDoc, SwTOXType & rType, SwTOXMark & rMark)
{
// re-use existing SwXDocumentIndexMark
// NB: xmloff depends on this caching to generate ID from the address!
// #i105557#: do not iterate over the registered clients: race condition
uno::Reference< text::XDocumentIndexMark > xTOXMark(rMark.GetXTOXMark());
if (!xTOXMark.is())
{
SwXDocumentIndexMark *const pNew =
new SwXDocumentIndexMark(rDoc, rType, rMark);
xTOXMark.set(pNew);
rMark.SetXTOXMark(xTOXMark);
}
return xTOXMark;
}
namespace
{
class theSwXDocumentIndexMarkUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXDocumentIndexMarkUnoTunnelId > {};
}
const uno::Sequence< sal_Int8 > & SwXDocumentIndexMark::getUnoTunnelId()
{
return theSwXDocumentIndexMarkUnoTunnelId::get().getSeq();
}
sal_Int64 SAL_CALL
SwXDocumentIndexMark::getSomething(const uno::Sequence< sal_Int8 >& rId)
throw (uno::RuntimeException)
{
return ::sw::UnoTunnelImpl<SwXDocumentIndexMark>(rId, this);
}
static const sal_Char cBaseMark[] = "com.sun.star.text.BaseIndexMark";
static const sal_Char cContentMark[] = "com.sun.star.text.ContentIndexMark";
static const sal_Char cIdxMark[] = "com.sun.star.text.DocumentIndexMark";
static const sal_Char cIdxMarkAsian[] = "com.sun.star.text.DocumentIndexMarkAsian";
static const sal_Char cUserMark[] = "com.sun.star.text.UserIndexMark";
static const sal_Char cTextContent[] = "com.sun.star.text.TextContent";
OUString SAL_CALL
SwXDocumentIndexMark::getImplementationName() throw (uno::RuntimeException)
{
return C2U("SwXDocumentIndexMark");
}
sal_Bool SAL_CALL
SwXDocumentIndexMark::supportsService(const OUString& rServiceName)
throw (uno::RuntimeException)
{
SolarMutexGuard g;
return rServiceName.equalsAscii(cBaseMark)
|| rServiceName.equalsAscii(cTextContent)
|| ((m_pImpl->m_eTOXType == TOX_USER)
&& rServiceName.equalsAscii(cUserMark))
|| ((m_pImpl->m_eTOXType == TOX_CONTENT)
&& rServiceName.equalsAscii(cContentMark))
|| ((m_pImpl->m_eTOXType == TOX_INDEX)
&& rServiceName.equalsAscii(cIdxMark))
|| ((m_pImpl->m_eTOXType == TOX_INDEX)
&& rServiceName.equalsAscii(cIdxMarkAsian));
}
uno::Sequence< OUString > SAL_CALL
SwXDocumentIndexMark::getSupportedServiceNames() throw (uno::RuntimeException)
{
SolarMutexGuard g;
const sal_Int32 nCnt = (m_pImpl->m_eTOXType == TOX_INDEX) ? 4 : 3;
uno::Sequence< OUString > aRet(nCnt);
OUString* pArray = aRet.getArray();
pArray[0] = C2U(cBaseMark);
pArray[1] = C2U(cTextContent);
switch (m_pImpl->m_eTOXType)
{
case TOX_USER:
pArray[2] = C2U(cUserMark);
break;
case TOX_CONTENT:
pArray[2] = C2U(cContentMark);
break;
case TOX_INDEX:
pArray[2] = C2U(cIdxMark);
pArray[3] = C2U(cIdxMarkAsian);
break;
default:
;
}
return aRet;
}
OUString SAL_CALL
SwXDocumentIndexMark::getMarkEntry() throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
OUString sRet;
SwTOXType *const pType = m_pImpl->GetTOXType();
if (pType && m_pImpl->m_pTOXMark)
{
sRet = OUString(m_pImpl->m_pTOXMark->GetAlternativeText());
}
else if (m_pImpl->m_bIsDescriptor)
{
sRet = m_pImpl->m_sAltText;
}
else
{
throw uno::RuntimeException();
}
return sRet;
}
void SAL_CALL
SwXDocumentIndexMark::setMarkEntry(const OUString& rIndexEntry)
throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
SwTOXType *const pType = m_pImpl->GetTOXType();
if (pType && m_pImpl->m_pTOXMark)
{
SwTOXMark aMark(*m_pImpl->m_pTOXMark);
aMark.SetAlternativeText(rIndexEntry);
SwTxtTOXMark const*const pTxtMark =
m_pImpl->m_pTOXMark->GetTxtTOXMark();
SwPaM aPam(pTxtMark->GetTxtNode(), *pTxtMark->GetStart());
aPam.SetMark();
if(pTxtMark->GetEnd())
{
aPam.GetPoint()->nContent = *pTxtMark->GetEnd();
}
else
aPam.GetPoint()->nContent++;
m_pImpl->ReplaceTOXMark(*pType, aMark, aPam);
}
else if (m_pImpl->m_bIsDescriptor)
{
m_pImpl->m_sAltText = rIndexEntry;
}
else
{
throw uno::RuntimeException();
}
}
void SAL_CALL
SwXDocumentIndexMark::attach(
const uno::Reference< text::XTextRange > & xTextRange)
throw (lang::IllegalArgumentException, uno::RuntimeException)
{
SolarMutexGuard aGuard;
if (!m_pImpl->m_bIsDescriptor)
{
throw uno::RuntimeException();
}
const uno::Reference<XUnoTunnel> xRangeTunnel(xTextRange, uno::UNO_QUERY);
SwXTextRange *const pRange =
::sw::UnoTunnelGetImplementation<SwXTextRange>(xRangeTunnel);
OTextCursorHelper *const pCursor =
::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xRangeTunnel);
SwDoc *const pDoc =
(pRange) ? pRange->GetDoc() : ((pCursor) ? pCursor->GetDoc() : 0);
if (!pDoc)
{
throw lang::IllegalArgumentException();
}
const SwTOXType* pTOXType = 0;
switch (m_pImpl->m_eTOXType)
{
case TOX_INDEX:
case TOX_CONTENT:
pTOXType = pDoc->GetTOXType( m_pImpl->m_eTOXType, 0 );
break;
case TOX_USER:
{
if (m_pImpl->m_sUserIndexName.isEmpty())
{
pTOXType = pDoc->GetTOXType( m_pImpl->m_eTOXType, 0 );
}
else
{
const sal_uInt16 nCount =
pDoc->GetTOXTypeCount(m_pImpl->m_eTOXType);
for (sal_uInt16 i = 0; i < nCount; i++)
{
SwTOXType const*const pTemp =
pDoc->GetTOXType( m_pImpl->m_eTOXType, i );
if (m_pImpl->m_sUserIndexName ==
OUString(pTemp->GetTypeName()))
{
pTOXType = pTemp;
break;
}
}
if (!pTOXType)
{
SwTOXType aUserType(TOX_USER, m_pImpl->m_sUserIndexName);
pTOXType = pDoc->InsertTOXType(aUserType);
}
}
}
break;
default:
break;
}
if (!pTOXType)
{
throw lang::IllegalArgumentException();
}
SwUnoInternalPaM aPam(*pDoc);
//which must now return sal_True
::sw::XTextRangeToSwPaM(aPam, xTextRange);
SwTOXMark aMark (pTOXType);
if (!m_pImpl->m_sAltText.isEmpty())
{
aMark.SetAlternativeText(m_pImpl->m_sAltText);
}
switch (m_pImpl->m_eTOXType)
{
case TOX_INDEX:
if (!m_pImpl->m_sPrimaryKey.isEmpty())
{
aMark.SetPrimaryKey(m_pImpl->m_sPrimaryKey);
}
if (!m_pImpl->m_sSecondaryKey.isEmpty())
{
aMark.SetSecondaryKey(m_pImpl->m_sSecondaryKey);
}
if (!m_pImpl->m_sTextReading.isEmpty())
{
aMark.SetTextReading(m_pImpl->m_sTextReading);
}
if (!m_pImpl->m_sPrimaryKeyReading.isEmpty())
{
aMark.SetPrimaryKeyReading(m_pImpl->m_sPrimaryKeyReading);
}
if (!m_pImpl->m_sSecondaryKeyReading.isEmpty())
{
aMark.SetSecondaryKeyReading(m_pImpl->m_sSecondaryKeyReading);
}
aMark.SetMainEntry(m_pImpl->m_bMainEntry);
break;
case TOX_USER:
case TOX_CONTENT:
if (USHRT_MAX != m_pImpl->m_nLevel)
{
aMark.SetLevel(m_pImpl->m_nLevel+1);
}
break;
default:
break;
}
m_pImpl->InsertTOXMark(*const_cast<SwTOXType *>(pTOXType), aMark, aPam,
dynamic_cast<SwXTextCursor const*>(pCursor));
m_pImpl->m_bIsDescriptor = sal_False;
}
template<typename T> struct NotContainedIn
{
::std::vector<T> const& m_rVector;
explicit NotContainedIn(::std::vector<T> const& rVector)
: m_rVector(rVector) { }
bool operator() (T const& rT) {
return ::std::find(m_rVector.begin(), m_rVector.end(), rT)
== m_rVector.end();
}
};
void SwXDocumentIndexMark::Impl::InsertTOXMark(
SwTOXType & rTOXType, SwTOXMark & rMark, SwPaM & rPam,
SwXTextCursor const*const pTextCursor)
{
SwDoc *const pDoc( rPam.GetDoc() );
UnoActionContext aAction(pDoc);
bool bMark = *rPam.GetPoint() != *rPam.GetMark();
// n.b.: toxmarks must have either alternative text or an extent
if (bMark && rMark.GetAlternativeText().Len())
{
rPam.Normalize(sal_True);
rPam.DeleteMark();
bMark = false;
}
// Marks ohne Alternativtext ohne selektierten Text koennen nicht eingefuegt werden,
// deshalb hier ein Leerzeichen - ob das die ideale Loesung ist?
if (!bMark && !rMark.GetAlternativeText().Len())
{
rMark.SetAlternativeText( String(' ') );
}
const bool bForceExpandHints( (!bMark && pTextCursor)
? pTextCursor->IsAtEndOfMeta() : false );
const SetAttrMode nInsertFlags = (bForceExpandHints)
? ( nsSetAttrMode::SETATTR_FORCEHINTEXPAND
| nsSetAttrMode::SETATTR_DONTEXPAND)
: nsSetAttrMode::SETATTR_DONTEXPAND;
::std::vector<SwTxtAttr *> oldMarks;
if (bMark)
{
oldMarks = rPam.GetNode()->GetTxtNode()->GetTxtAttrsAt(
rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_TOXMARK);
}
pDoc->InsertPoolItem(rPam, rMark, nInsertFlags);
if (bMark && *rPam.GetPoint() > *rPam.GetMark())
{
rPam.Exchange();
}
// rMark was copied into the document pool; now retrieve real format...
SwTxtAttr * pTxtAttr(0);
if (bMark)
{
// #i107672#
// ensure that we do not retrieve a different mark at the same position
::std::vector<SwTxtAttr *> const newMarks(
rPam.GetNode()->GetTxtNode()->GetTxtAttrsAt(
rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_TOXMARK));
::std::vector<SwTxtAttr *>::const_iterator const iter(
::std::find_if(newMarks.begin(), newMarks.end(),
NotContainedIn<SwTxtAttr *>(oldMarks)));
OSL_ASSERT(newMarks.end() != iter);
if (newMarks.end() != iter)
{
pTxtAttr = *iter;
}
}
else
{
pTxtAttr = rPam.GetNode()->GetTxtNode()->GetTxtAttrForCharAt(
rPam.GetPoint()->nContent.GetIndex()-1, RES_TXTATR_TOXMARK );
}
if (!pTxtAttr)
{
throw uno::RuntimeException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
"SwXDocumentIndexMark::InsertTOXMark(): cannot insert attribute")),
0);
}
m_pDoc = pDoc;
m_pTOXMark = & pTxtAttr->GetTOXMark();
const_cast<SwTOXMark*>(m_pTOXMark)->Add(this);
const_cast<SwTOXType &>(rTOXType).Add(& m_TypeDepend);
}
uno::Reference< text::XTextRange > SAL_CALL
SwXDocumentIndexMark::getAnchor() throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
SwTOXType *const pType = m_pImpl->GetTOXType();
if (!pType || !m_pImpl->m_pTOXMark)
{
throw uno::RuntimeException();
}
if (!m_pImpl->m_pTOXMark->GetTxtTOXMark())
{
throw uno::RuntimeException();
}
const SwTxtTOXMark* pTxtMark = m_pImpl->m_pTOXMark->GetTxtTOXMark();
SwPaM aPam(pTxtMark->GetTxtNode(), *pTxtMark->GetStart());
aPam.SetMark();
if(pTxtMark->GetEnd())
{
aPam.GetPoint()->nContent = *pTxtMark->GetEnd();
}
else
{
aPam.GetPoint()->nContent++;
}
const uno::Reference< frame::XModel > xModel =
m_pImpl->m_pDoc->GetDocShell()->GetBaseModel();
const uno::Reference< text::XTextDocument > xTDoc(xModel, uno::UNO_QUERY);
const uno::Reference< text::XTextRange > xRet =
new SwXTextRange(aPam, xTDoc->getText());
return xRet;
}
void SAL_CALL
SwXDocumentIndexMark::dispose() throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
SwTOXType *const pType = m_pImpl->GetTOXType();
if (pType && m_pImpl->m_pTOXMark)
{
m_pImpl->DeleteTOXMark(); // call Invalidate() via modify!
}
}
void SAL_CALL
SwXDocumentIndexMark::addEventListener(
const uno::Reference< lang::XEventListener > & xListener)
throw (uno::RuntimeException)
{
SolarMutexGuard g;
if (!m_pImpl->GetRegisteredIn())
{
throw uno::RuntimeException();
}
m_pImpl->m_ListenerContainer.AddListener(xListener);
}
void SAL_CALL
SwXDocumentIndexMark::removeEventListener(
const uno::Reference< lang::XEventListener > & xListener)
throw (uno::RuntimeException)
{
SolarMutexGuard g;
if (!m_pImpl->GetRegisteredIn() ||
!m_pImpl->m_ListenerContainer.RemoveListener(xListener))
{
throw uno::RuntimeException();
}
}
uno::Reference< beans::XPropertySetInfo > SAL_CALL
SwXDocumentIndexMark::getPropertySetInfo() throw (uno::RuntimeException)
{
SolarMutexGuard g;
static uno::Reference< beans::XPropertySetInfo > xInfos[3];
int nPos = 0;
switch (m_pImpl->m_eTOXType)
{
case TOX_INDEX: nPos = 0; break;
case TOX_CONTENT: nPos = 1; break;
case TOX_USER: nPos = 2; break;
default:
;
}
if(!xInfos[nPos].is())
{
const uno::Reference< beans::XPropertySetInfo > xInfo =
m_pImpl->m_rPropSet.getPropertySetInfo();
// extend PropertySetInfo!
const uno::Sequence<beans::Property> aPropSeq = xInfo->getProperties();
xInfos[nPos] = new SfxExtItemPropertySetInfo(
aSwMapProvider.GetPropertyMapEntries(
PROPERTY_MAP_PARAGRAPH_EXTENSIONS),
aPropSeq );
}
return xInfos[nPos];
}
void SAL_CALL
SwXDocumentIndexMark::setPropertyValue(
const OUString& rPropertyName, const uno::Any& rValue)
throw (beans::UnknownPropertyException, beans::PropertyVetoException,
lang::IllegalArgumentException, lang::WrappedTargetException,
uno::RuntimeException)
{
SolarMutexGuard aGuard;
SfxItemPropertySimpleEntry const*const pEntry =
m_pImpl->m_rPropSet.getPropertyMap().getByName(rPropertyName);
if (!pEntry)
{
throw beans::UnknownPropertyException(
OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
+ rPropertyName,
static_cast<cppu::OWeakObject *>(this));
}
if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
{
throw beans::PropertyVetoException(
OUString(RTL_CONSTASCII_USTRINGPARAM("Property is read-only: "))
+ rPropertyName,
static_cast<cppu::OWeakObject *>(this));
}
SwTOXType *const pType = m_pImpl->GetTOXType();
if (pType && m_pImpl->m_pTOXMark)
{
SwTOXMark aMark(*m_pImpl->m_pTOXMark);
switch(pEntry->nWID)
{
case WID_ALT_TEXT:
aMark.SetAlternativeText(lcl_AnyToString(rValue));
break;
case WID_LEVEL:
aMark.SetLevel(Min( static_cast<sal_Int8>( MAXLEVEL ),
static_cast<sal_Int8>(lcl_AnyToInt16(rValue)+1)));
break;
case WID_PRIMARY_KEY :
aMark.SetPrimaryKey(lcl_AnyToString(rValue));
break;
case WID_SECONDARY_KEY:
aMark.SetSecondaryKey(lcl_AnyToString(rValue));
break;
case WID_MAIN_ENTRY:
aMark.SetMainEntry(lcl_AnyToBool(rValue));
break;
case WID_TEXT_READING:
aMark.SetTextReading(lcl_AnyToString(rValue));
break;
case WID_PRIMARY_KEY_READING:
aMark.SetPrimaryKeyReading(lcl_AnyToString(rValue));
break;
case WID_SECONDARY_KEY_READING:
aMark.SetSecondaryKeyReading(lcl_AnyToString(rValue));
break;
}
SwTxtTOXMark const*const pTxtMark =
m_pImpl->m_pTOXMark->GetTxtTOXMark();
SwPaM aPam(pTxtMark->GetTxtNode(), *pTxtMark->GetStart());
aPam.SetMark();
if(pTxtMark->GetEnd())
{
aPam.GetPoint()->nContent = *pTxtMark->GetEnd();
}
else
{
aPam.GetPoint()->nContent++;
}
m_pImpl->ReplaceTOXMark(*pType, aMark, aPam);
}
else if (m_pImpl->m_bIsDescriptor)
{
switch(pEntry->nWID)
{
case WID_ALT_TEXT:
m_pImpl->m_sAltText = lcl_AnyToString(rValue);
break;
case WID_LEVEL:
{
const sal_Int16 nVal = lcl_AnyToInt16(rValue);
if(nVal >= 0 && nVal < MAXLEVEL)
{
m_pImpl->m_nLevel = nVal;
}
else
{
throw lang::IllegalArgumentException();
}
}
break;
case WID_PRIMARY_KEY:
m_pImpl->m_sPrimaryKey = lcl_AnyToString(rValue);
break;
case WID_SECONDARY_KEY:
m_pImpl->m_sSecondaryKey = lcl_AnyToString(rValue);
break;
case WID_TEXT_READING:
m_pImpl->m_sTextReading = lcl_AnyToString(rValue);
break;
case WID_PRIMARY_KEY_READING:
m_pImpl->m_sPrimaryKeyReading = lcl_AnyToString(rValue);
break;
case WID_SECONDARY_KEY_READING:
m_pImpl->m_sSecondaryKeyReading = lcl_AnyToString(rValue);
break;
case WID_USER_IDX_NAME:
{
OUString sTmp(lcl_AnyToString(rValue));
lcl_ConvertTOUNameToUserName(sTmp);
m_pImpl->m_sUserIndexName = sTmp;
}
break;
case WID_MAIN_ENTRY:
m_pImpl->m_bMainEntry = lcl_AnyToBool(rValue);
break;
}
}
else
{
throw uno::RuntimeException();
}
}
uno::Any SAL_CALL
SwXDocumentIndexMark::getPropertyValue(const OUString& rPropertyName)
throw (beans::UnknownPropertyException, lang::WrappedTargetException,
uno::RuntimeException)
{
SolarMutexGuard aGuard;
uno::Any aRet;
SfxItemPropertySimpleEntry const*const pEntry =
m_pImpl->m_rPropSet.getPropertyMap().getByName(rPropertyName);
if (!pEntry)
{
throw beans::UnknownPropertyException(
OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
+ rPropertyName,
static_cast<cppu::OWeakObject *>(this));
}
if (::sw::GetDefaultTextContentValue(aRet, rPropertyName, pEntry->nWID))
{
return aRet;
}
SwTOXType *const pType = m_pImpl->GetTOXType();
if (pType && m_pImpl->m_pTOXMark)
{
switch(pEntry->nWID)
{
case WID_ALT_TEXT:
aRet <<= OUString(m_pImpl->m_pTOXMark->GetAlternativeText());
break;
case WID_LEVEL:
aRet <<= static_cast<sal_Int16>(
m_pImpl->m_pTOXMark->GetLevel() - 1);
break;
case WID_PRIMARY_KEY :
aRet <<= OUString(m_pImpl->m_pTOXMark->GetPrimaryKey());
break;
case WID_SECONDARY_KEY:
aRet <<= OUString(m_pImpl->m_pTOXMark->GetSecondaryKey());
break;
case WID_TEXT_READING:
aRet <<= OUString(m_pImpl->m_pTOXMark->GetTextReading());
break;
case WID_PRIMARY_KEY_READING:
aRet <<= OUString(m_pImpl->m_pTOXMark->GetPrimaryKeyReading());
break;
case WID_SECONDARY_KEY_READING:
aRet <<= OUString(
m_pImpl->m_pTOXMark->GetSecondaryKeyReading());
break;
case WID_USER_IDX_NAME :
{
OUString sTmp(pType->GetTypeName());
lcl_ConvertTOUNameToProgrammaticName(sTmp);
aRet <<= sTmp;
}
break;
case WID_MAIN_ENTRY:
{
const sal_Bool bTemp = m_pImpl->m_pTOXMark->IsMainEntry();
aRet <<= bTemp;
}
break;
}
}
else if (m_pImpl->m_bIsDescriptor)
{
switch(pEntry->nWID)
{
case WID_ALT_TEXT:
aRet <<= m_pImpl->m_sAltText;
break;
case WID_LEVEL:
aRet <<= static_cast<sal_Int16>(m_pImpl->m_nLevel);
break;
case WID_PRIMARY_KEY:
aRet <<= m_pImpl->m_sPrimaryKey;
break;
case WID_SECONDARY_KEY:
aRet <<= m_pImpl->m_sSecondaryKey;
break;
case WID_TEXT_READING:
aRet <<= m_pImpl->m_sTextReading;
break;
case WID_PRIMARY_KEY_READING:
aRet <<= m_pImpl->m_sPrimaryKeyReading;
break;
case WID_SECONDARY_KEY_READING:
aRet <<= m_pImpl->m_sSecondaryKeyReading;
break;
case WID_USER_IDX_NAME :
aRet <<= m_pImpl->m_sUserIndexName;
break;
case WID_MAIN_ENTRY:
{
aRet <<= static_cast<sal_Bool>(m_pImpl->m_bMainEntry);
}
break;
}
}
else
{
throw uno::RuntimeException();
}
return aRet;
}
void SAL_CALL
SwXDocumentIndexMark::addPropertyChangeListener(
const ::rtl::OUString& /*rPropertyName*/,
const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
throw (beans::UnknownPropertyException, lang::WrappedTargetException,
uno::RuntimeException)
{
OSL_FAIL("SwXDocumentIndexMark::addPropertyChangeListener(): not implemented");
}
void SAL_CALL
SwXDocumentIndexMark::removePropertyChangeListener(
const ::rtl::OUString& /*rPropertyName*/,
const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
throw (beans::UnknownPropertyException, lang::WrappedTargetException,
uno::RuntimeException)
{
OSL_FAIL("SwXDocumentIndexMark::removePropertyChangeListener(): not implemented");
}
void SAL_CALL
SwXDocumentIndexMark::addVetoableChangeListener(
const ::rtl::OUString& /*rPropertyName*/,
const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
throw (beans::UnknownPropertyException, lang::WrappedTargetException,
uno::RuntimeException)
{
OSL_FAIL("SwXDocumentIndexMark::addVetoableChangeListener(): not implemented");
}
void SAL_CALL
SwXDocumentIndexMark::removeVetoableChangeListener(
const ::rtl::OUString& /*rPropertyName*/,
const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
throw (beans::UnknownPropertyException, lang::WrappedTargetException,
uno::RuntimeException)
{
OSL_FAIL("SwXDocumentIndexMark::removeVetoableChangeListener(): not implemented");
}
/******************************************************************
* SwXDocumentIndexes
******************************************************************/
SwXDocumentIndexes::SwXDocumentIndexes(SwDoc *const _pDoc)
: SwUnoCollection(_pDoc)
{
}
SwXDocumentIndexes::~SwXDocumentIndexes()
{
}
OUString SAL_CALL
SwXDocumentIndexes::getImplementationName() throw (uno::RuntimeException)
{
return C2U("SwXDocumentIndexes");
}
static char const*const g_ServicesDocumentIndexes[] =
{
"com.sun.star.text.DocumentIndexes",
};
static const size_t g_nServicesDocumentIndexes(
SAL_N_ELEMENTS(g_ServicesDocumentIndexes));
sal_Bool SAL_CALL
SwXDocumentIndexes::supportsService(const OUString& rServiceName)
throw (uno::RuntimeException)
{
return ::sw::SupportsServiceImpl(
g_nServicesDocumentIndexes, g_ServicesDocumentIndexes, rServiceName);
}
uno::Sequence< OUString > SAL_CALL
SwXDocumentIndexes::getSupportedServiceNames() throw (uno::RuntimeException)
{
return ::sw::GetSupportedServiceNamesImpl(
g_nServicesDocumentIndexes, g_ServicesDocumentIndexes);
}
sal_Int32 SAL_CALL
SwXDocumentIndexes::getCount() throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
if(!IsValid())
throw uno::RuntimeException();
sal_uInt32 nRet = 0;
const SwSectionFmts& rFmts = GetDoc()->GetSections();
for( sal_uInt16 n = 0; n < rFmts.Count(); ++n )
{
const SwSection* pSect = rFmts[ n ]->GetSection();
if( TOX_CONTENT_SECTION == pSect->GetType() &&
pSect->GetFmt()->GetSectionNode() )
{
++nRet;
}
}
return nRet;
}
uno::Any SAL_CALL
SwXDocumentIndexes::getByIndex(sal_Int32 nIndex)
throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException,
uno::RuntimeException)
{
SolarMutexGuard aGuard;
if(!IsValid())
throw uno::RuntimeException();
sal_Int32 nIdx = 0;
const SwSectionFmts& rFmts = GetDoc()->GetSections();
for( sal_uInt16 n = 0; n < rFmts.Count(); ++n )
{
const SwSection* pSect = rFmts[ n ]->GetSection();
if( TOX_CONTENT_SECTION == pSect->GetType() &&
pSect->GetFmt()->GetSectionNode() &&
nIdx++ == nIndex )
{
const uno::Reference< text::XDocumentIndex > xTmp =
SwXDocumentIndex::CreateXDocumentIndex(
*GetDoc(), static_cast<SwTOXBaseSection const&>(*pSect));
uno::Any aRet;
aRet <<= xTmp;
return aRet;
}
}
throw lang::IndexOutOfBoundsException();
}
uno::Any SAL_CALL
SwXDocumentIndexes::getByName(const OUString& rName)
throw (container::NoSuchElementException, lang::WrappedTargetException,
uno::RuntimeException)
{
SolarMutexGuard aGuard;
if(!IsValid())
throw uno::RuntimeException();
String sToFind(rName);
const SwSectionFmts& rFmts = GetDoc()->GetSections();
for( sal_uInt16 n = 0; n < rFmts.Count(); ++n )
{
const SwSection* pSect = rFmts[ n ]->GetSection();
if( TOX_CONTENT_SECTION == pSect->GetType() &&
pSect->GetFmt()->GetSectionNode() &&
(static_cast<SwTOXBaseSection const*>(pSect)->GetTOXName()
== sToFind))
{
const uno::Reference< text::XDocumentIndex > xTmp =
SwXDocumentIndex::CreateXDocumentIndex(
*GetDoc(), static_cast<SwTOXBaseSection const&>(*pSect));
uno::Any aRet;
aRet <<= xTmp;
return aRet;
}
}
throw container::NoSuchElementException();
}
uno::Sequence< OUString > SAL_CALL
SwXDocumentIndexes::getElementNames() throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
if(!IsValid())
throw uno::RuntimeException();
const SwSectionFmts& rFmts = GetDoc()->GetSections();
sal_Int32 nCount = 0;
sal_uInt16 n;
for( n = 0; n < rFmts.Count(); ++n )
{
SwSection const*const pSect = rFmts[ n ]->GetSection();
if( TOX_CONTENT_SECTION == pSect->GetType() &&
pSect->GetFmt()->GetSectionNode() )
{
++nCount;
}
}
uno::Sequence< OUString > aRet(nCount);
OUString* pArray = aRet.getArray();
sal_uInt16 nCnt;
for( n = 0, nCnt = 0; n < rFmts.Count(); ++n )
{
SwSection const*const pSect = rFmts[ n ]->GetSection();
if( TOX_CONTENT_SECTION == pSect->GetType() &&
pSect->GetFmt()->GetSectionNode())
{
pArray[nCnt++] = OUString(
static_cast<SwTOXBaseSection const*>(pSect)->GetTOXName());
}
}
return aRet;
}
sal_Bool SAL_CALL
SwXDocumentIndexes::hasByName(const OUString& rName)
throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
if(!IsValid())
throw uno::RuntimeException();
String sToFind(rName);
const SwSectionFmts& rFmts = GetDoc()->GetSections();
for( sal_uInt16 n = 0; n < rFmts.Count(); ++n )
{
SwSection const*const pSect = rFmts[ n ]->GetSection();
if( TOX_CONTENT_SECTION == pSect->GetType() &&
pSect->GetFmt()->GetSectionNode())
{
if (static_cast<SwTOXBaseSection const*>(pSect)->GetTOXName()
== sToFind)
{
return sal_True;
}
}
}
return sal_False;
}
uno::Type SAL_CALL
SwXDocumentIndexes::getElementType() throw (uno::RuntimeException)
{
return text::XDocumentIndex::static_type();
}
sal_Bool SAL_CALL
SwXDocumentIndexes::hasElements() throw (uno::RuntimeException)
{
return 0 != getCount();
}
/******************************************************************
* SwXDocumentIndex::StyleAccess_Impl
******************************************************************/
SwXDocumentIndex::StyleAccess_Impl::StyleAccess_Impl(
SwXDocumentIndex& rParentIdx)
: m_xParent(&rParentIdx)
{
}
SwXDocumentIndex::StyleAccess_Impl::~StyleAccess_Impl()
{
}
OUString SAL_CALL
SwXDocumentIndex::StyleAccess_Impl::getImplementationName()
throw (uno::RuntimeException)
{
return C2U("SwXDocumentIndex::StyleAccess_Impl");
}
static char const*const g_ServicesIndexStyleAccess[] =
{
"com.sun.star.text.DocumentIndexParagraphStyles",
};
static const size_t g_nServicesIndexStyleAccess(
SAL_N_ELEMENTS(g_ServicesIndexStyleAccess));
sal_Bool SAL_CALL
SwXDocumentIndex::StyleAccess_Impl::supportsService(
const OUString& rServiceName)
throw (uno::RuntimeException)
{
return ::sw::SupportsServiceImpl(
g_nServicesIndexStyleAccess, g_ServicesIndexStyleAccess, rServiceName);
}
uno::Sequence< OUString > SAL_CALL
SwXDocumentIndex::StyleAccess_Impl::getSupportedServiceNames()
throw (uno::RuntimeException)
{
return ::sw::GetSupportedServiceNamesImpl(
g_nServicesIndexStyleAccess, g_ServicesIndexStyleAccess);
}
void SAL_CALL
SwXDocumentIndex::StyleAccess_Impl::replaceByIndex(
sal_Int32 nIndex, const uno::Any& rElement)
throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException,
lang::WrappedTargetException, uno::RuntimeException)
{
SolarMutexGuard aGuard;
if(nIndex < 0 || nIndex > MAXLEVEL)
{
throw lang::IndexOutOfBoundsException();
}
SwTOXBase & rTOXBase( m_xParent->m_pImpl->GetTOXSectionOrThrow() );
uno::Sequence<OUString> aSeq;
if(!(rElement >>= aSeq))
{
throw lang::IllegalArgumentException();
}
const sal_Int32 nStyles = aSeq.getLength();
const OUString* pStyles = aSeq.getConstArray();
String sSetStyles;
String aString;
for(sal_Int32 i = 0; i < nStyles; i++)
{
if(i)
{
sSetStyles += TOX_STYLE_DELIMITER;
}
SwStyleNameMapper::FillUIName(pStyles[i], aString,
nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True);
sSetStyles += aString;
}
rTOXBase.SetStyleNames(sSetStyles, static_cast<sal_uInt16>(nIndex));
}
sal_Int32 SAL_CALL
SwXDocumentIndex::StyleAccess_Impl::getCount() throw (uno::RuntimeException)
{
return MAXLEVEL;
}
uno::Any SAL_CALL
SwXDocumentIndex::StyleAccess_Impl::getByIndex(sal_Int32 nIndex)
throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException,
uno::RuntimeException)
{
SolarMutexGuard aGuard;
if(nIndex < 0 || nIndex > MAXLEVEL)
{
throw lang::IndexOutOfBoundsException();
}
SwTOXBase & rTOXBase( m_xParent->m_pImpl->GetTOXSectionOrThrow() );
const String& rStyles =
rTOXBase.GetStyleNames(static_cast<sal_uInt16>(nIndex));
const sal_uInt16 nStyles = comphelper::string::getTokenCount(rStyles, TOX_STYLE_DELIMITER);
uno::Sequence<OUString> aStyles(nStyles);
OUString* pStyles = aStyles.getArray();
String aString;
for(sal_uInt16 i = 0; i < nStyles; i++)
{
SwStyleNameMapper::FillProgName(
rStyles.GetToken(i, TOX_STYLE_DELIMITER),
aString,
nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL,
sal_True);
pStyles[i] = OUString( aString );
}
uno::Any aRet(&aStyles, ::getCppuType((uno::Sequence<OUString>*)0));
return aRet;
}
uno::Type SAL_CALL
SwXDocumentIndex::StyleAccess_Impl::getElementType()
throw (uno::RuntimeException)
{
return ::getCppuType((uno::Sequence<OUString>*)0);
}
sal_Bool SAL_CALL
SwXDocumentIndex::StyleAccess_Impl::hasElements() throw (uno::RuntimeException)
{
return sal_True;
}
/******************************************************************
* SwXDocumentIndex::TokenAccess_Impl
******************************************************************/
SwXDocumentIndex::TokenAccess_Impl::TokenAccess_Impl(
SwXDocumentIndex& rParentIdx)
: m_xParent(&rParentIdx)
{
}
SwXDocumentIndex::TokenAccess_Impl::~TokenAccess_Impl()
{
}
OUString SAL_CALL
SwXDocumentIndex::TokenAccess_Impl::getImplementationName()
throw (uno::RuntimeException)
{
return C2U("SwXDocumentIndex::TokenAccess_Impl");
}
static char const*const g_ServicesIndexTokenAccess[] =
{
"com.sun.star.text.DocumentIndexLevelFormat",
};
static const size_t g_nServicesIndexTokenAccess(
SAL_N_ELEMENTS(g_ServicesIndexTokenAccess));
sal_Bool SAL_CALL
SwXDocumentIndex::TokenAccess_Impl::supportsService(
const OUString& rServiceName)
throw (uno::RuntimeException)
{
return ::sw::SupportsServiceImpl(
g_nServicesIndexTokenAccess, g_ServicesIndexTokenAccess, rServiceName);
}
uno::Sequence< OUString > SAL_CALL
SwXDocumentIndex::TokenAccess_Impl::getSupportedServiceNames()
throw (uno::RuntimeException)
{
return ::sw::GetSupportedServiceNamesImpl(
g_nServicesIndexTokenAccess, g_ServicesIndexTokenAccess);
}
struct TokenType {
const char *pName;
enum FormTokenType eTokenType;
};
static const struct TokenType g_TokenTypes[] =
{
{ "TokenEntryNumber", TOKEN_ENTRY_NO },
{ "TokenEntryText", TOKEN_ENTRY_TEXT },
{ "TokenTabStop", TOKEN_TAB_STOP },
{ "TokenText", TOKEN_TEXT },
{ "TokenPageNumber", TOKEN_PAGE_NUMS },
{ "TokenChapterInfo", TOKEN_CHAPTER_INFO },
{ "TokenHyperlinkStart", TOKEN_LINK_START },
{ "TokenHyperlinkEnd", TOKEN_LINK_END },
{ "TokenBibliographyDataField", TOKEN_AUTHORITY },
{ 0, static_cast<enum FormTokenType>(0) }
};
void SAL_CALL
SwXDocumentIndex::TokenAccess_Impl::replaceByIndex(
sal_Int32 nIndex, const uno::Any& rElement)
throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException,
lang::WrappedTargetException, uno::RuntimeException)
{
SolarMutexGuard aGuard;
SwTOXBase & rTOXBase( m_xParent->m_pImpl->GetTOXSectionOrThrow() );
if ((nIndex < 0) || (nIndex > rTOXBase.GetTOXForm().GetFormMax()))
{
throw lang::IndexOutOfBoundsException();
}
uno::Sequence<beans::PropertyValues> aSeq;
if(!(rElement >>= aSeq))
{
throw lang::IllegalArgumentException();
}
String sPattern;
const sal_Int32 nTokens = aSeq.getLength();
const beans::PropertyValues* pTokens = aSeq.getConstArray();
for(sal_Int32 i = 0; i < nTokens; i++)
{
const beans::PropertyValue* pProperties = pTokens[i].getConstArray();
const sal_Int32 nProperties = pTokens[i].getLength();
//create an invalid token
SwFormToken aToken(TOKEN_END);
for(sal_Int32 j = 0; j < nProperties; j++)
{
if ( pProperties[j].Name == "TokenType" )
{
const OUString sTokenType =
lcl_AnyToString(pProperties[j].Value);
for (TokenType const* pTokenType = g_TokenTypes;
pTokenType->pName; ++pTokenType)
{
if (sTokenType.equalsAscii(pTokenType->pName))
{
aToken.eTokenType = pTokenType->eTokenType;
break;
}
}
}
else if ( pProperties[j].Name == "CharacterStyleName" )
{
String sCharStyleName;
SwStyleNameMapper::FillUIName(
lcl_AnyToString(pProperties[j].Value),
sCharStyleName,
nsSwGetPoolIdFromName::GET_POOLID_CHRFMT,
sal_True);
aToken.sCharStyleName = sCharStyleName;
aToken.nPoolId = SwStyleNameMapper::GetPoolIdFromUIName (
sCharStyleName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
}
else if ( pProperties[j].Name == "TabStopRightAligned" )
{
const sal_Bool bRight = lcl_AnyToBool(pProperties[j].Value);
aToken.eTabAlign = bRight ?
SVX_TAB_ADJUST_END : SVX_TAB_ADJUST_LEFT;
}
else if ( pProperties[j].Name == "TabStopPosition" )
{
sal_Int32 nPosition = 0;
if (!(pProperties[j].Value >>= nPosition))
{
throw lang::IllegalArgumentException();
}
nPosition = MM100_TO_TWIP(nPosition);
if(nPosition < 0)
{
throw lang::IllegalArgumentException();
}
aToken.nTabStopPosition = nPosition;
}
else if ( pProperties[j].Name == "TabStopFillCharacter" )
{
const OUString sFillChar =
lcl_AnyToString(pProperties[j].Value);
if (sFillChar.getLength() > 1)
{
throw lang::IllegalArgumentException();
}
aToken.cTabFillChar =
sFillChar.isEmpty() ? ' ' : sFillChar[0];
}
else if ( pProperties[j].Name == "Text" )
{
const OUString sText = lcl_AnyToString(pProperties[j].Value);
aToken.sText = sText;
}
else if ( pProperties[j].Name == "ChapterFormat" )
{
sal_Int16 nFormat = lcl_AnyToInt16(pProperties[j].Value);
switch(nFormat)
{
case text::ChapterFormat::NUMBER:
nFormat = CF_NUMBER;
break;
case text::ChapterFormat::NAME:
nFormat = CF_TITLE;
break;
case text::ChapterFormat::NAME_NUMBER:
nFormat = CF_NUM_TITLE;
break;
case text::ChapterFormat::NO_PREFIX_SUFFIX:
nFormat = CF_NUMBER_NOPREPST;
break;
case text::ChapterFormat::DIGIT:
nFormat = CF_NUM_NOPREPST_TITLE;
break;
default:
throw lang::IllegalArgumentException();
}
aToken.nChapterFormat = nFormat;
}
// #i53420#
else if ( pProperties[j].Name == "ChapterLevel" )
{
const sal_Int16 nLevel = lcl_AnyToInt16(pProperties[j].Value);
if( nLevel < 1 || nLevel > MAXLEVEL )
{
throw lang::IllegalArgumentException();
}
aToken.nOutlineLevel = nLevel;
}
else if ( pProperties[j].Name == "BibliographyDataField" )
{
sal_Int16 nType = 0;
pProperties[j].Value >>= nType;
if(nType < 0 || nType > text::BibliographyDataField::ISBN)
{
lang::IllegalArgumentException aExcept;
aExcept.Message = C2U("BibliographyDataField - wrong value");
aExcept.ArgumentPosition = static_cast< sal_Int16 >(j);
throw aExcept;
}
aToken.nAuthorityField = nType;
}
// #i21237#
else if ( pProperties[j].Name == "WithTab" )
{
aToken.bWithTab = lcl_AnyToBool(pProperties[j].Value);
}
}
//exception if wrong TokenType
if(TOKEN_END <= aToken.eTokenType )
{
throw lang::IllegalArgumentException();
}
// set TokenType from TOKEN_ENTRY_TEXT to TOKEN_ENTRY if it is
// not a content index
if(TOKEN_ENTRY_TEXT == aToken.eTokenType &&
(TOX_CONTENT != rTOXBase.GetType()))
{
aToken.eTokenType = TOKEN_ENTRY;
}
// #i53420#
// check for chapter format allowed values if it was TOKEN_ENTRY_NO type
// only allowed value are CF_NUMBER and CF_NUM_NOPREPST_TITLE
// reading from file
if( TOKEN_ENTRY_NO == aToken.eTokenType )
{
switch(aToken.nChapterFormat)
{
case CF_NUMBER:
case CF_NUM_NOPREPST_TITLE:
break;
default:
throw lang::IllegalArgumentException();
}
}
sPattern += aToken.GetString();
}
SwForm aForm(rTOXBase.GetTOXForm());
aForm.SetPattern(static_cast<sal_uInt16>(nIndex), sPattern);
rTOXBase.SetTOXForm(aForm);
}
sal_Int32 SAL_CALL
SwXDocumentIndex::TokenAccess_Impl::getCount() throw (uno::RuntimeException)
{
SolarMutexGuard aGuard;
const sal_Int32 nRet = m_xParent->m_pImpl->GetFormMax();
return nRet;
}
uno::Any SAL_CALL
SwXDocumentIndex::TokenAccess_Impl::getByIndex(sal_Int32 nIndex)
throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException,
uno::RuntimeException)
{
SolarMutexGuard aGuard;
SwTOXBase & rTOXBase( m_xParent->m_pImpl->GetTOXSectionOrThrow() );
if ((nIndex < 0) || (nIndex > rTOXBase.GetTOXForm().GetFormMax()))
{
throw lang::IndexOutOfBoundsException();
}
// #i21237#
SwFormTokens aPattern = rTOXBase.GetTOXForm().
GetPattern(static_cast<sal_uInt16>(nIndex));
SwFormTokens::iterator aIt = aPattern.begin();
sal_uInt16 nTokenCount = 0;
uno::Sequence< beans::PropertyValues > aRetSeq;
String aString;
while(aIt != aPattern.end()) // #i21237#
{
nTokenCount++;
aRetSeq.realloc(nTokenCount);
beans::PropertyValues* pTokenProps = aRetSeq.getArray();
SwFormToken aToken = *aIt; // #i21237#
uno::Sequence< beans::PropertyValue >& rCurTokenSeq =
pTokenProps[nTokenCount-1];
SwStyleNameMapper::FillProgName(
aToken.sCharStyleName,
aString,
nsSwGetPoolIdFromName::GET_POOLID_CHRFMT,
sal_True );
const OUString aProgCharStyle( aString );
switch(aToken.eTokenType)
{
case TOKEN_ENTRY_NO:
{
// #i53420#
// writing to file (from doc to properties)
sal_Int32 nElements = 2;
sal_Int32 nCurrentElement = 0;
// check for default value
if (aToken.nChapterFormat != CF_NUMBER)
{
nElements++;//we need the element
}
if( aToken.nOutlineLevel != MAXLEVEL )
{
nElements++;
}
rCurTokenSeq.realloc( nElements );
beans::PropertyValue* pArr = rCurTokenSeq.getArray();
pArr[nCurrentElement].Name = C2U("TokenType");
pArr[nCurrentElement++].Value <<=
OUString(RTL_CONSTASCII_USTRINGPARAM("TokenEntryNumber"));
pArr[nCurrentElement].Name = C2U("CharacterStyleName");
pArr[nCurrentElement++].Value <<= aProgCharStyle;
if( aToken.nChapterFormat != CF_NUMBER )
{
pArr[nCurrentElement].Name = C2U("ChapterFormat");
sal_Int16 nVal;
// the allowed values for chapter format, when used as entry number,
// are CF_NUMBER and CF_NUM_NOPREPST_TITLE only, all else forced to
//CF_NUMBER
switch(aToken.nChapterFormat)
{
default:
case CF_NUMBER:
nVal = text::ChapterFormat::NUMBER;
break;
case CF_NUM_NOPREPST_TITLE:
nVal = text::ChapterFormat::DIGIT;
break;
}
pArr[nCurrentElement++].Value <<= nVal;
}
// only a ChapterLevel != MAXLEVEL is registered
if (aToken.nOutlineLevel != MAXLEVEL)
{
pArr[nCurrentElement].Name = C2U("ChapterLevel");
pArr[nCurrentElement].Value <<= aToken.nOutlineLevel;
}
}
break;
case TOKEN_ENTRY: // no difference between Entry and Entry Text
case TOKEN_ENTRY_TEXT:
{
rCurTokenSeq.realloc( 2 );
beans::PropertyValue* pArr = rCurTokenSeq.getArray();
pArr[0].Name = C2U("TokenType");
pArr[0].Value <<= OUString(RTL_CONSTASCII_USTRINGPARAM("TokenEntryText"));
pArr[1].Name = C2U("CharacterStyleName");
pArr[1].Value <<= aProgCharStyle;
}
break;
case TOKEN_TAB_STOP:
{
rCurTokenSeq.realloc(5); // #i21237#
beans::PropertyValue* pArr = rCurTokenSeq.getArray();
pArr[0].Name = C2U("TokenType");
pArr[0].Value <<= OUString(RTL_CONSTASCII_USTRINGPARAM("TokenTabStop"));
if(SVX_TAB_ADJUST_END == aToken.eTabAlign)
{
pArr[1].Name = C2U("TabStopRightAligned");
sal_Bool bTemp = sal_True;
pArr[1].Value.setValue(&bTemp, ::getCppuBooleanType());
}
else
{
pArr[1].Name = C2U("TabStopPosition");
sal_Int32 nPos = (TWIP_TO_MM100(aToken.nTabStopPosition));
if(nPos < 0)
nPos = 0;
pArr[1].Value <<= (sal_Int32)nPos;
}
pArr[2].Name = C2U("TabStopFillCharacter");
pArr[2].Value <<= OUString(aToken.cTabFillChar);
pArr[3].Name = C2U("CharacterStyleName");
pArr[3].Value <<= aProgCharStyle;
// #i21237#
pArr[4].Name = C2U("WithTab");
pArr[4].Value <<= static_cast<sal_Bool>(aToken.bWithTab);
}
break;
case TOKEN_TEXT:
{
rCurTokenSeq.realloc( 3 );
beans::PropertyValue* pArr = rCurTokenSeq.getArray();
pArr[0].Name = C2U("TokenType");
pArr[0].Value <<= OUString(RTL_CONSTASCII_USTRINGPARAM("TokenText"));
pArr[1].Name = C2U("CharacterStyleName");
pArr[1].Value <<= aProgCharStyle;
pArr[2].Name = C2U("Text");
pArr[2].Value <<= OUString(aToken.sText);
}
break;
case TOKEN_PAGE_NUMS:
{
rCurTokenSeq.realloc( 2 );
beans::PropertyValue* pArr = rCurTokenSeq.getArray();
pArr[0].Name = C2U("TokenType");
pArr[0].Value <<= OUString(RTL_CONSTASCII_USTRINGPARAM("TokenPageNumber"));
pArr[1].Name = C2U("CharacterStyleName");
pArr[1].Value <<= aProgCharStyle;
}
break;
case TOKEN_CHAPTER_INFO:
{
rCurTokenSeq.realloc( 4 );
beans::PropertyValue* pArr = rCurTokenSeq.getArray();
pArr[0].Name = C2U("TokenType");
pArr[0].Value <<= OUString(RTL_CONSTASCII_USTRINGPARAM("TokenChapterInfo"));
pArr[1].Name = C2U("CharacterStyleName");
pArr[1].Value <<= aProgCharStyle;
pArr[2].Name = C2U("ChapterFormat");
sal_Int16 nVal = text::ChapterFormat::NUMBER;
switch(aToken.nChapterFormat)
{
case CF_NUMBER:
nVal = text::ChapterFormat::NUMBER;
break;
case CF_TITLE:
nVal = text::ChapterFormat::NAME;
break;
case CF_NUM_TITLE:
nVal = text::ChapterFormat::NAME_NUMBER;
break;
case CF_NUMBER_NOPREPST:
nVal = text::ChapterFormat::NO_PREFIX_SUFFIX;
break;
case CF_NUM_NOPREPST_TITLE:
nVal = text::ChapterFormat::DIGIT;
break;
}
pArr[2].Value <<= nVal;
// #i53420#
pArr[3].Name = C2U("ChapterLevel");
pArr[3].Value <<= aToken.nOutlineLevel;
}
break;
case TOKEN_LINK_START:
{
rCurTokenSeq.realloc( 2 );
beans::PropertyValue* pArr = rCurTokenSeq.getArray();
pArr[0].Name = C2U("TokenType");
pArr[0].Value <<=
OUString(RTL_CONSTASCII_USTRINGPARAM("TokenHyperlinkStart"));
pArr[1].Name = C2U("CharacterStyleName");
pArr[1].Value <<= aProgCharStyle;
}
break;
case TOKEN_LINK_END:
{
rCurTokenSeq.realloc( 1 );
beans::PropertyValue* pArr = rCurTokenSeq.getArray();
pArr[0].Name = C2U("TokenType");
pArr[0].Value <<=
OUString(RTL_CONSTASCII_USTRINGPARAM("TokenHyperlinkEnd"));
}
break;
case TOKEN_AUTHORITY:
{
rCurTokenSeq.realloc( 3 );
beans::PropertyValue* pArr = rCurTokenSeq.getArray();
pArr[0].Name = C2U("TokenType");
pArr[0].Value <<=
OUString(RTL_CONSTASCII_USTRINGPARAM("TokenBibliographyDataField"));
pArr[1].Name = C2U("CharacterStyleName");
pArr[1].Value <<= aProgCharStyle;
pArr[2].Name = C2U("BibliographyDataField");
pArr[2].Value <<= sal_Int16(aToken.nAuthorityField);
}
break;
default:
;
}
++aIt; // #i21237#
}
uno::Any aRet;
aRet <<= aRetSeq;
return aRet;
}
uno::Type SAL_CALL
SwXDocumentIndex::TokenAccess_Impl::getElementType()
throw (uno::RuntimeException)
{
return ::getCppuType((uno::Sequence< beans::PropertyValues >*)0);
}
sal_Bool SAL_CALL
SwXDocumentIndex::TokenAccess_Impl::hasElements()
throw (uno::RuntimeException)
{
return sal_True;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|