1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <comphelper/lok.hxx>
#include <comphelper/string.hxx>
#include <editeng/frmdiritem.hxx>
#include <svl/urlbmk.hxx>
#include <osl/thread.h>
#include <sal/log.hxx>
#include <tools/urlobj.hxx>
#include <sfx2/docfile.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/event.hxx>
#include <sfx2/viewfrm.hxx>
#include <o3tl/enumrange.hxx>
#include <o3tl/sorted_vector.hxx>
#include <utility>
#include <vcl/commandevent.hxx>
#include <vcl/weldutils.hxx>
#include <sot/formats.hxx>
#include <o3tl/string_view.hxx>
#include <uiitems.hxx>
#include <fmtanchr.hxx>
#include <fmtinfmt.hxx>
#include <txtinet.hxx>
#include <fmtfld.hxx>
#include <swmodule.hxx>
#include <wrtsh.hxx>
#include <view.hxx>
#include <docsh.hxx>
#include <drawdoc.hxx>
#include <content.hxx>
#include <frmatr.hxx>
#include <frmfmt.hxx>
#include <fldbas.hxx>
#include <IMark.hxx>
#include <section.hxx>
#include <tox.hxx>
#include <navipi.hxx>
#include <navicont.hxx>
#include <navicfg.hxx>
#include <edtwin.hxx>
#include <doc.hxx>
#include <IDocumentSettingAccess.hxx>
#include <IDocumentDrawModelAccess.hxx>
#include <IDocumentOutlineNodes.hxx>
#include <unotxvw.hxx>
#include <cmdid.h>
#include <helpids.h>
#include <strings.hrc>
#include <com/sun/star/text/XTextSectionsSupplier.hpp>
#include <com/sun/star/text/XTextGraphicObjectsSupplier.hpp>
#include <com/sun/star/text/XTextTablesSupplier.hpp>
#include <com/sun/star/text/XDocumentIndexesSupplier.hpp>
#include <com/sun/star/text/XDocumentIndex.hpp>
#include <com/sun/star/text/XBookmarksSupplier.hpp>
#include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
#include <com/sun/star/text/XTextFramesSupplier.hpp>
#include <com/sun/star/ui/XSidebarProvider.hpp>
#include <com/sun/star/ui/XDecks.hpp>
#include <com/sun/star/ui/XDeck.hpp>
#include <com/sun/star/ui/XPanels.hpp>
#include <com/sun/star/ui/XPanel.hpp>
#include <svx/svdpage.hxx>
#include <svx/svdview.hxx>
#include <SwRewriter.hxx>
#include <hints.hxx>
#include <numrule.hxx>
#include <swundo.hxx>
#include <ndtxt.hxx>
#include <PostItMgr.hxx>
#include <postithelper.hxx>
#include <swabstdlg.hxx>
#include <bitmaps.hlst>
#include <AnnotationWin.hxx>
#include <memory>
#include <fmtcntnt.hxx>
#include <docstat.hxx>
#include <viewopt.hxx>
#include <IDocumentFieldsAccess.hxx>
#include <txtfld.hxx>
#include <fldmgr.hxx>
#include <frameformats.hxx>
#include <ftnidx.hxx>
#include <txtftn.hxx>
#include <fmtftn.hxx>
#include <txtannotationfld.hxx>
#include <txtfrm.hxx>
#include <txtrfmrk.hxx>
#include <svx/sdr/overlay/overlayselection.hxx>
#include <svx/sdr/overlay/overlayobject.hxx>
#include <svx/sdr/overlay/overlaymanager.hxx>
#include <svx/sdrpaintwindow.hxx>
#include <node2lay.hxx>
#include <sectfrm.hxx>
#include <docufld.hxx>
#define CTYPE_CNT 0
#define CTYPE_CTT 1
using namespace ::com::sun::star;
using namespace ::com::sun::star::text;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::container;
namespace {
/*
Symbolic name representations of numeric values used for the Outline Content Visibility popup
menu item ids. The numbers are chosen arbitrarily to not over overlap other menu item ids.
see: SwContentTree::ExecuteContextMenuAction, navigatorcontextmenu.ui
1512 toggle outline content visibility of the selected outline entry
1513 make the outline content of the selected outline entry and children not visible
1514 make the outline content of the selected entry and children visible
*/
const sal_uInt32 TOGGLE_OUTLINE_CONTENT_VISIBILITY = 1512;
const sal_uInt32 HIDE_OUTLINE_CONTENT_VISIBILITY = 1513;
const sal_uInt32 SHOW_OUTLINE_CONTENT_VISIBILITY = 1514;
constexpr char NAVI_BOOKMARK_DELIM = '\x01';
}
class SwContentArr
: public o3tl::sorted_vector<std::unique_ptr<SwContent>, o3tl::less_uniqueptr_to<SwContent>,
o3tl::find_partialorder_ptrequals>
{
};
namespace
{
std::map<OUString, std::map<void*, bool>> lcl_DocOutLineExpandStateMap;
bool lcl_IsContent(const weld::TreeIter& rEntry, const weld::TreeView& rTreeView)
{
return weld::fromId<const SwTypeNumber*>(rTreeView.get_id(rEntry))->GetTypeId() == CTYPE_CNT;
}
bool lcl_IsContentType(const weld::TreeIter& rEntry, const weld::TreeView& rTreeView)
{
return weld::fromId<const SwTypeNumber*>(rTreeView.get_id(rEntry))->GetTypeId() == CTYPE_CTT;
}
bool lcl_IsLowerOutlineContent(const weld::TreeIter& rEntry, const weld::TreeView& rTreeView, sal_uInt8 nLevel)
{
return weld::fromId<const SwOutlineContent*>(rTreeView.get_id(rEntry))->GetOutlineLevel() < nLevel;
}
bool lcl_FindShell(SwWrtShell const * pShell)
{
bool bFound = false;
SwView *pView = SwModule::GetFirstView();
while (pView)
{
if(pShell == &pView->GetWrtShell())
{
bFound = true;
break;
}
pView = SwModule::GetNextView(pView);
}
return bFound;
}
bool lcl_IsUiVisibleBookmark(const ::sw::mark::IMark* pMark)
{
return IDocumentMarkAccess::GetType(*pMark) == IDocumentMarkAccess::MarkType::BOOKMARK;
}
OUString lcl_GetFootnoteText(const SwTextFootnote& rTextFootnote)
{
SwNodeIndex aIdx(*rTextFootnote.GetStartNode(), 1);
SwContentNode* pCNd = aIdx.GetNode().GetTextNode();
if(!pCNd)
pCNd = aIdx.GetNodes().GoNext(&aIdx);
return pCNd->IsTextNode() ? static_cast<SwTextNode*>(pCNd)->GetText() : OUString();
}
void getAnchorPos(SwPosition& rPos)
{
// get the top most anchor position of the position
if (SwFrameFormat* pFlyFormat = rPos.GetNode().GetFlyFormat())
{
SwNode* pAnchorNode;
SwFrameFormat* pTmp = pFlyFormat;
while (pTmp && (pAnchorNode = pTmp->GetAnchor().GetAnchorNode()) &&
(pTmp = pAnchorNode->GetFlyFormat()))
{
pFlyFormat = pTmp;
}
if (const SwPosition* pPos = pFlyFormat->GetAnchor().GetContentAnchor())
rPos = *pPos;
}
}
bool lcl_IsLowerRegionContent(const weld::TreeIter& rEntry, const weld::TreeView& rTreeView, sal_uInt8 nLevel)
{
return weld::fromId<const SwRegionContent*>(rTreeView.get_id(rEntry))->GetRegionLevel() < nLevel;
}
}
// Content, contains names and reference at the content type.
SwContent::SwContent(const SwContentType* pCnt, OUString aName, double nYPos) :
SwTypeNumber(CTYPE_CNT),
m_pParent(pCnt),
m_sContentName(std::move(aName)),
m_nYPosition(nYPos),
m_bInvisible(false)
{
}
SwTypeNumber::~SwTypeNumber()
{
}
bool SwContent::IsProtect() const
{
return false;
}
bool SwTextFieldContent::IsProtect() const
{
return m_pFormatField->IsProtect();
}
bool SwPostItContent::IsProtect() const
{
return m_pField->IsProtect();
}
bool SwURLFieldContent::IsProtect() const
{
return m_pINetAttr->IsProtect();
}
bool SwRegionContent::IsProtect() const
{
return m_pSectionFormat->GetSection()->IsProtect();
}
SwGraphicContent::~SwGraphicContent()
{
}
SwTOXBaseContent::~SwTOXBaseContent()
{
}
const TranslateId STR_CONTENT_TYPE_ARY[] =
{
STR_CONTENT_TYPE_OUTLINE,
STR_CONTENT_TYPE_TABLE,
STR_CONTENT_TYPE_FRAME,
STR_CONTENT_TYPE_GRAPHIC,
STR_CONTENT_TYPE_OLE,
STR_CONTENT_TYPE_BOOKMARK,
STR_CONTENT_TYPE_REGION,
STR_CONTENT_TYPE_URLFIELD,
STR_CONTENT_TYPE_REFERENCE,
STR_CONTENT_TYPE_INDEX,
STR_CONTENT_TYPE_POSTIT,
STR_CONTENT_TYPE_DRAWOBJECT,
STR_CONTENT_TYPE_TEXTFIELD,
STR_CONTENT_TYPE_FOOTNOTE,
STR_CONTENT_TYPE_ENDNOTE
};
const TranslateId STR_CONTENT_TYPE_SINGLE_ARY[] =
{
STR_CONTENT_TYPE_SINGLE_OUTLINE,
STR_CONTENT_TYPE_SINGLE_TABLE,
STR_CONTENT_TYPE_SINGLE_FRAME,
STR_CONTENT_TYPE_SINGLE_GRAPHIC,
STR_CONTENT_TYPE_SINGLE_OLE,
STR_CONTENT_TYPE_SINGLE_BOOKMARK,
STR_CONTENT_TYPE_SINGLE_REGION,
STR_CONTENT_TYPE_SINGLE_URLFIELD,
STR_CONTENT_TYPE_SINGLE_REFERENCE,
STR_CONTENT_TYPE_SINGLE_INDEX,
STR_CONTENT_TYPE_SINGLE_POSTIT,
STR_CONTENT_TYPE_SINGLE_DRAWOBJECT,
STR_CONTENT_TYPE_SINGLE_TEXTFIELD,
STR_CONTENT_TYPE_SINGLE_FOOTNOTE,
STR_CONTENT_TYPE_SINGLE_ENDNOTE
};
namespace
{
bool checkVisibilityChanged(
const SwContentArr& rSwContentArrA,
const SwContentArr& rSwContentArrB)
{
if(rSwContentArrA.size() != rSwContentArrB.size())
{
return true;
}
for(size_t a(0); a < rSwContentArrA.size(); a++)
{
if(rSwContentArrA[a]->IsInvisible() != rSwContentArrB[a]->IsInvisible())
{
return true;
}
}
return false;
}
// Gets "YPos" for content, i.e. a number used to sort content members in Navigator's list
sal_Int32 getYPos(const SwNode& rNode)
{
SwNodeOffset nIndex = rNode.GetIndex();
if (rNode.GetNodes().GetEndOfExtras().GetIndex() >= nIndex)
{
// Not a node of BodyText
// Are we in a fly?
if (const auto pFlyFormat = rNode.GetFlyFormat())
{
// Get node index of anchor
if (SwNode* pAnchorNode = pFlyFormat->GetAnchor().GetAnchorNode())
{
return getYPos(*pAnchorNode);
}
}
}
return sal_Int32(nIndex);
}
} // end of anonymous namespace
SwContentType::SwContentType(SwWrtShell* pShell, ContentTypeId nType, sal_uInt8 nLevel) :
SwTypeNumber(CTYPE_CTT),
m_pWrtShell(pShell),
m_sContentTypeName(SwResId(STR_CONTENT_TYPE_ARY[static_cast<int>(nType)])),
m_sSingleContentTypeName(SwResId(STR_CONTENT_TYPE_SINGLE_ARY[static_cast<int>(nType)])),
m_nMemberCount(0),
m_nContentType(nType),
m_nOutlineLevel(nLevel),
m_bDataValid(false),
m_bEdit(false),
m_bDelete(true)
{
switch(m_nContentType)
{
case ContentTypeId::OUTLINE:
m_sTypeToken = "outline";
break;
case ContentTypeId::TABLE:
m_sTypeToken = "table";
m_bEdit = true;
break;
case ContentTypeId::FRAME:
m_sTypeToken = "frame";
m_bEdit = true;
break;
case ContentTypeId::GRAPHIC:
m_sTypeToken = "graphic";
m_bEdit = true;
break;
case ContentTypeId::OLE:
m_sTypeToken = "ole";
m_bEdit = true;
break;
case ContentTypeId::TEXTFIELD:
m_bEdit = true;
m_bDelete = true;
break;
case ContentTypeId::FOOTNOTE:
case ContentTypeId::ENDNOTE:
m_bEdit = true;
m_bDelete = false;
break;
case ContentTypeId::BOOKMARK:
{
const bool bProtectedBM = m_pWrtShell->getIDocumentSettingAccess().get(
DocumentSettingId::PROTECT_BOOKMARKS);
m_bEdit = true;
m_bDelete = !bProtectedBM;
}
break;
case ContentTypeId::REGION:
m_sTypeToken = "region";
m_bEdit = true;
m_bDelete = true;
break;
case ContentTypeId::INDEX:
m_bEdit = true;
m_bDelete = true;
break;
case ContentTypeId::REFERENCE:
m_bEdit = false;
m_bDelete = true;
break;
case ContentTypeId::URLFIELD:
m_bEdit = true;
m_bDelete = true;
break;
case ContentTypeId::POSTIT:
m_bEdit = true;
break;
case ContentTypeId::DRAWOBJECT:
m_sTypeToken = "drawingobject";
m_bEdit = true;
break;
default: break;
}
const int nShift = static_cast<int>(m_nContentType);
assert(nShift > -1);
const sal_Int32 nMask = 1 << nShift;
const sal_Int32 nBlock = SW_MOD()->GetNavigationConfig()->GetSortAlphabeticallyBlock();
m_bAlphabeticSort = nBlock & nMask;
FillMemberList();
}
SwContentType::~SwContentType()
{
}
const SwContent* SwContentType::GetMember(size_t nIndex)
{
if(!m_bDataValid || !m_pMember)
{
FillMemberList();
}
if(nIndex < m_pMember->size())
return (*m_pMember)[nIndex].get();
return nullptr;
}
void SwContentType::Invalidate()
{
m_bDataValid = false;
}
void SwContentType::FillMemberList(bool* pbContentChanged)
{
std::unique_ptr<SwContentArr> pOldMember;
size_t nOldMemberCount = 0;
if(m_pMember && pbContentChanged)
{
pOldMember = std::move(m_pMember);
nOldMemberCount = pOldMember->size();
m_pMember.reset( new SwContentArr );
*pbContentChanged = false;
}
else if(!m_pMember)
m_pMember.reset( new SwContentArr );
else
m_pMember->clear();
switch(m_nContentType)
{
case ContentTypeId::OUTLINE :
{
const SwNodeOffset nEndOfExtrasIndex = m_pWrtShell->GetNodes().GetEndOfExtras().GetIndex();
// provide for up to 99999 outline nodes in frames to be sorted in document layout order
double nOutlinesInFramesIndexAdjustment = 0.00001;
const SwOutlineNodes& rOutlineNodes(m_pWrtShell->GetNodes().GetOutLineNds());
const size_t nOutlineCount = rOutlineNodes.size();
for (size_t i = 0; i < nOutlineCount; ++i)
{
SwTextNode* pNode = rOutlineNodes[i]->GetTextNode();
const sal_uInt8 nLevel = pNode->GetAttrOutlineLevel() - 1;
if (nLevel >= m_nOutlineLevel)
continue;
double nYPos = m_bAlphabeticSort ? 0 : static_cast<double>(getYPos(*pNode));
if (nEndOfExtrasIndex >= pNode->GetIndex() && pNode->GetFlyFormat())
{
nYPos += nOutlinesInFramesIndexAdjustment;
nOutlinesInFramesIndexAdjustment += 0.00001;
}
OUString aEntry(comphelper::string::stripStart(
m_pWrtShell->getIDocumentOutlineNodesAccess()->getOutlineText(
i, m_pWrtShell->GetLayout(), true, false, false), ' '));
aEntry = SwNavigationPI::CleanEntry(aEntry);
auto pCnt(std::make_unique<SwOutlineContent>(this, aEntry, i, nLevel,
m_pWrtShell->IsOutlineMovable(i), nYPos));
if (!pNode->getLayoutFrame(m_pWrtShell->GetLayout()))
pCnt->SetInvisible();
m_pMember->insert(std::move(pCnt));
}
// need to check level and equal entry number after creation due to possible outline
// nodes in frames, headers, footers
if (pOldMember)
{
assert(pbContentChanged && "pbContentChanged is always set if pOldMember is");
if (pOldMember->size() != m_pMember->size())
{
*pbContentChanged = true;
break;
}
for (size_t i = 0; i < pOldMember->size(); i++)
{
if (static_cast<SwOutlineContent*>((*pOldMember)[i].get())->GetOutlineLevel() !=
static_cast<SwOutlineContent*>((*m_pMember)[i].get())->GetOutlineLevel())
{
*pbContentChanged = true;
break;
}
}
}
}
break;
case ContentTypeId::TABLE :
{
const size_t nCount = m_pWrtShell->GetTableFrameFormatCount(true);
const sw::TableFrameFormats* pFrameFormats = m_pWrtShell->GetDoc()->GetTableFrameFormats();
for(size_t n = 0, i = 0; i < nCount + n; ++i)
{
const SwTableFormat& rTableFormat = *(*pFrameFormats)[i];
if(!rTableFormat.IsUsed()) // skip deleted tables
{
n++;
continue;
}
tools::Long nYPos = 0;
if (!m_bAlphabeticSort)
{
if (SwTable* pTable = SwTable::FindTable(&rTableFormat))
nYPos = getYPos(*pTable->GetTableNode());
}
auto pCnt = std::make_unique<SwContent>(this, rTableFormat.GetName(), nYPos);
if(!rTableFormat.IsVisible())
pCnt->SetInvisible();
m_pMember->insert(std::move(pCnt));
}
if (pOldMember)
{
// need to check visibility (and equal entry number) after
// creation due to a sorted list being used here (before,
// entries with same index were compared already at creation
// time what worked before a sorted list was used)
*pbContentChanged = checkVisibilityChanged(
*pOldMember,
*m_pMember);
}
}
break;
case ContentTypeId::OLE :
case ContentTypeId::FRAME :
case ContentTypeId::GRAPHIC :
{
FlyCntType eType = FLYCNTTYPE_FRM;
if(m_nContentType == ContentTypeId::OLE)
eType = FLYCNTTYPE_OLE;
else if(m_nContentType == ContentTypeId::GRAPHIC)
eType = FLYCNTTYPE_GRF;
Point aNullPt;
size_t nCount = m_pWrtShell->GetFlyCount(eType, /*bIgnoreTextBoxes=*/true);
std::vector<SwFrameFormat const*> formats(m_pWrtShell->GetFlyFrameFormats(eType, /*bIgnoreTextBoxes=*/true));
SAL_WARN_IF(nCount != formats.size(), "sw.ui", "Count differs");
nCount = formats.size();
for (size_t i = 0; i < nCount; ++i)
{
SwFrameFormat const*const pFrameFormat = formats[i];
const OUString sFrameName = pFrameFormat->GetName();
SwContent* pCnt;
tools::Long nYPos =
m_bAlphabeticSort ? 0 : pFrameFormat->FindLayoutRect(false, &aNullPt).Top();
if(ContentTypeId::GRAPHIC == m_nContentType)
{
OUString sLink;
m_pWrtShell->GetGrfNms( &sLink, nullptr, static_cast<const SwFlyFrameFormat*>( pFrameFormat));
pCnt = new SwGraphicContent(this, sFrameName, INetURLObject::decode(sLink,
INetURLObject::DecodeMechanism::Unambiguous), nYPos);
}
else
{
pCnt = new SwContent(this, sFrameName, nYPos);
}
if(!pFrameFormat->IsVisible())
pCnt->SetInvisible();
m_pMember->insert(std::unique_ptr<SwContent>(pCnt));
}
if (pOldMember)
{
// need to check visibility (and equal entry number) after
// creation due to a sorted list being used here (before,
// entries with same index were compared already at creation
// time what worked before a sorted list was used)
assert(pbContentChanged && "pbContentChanged is always set if pOldMember is");
*pbContentChanged = checkVisibilityChanged(
*pOldMember,
*m_pMember);
}
}
break;
case ContentTypeId::BOOKMARK:
{
tools::Long nYPos = 0;
IDocumentMarkAccess* const pMarkAccess = m_pWrtShell->getIDocumentMarkAccess();
for(IDocumentMarkAccess::const_iterator_t ppBookmark = pMarkAccess->getBookmarksBegin();
ppBookmark != pMarkAccess->getBookmarksEnd();
++ppBookmark)
{
if(lcl_IsUiVisibleBookmark(*ppBookmark))
{
const OUString& rBkmName = (*ppBookmark)->GetName();
//nYPos from 0 -> text::Bookmarks will be sorted alphabetically
auto pCnt(std::make_unique<SwContent>(this, rBkmName,
m_bAlphabeticSort ? 0 : nYPos++));
m_pMember->insert(std::move(pCnt));
}
}
}
break;
case ContentTypeId::TEXTFIELD:
{
std::vector<SwTextField*> aArr;
const SwFieldTypes& rFieldTypes =
*m_pWrtShell->GetDoc()->getIDocumentFieldsAccess().GetFieldTypes();
const size_t nSize = rFieldTypes.size();
for (size_t i = 0; i < nSize; ++i)
{
const SwFieldType* pFieldType = rFieldTypes[i].get();
if (pFieldType->Which() == SwFieldIds::Postit)
continue;
std::vector<SwFormatField*> vFields;
pFieldType->GatherFields(vFields);
for (SwFormatField* pFormatField: vFields)
{
if (SwTextField* pTextField = pFormatField->GetTextField())
{
// fields in header footer don't behave well, skip them
if (m_pWrtShell->GetDoc()->IsInHeaderFooter(pTextField->GetTextNode()))
continue;
aArr.emplace_back(pTextField);
}
}
}
if (!m_bAlphabeticSort)
{
const SwNodeOffset nEndOfExtrasIndex =
m_pWrtShell->GetNodes().GetEndOfExtras().GetIndex();
// use stable sort array to list fields in document model order
std::stable_sort(aArr.begin(), aArr.end(),
[&nEndOfExtrasIndex, this](
const SwTextField* a, const SwTextField* b){
SwPosition aPos(a->GetTextNode(), a->GetStart());
SwPosition bPos(b->GetTextNode(), b->GetStart());
// use anchor position for entries that are located in flys
if (nEndOfExtrasIndex >= aPos.GetNodeIndex())
getAnchorPos(aPos);
if (nEndOfExtrasIndex >= bPos.GetNodeIndex())
getAnchorPos(bPos);
if (aPos == bPos)
{
// probably in same or nested fly frame
// sort using layout position
SwRect aCharRect, bCharRect;
std::shared_ptr<SwPaM> pPamForTextField;
if (SwTextFrame* pFrame = static_cast<SwTextFrame*>(
a->GetTextNode().getLayoutFrame(m_pWrtShell->GetLayout())))
{
SwTextField::GetPamForTextField(*a, pPamForTextField);
if (pPamForTextField)
pFrame->GetCharRect(aCharRect, *pPamForTextField->GetPoint());
}
if (SwTextFrame* pFrame = static_cast<SwTextFrame*>(
b->GetTextNode().getLayoutFrame(m_pWrtShell->GetLayout())))
{
SwTextField::GetPamForTextField(*b, pPamForTextField);
if (pPamForTextField)
pFrame->GetCharRect(bCharRect, *pPamForTextField->GetPoint());
}
return aCharRect.Top() < bCharRect.Top();
}
return aPos < bPos;});
}
std::vector<OUString> aDocumentStatisticsSubTypesList;
tools::Long nYPos = 0;
for (SwTextField* pTextField : aArr)
{
const SwField* pField = pTextField->GetFormatField().GetField();
OUString sExpandField = pField->ExpandField(true, m_pWrtShell->GetLayout());
if (!sExpandField.isEmpty())
sExpandField = u" - " + sExpandField;
OUString sText;
if (pField->GetTypeId() == SwFieldTypesEnum::DocumentStatistics)
{
if (aDocumentStatisticsSubTypesList.empty())
SwFieldMgr(m_pWrtShell).GetSubTypes(SwFieldTypesEnum::DocumentStatistics,
aDocumentStatisticsSubTypesList);
OUString sSubType;
if (pField->GetSubType() < aDocumentStatisticsSubTypesList.size())
sSubType = u" - " + aDocumentStatisticsSubTypesList[pField->GetSubType()];
sText = pField->GetDescription() + u" - " + pField->GetFieldName() + sSubType +
sExpandField;
}
else if (pField->GetTypeId() == SwFieldTypesEnum::GetRef)
{
assert(dynamic_cast<const SwGetRefField*>(pField));
const SwGetRefField* pRefField(static_cast<const SwGetRefField*>(pField));
if (pRefField->IsRefToHeadingCrossRefBookmark() ||
pRefField->IsRefToNumItemCrossRefBookmark())
{
OUString sExpandedTextOfReferencedTextNode =
pRefField->GetExpandedTextOfReferencedTextNode(
*m_pWrtShell->GetLayout(), nullptr, nullptr);
if (sExpandedTextOfReferencedTextNode.getLength() > 80)
{
sExpandedTextOfReferencedTextNode = OUString::Concat(
sExpandedTextOfReferencedTextNode.subView(0, 80)) + u"...";
}
sText = pField->GetDescription() + u" - "
+ sExpandedTextOfReferencedTextNode + sExpandField;
}
else
{
OUString sFieldSubTypeOrName;
auto nSubType = pField->GetSubType();
if (nSubType == REF_FOOTNOTE)
sFieldSubTypeOrName = SwResId(STR_FLDREF_FOOTNOTE);
else if (nSubType == REF_ENDNOTE)
sFieldSubTypeOrName = SwResId(STR_FLDREF_ENDNOTE);
else
sFieldSubTypeOrName = pField->GetFieldName();
sText = pField->GetDescription() + u" - " + sFieldSubTypeOrName
+ sExpandField;
}
}
else
sText = pField->GetDescription() + u" - " + pField->GetFieldName()
+ sExpandField;
auto pCnt(std::make_unique<SwTextFieldContent>(this, sText,
&pTextField->GetFormatField(),
m_bAlphabeticSort ? 0 : nYPos++));
if (!pTextField->GetTextNode().getLayoutFrame(m_pWrtShell->GetLayout()))
pCnt->SetInvisible();
m_pMember->insert(std::move(pCnt));
}
}
break;
// We will separate footnotes and endnotes here.
case ContentTypeId::FOOTNOTE:
case ContentTypeId::ENDNOTE:
{
const SwFootnoteIdxs& rFootnoteIdxs = m_pWrtShell->GetDoc()->GetFootnoteIdxs();
if (rFootnoteIdxs.size() == 0)
break;
// insert footnotes and endnotes
tools::Long nPos = 0;
for (const SwTextFootnote* pTextFootnote : rFootnoteIdxs)
{
if ((!pTextFootnote->GetFootnote().IsEndNote()
&& m_nContentType == ContentTypeId::FOOTNOTE)
|| (pTextFootnote->GetFootnote().IsEndNote()
&& m_nContentType == ContentTypeId::ENDNOTE))
{
const SwFormatFootnote& rFormatFootnote = pTextFootnote->GetFootnote();
const OUString& sText
= rFormatFootnote.GetViewNumStr(*m_pWrtShell->GetDoc(),
m_pWrtShell->GetLayout(), true)
+ " " + lcl_GetFootnoteText(*pTextFootnote);
auto pCnt(std::make_unique<SwTextFootnoteContent>(
this, sText, pTextFootnote, ++nPos));
if (!pTextFootnote->GetTextNode().getLayoutFrame(m_pWrtShell->GetLayout()))
pCnt->SetInvisible();
m_pMember->insert(std::move(pCnt));
}
}
}
break;
case ContentTypeId::REGION :
{
size_t nCount = m_pWrtShell->GetSectionFormatCount();
for (size_t i = 0; i < nCount; ++i)
{
const SwSectionFormat* pFormat = &m_pWrtShell->GetSectionFormat(i);
if (!pFormat->IsInNodesArr())
continue;
const SwSection* pSection = pFormat->GetSection();
if (SectionType eTmpType = pSection->GetType();
eTmpType == SectionType::ToxContent || eTmpType == SectionType::ToxHeader)
continue;
const SwNodeIndex* pNodeIndex = pFormat->GetContent().GetContentIdx();
if (pNodeIndex)
{
const OUString& sSectionName = pSection->GetSectionName();
sal_uInt8 nLevel = 0;
SwSectionFormat* pParentFormat = pFormat->GetParent();
while(pParentFormat)
{
nLevel++;
pParentFormat = pParentFormat->GetParent();
}
auto pCnt(std::make_unique<SwRegionContent>(this, sSectionName, nLevel,
m_bAlphabeticSort ? 0 : getYPos(pNodeIndex->GetNode()),
pFormat));
if (!pFormat->IsVisible() || pSection->IsHidden())
pCnt->SetInvisible();
m_pMember->insert(std::move(pCnt));
}
if (pOldMember)
{
// need to check visibility (and equal entry number) after
// creation due to a sorted list being used here (before,
// entries with same index were compared already at creation
// time what worked before a sorted list was used)
assert(pbContentChanged && "pbContentChanged is always set if pOldMember is");
*pbContentChanged = checkVisibilityChanged(
*pOldMember,
*m_pMember);
}
}
}
break;
case ContentTypeId::REFERENCE:
{
std::vector<OUString> aRefMarks;
m_pWrtShell->GetRefMarks( &aRefMarks );
tools::Long nYPos = 0;
for (const auto& rRefMark : aRefMarks)
{
m_pMember->insert(std::make_unique<SwContent>(this, rRefMark,
m_bAlphabeticSort ? 0 : nYPos++));
}
}
break;
case ContentTypeId::URLFIELD:
{
SwGetINetAttrs aArr;
m_pWrtShell->GetINetAttrs(aArr, false);
if (m_bAlphabeticSort)
{
for (auto& r : aArr)
{
auto pCnt(std::make_unique<SwURLFieldContent>(this, r.sText, INetURLObject::decode(
r.rINetAttr.GetINetFormat().GetValue(),
INetURLObject::DecodeMechanism::Unambiguous),
&r.rINetAttr, 0));
m_pMember->insert(std::move(pCnt));
}
break;
}
// use stable sort array to list hyperlinks in document order
const SwNodeOffset nEndOfExtrasIndex = m_pWrtShell->GetNodes().GetEndOfExtras().GetIndex();
bool bHasEntryInFly = false;
std::vector<SwGetINetAttr*> aStableSortINetAttrsArray;
for (SwGetINetAttr& r : aArr)
{
aStableSortINetAttrsArray.emplace_back(&r);
if (!bHasEntryInFly)
{
if (nEndOfExtrasIndex >= r.rINetAttr.GetTextNode().GetIndex())
{
// Not a node of BodyText
// Are we in a fly?
if (r.rINetAttr.GetTextNode().GetFlyFormat())
bHasEntryInFly = true;
}
}
}
std::stable_sort(aStableSortINetAttrsArray.begin(), aStableSortINetAttrsArray.end(),
[](const SwGetINetAttr* a, const SwGetINetAttr* b){
SwPosition aSwPos(a->rINetAttr.GetTextNode(),
a->rINetAttr.GetStart());
SwPosition bSwPos(b->rINetAttr.GetTextNode(),
b->rINetAttr.GetStart());
return aSwPos < bSwPos;});
// When there are hyperlinks in text frames do an additional sort using the text frame
// anchor position to place entries in the order of document layout appearance.
if (bHasEntryInFly)
{
std::stable_sort(aStableSortINetAttrsArray.begin(), aStableSortINetAttrsArray.end(),
[nEndOfExtrasIndex](const SwGetINetAttr* a, const SwGetINetAttr* b){
const SwTextNode& aTextNode = a->rINetAttr.GetTextNode();
const SwTextNode& bTextNode = b->rINetAttr.GetTextNode();
SwPosition aPos(aTextNode, a->rINetAttr.GetStart());
SwPosition bPos(bTextNode, b->rINetAttr.GetStart());
// use anchor position for entries that are located in flys
if (nEndOfExtrasIndex >= aTextNode.GetIndex())
if (auto pFlyFormat = aTextNode.GetFlyFormat())
if (const SwPosition* pPos = pFlyFormat->GetAnchor().GetContentAnchor())
aPos = *pPos;
if (nEndOfExtrasIndex >= bTextNode.GetIndex())
if (auto pFlyFormat = bTextNode.GetFlyFormat())
if (const SwPosition* pPos = pFlyFormat->GetAnchor().GetContentAnchor())
bPos = *pPos;
return aPos < bPos;});
}
SwGetINetAttrs::size_type n = 0;
for (auto p : aStableSortINetAttrsArray)
{
auto pCnt = std::make_unique<SwURLFieldContent>(this, p->sText,
INetURLObject::decode(p->rINetAttr.GetINetFormat().GetValue(),
INetURLObject::DecodeMechanism::Unambiguous),
&p->rINetAttr, ++n);
m_pMember->insert(std::move(pCnt));
}
}
break;
case ContentTypeId::INDEX:
{
const sal_uInt16 nCount = m_pWrtShell->GetTOXCount();
for ( sal_uInt16 nTox = 0; nTox < nCount; nTox++ )
{
const SwTOXBase* pBase = m_pWrtShell->GetTOX( nTox );
OUString sTOXNm( pBase->GetTOXName() );
SwContent* pCnt = new SwTOXBaseContent(
this, sTOXNm, m_bAlphabeticSort ? 0 : nTox, *pBase);
if(pBase && !pBase->IsVisible())
pCnt->SetInvisible();
m_pMember->insert( std::unique_ptr<SwContent>(pCnt) );
const size_t nPos = m_pMember->size() - 1;
if (pOldMember)
{
assert(pbContentChanged && "pbContentChanged is always set if pOldMember is");
if (!*pbContentChanged && nOldMemberCount > nPos &&
(*pOldMember)[nPos]->IsInvisible() != pCnt->IsInvisible())
*pbContentChanged = true;
}
}
}
break;
case ContentTypeId::POSTIT:
{
SwPostItMgr* aMgr = m_pWrtShell->GetView().GetPostItMgr();
if (aMgr)
{
tools::Long nYPos = 0;
for(SwPostItMgr::const_iterator i = aMgr->begin(); i != aMgr->end(); ++i)
{
if (const SwFormatField* pFormatField = dynamic_cast<const SwFormatField *>((*i)->GetBroadcaster())) // SwPostit
{
if (pFormatField->GetTextField() && pFormatField->IsFieldInDoc())
{
OUString sEntry = pFormatField->GetField()->GetPar2();
sEntry = RemoveNewline(sEntry);
std::unique_ptr<SwPostItContent> pCnt(new SwPostItContent(
this,
sEntry,
pFormatField,
nYPos));
if (!pFormatField->GetTextField()->GetTextNode().getLayoutFrame(
m_pWrtShell->GetLayout()))
pCnt->SetInvisible();
if (pOldMember)
{
assert(pbContentChanged && "pbContentChanged is always set if pOldMember is");
if (!*pbContentChanged &&
nOldMemberCount > o3tl::make_unsigned(nYPos) &&
(*pOldMember)[nYPos]->IsInvisible() != pCnt->IsInvisible())
*pbContentChanged = true;
}
m_pMember->insert(std::move(pCnt));
nYPos++;
}
}
}
}
}
break;
case ContentTypeId::DRAWOBJECT:
{
IDocumentDrawModelAccess& rIDDMA = m_pWrtShell->getIDocumentDrawModelAccess();
SwDrawModel* pModel = rIDDMA.GetDrawModel();
if(pModel)
{
SdrPage* pPage = pModel->GetPage(0);
for (const rtl::Reference<SdrObject>& pTemp : *pPage)
{
// #i51726# - all drawing objects can be named now
if (!pTemp->GetName().isEmpty())
{
tools::Long nYPos = LONG_MIN;
const bool bIsVisible = rIDDMA.IsVisibleLayerId(pTemp->GetLayer());
if (bIsVisible)
nYPos = m_bAlphabeticSort ? 0 : pTemp->GetLogicRect().Top();
auto pCnt(std::make_unique<SwContent>(this, pTemp->GetName(), nYPos));
if (!bIsVisible)
pCnt->SetInvisible();
m_pMember->insert(std::move(pCnt));
}
}
if (pOldMember)
{
// need to check visibility (and equal entry number) after
// creation due to a sorted list being used here (before,
// entries with same index were compared already at creation
// time what worked before a sorted list was used)
assert(pbContentChanged && "pbContentChanged is always set if pOldMember is");
*pbContentChanged = checkVisibilityChanged(
*pOldMember,
*m_pMember);
}
}
}
break;
default: break;
}
m_nMemberCount = m_pMember->size();
if (pOldMember)
{
assert(pbContentChanged && "pbContentChanged is always set if pOldMember is");
if (!*pbContentChanged && pOldMember->size() != m_nMemberCount)
*pbContentChanged = true;
}
m_bDataValid = true;
}
namespace {
enum STR_CONTEXT_IDX
{
IDX_STR_OUTLINE_LEVEL = 0,
IDX_STR_DRAGMODE = 1,
IDX_STR_HYPERLINK = 2,
IDX_STR_LINK_REGION = 3,
IDX_STR_COPY_REGION = 4,
IDX_STR_DISPLAY = 5,
IDX_STR_ACTIVE_VIEW = 6,
IDX_STR_HIDDEN = 7,
IDX_STR_ACTIVE = 8,
IDX_STR_INACTIVE = 9,
IDX_STR_EDIT_ENTRY = 10,
IDX_STR_DELETE_ENTRY = 11,
IDX_STR_SEND_OUTLINE_TO_CLIPBOARD_ENTRY = 12,
IDX_STR_OUTLINE_TRACKING = 13,
IDX_STR_OUTLINE_TRACKING_DEFAULT = 14,
IDX_STR_OUTLINE_TRACKING_FOCUS = 15,
IDX_STR_OUTLINE_TRACKING_OFF = 16
};
}
const TranslateId STR_CONTEXT_ARY[] =
{
STR_OUTLINE_LEVEL,
STR_DRAGMODE,
STR_HYPERLINK,
STR_LINK_REGION,
STR_COPY_REGION,
STR_DISPLAY,
STR_ACTIVE_VIEW,
STR_HIDDEN,
STR_ACTIVE,
STR_INACTIVE,
STR_EDIT_ENTRY,
STR_DELETE_ENTRY,
STR_SEND_OUTLINE_TO_CLIPBOARD_ENTRY,
STR_OUTLINE_TRACKING,
STR_OUTLINE_TRACKING_DEFAULT,
STR_OUTLINE_TRACKING_FOCUS,
STR_OUTLINE_TRACKING_OFF
};
SwContentTree::SwContentTree(std::unique_ptr<weld::TreeView> xTreeView, SwNavigationPI* pDialog)
: m_xTreeView(std::move(xTreeView))
, m_aDropTargetHelper(*this)
, m_pDialog(pDialog)
, m_sSpace(OUString(" "))
, m_aUpdTimer("SwContentTree m_aUpdTimer")
, m_aOverlayObjectDelayTimer("SwContentTree m_aOverlayObjectDelayTimer")
, m_sInvisible(SwResId(STR_INVISIBLE))
, m_pHiddenShell(nullptr)
, m_pActiveShell(nullptr)
, m_pConfig(SW_MOD()->GetNavigationConfig())
, m_nActiveBlock(0)
, m_nHiddenBlock(0)
, m_nEntryCount(0)
, m_nRootType(ContentTypeId::UNKNOWN)
, m_nLastSelType(ContentTypeId::UNKNOWN)
, m_nOutlineLevel(MAXLEVEL)
, m_eState(State::ACTIVE)
, m_bIsRoot(false)
, m_bIsIdleClear(false)
, m_bIsLastReadOnly(false)
, m_bIsOutlineMoveable(true)
, m_bViewHasChanged(false)
{
m_xTreeView->set_size_request(m_xTreeView->get_approximate_digit_width() * 30,
m_xTreeView->get_text_height() * 14);
m_xTreeView->set_help_id(HID_NAVIGATOR_TREELIST);
m_xTreeView->connect_expanding(LINK(this, SwContentTree, ExpandHdl));
m_xTreeView->connect_collapsing(LINK(this, SwContentTree, CollapseHdl));
m_xTreeView->connect_row_activated(LINK(this, SwContentTree, ContentDoubleClickHdl));
m_xTreeView->connect_changed(LINK(this, SwContentTree, SelectHdl));
m_xTreeView->connect_focus_in(LINK(this, SwContentTree, FocusInHdl));
m_xTreeView->connect_key_press(LINK(this, SwContentTree, KeyInputHdl));
m_xTreeView->connect_popup_menu(LINK(this, SwContentTree, CommandHdl));
m_xTreeView->connect_query_tooltip(LINK(this, SwContentTree, QueryTooltipHdl));
m_xTreeView->connect_drag_begin(LINK(this, SwContentTree, DragBeginHdl));
m_xTreeView->connect_mouse_move(LINK(this, SwContentTree, MouseMoveHdl));
m_xTreeView->connect_mouse_press(LINK(this, SwContentTree, MousePressHdl));
for (ContentTypeId i : o3tl::enumrange<ContentTypeId>())
{
if (i != ContentTypeId::OUTLINE)
mTrackContentType[i] = true;
m_aActiveContentArr[i] = nullptr;
m_aHiddenContentArr[i] = nullptr;
}
for (int i = 0; i < CONTEXT_COUNT; ++i)
{
m_aContextStrings[i] = SwResId(STR_CONTEXT_ARY[i]);
}
m_nActiveBlock = m_pConfig->GetActiveBlock();
// Restore outline headings expand state (same session persistence only)
if (SwView* pView = GetActiveView(); pView && pView->GetDocShell())
{
OUString sDocTitle = pView->GetDocShell()->GetTitle();
auto it = lcl_DocOutLineExpandStateMap.find(sDocTitle);
if (it != lcl_DocOutLineExpandStateMap.end())
mOutLineNodeMap = it->second;
if (comphelper::LibreOfficeKit::isActive()) {
if (pView->m_nNaviExpandedStatus < 0)
m_nActiveBlock = 1;
else
m_nActiveBlock = pView->m_nNaviExpandedStatus;
}
}
m_aUpdTimer.SetInvokeHandler(LINK(this, SwContentTree, TimerUpdate));
m_aUpdTimer.SetTimeout(1000);
m_aOverlayObjectDelayTimer.SetInvokeHandler(LINK(this, SwContentTree, OverlayObjectDelayTimerHdl));
m_aOverlayObjectDelayTimer.SetTimeout(500);
}
SwContentTree::~SwContentTree()
{
if (SwView* pView = GetActiveView(); pView && pView->GetDocShell())
{
OUString sDocTitle = pView->GetDocShell()->GetTitle();
lcl_DocOutLineExpandStateMap[sDocTitle] = mOutLineNodeMap;
if (comphelper::LibreOfficeKit::isActive())
pView->m_nNaviExpandedStatus = m_nActiveBlock;
}
clear(); // If applicable erase content types previously.
m_aUpdTimer.Stop();
SetActiveShell(nullptr);
}
IMPL_LINK(SwContentTree, MousePressHdl, const MouseEvent&, rMEvt, bool)
{
m_bSelectTo = rMEvt.IsShift() && (m_pConfig->IsNavigateOnSelect() || rMEvt.GetClicks() == 2);
return false;
}
IMPL_LINK(SwContentTree, MouseMoveHdl, const MouseEvent&, rMEvt, bool)
{
if (m_eState == State::HIDDEN)
return false;
if (std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
m_xTreeView->get_dest_row_at_pos(rMEvt.GetPosPixel(), xEntry.get(), false, false) &&
!rMEvt.IsLeaveWindow())
{
if (!m_xOverlayCompareEntry)
m_xOverlayCompareEntry.reset(m_xTreeView->make_iterator().release());
else if (m_xTreeView->iter_compare(*xEntry, *m_xOverlayCompareEntry) == 0)
return false; // The entry under the mouse has not changed.
m_xTreeView->copy_iterator(*xEntry, *m_xOverlayCompareEntry);
BringEntryToAttention(*xEntry);
}
else
{
if (m_xOverlayCompareEntry)
m_xOverlayCompareEntry.reset();
m_aOverlayObjectDelayTimer.Stop();
if (m_xOverlayObject && m_xOverlayObject->getOverlayManager())
{
m_xOverlayObject->getOverlayManager()->remove(*m_xOverlayObject);
m_xOverlayObject.reset();
}
}
return false;
}
// Drag&Drop methods
IMPL_LINK(SwContentTree, DragBeginHdl, bool&, rUnsetDragIcon, bool)
{
rUnsetDragIcon = true;
bool bDisallow = true;
// don't allow if tree root is selected
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
bool bEntry = m_xTreeView->get_selected(xEntry.get());
if (!bEntry || lcl_IsContentType(*xEntry, *m_xTreeView))
{
return true; // disallow
}
rtl::Reference<TransferDataContainer> xContainer = new TransferDataContainer;
sal_Int8 nDragMode = DND_ACTION_COPYMOVE | DND_ACTION_LINK;
if (FillTransferData(*xContainer, nDragMode))
bDisallow = false;
if (m_bIsRoot && m_nRootType == ContentTypeId::OUTLINE)
{
// Only move drag entry and continuous selected siblings:
m_aDndOutlinesSelected.clear();
std::unique_ptr<weld::TreeIter> xScratch(m_xTreeView->make_iterator());
// Find first selected of continuous siblings
while (true)
{
m_xTreeView->copy_iterator(*xEntry, *xScratch);
if (!m_xTreeView->iter_previous_sibling(*xScratch))
break;
if (!m_xTreeView->is_selected(*xScratch))
break;
m_xTreeView->copy_iterator(*xScratch, *xEntry);
}
// Record continuous selected siblings
do
{
m_aDndOutlinesSelected.push_back(m_xTreeView->make_iterator(xEntry.get()));
}
while (m_xTreeView->iter_next_sibling(*xEntry) && m_xTreeView->is_selected(*xEntry));
bDisallow = false;
}
if (!bDisallow)
m_xTreeView->enable_drag_source(xContainer, nDragMode);
return bDisallow;
}
SwContentTreeDropTarget::SwContentTreeDropTarget(SwContentTree& rTreeView)
: DropTargetHelper(rTreeView.get_widget().get_drop_target())
, m_rTreeView(rTreeView)
{
}
sal_Int8 SwContentTreeDropTarget::AcceptDrop(const AcceptDropEvent& rEvt)
{
sal_Int8 nAccept = m_rTreeView.AcceptDrop(rEvt);
if (nAccept != DND_ACTION_NONE)
{
// to enable the autoscroll when we're close to the edges
weld::TreeView& rWidget = m_rTreeView.get_widget();
rWidget.get_dest_row_at_pos(rEvt.maPosPixel, nullptr, true);
}
return nAccept;
}
bool SwContentTree::IsInDrag() const
{
return m_xTreeView->get_drag_source() == m_xTreeView.get();
}
bool SwContentTree::HasHeadings() const
{
const std::unique_ptr<SwContentType>& rpContentT = m_aActiveContentArr[ContentTypeId::OUTLINE];
if (rpContentT && rpContentT->GetMemberCount() > 0)
return true;
return false;
}
// QueryDrop will be executed in the navigator
sal_Int8 SwContentTree::AcceptDrop(const AcceptDropEvent& rEvt)
{
sal_Int8 nRet = DND_ACTION_NONE;
if( m_bIsRoot )
{
if( m_bIsOutlineMoveable )
nRet = rEvt.mnAction;
}
else if (!IsInDrag())
nRet = GetParentWindow()->AcceptDrop();
return nRet;
}
// Drop will be executed in the navigator
static void* lcl_GetOutlineKey(SwContentTree& rTree, SwOutlineContent const * pContent)
{
void* key = nullptr;
if (pContent)
{
SwWrtShell* pShell = rTree.GetWrtShell();
auto const nPos = pContent->GetOutlinePos();
key = static_cast<void*>(pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos ));
}
return key;
}
sal_Int8 SwContentTreeDropTarget::ExecuteDrop(const ExecuteDropEvent& rEvt)
{
return m_rTreeView.ExecuteDrop(rEvt);
}
sal_Int8 SwContentTree::ExecuteDrop(const ExecuteDropEvent& rEvt)
{
std::unique_ptr<weld::TreeIter> xDropEntry(m_xTreeView->make_iterator());
if (!m_xTreeView->get_dest_row_at_pos(rEvt.maPosPixel, xDropEntry.get(), true))
xDropEntry.reset();
if (m_nRootType == ContentTypeId::OUTLINE)
{
if (xDropEntry && lcl_IsContent(*xDropEntry, *m_xTreeView))
{
assert(dynamic_cast<SwContent*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(*xDropEntry))));
SwOutlineContent* pOutlineContent = weld::fromId<SwOutlineContent*>(m_xTreeView->get_id(*xDropEntry));
assert(pOutlineContent);
void* key = lcl_GetOutlineKey(*this, pOutlineContent);
assert(key);
if (!mOutLineNodeMap[key])
{
while (m_xTreeView->iter_has_child(*xDropEntry))
{
std::unique_ptr<weld::TreeIter> xChildEntry(m_xTreeView->make_iterator(xDropEntry.get()));
bool bChildEntry = m_xTreeView->iter_children(*xChildEntry);
while (bChildEntry)
{
m_xTreeView->copy_iterator(*xChildEntry, *xDropEntry);
bChildEntry = m_xTreeView->iter_next_sibling(*xChildEntry);
}
}
}
}
SwOutlineNodes::size_type nTargetPos = 0;
if (!xDropEntry)
{
// dropped in blank space -> move to bottom
nTargetPos = GetWrtShell()->getIDocumentOutlineNodesAccess()->getOutlineNodesCount() - 1;
}
else if (!lcl_IsContent(*xDropEntry, *m_xTreeView))
{
// dropped on "heading" parent -> move to start
nTargetPos = SwOutlineNodes::npos;
}
else
{
assert(dynamic_cast<SwOutlineContent*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(*xDropEntry))));
nTargetPos = weld::fromId<SwOutlineContent*>(m_xTreeView->get_id(*xDropEntry))->GetOutlinePos();
}
if( MAXLEVEL > m_nOutlineLevel && // Not all layers are displayed.
nTargetPos != SwOutlineNodes::npos)
{
std::unique_ptr<weld::TreeIter> xNext(m_xTreeView->make_iterator(xDropEntry.get()));
bool bNext = m_xTreeView->iter_next(*xNext);
if (bNext)
{
assert(dynamic_cast<SwOutlineContent*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(*xNext))));
nTargetPos = weld::fromId<SwOutlineContent*>(m_xTreeView->get_id(*xNext))->GetOutlinePos() - 1;
}
else
nTargetPos = GetWrtShell()->getIDocumentOutlineNodesAccess()->getOutlineNodesCount() - 1;
}
// remove the drop highlight before we change the contents of the tree so we don't
// try and dereference a removed entry in post-processing drop
m_xTreeView->unset_drag_dest_row();
MoveOutline(nTargetPos);
}
return IsInDrag() ? DND_ACTION_NONE : GetParentWindow()->ExecuteDrop(rEvt);
}
namespace
{
bool IsAllExpanded(const weld::TreeView& rContentTree, const weld::TreeIter& rEntry)
{
if (!rContentTree.get_row_expanded(rEntry))
return false;
if (!rContentTree.iter_has_child(rEntry))
return false;
std::unique_ptr<weld::TreeIter> xChild(rContentTree.make_iterator(&rEntry));
(void)rContentTree.iter_children(*xChild);
do
{
if (rContentTree.iter_has_child(*xChild) || rContentTree.get_children_on_demand(*xChild))
{
if (!IsAllExpanded(rContentTree, *xChild))
return false;
}
}
while (rContentTree.iter_next_sibling(*xChild));
return true;
}
void ExpandOrCollapseAll(weld::TreeView& rContentTree, weld::TreeIter& rEntry)
{
bool bExpand = !IsAllExpanded(rContentTree, rEntry);
bExpand ? rContentTree.expand_row(rEntry) : rContentTree.collapse_row(rEntry);
int nRefDepth = rContentTree.get_iter_depth(rEntry);
while (rContentTree.iter_next(rEntry) && rContentTree.get_iter_depth(rEntry) > nRefDepth)
{
if (rContentTree.iter_has_child(rEntry))
bExpand ? rContentTree.expand_row(rEntry) : rContentTree.collapse_row(rEntry);
}
}
}
// Handler for Dragging and ContextMenu
static bool lcl_InsertExpandCollapseAllItem(const weld::TreeView& rContentTree, const weld::TreeIter& rEntry, weld::Menu& rPop)
{
if (rContentTree.iter_has_child(rEntry) || rContentTree.get_children_on_demand(rEntry))
{
rPop.set_label(OUString::number(800), IsAllExpanded(rContentTree, rEntry) ? SwResId(STR_COLLAPSEALL) : SwResId(STR_EXPANDALL));
return false;
}
return true;
}
static void lcl_SetOutlineContentEntriesSensitivities(SwContentTree* pThis, const weld::TreeView& rContentTree, const weld::TreeIter& rEntry, weld::Menu& rPop)
{
rPop.set_sensitive(OUString::number(TOGGLE_OUTLINE_CONTENT_VISIBILITY), false);
rPop.set_sensitive(OUString::number(HIDE_OUTLINE_CONTENT_VISIBILITY), false);
rPop.set_sensitive(OUString::number(SHOW_OUTLINE_CONTENT_VISIBILITY), false);
// todo: multi selection
if (rContentTree.count_selected_rows() > 1)
return;
bool bIsRoot = lcl_IsContentType(rEntry, rContentTree);
const SwNodes& rNodes = pThis->GetWrtShell()->GetNodes();
const SwOutlineNodes& rOutlineNodes = rNodes.GetOutLineNds();
size_t nOutlinePos = weld::GetAbsPos(rContentTree, rEntry);
if (!bIsRoot)
--nOutlinePos;
if (nOutlinePos >= rOutlineNodes.size())
return;
int nFirstLevel = pThis->GetWrtShell()->getIDocumentOutlineNodesAccess()->getOutlineLevel(nOutlinePos);
{
// determine if any concerned outline node has content
bool bHasContent(false);
size_t nPos = nOutlinePos;
SwNode* pSttNd = rOutlineNodes[nPos];
SwNode* pEndNd = &rNodes.GetEndOfContent();
if (rOutlineNodes.size() > nPos + 1)
pEndNd = rOutlineNodes[nPos + 1];
// selected
SwNodeIndex aIdx(*pSttNd);
if (rNodes.GoNext(&aIdx) != pEndNd)
bHasContent = true;
// descendants
if (!bHasContent && (rContentTree.iter_has_child(rEntry) || rContentTree.get_children_on_demand(rEntry)))
{
while (++nPos < rOutlineNodes.size() &&
(bIsRoot || pThis->GetWrtShell()->getIDocumentOutlineNodesAccess()->getOutlineLevel(nPos) > nFirstLevel))
{
pSttNd = rOutlineNodes[nPos];
pEndNd = &rNodes.GetEndOfContent();
if (rOutlineNodes.size() > nPos + 1)
pEndNd = rOutlineNodes[nPos + 1];
// test for content in outline node
aIdx.Assign(*pSttNd);
if (rNodes.GoNext(&aIdx) != pEndNd)
{
bHasContent = true;
break;
}
}
}
if (!bHasContent)
return; // no content in any of the concerned outline nodes
}
// determine for subs if all are folded or unfolded or if they are mixed
if (rContentTree.iter_has_child(rEntry) || rContentTree.get_children_on_demand(rEntry))
{
// skip no content nodes
// we know there is content from results above so this is presumably safe
size_t nPos = nOutlinePos;
while (true)
{
SwNode* pSttNd = rOutlineNodes[nPos];
SwNode* pEndNd = rOutlineNodes.back();
if (!bIsRoot && rOutlineNodes.size() > nPos + 1)
pEndNd = rOutlineNodes[nPos + 1];
SwNodeIndex aIdx(*pSttNd);
if (rNodes.GoNext(&aIdx) != pEndNd)
break;
nPos++;
}
bool bHasFolded(!pThis->GetWrtShell()->IsOutlineContentVisible(nPos));
bool bHasUnfolded(!bHasFolded);
while ((++nPos < pThis->GetWrtShell()->getIDocumentOutlineNodesAccess()->getOutlineNodesCount()) &&
(bIsRoot || pThis->GetWrtShell()->getIDocumentOutlineNodesAccess()->getOutlineLevel(nPos) > nFirstLevel))
{
SwNode* pSttNd = rOutlineNodes[nPos];
SwNode* pEndNd = &rNodes.GetEndOfContent();
if (rOutlineNodes.size() > nPos + 1)
pEndNd = rOutlineNodes[nPos + 1];
SwNodeIndex aIdx(*pSttNd);
if (rNodes.GoNext(&aIdx) == pEndNd)
continue; // skip if no content
if (!pThis->GetWrtShell()->IsOutlineContentVisible(nPos))
bHasFolded = true;
else
bHasUnfolded = true;
if (bHasFolded && bHasUnfolded)
break; // mixed so no need to continue
}
rPop.set_sensitive(OUString::number(HIDE_OUTLINE_CONTENT_VISIBILITY), bHasUnfolded);
rPop.set_sensitive(OUString::number(SHOW_OUTLINE_CONTENT_VISIBILITY), bHasFolded);
}
rPop.set_sensitive(OUString::number(TOGGLE_OUTLINE_CONTENT_VISIBILITY), !bIsRoot);
}
IMPL_LINK(SwContentTree, CommandHdl, const CommandEvent&, rCEvt, bool)
{
if (rCEvt.GetCommand() != CommandEventId::ContextMenu)
return false;
grab_focus();
// select clicked entry or limit selection to root entry if needed
if (std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
rCEvt.IsMouseEvent() && m_xTreeView->get_dest_row_at_pos(
rCEvt.GetMousePosPixel(), xEntry.get(), false))
{
// if clicked entry is not currently selected then clear selections and select it
if (!m_xTreeView->is_selected(*xEntry))
m_xTreeView->set_cursor(*xEntry);
// if root entry is selected then clear selections and select it
else if (m_xTreeView->is_selected(0))
m_xTreeView->set_cursor(0);
}
std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xTreeView.get(), "modules/swriter/ui/navigatorcontextmenu.ui"));
std::unique_ptr<weld::Menu> xPop = xBuilder->weld_menu("navmenu");
bool bOutline(false);
std::unique_ptr<weld::Menu> xSubPop1 = xBuilder->weld_menu("outlinelevel");
std::unique_ptr<weld::Menu> xSubPop2 = xBuilder->weld_menu("dragmodemenu");
std::unique_ptr<weld::Menu> xSubPop3 = xBuilder->weld_menu("displaymenu");
std::unique_ptr<weld::Menu> xSubPopOutlineTracking = xBuilder->weld_menu("outlinetracking");
std::unique_ptr<weld::Menu> xSubPopOutlineContent = xBuilder->weld_menu("outlinecontent");
xSubPopOutlineContent->append(OUString::number(TOGGLE_OUTLINE_CONTENT_VISIBILITY),
SwResId(STR_OUTLINE_CONTENT_VISIBILITY_TOGGLE));
xSubPopOutlineContent->append(OUString::number(HIDE_OUTLINE_CONTENT_VISIBILITY),
SwResId(STR_OUTLINE_CONTENT_VISIBILITY_HIDE_ALL));
xSubPopOutlineContent->append(OUString::number(SHOW_OUTLINE_CONTENT_VISIBILITY),
SwResId(STR_OUTLINE_CONTENT_VISIBILITY_SHOW_ALL));
xSubPopOutlineContent->set_item_help_id(OUString::number(TOGGLE_OUTLINE_CONTENT_VISIBILITY),
HID_NAVIGATOR_TREELIST);
xSubPopOutlineContent->set_item_help_id(OUString::number(HIDE_OUTLINE_CONTENT_VISIBILITY),
HID_NAVIGATOR_TREELIST);
xSubPopOutlineContent->set_item_help_id(OUString::number(SHOW_OUTLINE_CONTENT_VISIBILITY),
HID_NAVIGATOR_TREELIST);
// Add entries to the Outline Tracking submenu
OUString sId;
for(int i = 1; i <= 3; ++i)
{
sId = OUString::number(i + 10);
xSubPopOutlineTracking->append_radio(sId, m_aContextStrings[IDX_STR_OUTLINE_TRACKING + i]);
xSubPopOutlineTracking->set_item_help_id(sId, HID_NAV_OUTLINE_TRACKING);
}
xSubPopOutlineTracking->set_active(OUString::number(10 + m_nOutlineTracking), true);
// Add entries to the Outline Level submenu
for (int i = 1; i <= MAXLEVEL; ++i)
{
sId = OUString::number(i + 100);
xSubPop1->append_radio(sId, OUString::number(i));
xSubPop1->set_item_help_id(sId, HID_NAV_OUTLINE_LEVEL);
}
xSubPop1->set_active(OUString::number(100 + m_nOutlineLevel), true);
// Add entries to the Drag Mode submenu
for (int i=0; i < 3; ++i)
{
sId = OUString::number(i + 201);
xSubPop2->append_radio(sId, m_aContextStrings[IDX_STR_HYPERLINK + i]);
xSubPop2->set_item_help_id(sId, HID_NAV_DRAG_MODE);
}
xSubPop2->set_active(OUString::number(201 + static_cast<int>(GetParentWindow()->GetRegionDropMode())), true);
// Insert the list of the open files in the Display submenu
{
sal_uInt16 nId = 301;
SwView *pView = SwModule::GetFirstView();
while (pView)
{
OUString sInsert = pView->GetDocShell()->GetTitle() + " (" +
m_aContextStrings[pView == GetActiveView() ? IDX_STR_ACTIVE :
IDX_STR_INACTIVE] + ")";
sId = OUString::number(nId);
xSubPop3->append_radio(sId, sInsert);
xSubPop3->set_item_help_id(sId, HID_NAV_DISPLAY);
if (State::CONSTANT == m_eState && m_pActiveShell == &pView->GetWrtShell())
xSubPop3->set_active(sId, true);
pView = SwModule::GetNextView(pView);
nId++;
}
// Active Window
sId = OUString::number(nId++);
xSubPop3->append_radio(sId, m_aContextStrings[IDX_STR_ACTIVE_VIEW]);
xSubPop3->set_item_help_id(sId, HID_NAV_DISPLAY);
// There can be only one hidden shell
if (m_pHiddenShell)
{
OUString sHiddenEntry = m_pHiddenShell->GetView().GetDocShell()->GetTitle() +
" (" +
m_aContextStrings[IDX_STR_HIDDEN] +
")";
sId = OUString::number(nId);
xSubPop3->append_radio(sId, sHiddenEntry);
xSubPop3->set_item_help_id(sId, HID_NAV_DISPLAY);
}
if (State::ACTIVE == m_eState)
xSubPop3->set_active(OUString::number(--nId), true);
else if (State::HIDDEN == m_eState)
xSubPop3->set_active(OUString::number(nId), true);
}
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
if (!m_xTreeView->get_selected(xEntry.get()))
xEntry.reset();
bool bRemoveGotoEntry = false;
if (State::HIDDEN == m_eState || !xEntry || !lcl_IsContent(*xEntry, *m_xTreeView) ||
weld::fromId<SwContent*>(m_xTreeView->get_id(*xEntry))->IsInvisible())
bRemoveGotoEntry = true;
bool bRemovePostItEntries = true;
bool bRemoveIndexEntries = true;
bool bRemoveCopyEntry = true;
bool bRemoveEditEntry = true;
bool bRemoveUnprotectEntry = true;
bool bRemoveDeleteChapterEntry = true,
bRemoveDeleteTableEntry = true,
bRemoveDeleteFrameEntry = true,
bRemoveDeleteImageEntry = true,
bRemoveDeleteOLEObjectEntry = true,
bRemoveDeleteBookmarkEntry = true,
bRemoveDeleteRegionEntry = true,
bRemoveDeleteHyperlinkEntry = true,
bRemoveDeleteReferenceEntry = true,
bRemoveDeleteIndexEntry= true,
bRemoveDeleteCommentEntry = true,
bRemoveDeleteDrawingObjectEntry = true,
bRemoveDeleteFieldEntry = true;
bool bRemoveRenameEntry = true;
bool bRemoveSelectEntry = true;
bool bRemoveToggleExpandEntry = true;
bool bRemoveChapterEntries = true;
bool bRemoveSendOutlineEntry = true;
bool bRemoveTableTracking = true;
bool bRemoveSectionTracking = true;
bool bRemoveFrameTracking = true;
bool bRemoveImageTracking = true;
bool bRemoveOLEobjectTracking = true;
bool bRemoveBookmarkTracking = true;
bool bRemoveHyperlinkTracking = true;
bool bRemoveReferenceTracking = true;
bool bRemoveIndexTracking = true;
bool bRemoveCommentTracking = true;
bool bRemoveDrawingObjectTracking = true;
bool bRemoveFieldTracking = true;
bool bRemoveFootnoteTracking = true;
bool bRemoveEndnoteTracking = true;
bool bRemoveSortEntry = true;
bool bRemoveProtectSection = true;
bool bRemoveHideSection = true;
if (xEntry)
{
const SwContentType* pType;
if (lcl_IsContentType(*xEntry, *m_xTreeView))
pType = weld::fromId<SwContentType*>(m_xTreeView->get_id(*xEntry));
else
pType = weld::fromId<SwContent*>(
m_xTreeView->get_id(*xEntry))->GetParent();
const ContentTypeId nContentType = pType->GetType();
if (nContentType != ContentTypeId::FOOTNOTE && nContentType != ContentTypeId::ENDNOTE
&& nContentType != ContentTypeId::POSTIT && nContentType != ContentTypeId::UNKNOWN)
{
bRemoveSortEntry = false;
const sal_Int32 nMask = 1 << static_cast<int>(nContentType);
sal_uInt64 nSortAlphabeticallyBlock = m_pConfig->GetSortAlphabeticallyBlock();
xPop->set_active("sort", nSortAlphabeticallyBlock & nMask);
}
OUString aIdent;
switch (nContentType)
{
case ContentTypeId::TABLE:
aIdent = "tabletracking";
bRemoveTableTracking = false;
break;
case ContentTypeId::REGION:
aIdent = "sectiontracking";
bRemoveSectionTracking = false;
break;
case ContentTypeId::FRAME:
aIdent = "frametracking";
bRemoveFrameTracking = false;
break;
case ContentTypeId::GRAPHIC:
aIdent = "imagetracking";
bRemoveImageTracking = false;
break;
case ContentTypeId::OLE:
aIdent = "oleobjecttracking";
bRemoveOLEobjectTracking = false;
break;
case ContentTypeId::BOOKMARK:
aIdent = "bookmarktracking";
bRemoveBookmarkTracking = false;
break;
case ContentTypeId::URLFIELD:
aIdent = "hyperlinktracking";
bRemoveHyperlinkTracking = false;
break;
case ContentTypeId::REFERENCE:
aIdent = "referencetracking";
bRemoveReferenceTracking = false;
break;
case ContentTypeId::INDEX:
aIdent = "indextracking";
bRemoveIndexTracking = false;
break;
case ContentTypeId::POSTIT:
aIdent = "commenttracking";
bRemoveCommentTracking = false;
break;
case ContentTypeId::DRAWOBJECT:
aIdent = "drawingobjecttracking";
bRemoveDrawingObjectTracking = false;
break;
case ContentTypeId::TEXTFIELD:
aIdent = "fieldtracking";
bRemoveFieldTracking = false;
break;
case ContentTypeId::FOOTNOTE:
aIdent = "footnotetracking";
bRemoveFootnoteTracking = false;
break;
case ContentTypeId::ENDNOTE:
aIdent = "endnotetracking";
bRemoveEndnoteTracking = false;
break;
default: break;
}
if (!aIdent.isEmpty())
xPop->set_active(aIdent, mTrackContentType[nContentType]);
// Edit only if the shown content is coming from the current view.
if (State::HIDDEN != m_eState &&
(State::ACTIVE == m_eState || (GetActiveView() && m_pActiveShell == GetActiveView()->GetWrtShellPtr()))
&& lcl_IsContent(*xEntry, *m_xTreeView))
{
const bool bReadonly = m_pActiveShell->GetView().GetDocShell()->IsReadOnly();
const bool bVisible = !weld::fromId<SwContent*>(m_xTreeView->get_id(*xEntry))->IsInvisible();
const bool bProtected = weld::fromId<SwContent*>(m_xTreeView->get_id(*xEntry))->IsProtect();
const bool bProtectBM = (ContentTypeId::BOOKMARK == nContentType)
&& m_pActiveShell->getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS);
const bool bEditable = pType->IsEditable() &&
((bVisible && !bProtected) || ContentTypeId::REGION == nContentType);
const bool bDeletable = pType->IsDeletable()
&& ((bVisible && !bProtected && !bProtectBM) || ContentTypeId::REGION == nContentType);
const bool bRenamable = bEditable && !bReadonly &&
(ContentTypeId::TABLE == nContentType ||
ContentTypeId::FRAME == nContentType ||
ContentTypeId::GRAPHIC == nContentType ||
ContentTypeId::OLE == nContentType ||
(ContentTypeId::BOOKMARK == nContentType && !bProtectBM) ||
ContentTypeId::REGION == nContentType ||
ContentTypeId::INDEX == nContentType ||
ContentTypeId::DRAWOBJECT == nContentType);
// Choose which Delete entry to show.
if (bDeletable)
{
switch (nContentType)
{
case ContentTypeId::OUTLINE:
bRemoveDeleteChapterEntry = false;
break;
case ContentTypeId::TABLE:
bRemoveDeleteTableEntry = false;
break;
case ContentTypeId::FRAME:
bRemoveDeleteFrameEntry = false;
break;
case ContentTypeId::GRAPHIC:
bRemoveDeleteImageEntry = false;
break;
case ContentTypeId::OLE:
bRemoveDeleteOLEObjectEntry = false;
break;
case ContentTypeId::BOOKMARK:
bRemoveDeleteBookmarkEntry = false;
break;
case ContentTypeId::REGION:
bRemoveDeleteRegionEntry = false;
break;
case ContentTypeId::URLFIELD:
bRemoveDeleteHyperlinkEntry = false;
break;
case ContentTypeId::REFERENCE:
bRemoveDeleteReferenceEntry = false;
break;
case ContentTypeId::INDEX:
bRemoveDeleteIndexEntry = false;
break;
case ContentTypeId::POSTIT:
bRemoveDeleteCommentEntry = false;
break;
case ContentTypeId::DRAWOBJECT:
bRemoveDeleteDrawingObjectEntry = false;
break;
case ContentTypeId::TEXTFIELD:
bRemoveDeleteFieldEntry = false;
break;
default: break;
}
}
if (ContentTypeId::FOOTNOTE == nContentType || ContentTypeId::ENDNOTE == nContentType)
{
void* pUserData = weld::fromId<void*>(m_xTreeView->get_id(*xEntry));
const SwTextFootnote* pFootnote =
static_cast<const SwTextFootnoteContent*>(pUserData)->GetTextFootnote();
if (!pFootnote)
bRemoveGotoEntry = true;
}
else if(ContentTypeId::OUTLINE == nContentType)
{
bOutline = true;
lcl_SetOutlineContentEntriesSensitivities(this, *m_xTreeView, *xEntry, *xSubPopOutlineContent);
bRemoveToggleExpandEntry = lcl_InsertExpandCollapseAllItem(*m_xTreeView, *xEntry, *xPop);
if (!bReadonly)
{
bRemoveSelectEntry = false;
bRemoveChapterEntries = false;
}
bRemoveCopyEntry = false;
}
else if (!bReadonly && bEditable)
{
if(ContentTypeId::INDEX == nContentType)
{
bRemoveIndexEntries = false;
const SwTOXBase* pBase = weld::fromId<SwTOXBaseContent*>(m_xTreeView->get_id(*xEntry))->GetTOXBase();
if (!pBase->IsTOXBaseInReadonly())
bRemoveEditEntry = false;
xPop->set_active(OUString::number(405), SwEditShell::IsTOXBaseReadonly(*pBase));
}
else if(ContentTypeId::TABLE == nContentType)
{
bRemoveSelectEntry = false;
bRemoveEditEntry = false;
bRemoveUnprotectEntry = false;
bool bFull = false;
OUString sTableName = weld::fromId<SwContent*>(m_xTreeView->get_id(*xEntry))->GetName();
bool bProt = m_pActiveShell->HasTableAnyProtection( &sTableName, &bFull );
xPop->set_sensitive(OUString::number(403), !bFull);
xPop->set_sensitive(OUString::number(404), bProt);
}
else if(ContentTypeId::REGION == nContentType)
{
bRemoveEditEntry = false;
bRemoveProtectSection = false;
bRemoveHideSection = false;
SwContent* pCnt = weld::fromId<SwContent*>(m_xTreeView->get_id(*xEntry));
assert(dynamic_cast<SwRegionContent*>(static_cast<SwTypeNumber*>(pCnt)));
const SwSectionFormat* pSectionFormat
= static_cast<SwRegionContent*>(pCnt)->GetSectionFormat();
bool bHidden = pSectionFormat->GetSection()->IsHidden();
bRemoveSelectEntry = bHidden || !bVisible;
xPop->set_active("protectsection", bProtected);
xPop->set_active("hidesection", bHidden);
}
else if (bEditable)
bRemoveEditEntry = false;
//Rename object
if (bRenamable)
bRemoveRenameEntry = false;
}
}
else
{
if (lcl_IsContentType(*xEntry, *m_xTreeView))
pType = weld::fromId<SwContentType*>(m_xTreeView->get_id(*xEntry));
else
pType = weld::fromId<SwContent*>(
m_xTreeView->get_id(*xEntry))->GetParent();
if (pType)
{
if (ContentTypeId::OUTLINE == nContentType)
{
bOutline = true;
if (State::HIDDEN != m_eState)
{
lcl_SetOutlineContentEntriesSensitivities(this, *m_xTreeView, *xEntry,
*xSubPopOutlineContent);
bRemoveSendOutlineEntry = false;
}
bRemoveToggleExpandEntry = lcl_InsertExpandCollapseAllItem(*m_xTreeView, *xEntry,
*xPop);
}
else if (State::HIDDEN != m_eState &&
nContentType == ContentTypeId::POSTIT &&
!m_pActiveShell->GetView().GetDocShell()->IsReadOnly() &&
pType->GetMemberCount() > 0)
bRemovePostItEntries = false;
}
}
}
if (bRemoveToggleExpandEntry)
xPop->remove(OUString::number(800));
if (bRemoveGotoEntry)
xPop->remove(OUString::number(900));
if (bRemoveSelectEntry)
xPop->remove(OUString::number(805));
if (bRemoveChapterEntries)
{
xPop->remove(OUString::number(801));
xPop->remove(OUString::number(802));
xPop->remove(OUString::number(803));
xPop->remove(OUString::number(804));
}
if (bRemoveSendOutlineEntry)
xPop->remove(OUString::number(700));
if (bRemovePostItEntries)
{
xPop->remove(OUString::number(600));
xPop->remove(OUString::number(601));
xPop->remove(OUString::number(602));
}
if (bRemoveDeleteChapterEntry)
xPop->remove("deletechapter");
if (bRemoveDeleteTableEntry)
xPop->remove("deletetable");
if (bRemoveDeleteFrameEntry)
xPop->remove("deleteframe");
if (bRemoveDeleteImageEntry)
xPop->remove("deleteimage");
if (bRemoveDeleteOLEObjectEntry)
xPop->remove("deleteoleobject");
if (bRemoveDeleteBookmarkEntry)
xPop->remove("deletebookmark");
if (bRemoveDeleteRegionEntry)
xPop->remove("deleteregion");
if (bRemoveDeleteHyperlinkEntry)
xPop->remove("deletehyperlink");
if (bRemoveDeleteReferenceEntry)
xPop->remove("deletereference");
if (bRemoveDeleteIndexEntry)
xPop->remove("deleteindex");
if (bRemoveDeleteCommentEntry)
xPop->remove("deletecomment");
if (bRemoveDeleteDrawingObjectEntry)
xPop->remove("deletedrawingobject");
if (bRemoveDeleteFieldEntry)
xPop->remove("deletefield");
bool bRemoveDeleteEntry =
bRemoveDeleteChapterEntry &&
bRemoveDeleteTableEntry &&
bRemoveDeleteFrameEntry &&
bRemoveDeleteImageEntry &&
bRemoveDeleteOLEObjectEntry &&
bRemoveDeleteBookmarkEntry &&
bRemoveDeleteRegionEntry &&
bRemoveDeleteHyperlinkEntry &&
bRemoveDeleteReferenceEntry &&
bRemoveDeleteIndexEntry &&
bRemoveDeleteCommentEntry &&
bRemoveDeleteDrawingObjectEntry &&
bRemoveDeleteFieldEntry;
if (bRemoveRenameEntry)
xPop->remove(OUString::number(502));
if (bRemoveIndexEntries)
{
xPop->remove(OUString::number(401));
xPop->remove(OUString::number(402));
xPop->remove(OUString::number(405));
}
if (bRemoveUnprotectEntry)
xPop->remove(OUString::number(404));
if (bRemoveEditEntry)
xPop->remove(OUString::number(403));
if (bRemoveToggleExpandEntry &&
bRemoveSendOutlineEntry)
xPop->remove("separator1");
if (bRemoveCopyEntry)
xPop->remove("copy");
if (bRemoveGotoEntry &&
bRemoveCopyEntry &&
bRemoveSelectEntry &&
bRemoveDeleteEntry &&
bRemoveChapterEntries &&
bRemovePostItEntries &&
bRemoveRenameEntry &&
bRemoveIndexEntries &&
bRemoveUnprotectEntry &&
bRemoveEditEntry)
xPop->remove("separator2");
if (!bOutline)
{
xSubPop1.reset();
xPop->remove(OUString::number(1)); // outline level menu
}
if (!bOutline || State::HIDDEN == m_eState)
{
xSubPopOutlineTracking.reset();
xPop->remove(OUString::number(4)); // outline tracking menu
}
if (!bOutline || State::HIDDEN == m_eState ||
!m_pActiveShell->GetViewOptions()->IsShowOutlineContentVisibilityButton() ||
m_pActiveShell->getIDocumentOutlineNodesAccess()->getOutlineNodesCount() == 0)
{
xSubPopOutlineContent.reset();
xPop->remove(OUString::number(5)); // outline folding menu
xPop->remove("separator3");
}
if (bRemoveTableTracking)
xPop->remove("tabletracking");
if (bRemoveSectionTracking)
xPop->remove("sectiontracking");
if (bRemoveFrameTracking)
xPop->remove("frametracking");
if (bRemoveImageTracking)
xPop->remove("imagetracking");
if (bRemoveOLEobjectTracking)
xPop->remove("oleobjecttracking");
if (bRemoveBookmarkTracking)
xPop->remove("bookmarktracking");
if (bRemoveHyperlinkTracking)
xPop->remove("hyperlinktracking");
if (bRemoveReferenceTracking)
xPop->remove("referencetracking");
if (bRemoveIndexTracking)
xPop->remove("indextracking");
if (bRemoveCommentTracking)
xPop->remove("commenttracking");
if (bRemoveDrawingObjectTracking)
xPop->remove("drawingobjecttracking");
if (bRemoveFieldTracking)
xPop->remove("fieldtracking");
if (bRemoveFootnoteTracking)
xPop->remove("footnotetracking");
if (bRemoveEndnoteTracking)
xPop->remove("endnotetracking");
if (bRemoveSortEntry)
xPop->remove("sort");
if (bRemoveProtectSection)
xPop->remove("protectsection");
if (bRemoveHideSection)
xPop->remove("hidesection");
bool bSetSensitiveCollapseAllCategories = false;
if (!m_bIsRoot && xEntry)
{
bool bEntry = m_xTreeView->get_iter_first(*xEntry);
while (bEntry)
{
if (m_xTreeView->get_row_expanded(*xEntry))
{
bSetSensitiveCollapseAllCategories = true;
break;
}
bEntry = m_xTreeView->iter_next_sibling(*xEntry);
}
}
xPop->set_sensitive("collapseallcategories", bSetSensitiveCollapseAllCategories);
OUString sCommand = xPop->popup_at_rect(m_xTreeView.get(), tools::Rectangle(rCEvt.GetMousePosPixel(), Size(1,1)));
if (!sCommand.isEmpty())
ExecuteContextMenuAction(sCommand);
return true;
}
void SwContentTree::InsertContent(const weld::TreeIter& rParent)
{
assert(dynamic_cast<SwContentType*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(rParent))));
SwContentType* pCntType = weld::fromId<SwContentType*>(m_xTreeView->get_id(rParent));
bool bGraphic = pCntType->GetType() == ContentTypeId::GRAPHIC;
std::unique_ptr<weld::TreeIter> xChild = m_xTreeView->make_iterator();
const size_t nCount = pCntType->GetMemberCount();
for(size_t i = 0; i < nCount; ++i)
{
const SwContent* pCnt = pCntType->GetMember(i);
OUString sEntry = pCnt->GetName();
if (sEntry.isEmpty())
sEntry = m_sSpace;
OUString sId(weld::toId(pCnt));
insert(&rParent, sEntry, sId, false, xChild.get());
m_xTreeView->set_sensitive(*xChild, !pCnt->IsInvisible());
if (bGraphic && !static_cast<const SwGraphicContent*>(pCnt)->GetLink().isEmpty())
m_xTreeView->set_image(*xChild, RID_BMP_NAVI_GRAPHIC_LINK);
}
}
void SwContentTree::insert(const weld::TreeIter* pParent, const OUString& rStr, const OUString& rId,
bool bChildrenOnDemand, weld::TreeIter* pRet)
{
m_xTreeView->insert(pParent, -1, &rStr, &rId, nullptr, nullptr, bChildrenOnDemand, pRet);
++m_nEntryCount;
}
void SwContentTree::remove(const weld::TreeIter& rIter)
{
if (m_xTreeView->iter_has_child(rIter))
{
std::unique_ptr<weld::TreeIter> xChild = m_xTreeView->make_iterator(&rIter);
(void)m_xTreeView->iter_children(*xChild);
remove(*xChild);
}
m_xTreeView->remove(rIter);
--m_nEntryCount;
}
// Content will be integrated into the Box only on demand.
bool SwContentTree::RequestingChildren(const weld::TreeIter& rParent)
{
// Does the parent already have children or is it not a 'children on demand' node?
if (m_xTreeView->iter_has_child(rParent) || !m_xTreeView->get_children_on_demand(rParent))
return false;
// Is this a content type?
if (lcl_IsContentType(rParent, *m_xTreeView))
{
std::unique_ptr<weld::TreeIter> xChild = m_xTreeView->make_iterator();
assert(dynamic_cast<SwContentType*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(rParent))));
SwContentType* pCntType = weld::fromId<SwContentType*>(m_xTreeView->get_id(rParent));
const size_t nCount = pCntType->GetMemberCount();
// Add for outline plus/minus
if (pCntType->GetType() == ContentTypeId::OUTLINE)
{
std::vector<std::unique_ptr<weld::TreeIter>> aParentCandidates;
for(size_t i = 0; i < nCount; ++i)
{
const SwContent* pCnt = pCntType->GetMember(i);
if(pCnt)
{
const auto nLevel = static_cast<const SwOutlineContent*>(pCnt)->GetOutlineLevel();
OUString sEntry = pCnt->GetName();
if(sEntry.isEmpty())
sEntry = m_sSpace;
OUString sId(weld::toId(pCnt));
auto lambda = [nLevel, this](const std::unique_ptr<weld::TreeIter>& entry)
{
return lcl_IsLowerOutlineContent(*entry, *m_xTreeView, nLevel);
};
// if there is a preceding outline node candidate with a lower outline level use
// that as a parent, otherwise use the root node
auto aFind = std::find_if(aParentCandidates.rbegin(), aParentCandidates.rend(), lambda);
if (aFind != aParentCandidates.rend())
insert(aFind->get(), sEntry, sId, false, xChild.get());
else
insert(&rParent, sEntry, sId, false, xChild.get());
m_xTreeView->set_sensitive(*xChild, !pCnt->IsInvisible());
m_xTreeView->set_extra_row_indent(*xChild, nLevel + 1 - m_xTreeView->get_iter_depth(*xChild));
// remove any parent candidates equal to or higher than this node
std::erase_if(aParentCandidates, std::not_fn(lambda));
// add this node as a parent candidate for any following nodes at a higher outline level
aParentCandidates.emplace_back(m_xTreeView->make_iterator(xChild.get()));
}
}
}
else if (pCntType->GetType() == ContentTypeId::REGION)
{
if (pCntType->IsAlphabeticSort())
{
for(size_t i = 0; i < nCount; ++i)
{
const SwRegionContent* pCnt =
static_cast<const SwRegionContent*>(pCntType->GetMember(i));
OUString sEntry = pCnt->GetName();
OUString sId(weld::toId(pCnt));
const auto nLevel = pCnt->GetRegionLevel();
insert(&rParent, sEntry, sId, false, xChild.get());
m_xTreeView->set_sensitive(*xChild, !pCnt->IsInvisible());
m_xTreeView->set_extra_row_indent(*xChild, nLevel);
bool bHidden = pCnt->GetSectionFormat()->GetSection()->IsHidden();
if (pCnt->IsProtect())
m_xTreeView->set_image(*xChild, bHidden ? RID_BMP_PROT_HIDE : RID_BMP_PROT_NO_HIDE);
else
m_xTreeView->set_image(*xChild, bHidden ? RID_BMP_HIDE : RID_BMP_NO_HIDE);
}
}
else
{
std::vector<std::unique_ptr<weld::TreeIter>> aParentCandidates;
for(size_t i = 0; i < nCount; ++i)
{
const SwRegionContent* pCnt =
static_cast<const SwRegionContent*>(pCntType->GetMember(i));
OUString sEntry = pCnt->GetName();
OUString sId(weld::toId(pCnt));
const auto nLevel = pCnt->GetRegionLevel();
auto lambda = [nLevel, this](const std::unique_ptr<weld::TreeIter>& xEntry)
{
return lcl_IsLowerRegionContent(*xEntry, *m_xTreeView, nLevel);
};
// if there is a preceding region node candidate with a lower region level use
// that as a parent, otherwise use the root node
auto aFind = std::find_if(aParentCandidates.rbegin(), aParentCandidates.rend(), lambda);
if (aFind != aParentCandidates.rend())
insert(aFind->get(), sEntry, sId, false, xChild.get());
else
insert(&rParent, sEntry, sId, false, xChild.get());
m_xTreeView->set_sensitive(*xChild, !pCnt->IsInvisible());
bool bHidden = pCnt->GetSectionFormat()->GetSection()->IsHidden();
if (pCnt->IsProtect())
m_xTreeView->set_image(*xChild, bHidden ? RID_BMP_PROT_HIDE : RID_BMP_PROT_NO_HIDE);
else
m_xTreeView->set_image(*xChild, bHidden ? RID_BMP_HIDE : RID_BMP_NO_HIDE);
// remove any parent candidates equal to or higher than this node
std::erase_if(aParentCandidates, std::not_fn(lambda));
// add this node as a parent candidate for any following nodes at a higher region level
aParentCandidates.emplace_back(m_xTreeView->make_iterator(xChild.get()));
}
}
}
else if (pCntType->GetType() == ContentTypeId::POSTIT)
{
std::vector<std::unique_ptr<weld::TreeIter>> aParentCandidates;
for(size_t i = 0; i < nCount; ++i)
{
const SwPostItContent* pCnt =
static_cast<const SwPostItContent*>(pCntType->GetMember(i));
OUString sEntry = pCnt->GetName();
OUString sId(weld::toId(pCnt));
const SwPostItField* pPostItField =
static_cast<const SwPostItField*>(pCnt->GetPostIt()->GetField());
auto lambda = [&pPostItField, this](const std::unique_ptr<weld::TreeIter>& xEntry)
{
SwPostItContent* pParentCandidateCnt =
weld::fromId<SwPostItContent*>(m_xTreeView->get_id(*xEntry));
return pPostItField->GetParentPostItId() ==
static_cast<const SwPostItField*>(pParentCandidateCnt->GetPostIt()
->GetField())->GetPostItId();
};
// if a parent candidate is not found use the passed root node
auto aFind = std::find_if(aParentCandidates.rbegin(), aParentCandidates.rend(), lambda);
if (aFind != aParentCandidates.rend())
insert(aFind->get(), sEntry, sId, false, xChild.get());
else
insert(&rParent, sEntry, sId, false, xChild.get());
m_xTreeView->set_sensitive(*xChild, !pCnt->IsInvisible());
// clear parent candidates when encountering a postit that doesn't have a parent
// following postits can't have a parent that is in these candidates
if (pPostItField->GetParentPostItId() == 0)
aParentCandidates.clear();
aParentCandidates.emplace_back(m_xTreeView->make_iterator(xChild.get()));
}
}
else
InsertContent(rParent);
return nCount != 0;
}
return false;
}
void SwContentTree::ExpandAllHeadings()
{
if (HasHeadings())
{
std::unique_ptr<weld::TreeIter> xEntry = GetEntryAtAbsPos(0);
if (xEntry)
{
if (!IsAllExpanded(*m_xTreeView, *xEntry))
ExpandOrCollapseAll(*m_xTreeView, *xEntry);
}
}
}
SdrObject* SwContentTree::GetDrawingObjectsByContent(const SwContent *pCnt)
{
SdrObject *pRetObj = nullptr;
switch(pCnt->GetParent()->GetType())
{
case ContentTypeId::DRAWOBJECT:
{
SdrView* pDrawView = m_pActiveShell->GetDrawView();
if (pDrawView)
{
SwDrawModel* pDrawModel = m_pActiveShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
SdrPage* pPage = pDrawModel->GetPage(0);
for (const rtl::Reference<SdrObject>& pTemp : *pPage)
{
if( pTemp->GetName() == pCnt->GetName())
{
pRetObj = pTemp.get();
break;
}
}
}
break;
}
default:
pRetObj = nullptr;
}
return pRetObj;
}
void SwContentTree::Expand(const weld::TreeIter& rParent,
std::vector<std::unique_ptr<weld::TreeIter>>* pNodesToExpand)
{
if (!m_xTreeView->iter_has_child(rParent) && !m_xTreeView->get_children_on_demand(rParent))
return;
// pNodesToExpand is used by the Display function to restore the trees expand structure for
// hierarchical content types, e.g., OUTLINE and REGION.
if (pNodesToExpand)
pNodesToExpand->emplace_back(m_xTreeView->make_iterator(&rParent));
// rParentId is a string representation of a pointer to SwContentType or SwContent
const OUString& rParentId = m_xTreeView->get_id(rParent);
// bParentIsContentType tells if the passed rParent tree entry is a content type or content
const bool bParentIsContentType = lcl_IsContentType(rParent, *m_xTreeView);
// eParentContentTypeId is the content type of the passed rParent tree entry
const ContentTypeId eParentContentTypeId =
bParentIsContentType ? weld::fromId<SwContentType*>(rParentId)->GetType() :
weld::fromId<SwContent*>(rParentId)->GetParent()->GetType();
if (m_nRootType == ContentTypeId::UNKNOWN && bParentIsContentType)
{
// m_nActiveBlock and m_nHiddenBlock are used to persist the content type expand state for
// the all content view mode
const int nShift = static_cast<int>(eParentContentTypeId);
SAL_WARN_IF(nShift < 0, "sw.ui", "ContentTypeId::UNKNOWN negative shift");
if (nShift >= 0)
{
const sal_Int32 nOr = 1 << nShift; //linear -> Bitposition
if (State::HIDDEN != m_eState)
{
m_nActiveBlock |= nOr;
m_pConfig->SetActiveBlock(m_nActiveBlock);
}
else
m_nHiddenBlock |= nOr;
}
}
if (m_nRootType == ContentTypeId::OUTLINE || (m_nRootType == ContentTypeId::UNKNOWN &&
eParentContentTypeId == ContentTypeId::OUTLINE))
{
if (bParentIsContentType)
{
std::map< void*, bool > aCurrOutLineNodeMap;
SwWrtShell* pShell = GetWrtShell();
bool bParentHasChild = RequestingChildren(rParent);
if (bParentHasChild)
{
std::unique_ptr<weld::TreeIter> xChild(m_xTreeView->make_iterator(&rParent));
bool bChild = m_xTreeView->iter_next(*xChild);
while (bChild && lcl_IsContent(*xChild, *m_xTreeView))
{
if (m_xTreeView->iter_has_child(*xChild))
{
assert(dynamic_cast<SwOutlineContent*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(*xChild))));
auto const nPos = weld::fromId<SwOutlineContent*>(m_xTreeView->get_id(*xChild))->GetOutlinePos();
void* key = static_cast<void*>(pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos ));
aCurrOutLineNodeMap.emplace( key, false );
std::map<void*, bool>::iterator iter = mOutLineNodeMap.find( key );
if( iter != mOutLineNodeMap.end() && mOutLineNodeMap[key])
{
aCurrOutLineNodeMap[key] = true;
RequestingChildren(*xChild);
if (pNodesToExpand)
pNodesToExpand->emplace_back(m_xTreeView->make_iterator(xChild.get()));
m_xTreeView->set_children_on_demand(*xChild, false);
}
}
bChild = m_xTreeView->iter_next(*xChild);
}
}
mOutLineNodeMap = aCurrOutLineNodeMap;
return;
}
else // content entry
{
SwWrtShell* pShell = GetWrtShell();
assert(dynamic_cast<SwOutlineContent*>(weld::fromId<SwTypeNumber*>(rParentId)));
auto const nPos = weld::fromId<SwOutlineContent*>(rParentId)->GetOutlinePos();
void* key = static_cast<void*>(pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos ));
mOutLineNodeMap[key] = true;
}
}
else if (m_nRootType == ContentTypeId::REGION || (m_nRootType == ContentTypeId::UNKNOWN &&
eParentContentTypeId == ContentTypeId::REGION))
{
if (bParentIsContentType)
{
std::map<const void*, bool> aCurrentRegionNodeExpandMap;
if (RequestingChildren(rParent))
{
std::unique_ptr<weld::TreeIter> xChild(m_xTreeView->make_iterator(&rParent));
while (m_xTreeView->iter_next(*xChild) && lcl_IsContent(*xChild, *m_xTreeView))
{
if (m_xTreeView->iter_has_child(*xChild))
{
assert(dynamic_cast<SwRegionContent*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(*xChild))));
const void* key =
static_cast<const void*>(weld::fromId<SwRegionContent*>(
m_xTreeView->get_id(*xChild))->GetSectionFormat());
bool bExpandNode =
m_aRegionNodeExpandMap.contains(key) && m_aRegionNodeExpandMap[key];
aCurrentRegionNodeExpandMap.emplace(key, bExpandNode);
if (bExpandNode)
{
if (pNodesToExpand)
pNodesToExpand->emplace_back(m_xTreeView->make_iterator(xChild.get()));
RequestingChildren(*xChild);
m_xTreeView->set_children_on_demand(*xChild, false);
}
}
}
}
m_aRegionNodeExpandMap = aCurrentRegionNodeExpandMap;
return;
}
else // content entry
{
assert(dynamic_cast<SwRegionContent*>(weld::fromId<SwTypeNumber*>(rParentId)));
const void* key = static_cast<const void*>(
weld::fromId<SwRegionContent*>(rParentId)->GetSectionFormat());
m_aRegionNodeExpandMap[key] = true;
}
}
else if (m_nRootType == ContentTypeId::POSTIT || (m_nRootType == ContentTypeId::UNKNOWN &&
eParentContentTypeId == ContentTypeId::POSTIT))
{
if (bParentIsContentType)
{
std::map<const void*, bool> aCurrentPostItNodeExpandMap;
if (RequestingChildren(rParent))
{
std::unique_ptr<weld::TreeIter> xChild(m_xTreeView->make_iterator(&rParent));
while (m_xTreeView->iter_next(*xChild) && lcl_IsContent(*xChild, *m_xTreeView))
{
if (m_xTreeView->iter_has_child(*xChild))
{
assert(dynamic_cast<SwPostItContent*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(*xChild))));
const void* key =
static_cast<const void*>(weld::fromId<SwPostItContent*>(
m_xTreeView->get_id(*xChild))->GetPostIt());
bool bExpandNode =
m_aPostItNodeExpandMap.contains(key) && m_aPostItNodeExpandMap[key];
aCurrentPostItNodeExpandMap.emplace(key, bExpandNode);
if (bExpandNode)
{
if (pNodesToExpand)
pNodesToExpand->emplace_back(m_xTreeView->make_iterator(xChild.get()));
RequestingChildren(*xChild);
m_xTreeView->set_children_on_demand(*xChild, false);
}
}
}
}
m_aPostItNodeExpandMap = aCurrentPostItNodeExpandMap;
return;
}
else // content entry
{
assert(dynamic_cast<SwPostItContent*>(weld::fromId<SwTypeNumber*>(rParentId)));
const void* key = static_cast<const void*>(
weld::fromId<SwPostItContent*>(rParentId)->GetPostIt());
m_aPostItNodeExpandMap[key] = true;
}
}
RequestingChildren(rParent);
}
IMPL_LINK(SwContentTree, ExpandHdl, const weld::TreeIter&, rParent, bool)
{
Expand(rParent, nullptr);
return true;
}
IMPL_LINK(SwContentTree, CollapseHdl, const weld::TreeIter&, rParent, bool)
{
if (!m_xTreeView->iter_has_child(rParent) || m_xTreeView->get_children_on_demand(rParent))
return true;
if (lcl_IsContentType(rParent, *m_xTreeView))
{
if (m_bIsRoot)
{
// collapse to children of root node
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator(&rParent));
if (m_xTreeView->iter_children(*xEntry))
{
do
{
m_xTreeView->collapse_row(*xEntry);
}
while (m_xTreeView->iter_next(*xEntry));
}
return false; // return false to notify caller not to do collapse
}
ContentTypeId eContentTypeId =
weld::fromId<SwContentType*>(m_xTreeView->get_id(rParent))->GetType();
const int nShift = static_cast<int>(eContentTypeId);
SAL_WARN_IF(nShift < 0, "sw.ui", "ContentTypeId::UNKNOWN negative shift");
if (nShift >= 0)
{
const sal_Int32 nAnd = ~(1 << nShift);
if (State::HIDDEN != m_eState)
{
m_nActiveBlock &= nAnd;
m_pConfig->SetActiveBlock(m_nActiveBlock);
}
else
m_nHiddenBlock &= nAnd;
}
}
else // content entry
{
SwWrtShell* pShell = GetWrtShell();
ContentTypeId eContentTypeId =
weld::fromId<SwContent*>(m_xTreeView->get_id(rParent))->GetParent()->GetType();
if (eContentTypeId == ContentTypeId::OUTLINE)
{
assert(dynamic_cast<SwOutlineContent*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(rParent))));
auto const nPos = weld::fromId<SwOutlineContent*>(m_xTreeView->get_id(rParent))->GetOutlinePos();
void* key = static_cast<void*>(pShell->getIDocumentOutlineNodesAccess()->getOutlineNode( nPos ));
mOutLineNodeMap[key] = false;
}
else if(eContentTypeId == ContentTypeId::REGION)
{
assert(dynamic_cast<SwRegionContent*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(rParent))));
const void* key = static_cast<const void*>(weld::fromId<SwRegionContent*>(m_xTreeView->get_id(rParent))->GetSectionFormat());
m_aRegionNodeExpandMap[key] = false;
}
else if(eContentTypeId == ContentTypeId::POSTIT)
{
assert(dynamic_cast<SwPostItContent*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(rParent))));
const void* key = static_cast<const void*>(weld::fromId<SwPostItContent*>(m_xTreeView->get_id(rParent))->GetPostIt());
m_aPostItNodeExpandMap[key] = false;
}
}
return true;
}
// Also on double click will be initially opened only.
IMPL_LINK_NOARG(SwContentTree, ContentDoubleClickHdl, weld::TreeView&, bool)
{
if (m_nRowActivateEventId)
Application::RemoveUserEvent(m_nRowActivateEventId);
// post the event to process row activate after mouse press event to be able to set key
// modifier for selection feature (tdf#154211)
m_nRowActivateEventId
= Application::PostUserEvent(LINK(this, SwContentTree, AsyncContentDoubleClickHdl));
bool bConsumed = false;
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
if (m_xTreeView->get_cursor(xEntry.get()) && lcl_IsContent(*xEntry, *m_xTreeView) &&
(State::HIDDEN != m_eState))
{
SwContent* pCnt = weld::fromId<SwContent*>(m_xTreeView->get_id(*xEntry));
assert(pCnt && "no UserData");
if (pCnt && !pCnt->IsInvisible())
{
// fdo#36308 don't expand outlines on double-click
bConsumed = pCnt->GetParent()->GetType() == ContentTypeId::OUTLINE;
}
}
return bConsumed; // false/true == allow/disallow more to be done, i.e. expand/collapse children
}
IMPL_LINK_NOARG(SwContentTree, AsyncContentDoubleClickHdl, void*, void)
{
m_nRowActivateEventId = nullptr;
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
bool bEntry = m_xTreeView->get_cursor(xEntry.get());
// Is it a content type?
OSL_ENSURE(bEntry, "no current entry!");
if (bEntry)
{
if (lcl_IsContentType(*xEntry, *m_xTreeView) && !m_xTreeView->iter_has_child(*xEntry))
{
RequestingChildren(*xEntry);
m_xTreeView->set_children_on_demand(*xEntry, false);
}
else if (!lcl_IsContentType(*xEntry, *m_xTreeView) && (State::HIDDEN != m_eState))
{
assert(dynamic_cast<SwContent*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(*xEntry))));
SwContent* pCnt = weld::fromId<SwContent*>(m_xTreeView->get_id(*xEntry));
assert(pCnt && "no UserData");
if (pCnt && !pCnt->IsInvisible())
{
if (State::CONSTANT == m_eState)
{
m_pActiveShell->GetView().GetViewFrame().GetWindow().ToTop();
}
//Jump to content type:
GotoContent(pCnt);
}
}
}
}
namespace
{
OUString GetImageIdForContentTypeId(ContentTypeId eType)
{
OUString sResId;
switch (eType)
{
case ContentTypeId::OUTLINE:
sResId = RID_BMP_NAVI_OUTLINE;
break;
case ContentTypeId::TABLE:
sResId = RID_BMP_NAVI_TABLE;
break;
case ContentTypeId::FRAME:
sResId = RID_BMP_NAVI_FRAME;
break;
case ContentTypeId::GRAPHIC:
sResId = RID_BMP_NAVI_GRAPHIC;
break;
case ContentTypeId::OLE:
sResId = RID_BMP_NAVI_OLE;
break;
case ContentTypeId::BOOKMARK:
sResId = RID_BMP_NAVI_BOOKMARK;
break;
case ContentTypeId::REGION:
sResId = RID_BMP_NAVI_REGION;
break;
case ContentTypeId::URLFIELD:
sResId = RID_BMP_NAVI_URLFIELD;
break;
case ContentTypeId::REFERENCE:
sResId = RID_BMP_NAVI_REFERENCE;
break;
case ContentTypeId::INDEX:
sResId = RID_BMP_NAVI_INDEX;
break;
case ContentTypeId::POSTIT:
sResId = RID_BMP_NAVI_POSTIT;
break;
case ContentTypeId::DRAWOBJECT:
sResId = RID_BMP_NAVI_DRAWOBJECT;
break;
case ContentTypeId::TEXTFIELD:
sResId = RID_BMP_NAVI_TEXTFIELD;
break;
case ContentTypeId::FOOTNOTE:
sResId = RID_BMP_NAVI_FOOTNOTE;
break;
case ContentTypeId::ENDNOTE:
sResId = RID_BMP_NAVI_ENDNOTE;
break;
case ContentTypeId::UNKNOWN:
SAL_WARN("sw.ui", "ContentTypeId::UNKNOWN has no bitmap preview");
break;
}
return sResId;
};
}
size_t SwContentTree::GetAbsPos(const weld::TreeIter& rIter)
{
return weld::GetAbsPos(*m_xTreeView, rIter);
}
size_t SwContentTree::GetEntryCount() const
{
return m_nEntryCount;
}
size_t SwContentTree::GetChildCount(const weld::TreeIter& rParent) const
{
if (!m_xTreeView->iter_has_child(rParent))
return 0;
std::unique_ptr<weld::TreeIter> xParent(m_xTreeView->make_iterator(&rParent));
size_t nCount = 0;
auto nRefDepth = m_xTreeView->get_iter_depth(*xParent);
auto nActDepth = nRefDepth;
do
{
if (!m_xTreeView->iter_next(*xParent))
xParent.reset();
else
nActDepth = m_xTreeView->get_iter_depth(*xParent);
nCount++;
} while(xParent && nRefDepth < nActDepth);
nCount--;
return nCount;
}
std::unique_ptr<weld::TreeIter> SwContentTree::GetEntryAtAbsPos(size_t nAbsPos) const
{
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
if (!m_xTreeView->get_iter_first(*xEntry))
xEntry.reset();
while (nAbsPos && xEntry)
{
if (!m_xTreeView->iter_next(*xEntry))
xEntry.reset();
nAbsPos--;
}
return xEntry;
}
void SwContentTree::Display( bool bActive )
{
// First read the selected entry to select it later again if necessary
// -> the user data here are no longer valid!
std::unique_ptr<weld::TreeIter> xOldSelEntry(m_xTreeView->make_iterator());
if (!m_xTreeView->get_selected(xOldSelEntry.get()))
xOldSelEntry.reset();
OUString sOldSelEntryId;
size_t nEntryRelPos = 0; // relative position to their parent
size_t nOldEntryCount = GetEntryCount();
sal_Int32 nOldScrollPos = 0;
if (xOldSelEntry)
{
UpdateLastSelType();
sOldSelEntryId = m_xTreeView->get_id(*xOldSelEntry);
nOldScrollPos = m_xTreeView->vadjustment_get_value();
std::unique_ptr<weld::TreeIter> xParentEntry = m_xTreeView->make_iterator(xOldSelEntry.get());
while (m_xTreeView->get_iter_depth(*xParentEntry))
m_xTreeView->iter_parent(*xParentEntry);
if (m_xTreeView->get_iter_depth(*xOldSelEntry))
nEntryRelPos = GetAbsPos(*xOldSelEntry) - GetAbsPos(*xParentEntry);
}
clear();
if (!bActive)
{
m_aOverlayObjectDelayTimer.Stop();
if (m_xOverlayObject && m_xOverlayObject->getOverlayManager())
{
m_xOverlayObject->getOverlayManager()->remove(*m_xOverlayObject);
m_xOverlayObject.reset();
}
m_eState = State::HIDDEN;
}
else if (State::HIDDEN == m_eState)
m_eState = State::ACTIVE;
SwWrtShell* pShell = GetWrtShell();
const bool bReadOnly = !pShell || pShell->GetView().GetDocShell()->IsReadOnly();
if(bReadOnly != m_bIsLastReadOnly)
{
m_bIsLastReadOnly = bReadOnly;
bool bDisable = pShell == nullptr || bReadOnly;
SwNavigationPI* pNavi = GetParentWindow();
pNavi->m_xContent6ToolBox->set_item_sensitive("chapterup", !bDisable);
pNavi->m_xContent6ToolBox->set_item_sensitive("chapterdown", !bDisable);
pNavi->m_xContent6ToolBox->set_item_sensitive("promote", !bDisable);
pNavi->m_xContent6ToolBox->set_item_sensitive("demote", !bDisable);
pNavi->m_xContent5ToolBox->set_item_sensitive("reminder", !bDisable);
}
if (pShell)
{
std::unique_ptr<weld::TreeIter> xEntry = m_xTreeView->make_iterator();
std::unique_ptr<weld::TreeIter> xCntTypeEntry;
std::vector<std::unique_ptr<weld::TreeIter>> aNodesToExpand;
// all content navigation view
if(m_nRootType == ContentTypeId::UNKNOWN)
{
m_xTreeView->freeze();
for( ContentTypeId nCntType : o3tl::enumrange<ContentTypeId>() )
{
std::unique_ptr<SwContentType>& rpContentT = bActive ?
m_aActiveContentArr[nCntType] :
m_aHiddenContentArr[nCntType];
if(!rpContentT)
rpContentT.reset(new SwContentType(pShell, nCntType, m_nOutlineLevel ));
OUString aImage(GetImageIdForContentTypeId(nCntType));
bool bChOnDemand = 0 != rpContentT->GetMemberCount();
// In case of LOK, empty content types must be hidden in the contenttree
if (comphelper::LibreOfficeKit::isActive() && !bChOnDemand)
{
continue;
}
OUString sId(weld::toId(rpContentT.get()));
insert(nullptr, rpContentT->GetName(), sId, bChOnDemand, xEntry.get());
m_xTreeView->set_image(*xEntry, aImage);
m_xTreeView->set_sensitive(*xEntry, bChOnDemand);
if (nCntType == m_nLastSelType)
xCntTypeEntry = m_xTreeView->make_iterator(xEntry.get());
sal_Int32 nExpandOptions = (State::HIDDEN == m_eState)
? m_nHiddenBlock
: m_nActiveBlock;
if (nExpandOptions & (1 << static_cast<int>(nCntType)))
{
// fill contents of to-be expanded entries while frozen
Expand(*xEntry, &aNodesToExpand);
m_xTreeView->set_children_on_demand(*xEntry, false);
}
}
m_xTreeView->thaw();
// restore visual expanded tree state
for (const auto& rNode : aNodesToExpand)
m_xTreeView->expand_row(*rNode);
}
// root content navigation view
else
{
m_xTreeView->freeze();
std::unique_ptr<SwContentType>& rpRootContentT = bActive ?
m_aActiveContentArr[m_nRootType] :
m_aHiddenContentArr[m_nRootType];
if(!rpRootContentT)
rpRootContentT.reset(new SwContentType(pShell, m_nRootType, m_nOutlineLevel ));
OUString aImage(GetImageIdForContentTypeId(m_nRootType));
bool bChOnDemand(m_nRootType == ContentTypeId::OUTLINE ||
m_nRootType == ContentTypeId::REGION ||
m_nRootType == ContentTypeId::POSTIT);
OUString sId(weld::toId(rpRootContentT.get()));
insert(nullptr, rpRootContentT->GetName(), sId, bChOnDemand, xEntry.get());
m_xTreeView->set_image(*xEntry, aImage);
xCntTypeEntry = m_xTreeView->make_iterator(xEntry.get());
if (!bChOnDemand)
InsertContent(*xEntry);
else
{
// fill contents of to-be expanded entries while frozen
Expand(*xEntry, &aNodesToExpand);
m_xTreeView->set_children_on_demand(*xEntry, false);
}
m_xTreeView->set_sensitive(*xEntry, m_xTreeView->iter_has_child(*xEntry));
m_xTreeView->thaw();
if (bChOnDemand)
{
// restore visual expanded tree state
for (const auto& rNode : aNodesToExpand)
m_xTreeView->expand_row(*rNode);
}
else
m_xTreeView->expand_row(*xEntry);
}
// Reselect the old selected entry. If it is not available, select the entry at the old
// selected entry position unless that entry position is now a content type or is past the
// end of the member list then select the entry at the previous entry position.
if (xOldSelEntry)
{
std::unique_ptr<weld::TreeIter> xSelEntry = m_xTreeView->make_iterator(xCntTypeEntry.get());
if (nEntryRelPos)
{
std::unique_ptr<weld::TreeIter> xIter(m_xTreeView->make_iterator(xCntTypeEntry.get()));
std::unique_ptr<weld::TreeIter> xTemp(m_xTreeView->make_iterator(xIter.get()));
sal_uLong nPos = 1;
bool bNext;
while ((bNext = m_xTreeView->iter_next(*xIter) && lcl_IsContent(*xIter, *m_xTreeView)))
{
if (m_xTreeView->get_id(*xIter) == sOldSelEntryId || nPos == nEntryRelPos)
{
m_xTreeView->copy_iterator(*xIter, *xSelEntry);
break;
}
m_xTreeView->copy_iterator(*xIter, *xTemp); // note previous entry
nPos++;
}
if (!bNext)
xSelEntry = std::move(xTemp);
}
// set_cursor unselects all entries, makes passed entry visible, and selects it
m_xTreeView->set_cursor(*xSelEntry);
Select();
}
}
if (!m_bIgnoreDocChange && GetEntryCount() == nOldEntryCount)
{
m_xTreeView->vadjustment_set_value(nOldScrollPos);
}
}
void SwContentTree::clear()
{
m_xTreeView->freeze();
m_xTreeView->clear();
m_nEntryCount = 0;
m_xTreeView->thaw();
}
bool SwContentTree::FillTransferData( TransferDataContainer& rTransfer,
sal_Int8& rDragMode )
{
bool bRet = false;
SwWrtShell* pWrtShell = GetWrtShell();
OSL_ENSURE(pWrtShell, "no Shell!");
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
bool bEntry = m_xTreeView->get_cursor(xEntry.get());
if (!bEntry || lcl_IsContentType(*xEntry, *m_xTreeView) || !pWrtShell)
return false;
OUString sEntry;
assert(dynamic_cast<SwContent*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(*xEntry))));
SwContent* pCnt = weld::fromId<SwContent*>(m_xTreeView->get_id(*xEntry));
const ContentTypeId nActType = pCnt->GetParent()->GetType();
OUString sUrl;
bool bOutline = false;
OUString sOutlineText;
switch( nActType )
{
case ContentTypeId::OUTLINE:
{
const SwOutlineNodes::size_type nPos = static_cast<SwOutlineContent*>(pCnt)->GetOutlinePos();
OSL_ENSURE(nPos < pWrtShell->getIDocumentOutlineNodesAccess()->getOutlineNodesCount(),
"outlinecnt changed");
// make sure outline may actually be copied
if( pWrtShell->IsOutlineCopyable( nPos ) )
{
const SwNumRule* pOutlRule = pWrtShell->GetOutlineNumRule();
const SwTextNode* pTextNd =
pWrtShell->getIDocumentOutlineNodesAccess()->getOutlineNode(nPos);
if (pTextNd && pOutlRule && pTextNd->IsNumbered(pWrtShell->GetLayout()))
{
SwNumberTree::tNumberVector aNumVector =
pTextNd->GetNumberVector(pWrtShell->GetLayout());
for( int nLevel = 0;
nLevel <= pTextNd->GetActualListLevel();
nLevel++ )
{
const SwNumberTree::tSwNumTreeNumber nVal = aNumVector[nLevel] + 1;
sEntry += OUString::number( nVal - pOutlRule->Get(nLevel).GetStart() ) + ".";
}
}
sEntry += pWrtShell->getIDocumentOutlineNodesAccess()->getOutlineText(nPos, pWrtShell->GetLayout(), false);
sOutlineText = pWrtShell->getIDocumentOutlineNodesAccess()->getOutlineText(nPos, pWrtShell->GetLayout());
m_bIsOutlineMoveable = static_cast<SwOutlineContent*>(pCnt)->IsMoveable();
bOutline = true;
}
}
break;
case ContentTypeId::POSTIT:
case ContentTypeId::INDEX:
case ContentTypeId::REFERENCE :
case ContentTypeId::TEXTFIELD:
case ContentTypeId::FOOTNOTE:
case ContentTypeId::ENDNOTE:
// cannot be inserted, neither as URL nor as section
break;
case ContentTypeId::URLFIELD:
sUrl = static_cast<SwURLFieldContent*>(pCnt)->GetURL();
[[fallthrough]];
case ContentTypeId::OLE:
case ContentTypeId::GRAPHIC:
if(GetParentWindow()->GetRegionDropMode() != RegionMode::NONE)
break;
else
rDragMode &= ~( DND_ACTION_MOVE | DND_ACTION_LINK );
[[fallthrough]];
default:
sEntry = m_xTreeView->get_text(*xEntry);
}
if(!sEntry.isEmpty())
{
const SwDocShell* pDocShell = pWrtShell->GetView().GetDocShell();
if(sUrl.isEmpty())
{
if(pDocShell->HasName())
{
SfxMedium* pMedium = pDocShell->GetMedium();
sUrl = pMedium->GetURLObject().GetURLNoMark();
// only if a primarily link shall be integrated.
bRet = true;
}
else if ( nActType == ContentTypeId::REGION || nActType == ContentTypeId::BOOKMARK )
{
// For field and bookmarks a link is also allowed
// without a filename into its own document.
bRet = true;
}
else if (State::CONSTANT == m_eState &&
( !::GetActiveView() ||
m_pActiveShell != ::GetActiveView()->GetWrtShellPtr()))
{
// Urls of inactive views cannot dragged without
// file names, also.
bRet = false;
}
else
{
bRet = GetParentWindow()->GetRegionDropMode() == RegionMode::NONE;
rDragMode = DND_ACTION_MOVE;
}
const OUString& rToken = pCnt->GetParent()->GetTypeToken();
sUrl += "#" + sEntry;
if(!rToken.isEmpty())
{
sUrl += OUStringChar(cMarkSeparator) + rToken;
}
}
else
bRet = true;
if( bRet )
{
// In Outlines of heading text must match
// the real number into the description.
if(bOutline)
sEntry = sOutlineText;
{
NaviContentBookmark aBmk( sUrl, sEntry,
GetParentWindow()->GetRegionDropMode(),
pDocShell);
aBmk.Copy( rTransfer );
}
// An INetBookmark must a be delivered to foreign DocShells
if( pDocShell->HasName() )
{
INetBookmark aBkmk( sUrl, sEntry );
rTransfer.CopyINetBookmark( aBkmk );
}
}
}
return bRet;
}
void SwContentTree::ToggleToRoot()
{
if(!m_bIsRoot)
{
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
bool bEntry = m_xTreeView->get_cursor(xEntry.get());
if (bEntry)
{
const SwContentType* pCntType;
if (lcl_IsContentType(*xEntry, *m_xTreeView))
{
assert(dynamic_cast<SwContentType*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(*xEntry))));
pCntType = weld::fromId<SwContentType*>(m_xTreeView->get_id(*xEntry));
}
else
{
assert(dynamic_cast<SwContent*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(*xEntry))));
pCntType = weld::fromId<SwContent*>(m_xTreeView->get_id(*xEntry))->GetParent();
}
m_nRootType = pCntType->GetType();
m_bIsRoot = true;
if (m_nRootType == ContentTypeId::OUTLINE || m_nRootType == ContentTypeId::DRAWOBJECT)
{
m_xTreeView->set_selection_mode(SelectionMode::Multiple);
}
Display(State::HIDDEN != m_eState);
}
}
else
{
m_xTreeView->set_selection_mode(SelectionMode::Single);
m_nLastSelType = m_nRootType;
m_nRootType = ContentTypeId::UNKNOWN;
m_bIsRoot = false;
// Other content type member data could have changed while in root view. Fill the content
// member lists excluding the toggled from root content which should already have the most
// recent data.
if (State::HIDDEN != m_eState)
{
for (ContentTypeId i : o3tl::enumrange<ContentTypeId>())
{
if (i != m_nLastSelType && m_aActiveContentArr[i])
m_aActiveContentArr[i]->FillMemberList();
}
}
Display(State::HIDDEN != m_eState);
}
m_pConfig->SetRootType( m_nRootType );
weld::Toolbar* pBox = GetParentWindow()->m_xContent5ToolBox.get();
pBox->set_item_active("root", m_bIsRoot);
}
bool SwContentTree::HasContentChanged()
{
bool bContentChanged = false;
// - Run through the local array and the Treelistbox in parallel.
// - Are the records not expanded, they are discarded only in the array
// and the content type will be set as the new UserData.
// - Is the root mode is active only this will be updated.
// Valid for the displayed content types is:
// the Memberlist will be erased and the membercount will be updated
// If content will be checked, the memberlists will be replenished
// at the same time. Once a difference occurs it will be only replenished
// no longer checked. Finally, the box is filled again.
if (State::HIDDEN == m_eState)
{
for(ContentTypeId i : o3tl::enumrange<ContentTypeId>())
{
if(m_aActiveContentArr[i])
m_aActiveContentArr[i]->Invalidate();
}
return false;
}
// single content type navigation view
if(m_bIsRoot)
{
std::unique_ptr<weld::TreeIter> xRootEntry(m_xTreeView->make_iterator());
if (!m_xTreeView->get_iter_first(*xRootEntry))
return true;
assert(dynamic_cast<SwContentType*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(*xRootEntry))));
const ContentTypeId nType = weld::fromId<SwContentType*>(m_xTreeView->get_id(*xRootEntry))->GetType();
SwContentType* pArrType = m_aActiveContentArr[nType].get();
assert(weld::toId(pArrType) == m_xTreeView->get_id(*xRootEntry));
if (!pArrType)
return true;
pArrType->FillMemberList(&bContentChanged);
if (bContentChanged)
return true;
// FillMemberList tests if member count in old member array equals member count in new
// member array. Test here for member count difference between array and tree.
const size_t nChildCount = GetChildCount(*xRootEntry);
if (nChildCount != pArrType->GetMemberCount())
return true;
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator(xRootEntry.get()));
for (size_t j = 0; j < nChildCount; ++j)
{
if (!m_xTreeView->iter_next(*xEntry))
{
SAL_WARN("sw.ui", "unexpected missing entry");
return true;
}
// FillMemberList clears the content type member list and refills with new data.
// Treeview entry user data is set here to the string representation of the pointer to
// the member data in the array. The Display function will clear and recreate the
// treeview from the content type member arrays if content change is detected.
const SwContent* pCnt = pArrType->GetMember(j);
if (pCnt->IsInvisible() != m_xTreeView->get_sensitive(*xEntry, 0))
return true;
OUString sEntryText = m_xTreeView->get_text(*xEntry);
if (sEntryText != pCnt->GetName() &&
!(sEntryText == m_sSpace && pCnt->GetName().isEmpty()))
{
return true;
}
// Set_id needs to be done here because FillMemberList clears the content type member
// list and refills with new data making the previously set id invalid. If there is no
// content change detected the Display function will not be called and the tree entry
// user data will not be set to the new content member pointer address.
OUString sSubId(weld::toId(pCnt));
m_xTreeView->set_id(*xEntry, sSubId);
}
}
// all content types navigation view
else
{
// Fill member list for each content type and check for content change. If content change
// is detected only fill member lists for remaining content types. The Display function
// will clear and recreate the treeview from the content type member arrays if content has
// changed.
if (comphelper::LibreOfficeKit::isActive())
{
// In case of LOK, empty contentTypes are hidden, even in all content view
// so it is not enough to check only the m_xTreeView.
bool bCountChanged = false;
bool bHasContentChanged = false;
for (ContentTypeId i : o3tl::enumrange<ContentTypeId>())
{
if (m_aActiveContentArr[i])
{
auto nLastTMCount = m_aActiveContentArr[i]->GetMemberCount();
if (i == ContentTypeId::OUTLINE) // this is required for checking if header level is changed
m_aActiveContentArr[i]->FillMemberList(&bHasContentChanged);
else
m_aActiveContentArr[i]->FillMemberList();
// If the member count of a type is changed, then the content is surely changed
if (m_aActiveContentArr[i]->GetMemberCount() != nLastTMCount)
bCountChanged = true;
if (bHasContentChanged)
bContentChanged = true;
}
}
if (bCountChanged || bContentChanged)
return true;
}
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
// lambda function to find the next content type entry
auto lcl_nextContentTypeEntry = [this, &xEntry](){
while (m_xTreeView->get_iter_depth(*xEntry))
m_xTreeView->iter_parent(*xEntry);
return m_xTreeView->iter_next_sibling(*xEntry);
};
for (bool bEntry = m_xTreeView->get_iter_first(*xEntry); bEntry;
bEntry = lcl_nextContentTypeEntry())
{
assert(dynamic_cast<SwContentType*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(*xEntry))));
SwContentType* pCntType = weld::fromId<SwContentType*>(m_xTreeView->get_id(*xEntry));
const size_t nCntCount = pCntType->GetMemberCount();
const ContentTypeId nType = pCntType->GetType();
SwContentType* pArrType = m_aActiveContentArr[nType].get();
assert(weld::toId(pArrType) == m_xTreeView->get_id(*xEntry));
if (!pArrType)
{
bContentChanged = true;
continue;
}
// all content type member lists must be filled!
if (bContentChanged)
{
// If content change has already been detected there is no need to detect
// other content change so no argument is supplied here to FillMemberList.
pArrType->FillMemberList();
continue;
}
pArrType->FillMemberList(&bContentChanged);
if (bContentChanged)
continue;
// does entry have children?
if (m_xTreeView->get_row_expanded(*xEntry))
{
const size_t nChildCount = GetChildCount(*xEntry);
if(nChildCount != pArrType->GetMemberCount())
{
bContentChanged = true;
continue;
}
for(size_t j = 0; j < nChildCount; ++j)
{
if (!m_xTreeView->iter_next(*xEntry))
{
SAL_WARN("sw.ui", "unexpected missing entry");
bContentChanged = true;
break;
}
const SwContent* pCnt = pArrType->GetMember(j);
if (pCnt->IsInvisible() != m_xTreeView->get_sensitive(*xEntry, 0))
{
bContentChanged = true;
break;
}
OUString sEntryText = m_xTreeView->get_text(*xEntry);
if( sEntryText != pCnt->GetName() &&
!(sEntryText == m_sSpace && pCnt->GetName().isEmpty()))
{
bContentChanged = true;
break;
}
// See comment above in single content type navigation view block for why the
// following is done here.
OUString sSubId(weld::toId(pCnt));
m_xTreeView->set_id(*xEntry, sSubId);
}
}
// not expanded and has children
else if (m_xTreeView->iter_has_child(*xEntry))
{
bool bRemoveChildren = false;
const size_t nOldChildCount = GetChildCount(*xEntry);
const size_t nNewChildCount = pArrType->GetMemberCount();
if (nOldChildCount != nNewChildCount)
{
bRemoveChildren = true;
}
else
{
std::unique_ptr<weld::TreeIter> xChild(m_xTreeView->make_iterator(xEntry.get()));
(void)m_xTreeView->iter_children(*xChild);
for (size_t j = 0; j < nOldChildCount; ++j)
{
const SwContent* pCnt = pArrType->GetMember(j);
OUString sSubId(weld::toId(pCnt));
m_xTreeView->set_id(*xChild, sSubId);
OUString sEntryText = m_xTreeView->get_text(*xChild);
if( sEntryText != pCnt->GetName() &&
!(sEntryText == m_sSpace && pCnt->GetName().isEmpty()))
{
bRemoveChildren = true;
}
(void)m_xTreeView->iter_next(*xChild);
}
}
if (bRemoveChildren)
{
std::unique_ptr<weld::TreeIter> xRemove(m_xTreeView->make_iterator(xEntry.get()));
while (m_xTreeView->iter_children(*xRemove))
{
remove(*xRemove);
m_xTreeView->copy_iterator(*xEntry, *xRemove);
}
m_xTreeView->set_children_on_demand(*xEntry, nNewChildCount != 0);
}
}
else if((nCntCount != 0)
!= (pArrType->GetMemberCount()!=0))
{
bContentChanged = true;
continue;
}
}
}
return bContentChanged;
}
void SwContentTree::UpdateLastSelType()
{
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
if (m_xTreeView->get_selected(xEntry.get()))
{
while (m_xTreeView->get_iter_depth(*xEntry))
m_xTreeView->iter_parent(*xEntry);
void* pId = weld::fromId<void*>(m_xTreeView->get_id(*xEntry));
if (pId && lcl_IsContentType(*xEntry, *m_xTreeView))
{
assert(dynamic_cast<SwContentType*>(static_cast<SwTypeNumber*>(pId)));
m_nLastSelType = static_cast<SwContentType*>(pId)->GetType();
}
}
}
void SwContentTree::FindActiveTypeAndRemoveUserData()
{
UpdateLastSelType();
// If clear is called by TimerUpdate:
// Only for root can the validity of the UserData be guaranteed.
m_xTreeView->all_foreach([this](weld::TreeIter& rEntry){
m_xTreeView->set_id(rEntry, "");
return false;
});
}
void SwContentTree::SetHiddenShell(SwWrtShell* pSh)
{
m_pHiddenShell = pSh;
m_eState = State::HIDDEN;
FindActiveTypeAndRemoveUserData();
for(ContentTypeId i : o3tl::enumrange<ContentTypeId>())
{
m_aHiddenContentArr[i].reset();
}
Display(false);
GetParentWindow()->UpdateListBox();
}
void SwContentTree::SetActiveShell(SwWrtShell* pSh)
{
bool bClear = m_pActiveShell != pSh;
if (State::ACTIVE == m_eState && bClear)
{
EndListeningAll();
m_pActiveShell = pSh;
FindActiveTypeAndRemoveUserData();
clear();
}
else if (State::CONSTANT == m_eState)
{
EndListeningAll();
m_pActiveShell = pSh;
m_eState = State::ACTIVE;
bClear = true;
}
// tdf#148432 in LTR UI override the navigator treeview direction based on
// the first page directionality
if (m_pActiveShell && !AllSettings::GetLayoutRTL())
{
const SwPageDesc& rDesc = m_pActiveShell->GetPageDesc(0);
const SvxFrameDirectionItem& rFrameDir = rDesc.GetMaster().GetFrameDir();
m_xTreeView->set_direction(rFrameDir.GetValue() == SvxFrameDirection::Horizontal_RL_TB);
}
// Only if it is the active view, the array will be deleted and
// the screen filled new.
if (State::ACTIVE == m_eState && bClear)
{
if (m_pActiveShell)
StartListening(*m_pActiveShell->GetView().GetDocShell());
FindActiveTypeAndRemoveUserData();
for(ContentTypeId i : o3tl::enumrange<ContentTypeId>())
{
m_aActiveContentArr[i].reset();
}
Display(true);
}
}
void SwContentTree::SetConstantShell(SwWrtShell* pSh)
{
EndListeningAll();
m_pActiveShell = pSh;
m_eState = State::CONSTANT;
StartListening(*m_pActiveShell->GetView().GetDocShell());
FindActiveTypeAndRemoveUserData();
for(ContentTypeId i : o3tl::enumrange<ContentTypeId>())
{
m_aActiveContentArr[i].reset();
}
Display(true);
}
void SwContentTree::Notify(SfxBroadcaster & rBC, SfxHint const& rHint)
{
SfxViewEventHint const*const pVEHint(dynamic_cast<SfxViewEventHint const*>(&rHint));
SwXTextView* pDyingShell = nullptr;
if (m_pActiveShell && pVEHint && pVEHint->GetEventName() == "OnViewClosed")
pDyingShell = dynamic_cast<SwXTextView*>(pVEHint->GetController().get());
if (pDyingShell && pDyingShell->GetView() == &m_pActiveShell->GetView())
{
SetActiveShell(nullptr); // our view is dying, clear our pointers to it
}
else
{
SfxListener::Notify(rBC, rHint);
}
switch (rHint.GetId())
{
case SfxHintId::SwNavigatorUpdateTracking:
UpdateTracking();
break;
case SfxHintId::SwNavigatorSelectOutlinesWithSelections:
{
if (m_nRootType == ContentTypeId::OUTLINE)
{
SelectOutlinesWithSelection();
// make first selected entry visible
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
if (xEntry && m_xTreeView->get_selected(xEntry.get()))
m_xTreeView->scroll_to_row(*xEntry);
}
else if (m_nRootType == ContentTypeId::UNKNOWN)
m_xTreeView->unselect_all();
break;
}
case SfxHintId::DocChanged:
OverlayObject();
if (!m_bIgnoreDocChange)
{
m_bDocHasChanged = true;
TimerUpdate(&m_aUpdTimer);
}
break;
case SfxHintId::ModeChanged:
if (SwWrtShell* pShell = GetWrtShell())
{
const bool bReadOnly = pShell->GetView().GetDocShell()->IsReadOnly();
if (bReadOnly != m_bIsLastReadOnly)
{
m_bIsLastReadOnly = bReadOnly;
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
if (m_xTreeView->get_cursor(xEntry.get()))
{
m_xTreeView->select(*xEntry);
Select();
}
else
m_xTreeView->unselect_all();
}
}
break;
default:
break;
}
}
// Handler for outline entry up/down left/right movement
void SwContentTree::ExecCommand(std::u16string_view rCmd, bool bOutlineWithChildren)
{
if (m_xTreeView->count_selected_rows() == 0)
return;
const bool bUp = rCmd == u"chapterup";
const bool bUpDown = bUp || rCmd == u"chapterdown";
const bool bLeft = rCmd == u"promote";
const bool bLeftRight = bLeft || rCmd == u"demote";
if (!bUpDown && !bLeftRight)
return;
if (GetWrtShell()->GetView().GetDocShell()->IsReadOnly() ||
(State::ACTIVE != m_eState &&
(State::CONSTANT != m_eState || m_pActiveShell != GetParentWindow()->GetCreateView()->GetWrtShellPtr())))
{
return;
}
SwWrtShell *const pShell = GetWrtShell();
const SwNodes& rNodes = pShell->GetNodes();
const SwOutlineNodes& rOutlineNodes = rNodes.GetOutLineNds();
const SwOutlineNodes::size_type nOutlineNdsSize = rOutlineNodes.size();
std::vector<SwTextNode*> selectedOutlineNodes;
std::vector<std::unique_ptr<weld::TreeIter>> selected;
m_xTreeView->selected_foreach([&](weld::TreeIter& rEntry){
// it's possible to select the root node too which is a really bad idea
if (lcl_IsContentType(rEntry, *m_xTreeView))
return false;
// filter out children of selected parents so they don't get promoted
// or moved twice (except if there is Ctrl modifier, since in that
// case children are re-parented)
if ((bLeftRight || bOutlineWithChildren) && !selected.empty())
{
std::unique_ptr<weld::TreeIter> xParent(m_xTreeView->make_iterator(&rEntry));
for (bool bParent = m_xTreeView->iter_parent(*xParent); bParent; bParent = m_xTreeView->iter_parent(*xParent))
{
if (m_xTreeView->iter_compare(*selected.back(), *xParent) == 0)
{
return false;
}
}
}
selected.emplace_back(m_xTreeView->make_iterator(&rEntry));
// Use the outline node position in the SwOutlineNodes array. Bad things
// happen if the tree entry position is used and it doesn't match the node position
// in SwOutlineNodes, which is usually the case for outline nodes in frames.
const SwOutlineNodes::size_type nPos
= weld::fromId<SwOutlineContent*>(m_xTreeView->get_id(rEntry))->GetOutlinePos();
if (nPos < nOutlineNdsSize)
{
SwNode* pNode = rNodes.GetOutLineNds()[ nPos ];
if (pNode)
{
selectedOutlineNodes.push_back(pNode->GetTextNode());
}
}
return false;
});
if (!selected.size())
return;
if (bUpDown && !bUp)
{ // to move down, start at the end!
std::reverse(selected.begin(), selected.end());
}
m_bIgnoreDocChange = true;
SwOutlineNodes::size_type nActPos;
bool bStartedAction = false;
MakeAllOutlineContentTemporarilyVisible a(GetWrtShell()->GetDoc());
// get first regular document content node outline node position in outline nodes array
SwOutlineNodes::size_type nFirstRegularDocContentOutlineNodePos = SwOutlineNodes::npos;
SwNodeOffset nEndOfExtrasIndex = rNodes.GetEndOfExtras().GetIndex();
for (SwOutlineNodes::size_type nPos = 0; nPos < nOutlineNdsSize; nPos++)
{
if (rOutlineNodes[nPos]->GetIndex() > nEndOfExtrasIndex)
{
nFirstRegularDocContentOutlineNodePos = nPos;
break;
}
}
for (auto const& pCurrentEntry : selected)
{
nActPos = weld::fromId<SwOutlineContent*>(
m_xTreeView->get_id(*pCurrentEntry))->GetOutlinePos();
// outline nodes in frames and tables are not up/down moveable
if (nActPos == SwOutlineNodes::npos ||
(bUpDown && (!pShell->IsOutlineMovable(nActPos) ||
nFirstRegularDocContentOutlineNodePos == SwOutlineNodes::npos)))
{
continue;
}
if (!bStartedAction)
{
pShell->StartAllAction();
pShell->StartUndo(bLeftRight ? SwUndoId::OUTLINE_LR : SwUndoId::OUTLINE_UD);
bStartedAction = true;
}
pShell->GotoOutline( nActPos); // If text selection != box selection
pShell->Push();
if (bUpDown)
{
// move outline position up/down (outline position promote/demote)
SwOutlineNodes::difference_type nDir = bUp ? -1 : 1;
if ((nDir == -1 && nActPos > 0) || (nDir == 1 && nActPos < nOutlineNdsSize - 1))
{
// make outline selection for use by MoveOutlinePara
pShell->MakeOutlineSel(nActPos, nActPos, bOutlineWithChildren);
int nActPosOutlineLevel =
rOutlineNodes[nActPos]->GetTextNode()->GetAttrOutlineLevel();
SwOutlineNodes::size_type nPos = nActPos;
if (!bUp)
{
// move down
int nPosOutlineLevel = -1;
while (++nPos < nOutlineNdsSize)
{
nPosOutlineLevel =
rOutlineNodes[nPos]->GetTextNode()->GetAttrOutlineLevel();
// discontinue if moving out of parent or equal level is found
if (nPosOutlineLevel <= nActPosOutlineLevel)
break;
// count the children of the node when they are not included in the move
if (!bOutlineWithChildren)
nDir++;
}
if (nPosOutlineLevel >= nActPosOutlineLevel)
{
// move past children
while (++nPos < nOutlineNdsSize)
{
nPosOutlineLevel =
rOutlineNodes[nPos]->GetTextNode()->GetAttrOutlineLevel();
// discontinue if moving out of parent or equal level is found
if (nPosOutlineLevel <= nActPosOutlineLevel)
break;
nDir++;
}
}
}
else
{
// move up
while (nPos && --nPos >= nFirstRegularDocContentOutlineNodePos)
{
int nPosOutlineLevel =
rOutlineNodes[nPos]->GetTextNode()->GetAttrOutlineLevel();
// discontinue if equal level is found
if (nPosOutlineLevel == nActPosOutlineLevel)
break;
// discontinue if moving out of parent
if (nPosOutlineLevel < nActPosOutlineLevel)
{
// Required for expected chapter placement when the chapter being moved
// up has an outline level less than the outline level of chapters it
// is being moved above and then encounters a chapter with an outline
// level that is greater before reaching a chapter with the same
// outline level as itself.
if (nDir < -1)
nDir++;
break;
}
nDir--;
}
}
pShell->MoveOutlinePara(nDir);
}
pShell->ClearMark();
}
else
{
// move outline left/right (outline level promote/demote)
if (!pShell->IsProtectedOutlinePara())
{
bool bAllow = true;
const SwOutlineNodes& rOutlNds = pShell->GetDoc()->GetNodes().GetOutLineNds();
const int nActLevel = rOutlNds[nActPos]->GetTextNode()->GetAttrOutlineLevel();
if (!bLeft)
{
// disallow if any outline node to demote will exceed MAXLEVEL
SwOutlineNodes::size_type nPos = nActPos;
do
{
int nLevel = rOutlNds[nPos]->GetTextNode()->GetAttrOutlineLevel();
if (nLevel == MAXLEVEL)
{
bAllow = false;
break;
}
} while (bOutlineWithChildren && ++nPos < rOutlNds.size() &&
rOutlNds[nPos]->GetTextNode()->GetAttrOutlineLevel() > nActLevel);
}
else
{
// disallow if trying to promote outline of level 1
if (nActLevel == 1)
bAllow = false;
}
if (bAllow)
{
SwOutlineNodes::size_type nPos = nActPos;
do
{
pShell->SwCursorShell::GotoOutline(nPos);
pShell->OutlineUpDown(bLeft ? -1 : 1);
} while (bOutlineWithChildren && ++nPos < rOutlNds.size() &&
rOutlNds[nPos]->GetTextNode()->GetAttrOutlineLevel() > nActLevel);
}
}
}
pShell->Pop(SwCursorShell::PopMode::DeleteCurrent); // Cursor is now back at the current heading.
}
if (bStartedAction)
{
pShell->EndUndo();
pShell->EndAllAction();
if (m_aActiveContentArr[ContentTypeId::OUTLINE])
m_aActiveContentArr[ContentTypeId::OUTLINE]->Invalidate();
// tdf#143547 LO Writer: navigator should stand still on promoting and demoting
// In addition to m_bIgnoreDocChange being true, selections are cleared before the Display
// call. Either of these conditions disable restore of scroll position happening in the
// Display function so it needs to be done here.
auto nOldScrollPos = m_xTreeView->vadjustment_get_value();
// clear all selections to prevent the Display function from trying to reselect selected entries
m_xTreeView->unselect_all();
Display(true);
m_xTreeView->vadjustment_set_value(nOldScrollPos);
if (m_bIsRoot)
{
// reselect entries, do this only when in outline content navigation mode
const SwOutlineNodes& rOutlineNds = pShell->GetNodes().GetOutLineNds();
for (SwTextNode* pNode : selectedOutlineNodes)
{
m_xTreeView->all_foreach([this, &rOutlineNds, pNode](weld::TreeIter& rEntry){
if (lcl_IsContentType(rEntry, *m_xTreeView))
return false;
SwOutlineNodes::size_type nPos = weld::fromId<SwOutlineContent*>(
m_xTreeView->get_id(rEntry))->GetOutlinePos();
if (pNode == rOutlineNds[nPos]->GetTextNode())
{
std::unique_ptr<weld::TreeIter> xParent(m_xTreeView->make_iterator(&rEntry));
if (m_xTreeView->iter_parent(*xParent)
&& !m_xTreeView->get_row_expanded(*xParent))
{
m_xTreeView->expand_row(*xParent);
}
m_xTreeView->select(rEntry);
return true;
}
return false;
});
}
}
else
{
m_pActiveShell->GetView().GetEditWin().GrabFocus();
m_bIgnoreDocChange = false;
UpdateTracking();
grab_focus();
}
}
m_bIgnoreDocChange = false;
}
void SwContentTree::ShowTree()
{
m_xTreeView->show();
m_aUpdTimer.Start();
}
void SwContentTree::HideTree()
{
// folded together will not be idled
m_aUpdTimer.Stop();
m_xTreeView->hide();
}
static void lcl_SelectByContentTypeAndAddress(SwContentTree* pThis, weld::TreeView& rContentTree,
ContentTypeId nType, const void* ptr)
{
if (!ptr)
{
rContentTree.set_cursor(-1);
pThis->Select();
return;
}
// find content type entry
std::unique_ptr<weld::TreeIter> xIter(rContentTree.make_iterator());
bool bFoundEntry = rContentTree.get_iter_first(*xIter);
while (bFoundEntry)
{
void* pUserData = weld::fromId<void*>(rContentTree.get_id(*xIter));
assert(dynamic_cast<SwContentType*>(static_cast<SwTypeNumber*>(pUserData)));
if (nType == static_cast<SwContentType*>(pUserData)->GetType())
break;
bFoundEntry = rContentTree.iter_next_sibling(*xIter);
}
if (!bFoundEntry)
{
rContentTree.set_cursor(-1);
pThis->Select();
return;
}
// assure content type entry is expanded
rContentTree.expand_row(*xIter);
// find content type content entry and select it
const void* p = nullptr;
while (rContentTree.iter_next(*xIter) && lcl_IsContent(*xIter, rContentTree))
{
void* pUserData = weld::fromId<void*>(rContentTree.get_id(*xIter));
switch( nType )
{
case ContentTypeId::FOOTNOTE:
case ContentTypeId::ENDNOTE:
{
assert(dynamic_cast<SwTextFootnoteContent*>(static_cast<SwTypeNumber*>(pUserData)));
SwTextFootnoteContent* pCnt = static_cast<SwTextFootnoteContent*>(pUserData);
p = pCnt->GetTextFootnote();
break;
}
case ContentTypeId::URLFIELD:
{
assert(dynamic_cast<SwURLFieldContent*>(static_cast<SwTypeNumber*>(pUserData)));
SwURLFieldContent* pCnt = static_cast<SwURLFieldContent*>(pUserData);
p = static_cast<const SwTextAttr*>(pCnt->GetINetAttr());
break;
}
case ContentTypeId::TEXTFIELD:
{
assert(dynamic_cast<SwTextFieldContent*>(static_cast<SwTypeNumber*>(pUserData)));
SwTextFieldContent* pCnt = static_cast<SwTextFieldContent*>(pUserData);
p = pCnt->GetFormatField()->GetField();
break;
}
case ContentTypeId::POSTIT:
{
assert(dynamic_cast<SwPostItContent*>(static_cast<SwTypeNumber*>(pUserData)));
SwPostItContent* pCnt = static_cast<SwPostItContent*>(pUserData);
p = pCnt->GetPostIt()->GetField();
break;
}
default:
break;
}
if (ptr == p)
{
// get first selected for comparison
std::unique_ptr<weld::TreeIter> xFirstSelected(rContentTree.make_iterator());
if (!rContentTree.get_selected(xFirstSelected.get()))
xFirstSelected.reset();
if (rContentTree.count_selected_rows() != 1 || !xFirstSelected ||
rContentTree.iter_compare(*xIter, *xFirstSelected) != 0)
{
// unselect all entries and make passed entry visible and selected
rContentTree.set_cursor(*xIter);
pThis->Select();
}
return;
}
}
rContentTree.set_cursor(-1);
pThis->Select();
return;
}
static void lcl_SelectByContentTypeAndName(SwContentTree* pThis, weld::TreeView& rContentTree,
std::u16string_view rContentTypeName, std::u16string_view rName)
{
if (rName.empty())
return;
// find content type entry
std::unique_ptr<weld::TreeIter> xIter(rContentTree.make_iterator());
bool bFoundEntry = rContentTree.get_iter_first(*xIter);
while (bFoundEntry && rContentTypeName != rContentTree.get_text(*xIter))
bFoundEntry = rContentTree.iter_next_sibling(*xIter);
// find content type content entry and select it
if (!bFoundEntry)
return;
rContentTree.expand_row(*xIter); // assure content type entry is expanded
while (rContentTree.iter_next(*xIter) && lcl_IsContent(*xIter, rContentTree))
{
if (rName == rContentTree.get_text(*xIter))
{
// get first selected for comparison
std::unique_ptr<weld::TreeIter> xFirstSelected(rContentTree.make_iterator());
if (!rContentTree.get_selected(xFirstSelected.get()))
xFirstSelected.reset();
if (rContentTree.count_selected_rows() != 1 || !xFirstSelected ||
rContentTree.iter_compare(*xIter, *xFirstSelected) != 0)
{
// unselect all entries and make passed entry visible and selected
rContentTree.set_cursor(*xIter);
pThis->Select();
}
break;
}
}
}
static void lcl_SelectDrawObjectByName(weld::TreeView& rContentTree, std::u16string_view rName)
{
if (rName.empty())
return;
// find content type entry
std::unique_ptr<weld::TreeIter> xIter(rContentTree.make_iterator());
bool bFoundEntry = rContentTree.get_iter_first(*xIter);
while (bFoundEntry && SwResId(STR_CONTENT_TYPE_DRAWOBJECT) != rContentTree.get_text(*xIter))
bFoundEntry = rContentTree.iter_next_sibling(*xIter);
// find content type content entry and select it
if (bFoundEntry)
{
rContentTree.expand_row(*xIter); // assure content type entry is expanded
while (rContentTree.iter_next(*xIter) && lcl_IsContent(*xIter, rContentTree))
{
if (rName == rContentTree.get_text(*xIter))
{
if (!rContentTree.is_selected(*xIter))
{
rContentTree.select(*xIter);
rContentTree.scroll_to_row(*xIter);
}
break;
}
}
}
}
/** No idle with focus or while dragging */
IMPL_LINK_NOARG(SwContentTree, TimerUpdate, Timer *, void)
{
// No need to update if content tree is not visible
if (!m_xTreeView->is_visible())
return;
// No update while focus is not in document.
// No update while drag and drop.
// Query view because the Navigator is cleared too late.
SwView* pView = GetParentWindow()->GetCreateView();
SwWrtShell* pActShell = pView ? pView->GetWrtShellPtr() : nullptr;
if(pActShell && pActShell->GetWin() &&
(pActShell->GetWin()->HasFocus() || m_bDocHasChanged || m_bViewHasChanged) &&
!IsInDrag() && !pActShell->ActionPend())
{
if (m_bDocHasChanged || m_bViewHasChanged)
{
if (State::CONSTANT == m_eState && !lcl_FindShell(m_pActiveShell))
{
SetActiveShell(pActShell);
GetParentWindow()->UpdateListBox();
}
if (State::ACTIVE == m_eState && pActShell != GetWrtShell())
{
SetActiveShell(pActShell);
}
else if ((State::ACTIVE == m_eState || (State::CONSTANT == m_eState && pActShell == GetWrtShell())) &&
HasContentChanged())
{
FindActiveTypeAndRemoveUserData();
Display(true);
}
}
UpdateTracking();
m_bIsIdleClear = false;
m_bDocHasChanged = false;
m_bViewHasChanged = false;
}
else if (!pView && State::ACTIVE == m_eState && !m_bIsIdleClear) // this block seems never to be entered
{
if(m_pActiveShell)
{
SetActiveShell(nullptr);
}
clear();
m_bIsIdleClear = true;
}
}
void SwContentTree::UpdateTracking()
{
if (State::HIDDEN == m_eState || !m_pActiveShell)
return;
// only when treeview or treeview context menu does not have focus
if (m_xTreeView->has_focus() || m_xTreeView->has_child_focus())
return;
// m_bIgnoreDocChange is set on delete and outline visibility toggle
if (m_bIgnoreDocChange)
{
m_bIgnoreDocChange = false;
return;
}
// bTrack is used to disallow tracking after jumping to an outline until the outline position
// that was jumped to is no longer the current outline position.
bool bTrack = true;
if (m_nLastGotoContentWasOutlinePos != SwOutlineNodes::npos)
{
if (m_pActiveShell->GetOutlinePos() == m_nLastGotoContentWasOutlinePos)
bTrack = false;
else
m_nLastGotoContentWasOutlinePos = SwOutlineNodes::npos;
}
if (bTrack)
{
// graphic, frame, and ole
if (m_pActiveShell->GetSelectionType() &
(SelectionType::Graphic | SelectionType::Frame | SelectionType::Ole))
{
OUString aContentTypeName;
if (m_pActiveShell->GetSelectionType() == SelectionType::Graphic &&
!(m_bIsRoot && m_nRootType != ContentTypeId::GRAPHIC))
{
if (!mTrackContentType[ContentTypeId::GRAPHIC]) return;
aContentTypeName = SwResId(STR_CONTENT_TYPE_GRAPHIC);
}
else if (m_pActiveShell->GetSelectionType() == SelectionType::Frame &&
!(m_bIsRoot && m_nRootType != ContentTypeId::FRAME))
{
if (!mTrackContentType[ContentTypeId::FRAME]) return;
aContentTypeName = SwResId(STR_CONTENT_TYPE_FRAME);
}
else if (m_pActiveShell->GetSelectionType() == SelectionType::Ole &&
!(m_bIsRoot && m_nRootType != ContentTypeId::OLE))
{
if (!mTrackContentType[ContentTypeId::OLE]) return;
aContentTypeName = SwResId(STR_CONTENT_TYPE_OLE);
}
if (!aContentTypeName.isEmpty())
{
OUString aName(m_pActiveShell->GetFlyName());
lcl_SelectByContentTypeAndName(this, *m_xTreeView, aContentTypeName, aName);
return;
}
}
// drawing
if ((m_pActiveShell->GetSelectionType() & (SelectionType::DrawObject |
SelectionType::DrawObjectEditMode |
SelectionType::DbForm)) &&
!(m_bIsRoot && m_nRootType != ContentTypeId::DRAWOBJECT))
{
if (mTrackContentType[ContentTypeId::DRAWOBJECT])
{
// Multiple selection is possible when in root content navigation view so unselect all
// selected entries before reselecting. This causes a bit of an annoyance when the treeview
// scroll bar is used and focus is in the document by causing the last selected entry to
// scroll back into view.
if (m_bIsRoot)
m_xTreeView->unselect_all();
SdrView* pSdrView = m_pActiveShell->GetDrawView();
if (pSdrView)
{
for (size_t nIdx(0); nIdx < pSdrView->GetMarkedObjectCount(); nIdx++)
{
SdrObject* pSelected = pSdrView->GetMarkedObjectByIndex(nIdx);
OUString aName(pSelected->GetName());
if (!aName.isEmpty())
lcl_SelectDrawObjectByName(*m_xTreeView, aName);
}
}
else
{
// clear treeview selections
m_xTreeView->unselect_all();
}
Select();
}
return;
}
// footnotes and endnotes
if (SwContentAtPos aContentAtPos(IsAttrAtPos::Ftn);
m_pActiveShell->GetContentAtPos(m_pActiveShell->GetCursorDocPos(), aContentAtPos)
&& aContentAtPos.pFndTextAttr &&
!(m_bIsRoot && (m_nRootType != ContentTypeId::FOOTNOTE &&
m_nRootType != ContentTypeId::ENDNOTE)))
{
if (!aContentAtPos.pFndTextAttr->GetFootnote().IsEndNote())
{
if (mTrackContentType[ContentTypeId::FOOTNOTE])
lcl_SelectByContentTypeAndAddress(this, *m_xTreeView, ContentTypeId::FOOTNOTE,
aContentAtPos.pFndTextAttr);
}
else if (mTrackContentType[ContentTypeId::ENDNOTE])
lcl_SelectByContentTypeAndAddress(this, *m_xTreeView, ContentTypeId::ENDNOTE,
aContentAtPos.pFndTextAttr);
return;
}
// bookmarks - track first bookmark at cursor
if (mTrackContentType[ContentTypeId::BOOKMARK] &&
(m_pActiveShell->GetSelectionType() & SelectionType::Text))
{
SwPaM* pCursor = m_pActiveShell->GetCursor();
IDocumentMarkAccess* const pMarkAccess = m_pActiveShell->getIDocumentMarkAccess();
IDocumentMarkAccess::const_iterator_t ppBookmark = pMarkAccess->getBookmarksBegin();
if (pCursor && ppBookmark != pMarkAccess->getBookmarksEnd() &&
!(m_bIsRoot && m_nRootType != ContentTypeId::BOOKMARK))
{
OUString sBookmarkName;
SwPosition* pCursorPoint = pCursor->GetPoint();
while (ppBookmark != pMarkAccess->getBookmarksEnd())
{
if (lcl_IsUiVisibleBookmark(*ppBookmark) &&
*pCursorPoint >= (*ppBookmark)->GetMarkStart() &&
*pCursorPoint <= (*ppBookmark)->GetMarkEnd())
{
sBookmarkName = (*ppBookmark)->GetName();
// keep previously selected bookmark instead
// of selecting a different bookmark inside of it
if (sBookmarkName == m_sSelectedItem)
break;
}
else if (!sBookmarkName.isEmpty() &&
*pCursorPoint < (*ppBookmark)->GetMarkStart())
{
// don't search a different bookmark inside the
// previous one, if the starting position of the next bookmarks
// is after the cursor position (assuming that the
// bookmark iterator jumps inside the same text by positions)
break;
}
++ppBookmark;
}
if (!sBookmarkName.isEmpty())
{
// select the bookmark
lcl_SelectByContentTypeAndName(this, *m_xTreeView,
SwResId(STR_CONTENT_TYPE_BOOKMARK),
sBookmarkName);
return;
}
}
}
// references
if (SwContentAtPos aContentAtPos(IsAttrAtPos::RefMark);
m_pActiveShell->GetContentAtPos(m_pActiveShell->GetCursorDocPos(), aContentAtPos) &&
aContentAtPos.pFndTextAttr &&
!(m_bIsRoot && m_nRootType != ContentTypeId::REFERENCE))
{
if (mTrackContentType[ContentTypeId::REFERENCE])
{
const SwFormatRefMark& rRefMark = aContentAtPos.pFndTextAttr->GetRefMark();
lcl_SelectByContentTypeAndName(this, *m_xTreeView, SwResId(STR_CONTENT_TYPE_REFERENCE),
rRefMark.GetRefName());
}
return;
}
// hyperlinks
// not in ToxContent tdf#148312
if (const SwSection* pSection = m_pActiveShell->GetCurrSection(); !pSection
|| (pSection && pSection->GetType() != SectionType::ToxContent))
{
if (SwContentAtPos aContentAtPos(IsAttrAtPos::InetAttr);
m_pActiveShell->GetContentAtPos(m_pActiveShell->GetCursorDocPos(), aContentAtPos)
&& (!m_bIsRoot || m_nRootType == ContentTypeId::URLFIELD))
{
// Because hyperlink item names do not need to be unique, finding the corresponding
// item in the tree by name may result in incorrect selection. Find the item in the
// tree by comparing the SwTextINetFormat pointer at the document cursor position to
// that stored in the item SwURLFieldContent.
if (mTrackContentType[ContentTypeId::URLFIELD])
lcl_SelectByContentTypeAndAddress(this, *m_xTreeView, ContentTypeId::URLFIELD,
aContentAtPos.pFndTextAttr);
return;
}
}
// fields, comments
if (SwField* pField = m_pActiveShell->GetCurField(); pField &&
!(m_bIsRoot &&
m_nRootType != ContentTypeId::TEXTFIELD &&
m_nRootType != ContentTypeId::POSTIT))
{
ContentTypeId eCntTypeId =
pField->GetTypeId() == SwFieldTypesEnum::Postit ? ContentTypeId::POSTIT :
ContentTypeId::TEXTFIELD;
if (mTrackContentType[eCntTypeId])
lcl_SelectByContentTypeAndAddress(this, *m_xTreeView, eCntTypeId, pField);
return;
}
// table
if (m_pActiveShell->IsCursorInTable() &&
!(m_bIsRoot && m_nRootType != ContentTypeId::TABLE))
{
if (mTrackContentType[ContentTypeId::TABLE] && m_pActiveShell->GetTableFormat())
{
OUString aName = m_pActiveShell->GetTableFormat()->GetName();
lcl_SelectByContentTypeAndName(this, *m_xTreeView, SwResId(STR_CONTENT_TYPE_TABLE),
aName);
return;
}
}
// indexes
if (const SwTOXBase* pTOX = m_pActiveShell->GetCurTOX(); pTOX &&
!(m_bIsRoot && m_nRootType != ContentTypeId::INDEX))
{
if (mTrackContentType[ContentTypeId::INDEX])
lcl_SelectByContentTypeAndName(this, *m_xTreeView, SwResId(STR_CONTENT_TYPE_INDEX),
pTOX->GetTOXName());
return;
}
// section
if (const SwSection* pSection = m_pActiveShell->GetCurrSection(); pSection &&
!(m_bIsRoot && m_nRootType != ContentTypeId::REGION))
{
if (mTrackContentType[ContentTypeId::REGION])
{
lcl_SelectByContentTypeAndName(this, *m_xTreeView, SwResId(STR_CONTENT_TYPE_REGION),
pSection->GetSectionName());
return;
}
else
{
// prevent fall through to outline tracking when section tracking is off and the last
// GotoContent is the current section
if (m_nLastSelType == ContentTypeId::REGION &&
m_xTreeView->get_selected_text() == pSection->GetSectionName())
return;
}
// fall through to outline tracking when section tracking is off and the last GotoContent
// is not the current section
}
}
// outline
if (m_nOutlineTracking == 3)
return;
// find out where the cursor is
const SwOutlineNodes::size_type nActPos = GetWrtShell()->GetOutlinePos(MAXLEVEL);
if (!((m_bIsRoot && m_nRootType != ContentTypeId::OUTLINE) || nActPos == SwOutlineNodes::npos))
{
// assure outline content type is expanded
// this assumes outline content type is first in treeview
std::unique_ptr<weld::TreeIter> xFirstEntry(m_xTreeView->make_iterator());
if (m_xTreeView->get_iter_first(*xFirstEntry))
m_xTreeView->expand_row(*xFirstEntry);
m_xTreeView->all_foreach([this, nActPos](weld::TreeIter& rEntry){
bool bRet = false;
if (lcl_IsContent(rEntry, *m_xTreeView) && weld::fromId<SwContent*>(
m_xTreeView->get_id(rEntry))->GetParent()->GetType() ==
ContentTypeId::OUTLINE)
{
if (weld::fromId<SwOutlineContent*>(
m_xTreeView->get_id(rEntry))->GetOutlinePos() == nActPos)
{
std::unique_ptr<weld::TreeIter> xFirstSelected(
m_xTreeView->make_iterator());
if (!m_xTreeView->get_selected(xFirstSelected.get()))
xFirstSelected.reset();
// only select if not already selected or tree has multiple entries selected
if (m_xTreeView->count_selected_rows() != 1 || !xFirstSelected ||
m_xTreeView->iter_compare(rEntry, *xFirstSelected) != 0)
{
if (m_nOutlineTracking == 2) // focused outline tracking
{
// collapse to children of root node
std::unique_ptr<weld::TreeIter> xChildEntry(
m_xTreeView->make_iterator());
if (m_xTreeView->get_iter_first(*xChildEntry) &&
m_xTreeView->iter_children(*xChildEntry))
{
do
{
if (weld::fromId<SwContent*>(
m_xTreeView->get_id(*xChildEntry))->
GetParent()->GetType() == ContentTypeId::OUTLINE)
m_xTreeView->collapse_row(*xChildEntry);
else
break;
}
while (m_xTreeView->iter_next(*xChildEntry));
}
}
// unselect all entries, make pEntry visible, and select
m_xTreeView->set_cursor(rEntry);
Select();
// tdf#149279 show at least two outline entries before the set cursor entry
std::unique_ptr<weld::TreeIter> xIter(m_xTreeView->make_iterator(&rEntry));
for (int i = 0; i < 2; i++)
{
if (m_xTreeView->get_iter_depth(*xIter) == 0)
break;
if (!m_xTreeView->iter_previous(*xIter))
break;
while (!weld::IsEntryVisible(*m_xTreeView, *xIter))
m_xTreeView->iter_parent(*xIter);
}
// Assure the scroll to row is collapsed after scrolling if it was collapsed
// before. This is required here to make gtkinst scroll_to_row behave like
// salinst.
const bool bRowExpanded = m_xTreeView->get_row_expanded(*xIter);
m_xTreeView->scroll_to_row(*xIter);
if (!bRowExpanded)
m_xTreeView->collapse_row(*xIter);
}
bRet = true;
}
}
else
{
// use of this break assumes outline content type is first in tree
if (lcl_IsContentType(rEntry, *m_xTreeView) &&
weld::fromId<SwContentType*>(
m_xTreeView->get_id(rEntry))->GetType() !=
ContentTypeId::OUTLINE)
bRet = true;
}
return bRet;
});
}
else
{
// clear treeview selections
if (m_xTreeView->count_selected_rows() > 0)
{
m_xTreeView->unselect_all();
m_xTreeView->set_cursor(-1);
Select();
}
}
}
void SwContentTree::SelectOutlinesWithSelection()
{
SwCursor* pFirstCursor = m_pActiveShell->GetCursor();
SwCursor* pCursor = pFirstCursor;
std::vector<SwOutlineNodes::size_type> aOutlinePositions;
do
{
if (pCursor)
{
if (pCursor->HasMark())
{
aOutlinePositions.push_back(m_pActiveShell->GetOutlinePos(UCHAR_MAX, pCursor));
}
pCursor = pCursor->GetNext();
}
} while (pCursor && pCursor != pFirstCursor);
if (aOutlinePositions.empty())
return;
// remove duplicates before selecting
aOutlinePositions.erase(std::unique(aOutlinePositions.begin(), aOutlinePositions.end()),
aOutlinePositions.end());
m_xTreeView->unselect_all();
for (auto nOutlinePosition : aOutlinePositions)
{
m_xTreeView->all_foreach([this, nOutlinePosition](const weld::TreeIter& rEntry){
if (lcl_IsContent(rEntry, *m_xTreeView) &&
weld::fromId<SwContent*>(
m_xTreeView->get_id(rEntry))->GetParent()->GetType() ==
ContentTypeId::OUTLINE)
{
if (weld::fromId<SwOutlineContent*>(
m_xTreeView->get_id(rEntry))->GetOutlinePos() ==
nOutlinePosition)
{
std::unique_ptr<weld::TreeIter> xParent =
m_xTreeView->make_iterator(&rEntry);
if (m_xTreeView->iter_parent(*xParent) &&
!m_xTreeView->get_row_expanded(*xParent))
m_xTreeView->expand_row(*xParent);
m_xTreeView->select(rEntry);
return true;
}
}
return false;
});
}
Select();
}
void SwContentTree::MoveOutline(SwOutlineNodes::size_type nTargetPos)
{
MakeAllOutlineContentTemporarilyVisible a(GetWrtShell()->GetDoc());
SwWrtShell *const pShell = GetWrtShell();
pShell->StartAllAction();
pShell->StartUndo(SwUndoId::OUTLINE_UD);
SwOutlineNodes::size_type nPrevSourcePos = SwOutlineNodes::npos;
SwOutlineNodes::size_type nPrevTargetPosOrOffset = SwOutlineNodes::npos;
bool bFirstMove = true;
for (const auto& source : m_aDndOutlinesSelected)
{
SwOutlineNodes::size_type nSourcePos = weld::fromId<SwOutlineContent*>(m_xTreeView->get_id(*source))->GetOutlinePos();
// Done on the first selection move
if (bFirstMove) // only do once
{
if (nTargetPos == SwOutlineNodes::npos || nSourcePos > nTargetPos)
{
// Up moves
// The first up move sets the up move amount for the remaining selected outlines to be moved
if (nTargetPos != SwOutlineNodes::npos)
nPrevTargetPosOrOffset = nSourcePos - nTargetPos;
else
nPrevTargetPosOrOffset = nSourcePos + 1;
}
else if (nSourcePos < nTargetPos)
{
// Down moves
// The first down move sets the source and target positions for the remaining selected outlines to be moved
nPrevSourcePos = nSourcePos;
nPrevTargetPosOrOffset = nTargetPos;
}
bFirstMove = false;
}
else
{
if (nTargetPos == SwOutlineNodes::npos || nSourcePos > nTargetPos)
{
// Move up
nTargetPos = nSourcePos - nPrevTargetPosOrOffset;
}
else if (nSourcePos < nTargetPos)
{
// Move down
nSourcePos = nPrevSourcePos;
nTargetPos = nPrevTargetPosOrOffset;
}
}
GetParentWindow()->MoveOutline(nSourcePos, nTargetPos);
}
pShell->EndUndo();
pShell->EndAllAction();
m_aActiveContentArr[ContentTypeId::OUTLINE]->Invalidate();
Display(true);
m_aDndOutlinesSelected.clear();
}
// Update immediately
IMPL_LINK_NOARG(SwContentTree, FocusInHdl, weld::Widget&, void)
{
SwView* pActView = GetParentWindow()->GetCreateView();
if(pActView)
{
SwWrtShell* pActShell = pActView->GetWrtShellPtr();
if (State::CONSTANT == m_eState && !lcl_FindShell(m_pActiveShell))
{
SetActiveShell(pActShell);
}
if (State::ACTIVE == m_eState && pActShell != GetWrtShell())
SetActiveShell(pActShell);
// Only call HasContentChanged() if the document has changed since last called
else if ((State::ACTIVE == m_eState || (State::CONSTANT == m_eState && pActShell == GetWrtShell())) &&
m_bDocHasChanged)
{
if (HasContentChanged())
Display(true);
m_bDocHasChanged = false;
}
}
else if (State::ACTIVE == m_eState)
clear();
}
IMPL_LINK(SwContentTree, KeyInputHdl, const KeyEvent&, rEvent, bool)
{
bool bConsumed = true;
const vcl::KeyCode aCode = rEvent.GetKeyCode();
if (aCode.GetCode() == KEY_MULTIPLY && aCode.IsMod1())
{
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
if (m_xTreeView->get_selected(xEntry.get()))
ExpandOrCollapseAll(*m_xTreeView, *xEntry);
}
else if (aCode.GetCode() == KEY_RETURN)
{
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
if (m_xTreeView->get_selected(xEntry.get()))
{
switch(aCode.GetModifier())
{
case KEY_MOD2:
// Switch boxes
GetParentWindow()->ToggleTree();
break;
case KEY_MOD1:
// Switch RootMode
ToggleToRoot();
break;
case 0:
if (lcl_IsContentType(*xEntry, *m_xTreeView))
{
m_xTreeView->get_row_expanded(*xEntry) ? m_xTreeView->collapse_row(*xEntry)
: m_xTreeView->expand_row(*xEntry);
}
else
ContentDoubleClickHdl(*m_xTreeView);
break;
case KEY_SHIFT:
m_bSelectTo = true;
ContentDoubleClickHdl(*m_xTreeView);
break;
}
}
}
else if(aCode.GetCode() == KEY_DELETE && 0 == aCode.GetModifier())
{
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
if (m_xTreeView->get_selected(xEntry.get()) && lcl_IsContent(*xEntry, *m_xTreeView))
{
assert(dynamic_cast<SwContent*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(*xEntry))));
if (weld::fromId<SwContent*>(m_xTreeView->get_id(*xEntry))->GetParent()->IsDeletable() &&
!m_pActiveShell->GetView().GetDocShell()->IsReadOnly())
{
EditEntry(*xEntry, EditEntryMode::DELETE);
}
}
}
//Make KEY_SPACE has same function as DoubleClick, and realize
//multi-selection.
else if (aCode.GetCode() == KEY_SPACE && 0 == aCode.GetModifier())
{
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
if (m_xTreeView->get_cursor(xEntry.get()))
{
if (State::HIDDEN != m_eState)
{
if (State::CONSTANT == m_eState)
{
m_pActiveShell->GetView().GetViewFrame().GetWindow().ToTop();
}
SwContent* pCnt = dynamic_cast<SwContent*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(*xEntry)));
if (pCnt && pCnt->GetParent()->GetType() == ContentTypeId::DRAWOBJECT)
{
SdrView* pDrawView = m_pActiveShell->GetDrawView();
if (pDrawView)
{
pDrawView->SdrEndTextEdit();
SwDrawModel* pDrawModel = m_pActiveShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
SdrPage* pPage = pDrawModel->GetPage(0);
bool hasObjectMarked = false;
if (SdrObject* pObject = GetDrawingObjectsByContent(pCnt))
{
SdrPageView* pPV = pDrawView->GetSdrPageView/*GetPageViewPvNum*/(/*0*/);
if( pPV )
{
bool bUnMark = pDrawView->IsObjMarked(pObject);
pDrawView->MarkObj( pObject, pPV, bUnMark);
}
}
for (const rtl::Reference<SdrObject>& pTemp : *pPage)
{
bool bMark = pDrawView->IsObjMarked(pTemp.get());
switch( pTemp->GetObjIdentifier() )
{
case SdrObjKind::Group:
case SdrObjKind::Text:
case SdrObjKind::Line:
case SdrObjKind::Rectangle:
case SdrObjKind::CircleOrEllipse:
case SdrObjKind::CircleSection:
case SdrObjKind::CircleArc:
case SdrObjKind::CircleCut:
case SdrObjKind::Polygon:
case SdrObjKind::PolyLine:
case SdrObjKind::PathLine:
case SdrObjKind::PathFill:
case SdrObjKind::FreehandLine:
case SdrObjKind::FreehandFill:
case SdrObjKind::PathPoly:
case SdrObjKind::PathPolyLine:
case SdrObjKind::Caption:
case SdrObjKind::CustomShape:
if( bMark )
hasObjectMarked = true;
break;
default:
if ( bMark )
{
SdrPageView* pPV = pDrawView->GetSdrPageView/*GetPageViewPvNum*/(/*0*/);
if (pPV)
{
pDrawView->MarkObj(pTemp.get(), pPV, true);
}
}
}
//mod end
}
if ( !hasObjectMarked )
{
SwEditWin& rEditWindow = m_pActiveShell->GetView().GetEditWin();
vcl::KeyCode tempKeycode( KEY_ESCAPE );
KeyEvent rKEvt( 0 , tempKeycode );
static_cast<vcl::Window*>(&rEditWindow)->KeyInput( rKEvt );
}
}
}
m_bViewHasChanged = true;
}
}
}
else
{
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
if (m_xTreeView->get_cursor(xEntry.get()))
{
SwContent* pCnt = dynamic_cast<SwContent*>(weld::fromId<SwTypeNumber*>(m_xTreeView->get_id(*xEntry)));
if (pCnt && pCnt->GetParent()->GetType() == ContentTypeId::OUTLINE)
{
if (m_bIsRoot && aCode.GetCode() == KEY_LEFT && aCode.GetModifier() == 0)
{
m_xTreeView->unselect_all();
bConsumed = false;
}
else if (aCode.IsMod1())
{
if (aCode.GetCode() == KEY_LEFT)
ExecCommand(u"promote", !aCode.IsShift());
else if (aCode.GetCode() == KEY_RIGHT)
ExecCommand(u"demote", !aCode.IsShift());
else if (aCode.GetCode() == KEY_UP)
ExecCommand(u"chapterup", !aCode.IsShift());
else if (aCode.GetCode() == KEY_DOWN)
ExecCommand(u"chapterdown", !aCode.IsShift());
else if (aCode.GetCode() == KEY_C)
CopyOutlineSelections();
else
bConsumed = false;
}
else
bConsumed = false;
}
else
bConsumed = false;
}
else
bConsumed = false;
}
return bConsumed;
}
IMPL_LINK(SwContentTree, QueryTooltipHdl, const weld::TreeIter&, rEntry, OUString)
{
ContentTypeId nType;
bool bContent = false;
void* pUserData = weld::fromId<void*>(m_xTreeView->get_id(rEntry));
if (lcl_IsContentType(rEntry, *m_xTreeView))
{
assert(dynamic_cast<SwContentType*>(static_cast<SwTypeNumber*>(pUserData)));
nType = static_cast<SwContentType*>(pUserData)->GetType();
}
else
{
assert(dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pUserData)));
nType = static_cast<SwContent*>(pUserData)->GetParent()->GetType();
bContent = true;
}
OUString sEntry;
if(bContent)
{
switch( nType )
{
case ContentTypeId::URLFIELD:
assert(dynamic_cast<SwURLFieldContent*>(static_cast<SwTypeNumber*>(pUserData)));
sEntry = static_cast<SwURLFieldContent*>(pUserData)->GetURL();
break;
case ContentTypeId::POSTIT:
assert(dynamic_cast<SwPostItContent*>(static_cast<SwTypeNumber*>(pUserData)));
sEntry = static_cast<SwPostItContent*>(pUserData)->GetName();
break;
case ContentTypeId::OUTLINE:
assert(dynamic_cast<SwOutlineContent*>(static_cast<SwTypeNumber*>(pUserData)));
sEntry = static_cast<SwOutlineContent*>(pUserData)->GetName();
break;
case ContentTypeId::GRAPHIC:
assert(dynamic_cast<SwGraphicContent*>(static_cast<SwTypeNumber*>(pUserData)));
sEntry = static_cast<SwGraphicContent*>(pUserData)->GetLink();
break;
case ContentTypeId::REGION:
{
assert(dynamic_cast<SwRegionContent*>(static_cast<SwTypeNumber*>(pUserData)));
sEntry = static_cast<SwRegionContent*>(pUserData)->GetName();
const SwSectionFormats& rFormats = GetWrtShell()->GetDoc()->GetSections();
for (SwSectionFormats::size_type n = rFormats.size(); n;)
{
const SwNodeIndex* pIdx = nullptr;
const SwSectionFormat* pFormat = rFormats[--n];
const SwSection* pSect;
if (nullptr != (pSect = pFormat->GetSection()) &&
pSect->GetSectionName() == sEntry &&
nullptr != (pIdx = pFormat->GetContent().GetContentIdx()) &&
pIdx->GetNode().GetNodes().IsDocNodes())
{
SwDocStat aDocStat;
SwPaM aPaM(pIdx->GetNode(), *pIdx->GetNode().EndOfSectionNode());
SwDoc::CountWords(aPaM, aDocStat);
sEntry = SwResId(STR_REGION_DEFNAME) + ": " + sEntry + "\n" +
SwResId(FLD_STAT_WORD) + ": " + OUString::number(aDocStat.nWord) + "\n" +
SwResId(FLD_STAT_CHAR) + ": " + OUString::number(aDocStat.nChar);
break;
}
}
}
break;
case ContentTypeId::FOOTNOTE:
case ContentTypeId::ENDNOTE:
{
assert(dynamic_cast<SwTextFootnoteContent*>(static_cast<SwTypeNumber*>(pUserData)));
const SwTextFootnote* pFootnote =
static_cast<const SwTextFootnoteContent*>(pUserData)->GetTextFootnote();
sEntry = pFootnote->GetFootnote().IsEndNote() ? SwResId(STR_CONTENT_ENDNOTE) :
SwResId(STR_CONTENT_FOOTNOTE);
}
break;
default: break;
}
if(static_cast<SwContent*>(pUserData)->IsInvisible())
{
if(!sEntry.isEmpty())
sEntry += ", ";
sEntry += m_sInvisible;
}
}
else
{
size_t nMemberCount = static_cast<SwContentType*>(pUserData)->GetMemberCount();
sEntry = OUString::number(nMemberCount) + " " +
(nMemberCount == 1
? static_cast<SwContentType*>(pUserData)->GetSingleName()
: static_cast<SwContentType*>(pUserData)->GetName());
}
return sEntry;
}
void SwContentTree::ExecuteContextMenuAction(const OUString& rSelectedPopupEntry)
{
if (rSelectedPopupEntry == "copy")
{
CopyOutlineSelections();
return;
}
if (rSelectedPopupEntry == "collapseallcategories")
{
std::unique_ptr<weld::TreeIter> xEntry = m_xTreeView->make_iterator();
bool bEntry = m_xTreeView->get_iter_first(*xEntry);
while (bEntry)
{
m_xTreeView->collapse_row(*xEntry);
bEntry = m_xTreeView->iter_next_sibling(*xEntry);
}
return;
}
{
std::map<OUString, ContentTypeId> mPopupEntryToContentTypeId
{
{"tabletracking", ContentTypeId::TABLE},
{"frametracking", ContentTypeId::FRAME},
{"imagetracking", ContentTypeId::GRAPHIC},
{"oleobjecttracking", ContentTypeId::OLE},
{"bookmarktracking", ContentTypeId::BOOKMARK},
{"sectiontracking", ContentTypeId::REGION},
{"hyperlinktracking", ContentTypeId::URLFIELD},
{"referencetracking", ContentTypeId::REFERENCE},
{"indextracking", ContentTypeId::INDEX},
{"commenttracking", ContentTypeId::POSTIT},
{"drawingobjecttracking", ContentTypeId::DRAWOBJECT},
{"fieldtracking", ContentTypeId::TEXTFIELD},
{"footnotetracking", ContentTypeId::FOOTNOTE},
{"endnotetracking", ContentTypeId::ENDNOTE}
};
if (mPopupEntryToContentTypeId.count(rSelectedPopupEntry))
{
ContentTypeId eCntTypeId = mPopupEntryToContentTypeId[rSelectedPopupEntry];
SetContentTypeTracking(eCntTypeId, !mTrackContentType[eCntTypeId]);
return;
}
}
std::unique_ptr<weld::TreeIter> xFirst(m_xTreeView->make_iterator());
if (!m_xTreeView->get_selected(xFirst.get()))
return; // this shouldn't happen, but better to be safe than ...
if (rSelectedPopupEntry == "protectsection" || rSelectedPopupEntry == "hidesection")
{
SwRegionContent* pCnt = weld::fromId<SwRegionContent*>(m_xTreeView->get_id(*xFirst));
assert(dynamic_cast<SwRegionContent*>(static_cast<SwTypeNumber*>(pCnt)));
const SwSectionFormat* pSectionFormat = pCnt->GetSectionFormat();
SwSection* pSection = pSectionFormat->GetSection();
SwSectionData aSectionData(*pSection);
if (rSelectedPopupEntry == "protectsection")
aSectionData.SetProtectFlag(!pSection->IsProtect());
else
aSectionData.SetHidden(!pSection->IsHidden());
m_pActiveShell->UpdateSection(m_pActiveShell->GetSectionFormatPos(*pSectionFormat),
aSectionData);
}
else if (rSelectedPopupEntry == "sort")
{
SwContentType* pCntType;
const OUString& rId(m_xTreeView->get_id(*xFirst));
if (lcl_IsContentType(*xFirst, *m_xTreeView))
pCntType = weld::fromId<SwContentType*>(rId);
else
pCntType = const_cast<SwContentType*>(weld::fromId<SwContent*>(rId)->GetParent());
// toggle and persist alphabetical sort setting
const int nShift = static_cast<int>(pCntType->GetType());
assert(nShift > -1);
const sal_Int32 nMask = 1 << nShift;
const sal_Int32 nBlock = m_pConfig->GetSortAlphabeticallyBlock();
pCntType->SetAlphabeticSort(~nBlock & nMask);
m_pConfig->SetSortAlphabeticallyBlock(nBlock ^ nMask);
pCntType->FillMemberList();
Display(true);
return;
}
else if (rSelectedPopupEntry == "deletechapter" ||
rSelectedPopupEntry == "deletetable" ||
rSelectedPopupEntry == "deleteframe" ||
rSelectedPopupEntry == "deleteimage" ||
rSelectedPopupEntry == "deleteoleobject" ||
rSelectedPopupEntry == "deletebookmark" ||
rSelectedPopupEntry == "deleteregion" ||
rSelectedPopupEntry == "deletehyperlink" ||
rSelectedPopupEntry == "deletereference" ||
rSelectedPopupEntry == "deleteindex" ||
rSelectedPopupEntry == "deletecomment" ||
rSelectedPopupEntry == "deletedrawingobject" ||
rSelectedPopupEntry == "deletefield")
{
EditEntry(*xFirst, EditEntryMode::DELETE);
return;
}
auto nSelectedPopupEntry = rSelectedPopupEntry.toUInt32();
switch (nSelectedPopupEntry)
{
case TOGGLE_OUTLINE_CONTENT_VISIBILITY:
case HIDE_OUTLINE_CONTENT_VISIBILITY:
case SHOW_OUTLINE_CONTENT_VISIBILITY:
{
m_pActiveShell->EnterStdMode();
m_bIgnoreDocChange = true;
SwOutlineContent* pCntFirst = weld::fromId<SwOutlineContent*>(m_xTreeView->get_id(*xFirst));
// toggle the outline node outline content visible attribute
if (nSelectedPopupEntry == TOGGLE_OUTLINE_CONTENT_VISIBILITY)
{
SwNode* pNode = m_pActiveShell->GetDoc()->GetNodes().GetOutLineNds()[pCntFirst->GetOutlinePos()];
pNode->GetTextNode()->SetAttrOutlineContentVisible(
!m_pActiveShell->GetAttrOutlineContentVisible(pCntFirst->GetOutlinePos()));
}
else
{
// with subs
SwOutlineNodes::size_type nPos = pCntFirst->GetOutlinePos();
if (lcl_IsContentType(*xFirst, *m_xTreeView)) // Headings root entry
nPos = SwOutlineNodes::npos;
SwOutlineNodes::size_type nOutlineNodesCount = m_pActiveShell->getIDocumentOutlineNodesAccess()->getOutlineNodesCount();
int nLevel = -1;
if (nPos != SwOutlineNodes::npos) // not root
nLevel = m_pActiveShell->getIDocumentOutlineNodesAccess()->getOutlineLevel(nPos);
else
nPos = 0;
bool bShow(nSelectedPopupEntry == SHOW_OUTLINE_CONTENT_VISIBILITY);
do
{
if (m_pActiveShell->IsOutlineContentVisible(nPos) != bShow)
m_pActiveShell->GetDoc()->GetNodes().GetOutLineNds()[nPos]->GetTextNode()->SetAttrOutlineContentVisible(bShow);
} while (++nPos < nOutlineNodesCount
&& (nLevel == -1 || m_pActiveShell->getIDocumentOutlineNodesAccess()->getOutlineLevel(nPos) > nLevel));
}
m_pActiveShell->InvalidateOutlineContentVisibility();
// show in the document what was toggled
if (lcl_IsContentType(*xFirst, *m_xTreeView)) // Headings root entry
m_pActiveShell->GotoPage(1, true);
else
m_pActiveShell->GotoOutline(pCntFirst->GetOutlinePos());
grab_focus();
m_bIgnoreDocChange = false;
m_pActiveShell->SetModified();
m_pActiveShell->GetDoc()->GetDocShell()->Broadcast(SfxHint(SfxHintId::DocChanged));
}
break;
case 11:
case 12:
case 13:
nSelectedPopupEntry -= 10;
if(m_nOutlineTracking != nSelectedPopupEntry)
SetOutlineTracking(static_cast<sal_uInt8>(nSelectedPopupEntry));
break;
//Outlinelevel
case 101:
case 102:
case 103:
case 104:
case 105:
case 106:
case 107:
case 108:
case 109:
case 110:
nSelectedPopupEntry -= 100;
if(m_nOutlineLevel != nSelectedPopupEntry )
SetOutlineLevel(static_cast<sal_Int8>(nSelectedPopupEntry));
break;
case 201:
case 202:
case 203:
GetParentWindow()->SetRegionDropMode(static_cast<RegionMode>(nSelectedPopupEntry - 201));
break;
case 401:
case 402:
EditEntry(*xFirst, nSelectedPopupEntry == 401 ? EditEntryMode::RMV_IDX : EditEntryMode::UPD_IDX);
break;
// Edit entry
case 403:
EditEntry(*xFirst, EditEntryMode::EDIT);
break;
case 404:
EditEntry(*xFirst, EditEntryMode::UNPROTECT_TABLE);
break;
case 405 :
{
const SwTOXBase* pBase = weld::fromId<SwTOXBaseContent*>(m_xTreeView->get_id(*xFirst))
->GetTOXBase();
m_pActiveShell->SetTOXBaseReadonly(*pBase, !SwEditShell::IsTOXBaseReadonly(*pBase));
}
break;
case 502 :
EditEntry(*xFirst, EditEntryMode::RENAME);
break;
case 600:
m_pActiveShell->GetView().GetPostItMgr()->Show();
break;
case 601:
m_pActiveShell->GetView().GetPostItMgr()->Hide();
break;
case 602:
{
m_pActiveShell->GetView().GetPostItMgr()->SetActiveSidebarWin(nullptr);
m_pActiveShell->GetView().GetPostItMgr()->Delete();
break;
}
case 700:
{
m_pActiveShell->GetView().GetViewFrame().GetDispatcher()->Execute(FN_OUTLINE_TO_CLIPBOARD);
break;
}
case 800:
ExpandOrCollapseAll(*m_xTreeView, *xFirst);
break;
case 801:
ExecCommand(u"chapterup", true);
break;
case 802:
ExecCommand(u"chapterdown", true);
break;
case 803:
ExecCommand(u"promote", true);
break;
case 804:
ExecCommand(u"demote", true);
break;
case 805: // select document content
{
m_pActiveShell->KillPams();
m_pActiveShell->ClearMark();
m_pActiveShell->EnterAddMode();
SwContent* pCnt = weld::fromId<SwContent*>(m_xTreeView->get_id(*xFirst));
const ContentTypeId eTypeId = pCnt->GetParent()->GetType();
if (eTypeId == ContentTypeId::OUTLINE)
{
SwOutlineNodes::size_type nActPos = weld::fromId<SwOutlineContent*>(
m_xTreeView->get_id(*xFirst))->GetOutlinePos();
m_pActiveShell->GotoOutline(nActPos);
m_xTreeView->selected_foreach([this](weld::TreeIter& rEntry){
SwOutlineNodes::size_type nPos = weld::fromId<SwOutlineContent*>(
m_xTreeView->get_id(rEntry))->GetOutlinePos();
m_pActiveShell->SttSelect();
// select children if not expanded and don't kill PaMs
m_pActiveShell->MakeOutlineSel(nPos, nPos,
!m_xTreeView->get_row_expanded(rEntry), false);
m_pActiveShell->EndSelect();
return false;
});
}
else if (eTypeId == ContentTypeId::TABLE)
{
m_pActiveShell->GotoTable(pCnt->GetName());
m_pActiveShell->GetView().GetViewFrame().GetDispatcher()->Execute(FN_TABLE_SELECT_ALL);
}
else if (eTypeId == ContentTypeId::REGION)
{
m_pActiveShell->EnterStdMode();
m_pActiveShell->GotoRegion(pCnt->GetName());
GotoCurrRegionAndSkip(m_pActiveShell->GetCurrentShellCursor(), fnRegionEnd, m_pActiveShell->IsReadOnlyAvailable());
m_pActiveShell->SttSelect();
GotoCurrRegionAndSkip(m_pActiveShell->GetCurrentShellCursor(), fnRegionStart, m_pActiveShell->IsReadOnlyAvailable());
m_pActiveShell->EndSelect();
m_pActiveShell->UpdateCursor();
}
m_pActiveShell->LeaveAddMode();
}
break;
case 900:
{
SwContent* pCnt = weld::fromId<SwContent*>(m_xTreeView->get_id(*xFirst));
GotoContent(pCnt);
}
break;
//Display
default:
if(nSelectedPopupEntry > 300 && nSelectedPopupEntry < 400)
{
nSelectedPopupEntry -= 300;
SwView *pView = SwModule::GetFirstView();
while (pView)
{
nSelectedPopupEntry --;
if(nSelectedPopupEntry == 0)
{
SetConstantShell(&pView->GetWrtShell());
break;
}
pView = SwModule::GetNextView(pView);
}
if(nSelectedPopupEntry)
{
m_bViewHasChanged = nSelectedPopupEntry == 1;
m_eState = (nSelectedPopupEntry == 1) ? State::ACTIVE : State::HIDDEN;
Display(nSelectedPopupEntry == 1);
}
GetParentWindow()->UpdateListBox();
}
}
}
void SwContentTree::DeleteOutlineSelections()
{
const SwOutlineNodes& rOutlineNodes = m_pActiveShell->GetNodes().GetOutLineNds();
auto nChapters(0);
m_pActiveShell->StartAction();
m_pActiveShell->EnterAddMode();
m_xTreeView->selected_foreach([this, &rOutlineNodes, &nChapters](weld::TreeIter& rEntry){
++nChapters;
if (m_xTreeView->iter_has_child(rEntry) &&
!m_xTreeView->get_row_expanded(rEntry)) // only count children if not expanded
{
nChapters += m_xTreeView->iter_n_children(rEntry);
}
SwOutlineNodes::size_type nActPos = weld::fromId<SwOutlineContent*>(m_xTreeView->get_id(rEntry))->GetOutlinePos();
if (m_pActiveShell->GetViewOptions()->IsShowOutlineContentVisibilityButton())
{
// make folded content visible so it can be selected
if (!m_pActiveShell->IsOutlineContentVisible(nActPos))
m_pActiveShell->MakeOutlineContentVisible(nActPos);
if (!m_xTreeView->get_row_expanded(rEntry))
{
// include children
SwNode* pNode = rOutlineNodes[nActPos];
const int nLevel = pNode->GetTextNode()->GetAttrOutlineLevel() - 1;
for (auto nPos = nActPos + 1; nPos < rOutlineNodes.size(); ++nPos)
{
pNode = rOutlineNodes[nPos];
const int nNextLevel = pNode->GetTextNode()->GetAttrOutlineLevel() - 1;
if (nNextLevel <= nLevel)
break;
if (!m_pActiveShell->IsOutlineContentVisible(nNextLevel))
m_pActiveShell->MakeOutlineContentVisible(nNextLevel);
}
}
}
m_pActiveShell->SttSelect();
m_pActiveShell->MakeOutlineSel(nActPos, nActPos, !m_xTreeView->get_row_expanded(rEntry), false); // select children if not expanded
// The outline selection may already be to the start of the following outline paragraph
// as happens when a table is the last content of the to be deleted outline. In this case
// do not extend the to be deleted selection right or the first character of the following
// outline paragraph will be removed. Also check if no selection was made which indicates
// an empty paragraph and selection right is needed.
if (!m_pActiveShell->IsSttPara() || !m_pActiveShell->HasSelection())
m_pActiveShell->Right(SwCursorSkipMode::Chars, true, 1, false);
m_pActiveShell->EndSelect();
return false;
});
m_pActiveShell->LeaveAddMode();
SwRewriter aRewriter;
aRewriter.AddRule(UndoArg1, SwResId(STR_CHAPTERS, nChapters));
m_pActiveShell->StartUndo(SwUndoId::DELETE, &aRewriter);
m_pActiveShell->Delete(false);
m_pActiveShell->EndUndo();
m_pActiveShell->EndAction();
}
void SwContentTree::SetOutlineLevel(sal_uInt8 nSet)
{
if (nSet == m_nOutlineLevel)
return;
m_nOutlineLevel = nSet;
m_pConfig->SetOutlineLevel( m_nOutlineLevel );
std::unique_ptr<SwContentType>& rpContentT = (State::ACTIVE == m_eState)
? m_aActiveContentArr[ContentTypeId::OUTLINE]
: m_aHiddenContentArr[ContentTypeId::OUTLINE];
if(rpContentT)
{
rpContentT->SetOutlineLevel(m_nOutlineLevel);
rpContentT->FillMemberList();
}
Display(State::ACTIVE == m_eState);
}
void SwContentTree::SetOutlineTracking(sal_uInt8 nSet)
{
m_nOutlineTracking = nSet;
m_pConfig->SetOutlineTracking(m_nOutlineTracking);
}
void SwContentTree::SetContentTypeTracking(ContentTypeId eCntTypeId, bool bSet)
{
mTrackContentType[eCntTypeId] = bSet;
m_pConfig->SetContentTypeTrack(eCntTypeId, bSet);
}
// Mode Change: Show dropped Doc
void SwContentTree::ShowHiddenShell()
{
if(m_pHiddenShell)
{
m_eState = State::HIDDEN;
Display(false);
}
}
// Mode Change: Show active view
void SwContentTree::ShowActualView()
{
m_eState = State::ACTIVE;
Display(true);
GetParentWindow()->UpdateListBox();
}
IMPL_LINK_NOARG(SwContentTree, SelectHdl, weld::TreeView&, void)
{
if (m_pConfig->IsNavigateOnSelect())
{
ContentDoubleClickHdl(*m_xTreeView);
grab_focus();
}
Select();
if (m_bIsRoot)
return;
// Select the content type in the Navigate By control
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
if (!m_xTreeView->get_selected(xEntry.get()))
return;
while (m_xTreeView->get_iter_depth(*xEntry))
m_xTreeView->iter_parent(*xEntry);
m_pDialog->SelectNavigateByContentType(m_xTreeView->get_text(*xEntry));
}
// Here the buttons for moving outlines are en-/disabled.
void SwContentTree::Select()
{
std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
if (!m_xTreeView->get_selected(xEntry.get()))
return;
bool bEnable = false;
std::unique_ptr<weld::TreeIter> xParentEntry(m_xTreeView->make_iterator(xEntry.get()));
bool bParentEntry = m_xTreeView->iter_parent(*xParentEntry);
while (bParentEntry && (!lcl_IsContentType(*xParentEntry, *m_xTreeView)))
bParentEntry = m_xTreeView->iter_parent(*xParentEntry);
if (!m_bIsLastReadOnly)
{
if (!m_xTreeView->get_visible())
bEnable = true;
else if (bParentEntry)
{
if ((m_bIsRoot && m_nRootType == ContentTypeId::OUTLINE) ||
(lcl_IsContent(*xEntry, *m_xTreeView) &&
weld::fromId<SwContentType*>(m_xTreeView->get_id(*xParentEntry))->GetType() == ContentTypeId::OUTLINE))
{
bEnable = true;
}
}
}
SwNavigationPI* pNavi = GetParentWindow();
pNavi->m_xContent6ToolBox->set_item_sensitive("chapterup", bEnable);
pNavi->m_xContent6ToolBox->set_item_sensitive("chapterdown", bEnable);
pNavi->m_xContent6ToolBox->set_item_sensitive("promote", bEnable);
pNavi->m_xContent6ToolBox->set_item_sensitive("demote", bEnable);
}
void SwContentTree::SetRootType(ContentTypeId nType)
{
m_nRootType = nType;
m_bIsRoot = true;
m_pConfig->SetRootType( m_nRootType );
}
OUString SwContentType::RemoveNewline(const OUString& rEntry)
{
if (rEntry.isEmpty())
return rEntry;
OUStringBuffer aEntry(rEntry);
for (sal_Int32 i = 0; i < rEntry.getLength(); ++i)
if(aEntry[i] == 10 || aEntry[i] == 13)
aEntry[i] = 0x20;
return aEntry.makeStringAndClear();
}
void SwContentTree::EditEntry(const weld::TreeIter& rEntry, EditEntryMode nMode)
{
SwContent* pCnt = weld::fromId<SwContent*>(m_xTreeView->get_id(rEntry));
GotoContent(pCnt);
const ContentTypeId nType = pCnt->GetParent()->GetType();
sal_uInt16 nSlot = 0;
if(EditEntryMode::DELETE == nMode)
m_bIgnoreDocChange = true;
uno::Reference< container::XNameAccess > xNameAccess, xSecond, xThird;
switch(nType)
{
case ContentTypeId::OUTLINE :
if(nMode == EditEntryMode::DELETE)
{
DeleteOutlineSelections();
}
break;
case ContentTypeId::TABLE :
if(nMode == EditEntryMode::UNPROTECT_TABLE)
{
m_pActiveShell->GetView().GetDocShell()->
GetDoc()->UnProtectCells( pCnt->GetName());
}
else if(nMode == EditEntryMode::DELETE)
{
m_pActiveShell->StartAction();
OUString sTable = SwResId(STR_TABLE_NAME);
SwRewriter aRewriterTableName;
aRewriterTableName.AddRule(UndoArg1, SwResId(STR_START_QUOTE));
aRewriterTableName.AddRule(UndoArg2, pCnt->GetName());
aRewriterTableName.AddRule(UndoArg3, SwResId(STR_END_QUOTE));
sTable = aRewriterTableName.Apply(sTable);
SwRewriter aRewriter;
aRewriter.AddRule(UndoArg1, sTable);
m_pActiveShell->StartUndo(SwUndoId::DELETE, &aRewriter);
m_pActiveShell->GetView().GetViewFrame().GetDispatcher()->Execute(FN_TABLE_SELECT_ALL);
m_pActiveShell->DeleteRow();
m_pActiveShell->EndUndo();
m_pActiveShell->EndAction();
}
else if(nMode == EditEntryMode::RENAME)
{
uno::Reference< frame::XModel > xModel = m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
uno::Reference< text::XTextTablesSupplier > xTables(xModel, uno::UNO_QUERY);
xNameAccess = xTables->getTextTables();
}
else
nSlot = FN_FORMAT_TABLE_DLG;
break;
case ContentTypeId::GRAPHIC :
if(nMode == EditEntryMode::DELETE)
{
m_pActiveShell->DelRight();
}
else if(nMode == EditEntryMode::RENAME)
{
uno::Reference< frame::XModel > xModel = m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
uno::Reference< text::XTextGraphicObjectsSupplier > xGraphics(xModel, uno::UNO_QUERY);
xNameAccess = xGraphics->getGraphicObjects();
uno::Reference< text::XTextFramesSupplier > xFrames(xModel, uno::UNO_QUERY);
xSecond = xFrames->getTextFrames();
uno::Reference< text::XTextEmbeddedObjectsSupplier > xObjs(xModel, uno::UNO_QUERY);
xThird = xObjs->getEmbeddedObjects();
}
else
nSlot = FN_FORMAT_GRAFIC_DLG;
break;
case ContentTypeId::FRAME :
case ContentTypeId::OLE :
if(nMode == EditEntryMode::DELETE)
{
m_pActiveShell->DelRight();
}
else if(nMode == EditEntryMode::RENAME)
{
uno::Reference< frame::XModel > xModel = m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
uno::Reference< text::XTextFramesSupplier > xFrames(xModel, uno::UNO_QUERY);
uno::Reference< text::XTextEmbeddedObjectsSupplier > xObjs(xModel, uno::UNO_QUERY);
if(ContentTypeId::FRAME == nType)
{
xNameAccess = xFrames->getTextFrames();
xSecond = xObjs->getEmbeddedObjects();
}
else
{
xNameAccess = xObjs->getEmbeddedObjects();
xSecond = xFrames->getTextFrames();
}
uno::Reference< text::XTextGraphicObjectsSupplier > xGraphics(xModel, uno::UNO_QUERY);
xThird = xGraphics->getGraphicObjects();
}
else
nSlot = FN_FORMAT_FRAME_DLG;
break;
case ContentTypeId::BOOKMARK :
if(nMode == EditEntryMode::DELETE)
{
assert(!m_pActiveShell->getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS));
IDocumentMarkAccess* const pMarkAccess = m_pActiveShell->getIDocumentMarkAccess();
pMarkAccess->deleteMark(pMarkAccess->findMark(pCnt->GetName()), false);
}
else if(nMode == EditEntryMode::RENAME)
{
assert(!m_pActiveShell->getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS));
uno::Reference< frame::XModel > xModel = m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
uno::Reference< text::XBookmarksSupplier > xBkms(xModel, uno::UNO_QUERY);
xNameAccess = xBkms->getBookmarks();
}
else
{
// allowed despite PROTECT_BOOKMARKS: the dialog itself enforces it
SfxStringItem const name(FN_EDIT_BOOKMARK, pCnt->GetName());
SfxPoolItem const* args[2] = { &name, nullptr };
m_pActiveShell->GetView().GetViewFrame().
GetDispatcher()->Execute(FN_EDIT_BOOKMARK, SfxCallMode::SYNCHRON, args);
}
break;
case ContentTypeId::REGION :
if (nMode == EditEntryMode::DELETE)
{
assert(dynamic_cast<SwRegionContent*>(static_cast<SwTypeNumber*>(pCnt)));
const SwSectionFormat* pSectionFormat
= static_cast<SwRegionContent*>(pCnt)->GetSectionFormat();
m_pActiveShell->GetDoc()->DelSectionFormat(
const_cast<SwSectionFormat*>(pSectionFormat), false);
}
else if (nMode == EditEntryMode::RENAME)
{
uno::Reference< frame::XModel > xModel = m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
uno::Reference< text::XTextSectionsSupplier > xSects(xModel, uno::UNO_QUERY);
xNameAccess = xSects->getTextSections();
}
else
nSlot = FN_EDIT_REGION;
break;
case ContentTypeId::URLFIELD:
if (nMode == EditEntryMode::DELETE)
nSlot = SID_REMOVE_HYPERLINK;
else
nSlot = SID_EDIT_HYPERLINK;
break;
case ContentTypeId::REFERENCE:
{
if(nMode == EditEntryMode::DELETE)
{
const OUString& rName = pCnt->GetName();
for (const SfxPoolItem* pItem :
m_pActiveShell->GetDoc()->GetAttrPool().GetItemSurrogates(RES_TXTATR_REFMARK))
{
assert(dynamic_cast<const SwFormatRefMark*>(pItem));
const auto pFormatRefMark = static_cast<const SwFormatRefMark*>(pItem);
if (!pFormatRefMark)
continue;
const SwTextRefMark* pTextRef = pFormatRefMark->GetTextRefMark();
if (pTextRef && &pTextRef->GetTextNode().GetNodes() ==
&m_pActiveShell->GetNodes() && rName == pFormatRefMark->GetRefName())
{
m_pActiveShell->GetDoc()->DeleteFormatRefMark(pFormatRefMark);
m_pActiveShell->SwViewShell::UpdateFields();
break;
}
}
}
}
break;
case ContentTypeId::TEXTFIELD:
{
if (nMode == EditEntryMode::DELETE)
{
const SwTextFieldContent* pTextFieldCnt =
static_cast<const SwTextFieldContent*>(pCnt);
const SwTextField* pTextField = pTextFieldCnt->GetFormatField()->GetTextField();
SwTextField::DeleteTextField(*pTextField);
}
else
nSlot = FN_EDIT_FIELD;
}
break;
case ContentTypeId::POSTIT:
{
auto& rView = m_pActiveShell->GetView();
auto pPostItMgr = rView.GetPostItMgr();
pPostItMgr->AssureStdModeAtShell();
pPostItMgr->SetActiveSidebarWin(nullptr);
rView.GetEditWin().GrabFocus();
if(nMode == EditEntryMode::DELETE)
m_pActiveShell->DelRight();
else
nSlot = FN_POSTIT;
}
break;
case ContentTypeId::INDEX:
{
const SwTOXBase* pBase = static_cast<SwTOXBaseContent*>(pCnt)->GetTOXBase();
switch(nMode)
{
case EditEntryMode::EDIT:
if(pBase)
{
SwPtrItem aPtrItem( FN_INSERT_MULTI_TOX, const_cast<SwTOXBase *>(pBase));
m_pActiveShell->GetView().GetViewFrame().
GetDispatcher()->ExecuteList(FN_INSERT_MULTI_TOX,
SfxCallMode::ASYNCHRON, { &aPtrItem });
}
break;
case EditEntryMode::RMV_IDX:
case EditEntryMode::DELETE:
{
if( pBase )
m_pActiveShell->DeleteTOX(*pBase, EditEntryMode::DELETE == nMode);
}
break;
case EditEntryMode::UPD_IDX:
case EditEntryMode::RENAME:
{
Reference< frame::XModel > xModel = m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
Reference< XDocumentIndexesSupplier > xIndexes(xModel, UNO_QUERY);
Reference< XIndexAccess> xIdxAcc(xIndexes->getDocumentIndexes());
Reference< XNameAccess >xLocalNameAccess(xIdxAcc, UNO_QUERY);
if(EditEntryMode::RENAME == nMode)
xNameAccess = xLocalNameAccess;
else if(xLocalNameAccess.is() && xLocalNameAccess->hasByName(pBase->GetTOXName()))
{
Any aIdx = xLocalNameAccess->getByName(pBase->GetTOXName());
Reference< XDocumentIndex> xIdx;
if(aIdx >>= xIdx)
xIdx->update();
}
}
break;
default: break;
}
}
break;
case ContentTypeId::DRAWOBJECT :
if(EditEntryMode::DELETE == nMode)
nSlot = SID_DELETE;
else if(nMode == EditEntryMode::RENAME)
nSlot = FN_NAME_SHAPE;
else if (nMode == EditEntryMode::EDIT)
{
vcl::KeyCode aKeyCode(KEY_RETURN, false, false, false, false);
KeyEvent aKeyEvent(0, aKeyCode);
m_pActiveShell->GetWin()->KeyInput(aKeyEvent);
}
break;
case ContentTypeId::FOOTNOTE:
case ContentTypeId::ENDNOTE:
if (EditEntryMode::EDIT == nMode)
nSlot = FN_FORMAT_FOOTNOTE_DLG;
break;
default: break;
}
if(nSlot)
m_pActiveShell->GetView().GetViewFrame().
GetDispatcher()->Execute(nSlot, SfxCallMode::SYNCHRON);
else if(xNameAccess.is())
{
uno::Any aObj = xNameAccess->getByName(pCnt->GetName());
uno::Reference< uno::XInterface > xTmp;
aObj >>= xTmp;
uno::Reference< container::XNamed > xNamed(xTmp, uno::UNO_QUERY);
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
ScopedVclPtr<AbstractSwRenameXNamedDlg> pDlg(pFact->CreateSwRenameXNamedDlg(m_xTreeView.get(), xNamed, xNameAccess));
if(xSecond.is())
pDlg->SetAlternativeAccess( xSecond, xThird);
OUString sForbiddenChars;
if(ContentTypeId::BOOKMARK == nType)
{
sForbiddenChars = "/\\@:*?\";,.#";
}
else if(ContentTypeId::TABLE == nType)
{
sForbiddenChars = " .<>";
}
pDlg->SetForbiddenChars(sForbiddenChars);
pDlg->Execute();
}
if(EditEntryMode::DELETE == nMode)
{
auto nPos = m_xTreeView->vadjustment_get_value();
m_bViewHasChanged = true;
TimerUpdate(&m_aUpdTimer);
grab_focus();
m_xTreeView->vadjustment_set_value(nPos);
}
}
void SwContentTree::CopyOutlineSelections()
{
m_pActiveShell->LockView(true);
{
MakeAllOutlineContentTemporarilyVisible a(m_pActiveShell->GetDoc());
m_pActiveShell->AssureStdMode();
m_pActiveShell->EnterAddMode();
size_t nCount = m_xTreeView->get_selected_rows().size();
m_xTreeView->selected_foreach([this, &nCount](weld::TreeIter& rEntry){
SwOutlineNodes::size_type nOutlinePos = reinterpret_cast<SwOutlineContent*>(
m_xTreeView->get_id(rEntry).toInt64())->GetOutlinePos();
m_pActiveShell->SttSelect();
m_pActiveShell->MakeOutlineSel(nOutlinePos, nOutlinePos,
!m_xTreeView->get_row_expanded(rEntry), false);
// don't move if this is the last selected outline or the cursor is at start of para
if (--nCount && !m_pActiveShell->IsSttPara())
m_pActiveShell->Right(SwCursorSkipMode::Chars, true, 1, false);
m_pActiveShell->EndSelect();
return false;
});
m_pActiveShell->LeaveAddMode();
m_pActiveShell->GetView().GetViewFrame().GetBindings().Execute(SID_COPY);
}
m_pActiveShell->LockView(false);
}
void SwContentTree::GotoContent(const SwContent* pCnt)
{
if (pCnt->GetParent()->GetType() == ContentTypeId::OUTLINE)
{
// Maybe the outline node doesn't have a layout frame to go to.
const SwOutlineNodes::size_type nPos =
static_cast<const SwOutlineContent*>(pCnt)->GetOutlinePos();
const SwNodes& rNds = m_pActiveShell->GetDoc()->GetNodes();
SwTextNode* pTextNd = rNds.GetOutLineNds()[nPos]->GetTextNode();
if (!pTextNd->getLayoutFrame(m_pActiveShell->GetLayout()))
return;
}
if (m_bSelectTo)
{
if (m_pActiveShell->IsCursorInTable() ||
(m_pActiveShell->GetCursor()->GetPoint()->nNode.GetIndex() <=
m_pActiveShell->GetDoc()->GetNodes().GetEndOfExtras().GetIndex()))
{
m_bSelectTo = false;
m_pActiveShell->GetView().GetEditWin().GrabFocus();
return;
}
}
m_nLastGotoContentWasOutlinePos = SwOutlineNodes::npos;
m_sSelectedItem = "";
m_pActiveShell->AssureStdMode();
std::optional<std::unique_ptr<SwPosition>> oPosition;
if (m_bSelectTo)
oPosition.emplace(new SwPosition(m_pActiveShell->GetCursor()->GetPoint()->nNode,
m_pActiveShell->GetCursor()->GetPoint()->nContent));
switch(m_nLastSelType = pCnt->GetParent()->GetType())
{
case ContentTypeId::TEXTFIELD:
{
m_pActiveShell->GotoFormatField(
*static_cast<const SwTextFieldContent*>(pCnt)->GetFormatField());
}
break;
case ContentTypeId::OUTLINE :
{
const SwOutlineNodes::size_type nPos =
static_cast<const SwOutlineContent*>(pCnt)->GetOutlinePos();
m_pActiveShell->GotoOutline(nPos);
m_nLastGotoContentWasOutlinePos = nPos;
}
break;
case ContentTypeId::TABLE :
{
m_pActiveShell->GotoTable(pCnt->GetName());
}
break;
case ContentTypeId::FRAME :
case ContentTypeId::GRAPHIC :
case ContentTypeId::OLE :
{
m_pActiveShell->GotoFly(pCnt->GetName());
}
break;
case ContentTypeId::BOOKMARK:
{
m_pActiveShell->StartAction();
m_pActiveShell->GotoMark(pCnt->GetName());
m_pActiveShell->EndAction();
m_sSelectedItem = pCnt->GetName();
// If the hidden title of SwNavigatorPanel was emptied via UNO XPanel interface,
// store the name of the selected bookmark there. This allows to query the
// selected bookmark using UNO e.g. in add-ons, i.e. to disambiguate when
// multiple bookmarks are there on the selected text range.
// Note: this is a workaround because getDialog() of XPanel is not implemented
// for SwNavigatorPanel.
uno::Reference< frame::XModel > xModel = m_pActiveShell->GetView().GetDocShell()->GetBaseModel();
Reference<frame::XController2> xController( xModel->getCurrentController(), uno::UNO_QUERY);
if ( !xController.is() )
break;
Reference<ui::XSidebarProvider> xSidebarProvider = xController->getSidebar();
if ( !xSidebarProvider.is() )
break;
Reference<ui::XDecks> xDecks = xSidebarProvider->getDecks();
if ( !xDecks.is() )
break;
if (!xDecks->hasByName("NavigatorDeck"))
break;
Reference<ui::XDeck> xDeck ( xDecks->getByName("NavigatorDeck"), uno::UNO_QUERY);
if ( !xDeck.is() )
break;
Reference<ui::XPanels> xPanels = xDeck->getPanels();
if ( !xPanels.is() )
break;
if (xPanels->hasByName("SwNavigatorPanel"))
{
Reference<ui::XPanel> xPanel ( xPanels->getByName("SwNavigatorPanel"), uno::UNO_QUERY);
if ( !xPanel.is() || !xPanel->getTitle().isEmpty() )
break;
xPanel->setTitle( pCnt->GetName() );
}
}
break;
case ContentTypeId::REGION :
{
m_pActiveShell->GotoRegion(pCnt->GetName());
}
break;
case ContentTypeId::URLFIELD:
{
if(m_pActiveShell->GotoINetAttr(
*static_cast<const SwURLFieldContent*>(pCnt)->GetINetAttr() ))
{
m_pActiveShell->Right( SwCursorSkipMode::Chars, true, 1, false);
m_pActiveShell->SwCursorShell::SelectTextAttr( RES_TXTATR_INETFMT, true );
}
}
break;
case ContentTypeId::REFERENCE:
{
m_pActiveShell->GotoRefMark(pCnt->GetName());
}
break;
case ContentTypeId::INDEX:
{
const OUString& sName(pCnt->GetName());
if (!m_pActiveShell->GotoNextTOXBase(&sName))
m_pActiveShell->GotoPrevTOXBase(&sName);
}
break;
case ContentTypeId::POSTIT:
m_pActiveShell->GotoFormatField(*static_cast<const SwPostItContent*>(pCnt)->GetPostIt());
break;
case ContentTypeId::DRAWOBJECT:
{
m_pActiveShell->GotoDrawingObject(pCnt->GetName());
}
break;
case ContentTypeId::FOOTNOTE:
case ContentTypeId::ENDNOTE:
{
const SwTextFootnote* pFootnote =
static_cast<const SwTextFootnoteContent*>(pCnt)->GetTextFootnote();
if (!pFootnote)
return;
m_pActiveShell->GotoFootnoteAnchor(*pFootnote);
}
break;
default: break;
}
if (m_bSelectTo)
{
m_pActiveShell->SttCursorMove();
while (m_pActiveShell->IsCursorInTable())
{
m_pActiveShell->MoveTable(GotoCurrTable, fnTableStart);
if (!m_pActiveShell->Left(SwCursorSkipMode::Chars, false, 1, false))
break; // Table is at the beginning of the document. It can't be selected this way.
}
m_pActiveShell->EndCursorMove();
m_pActiveShell->AssureStdMode();
m_pActiveShell->SetMark();
m_pActiveShell->GetCursor()->GetMark()->nNode = oPosition.value()->nNode;
m_pActiveShell->GetCursor()->GetMark()->nContent = oPosition.value()->nContent;
m_pActiveShell->UpdateCursor();
m_pActiveShell->GetView().GetEditWin().GrabFocus();
m_bSelectTo = false;
}
else
{
if (m_pActiveShell->IsFrameSelected() || m_pActiveShell->IsObjSelected())
{
m_pActiveShell->HideCursor();
m_pActiveShell->EnterSelFrameMode();
}
SwView& rView = m_pActiveShell->GetView();
rView.StopShellTimer();
rView.GetPostItMgr()->SetActiveSidebarWin(nullptr);
rView.GetEditWin().GrabFocus();
// Assure cursor is in visible view area.
// (tdf#147041) Always show the navigated outline at the top of the visible view area.
if (pCnt->GetParent()->GetType() == ContentTypeId::OUTLINE ||
(!m_pActiveShell->IsCursorVisible() && !m_pActiveShell->IsFrameSelected() &&
!m_pActiveShell->IsObjSelected()))
{
Point aPoint(rView.GetVisArea().getX(), m_pActiveShell->GetCursorDocPos().getY());
rView.SetVisArea(aPoint);
}
}
}
// Now even the matching text::Bookmark
NaviContentBookmark::NaviContentBookmark()
:
m_nDocSh(0),
m_nDefaultDrag( RegionMode::NONE )
{
}
NaviContentBookmark::NaviContentBookmark( OUString aUrl,
OUString aDesc,
RegionMode nDragType,
const SwDocShell* pDocSh ) :
m_aUrl(std::move( aUrl )),
m_aDescription(std::move(aDesc)),
m_nDocSh(reinterpret_cast<sal_IntPtr>(pDocSh)),
m_nDefaultDrag( nDragType )
{
}
void NaviContentBookmark::Copy( TransferDataContainer& rData ) const
{
rtl_TextEncoding eSysCSet = osl_getThreadTextEncoding();
OString sStrBuf(OUStringToOString(m_aUrl, eSysCSet) + OStringChar(NAVI_BOOKMARK_DELIM) +
OUStringToOString(m_aDescription, eSysCSet) + OStringChar(NAVI_BOOKMARK_DELIM) +
OString::number(static_cast<int>(m_nDefaultDrag)) + OStringChar(NAVI_BOOKMARK_DELIM) +
OString::number(m_nDocSh));
rData.CopyByteString(SotClipboardFormatId::SONLK, sStrBuf);
}
bool NaviContentBookmark::Paste( const TransferableDataHelper& rData, const OUString& rsDesc )
{
OUString sStr;
bool bRet = rData.GetString( SotClipboardFormatId::SONLK, sStr );
if( bRet )
{
sal_Int32 nPos = 0;
m_aUrl = sStr.getToken(0, NAVI_BOOKMARK_DELIM, nPos );
m_aDescription = sStr.getToken(0, NAVI_BOOKMARK_DELIM, nPos );
m_nDefaultDrag= static_cast<RegionMode>( o3tl::toInt32(o3tl::getToken(sStr, 0, NAVI_BOOKMARK_DELIM, nPos )) );
m_nDocSh = o3tl::toInt32(o3tl::getToken(sStr, 0, NAVI_BOOKMARK_DELIM, nPos ));
if (!rsDesc.isEmpty())
m_aDescription = rsDesc;
}
return bRet;
}
SwNavigationPI* SwContentTree::GetParentWindow()
{
return m_pDialog;
}
void SwContentTree::SelectContentType(std::u16string_view rContentTypeName)
{
std::unique_ptr<weld::TreeIter> xIter(m_xTreeView->make_iterator());
if (!m_xTreeView->get_iter_first(*xIter))
return;
do
{
if (m_xTreeView->get_text(*xIter) == rContentTypeName)
{
m_xTreeView->set_cursor(*xIter);
Select();
break;
}
} while (m_xTreeView->iter_next_sibling(*xIter));
}
IMPL_LINK_NOARG(SwContentTree, OverlayObjectDelayTimerHdl, Timer *, void)
{
m_aOverlayObjectDelayTimer.Stop();
if (m_xOverlayObject)
{
if (SdrView* pView = m_pActiveShell->GetDrawView())
{
if (SdrPaintWindow* pPaintWindow = pView->GetPaintWindow(0))
{
const rtl::Reference<sdr::overlay::OverlayManager>& xOverlayManager =
pPaintWindow->GetOverlayManager();
xOverlayManager->add(*m_xOverlayObject);
}
}
}
}
void SwContentTree::OverlayObject(std::vector<basegfx::B2DRange>&& aRanges)
{
m_aOverlayObjectDelayTimer.Stop();
if (m_xOverlayObject && m_xOverlayObject->getOverlayManager())
m_xOverlayObject->getOverlayManager()->remove(*m_xOverlayObject);
if (aRanges.empty())
m_xOverlayObject.reset();
else
{
m_xOverlayObject.reset(new sdr::overlay::OverlaySelection(
sdr::overlay::OverlayType::Invert,
Color(), std::move(aRanges), true/*unused for Invert type*/));
m_aOverlayObjectDelayTimer.Start();
}
}
void SwContentTree::BringEntryToAttention(const weld::TreeIter& rEntry)
{
if (lcl_IsContent(rEntry, *m_xTreeView)) // content entry
{
SwContent* pCnt = weld::fromId<SwContent*>(m_xTreeView->get_id(rEntry));
if (pCnt->IsInvisible())
OverlayObject();
else
{
const ContentTypeId nType = pCnt->GetParent()->GetType();
if (nType == ContentTypeId::OUTLINE)
{
BringTypesWithFlowFramesToAttention({m_pActiveShell->GetNodes().
GetOutLineNds()[static_cast<SwOutlineContent*>(pCnt)->GetOutlinePos()]},
/*bIncludeTopMargin*/ false);
}
else if (nType == ContentTypeId::TABLE)
{
if (const sw::TableFrameFormats* pFrameFormats = m_pActiveShell->GetDoc()->GetTableFrameFormats())
if (const SwTableFormat* pFrameFormat = pFrameFormats->FindFrameFormatByName(pCnt->GetName()))
{
SwTable* pTable = SwTable::FindTable(pFrameFormat);
if (pTable)
BringTypesWithFlowFramesToAttention({pTable->GetTableNode()}, false);
}
}
else if (nType == ContentTypeId::FRAME || nType == ContentTypeId::GRAPHIC ||
nType == ContentTypeId::OLE)
{
SwNodeType eNodeType = SwNodeType::Text;
if(nType == ContentTypeId::GRAPHIC)
eNodeType = SwNodeType::Grf;
else if(nType == ContentTypeId::OLE)
eNodeType = SwNodeType::Ole;
if (const SwFrameFormat* pFrameFormat =
m_pActiveShell->GetDoc()->FindFlyByName(pCnt->GetName(), eNodeType))
BringFramesToAttention(std::vector<const SwFrameFormat*> {pFrameFormat});
}
else if (nType == ContentTypeId::BOOKMARK)
{
BringBookmarksToAttention(std::vector<OUString> {pCnt->GetName()});
}
else if (nType == ContentTypeId::REGION || nType == ContentTypeId::INDEX)
{
size_t nSectionFormatCount = m_pActiveShell->GetSectionFormatCount();
for (size_t i = 0; i < nSectionFormatCount; ++i)
{
const SwSectionFormat& rSectionFormat = m_pActiveShell->GetSectionFormat(i);
if (!rSectionFormat.IsInNodesArr())
continue;
const SwSection* pSection = rSectionFormat.GetSection();
if (!pSection)
continue;
if (pCnt->GetName() == pSection->GetSectionName())
{
BringTypesWithFlowFramesToAttention({rSectionFormat.GetSectionNode()});
break;
}
}
}
else if (nType == ContentTypeId::URLFIELD)
{
// tdf#159147 - Assure the SwURLFieldContent::SwTextINetFormat pointer is valid
// before bringing to attention.
const SwTextINetFormat* pTextINetFormat
= static_cast<SwURLFieldContent*>(pCnt)->GetINetAttr();
const SwCharFormats* pFormats = m_pActiveShell->GetDoc()->GetCharFormats();
for (auto n = pFormats->size(); 1 < n;)
{
SwIterator<SwTextINetFormat, SwCharFormat> aIter(*(*pFormats)[--n]);
for (SwTextINetFormat* pFnd = aIter.First(); pFnd; pFnd = aIter.Next() )
{
if (pTextINetFormat == pFnd)
{
BringURLFieldsToAttention(SwGetINetAttrs {SwGetINetAttr(pCnt->GetName(),
*pTextINetFormat)});
break;
}
}
}
}
else if (nType == ContentTypeId::REFERENCE)
{
if (const SwTextAttr* pTextAttr =
m_pActiveShell->GetDoc()->GetRefMark(pCnt->GetName())->GetTextRefMark())
{
std::vector<const SwTextAttr*> aTextAttrArr {pTextAttr};
BringReferencesToAttention(aTextAttrArr);
}
}
else if (nType == ContentTypeId::POSTIT)
{
if (const SwTextAttr* pTextAttr =
static_cast<SwPostItContent*>(pCnt)->GetPostIt()->GetTextField())
{
std::vector<const SwTextAttr*> aTextAttrArr {pTextAttr};
BringPostItFieldsToAttention(aTextAttrArr);
}
}
else if (nType == ContentTypeId::DRAWOBJECT)
{
std::vector<const SdrObject*> aSdrObjectArr {GetDrawingObjectsByContent(pCnt)};
BringDrawingObjectsToAttention(aSdrObjectArr);
}
else if (nType == ContentTypeId::TEXTFIELD)
{
if (const SwTextAttr* pTextAttr =
static_cast<SwTextFieldContent*>(pCnt)->GetFormatField()->GetTextField())
{
std::vector<const SwTextAttr*> aTextAttrArr {pTextAttr};
BringTextFieldsToAttention(aTextAttrArr);
}
}
else if (nType == ContentTypeId::FOOTNOTE || nType == ContentTypeId::ENDNOTE)
{
if (const SwTextAttr* pTextAttr =
static_cast<SwTextFootnoteContent*> (pCnt)->GetTextFootnote())
{
std::vector<const SwTextAttr*> aTextAttrArr {pTextAttr};
BringFootnotesToAttention(aTextAttrArr);
}
}
}
}
else // content type entry
{
SwContentType* pCntType = weld::fromId<SwContentType*>(m_xTreeView->get_id(rEntry));
if (pCntType->GetMemberCount() == 0)
OverlayObject();
else
{
const ContentTypeId nType = pCntType->GetType();
if (nType == ContentTypeId::OUTLINE)
{
std::vector<const SwNode*> aNodesArr(
m_pActiveShell->GetNodes().GetOutLineNds().begin(),
m_pActiveShell->GetNodes().GetOutLineNds().end());
BringTypesWithFlowFramesToAttention(aNodesArr, /*bIncludeTopMargin*/ false);
}
else if (nType == ContentTypeId::TABLE)
{
std::vector<const SwNode*> aNodesArr;
const size_t nCount = m_pActiveShell->GetTableFrameFormatCount(false);
const sw::TableFrameFormats& rTableFormats = *m_pActiveShell->GetDoc()->GetTableFrameFormats();
for(size_t i = 0; i < nCount; ++i)
{
if (const SwTableFormat* pTableFormat = rTableFormats[i])
if(pTableFormat->IsUsed()) // skip deleted tables
{
SwTable* pTable = SwTable::FindTable(pTableFormat);
if (pTable)
aNodesArr.push_back(pTable->GetTableNode());
}
}
BringTypesWithFlowFramesToAttention(aNodesArr, false);
}
else if (nType == ContentTypeId::FRAME || nType == ContentTypeId::GRAPHIC ||
nType == ContentTypeId::OLE)
{
FlyCntType eType = FLYCNTTYPE_FRM;
if(nType == ContentTypeId::GRAPHIC)
eType = FLYCNTTYPE_GRF;
else if(nType == ContentTypeId::OLE)
eType = FLYCNTTYPE_OLE;
BringFramesToAttention(m_pActiveShell->GetFlyFrameFormats(eType, true));
}
else if (nType == ContentTypeId::BOOKMARK)
{
std::vector<OUString> aNames;
const auto nCount = pCntType->GetMemberCount();
for (size_t i = 0; i < nCount; i++)
{
const SwContent* pMember = pCntType->GetMember(i);
if (pMember && !pMember->IsInvisible())
aNames.push_back(pMember->GetName());
}
BringBookmarksToAttention(aNames);
}
else if (nType == ContentTypeId::REGION || nType == ContentTypeId::INDEX)
{
std::vector<const SwNode*> aNodesArr;
const SwSectionFormats& rFormats = m_pActiveShell->GetDoc()->GetSections();
const size_t nSize = rFormats.size();
for (SwSectionFormats::size_type n = nSize; n;)
{
const SwSectionFormat* pSectionFormat = rFormats[--n];
if (pSectionFormat && pSectionFormat->IsInNodesArr())
{
const SwSection* pSection = pSectionFormat->GetSection();
if (pSection && !pSection->IsHiddenFlag())
{
const SectionType eSectionType = pSection->GetType();
if (nType == ContentTypeId::REGION &&
(eSectionType == SectionType::ToxContent ||
eSectionType == SectionType::ToxHeader))
continue;
if (nType == ContentTypeId::INDEX &&
eSectionType != SectionType::ToxContent)
continue;
if (const SwNode* pNode = pSectionFormat->GetSectionNode())
aNodesArr.push_back(pNode);
}
}
}
BringTypesWithFlowFramesToAttention(aNodesArr);
}
else if (nType == ContentTypeId::URLFIELD)
{
SwGetINetAttrs aINetAttrsArr;
m_pActiveShell->GetINetAttrs(aINetAttrsArr, false);
BringURLFieldsToAttention(aINetAttrsArr);
}
else if (nType == ContentTypeId::REFERENCE)
{
std::vector<const SwTextAttr*> aTextAttrArr;
for (const SfxPoolItem* pItem :
m_pActiveShell->GetAttrPool().GetItemSurrogates(RES_TXTATR_REFMARK))
{
if (const auto pRefMark = dynamic_cast<const SwFormatRefMark*>(pItem))
{
const SwTextRefMark* pTextRef = pRefMark->GetTextRefMark();
if (pTextRef && &pTextRef->GetTextNode().GetNodes() ==
&m_pActiveShell->GetNodes())
aTextAttrArr.push_back(pTextRef);
}
}
BringReferencesToAttention(aTextAttrArr);
}
else if (nType == ContentTypeId::POSTIT)
{
std::vector<const SwTextAttr*> aTextAttrArr;
const auto nCount = pCntType->GetMemberCount();
for (size_t i = 0; i < nCount; i++)
{
const SwPostItContent* pPostItContent = static_cast<const SwPostItContent*>(
pCntType->GetMember(i));
if (pPostItContent && !pPostItContent->IsInvisible())
if (const SwFormatField* pFormatField = pPostItContent->GetPostIt())
if (const SwTextAttr* pTextAttr = pFormatField->GetTextField())
aTextAttrArr.push_back(pTextAttr);
}
BringPostItFieldsToAttention(aTextAttrArr);
}
else if (nType == ContentTypeId::DRAWOBJECT)
{
IDocumentDrawModelAccess& rIDDMA = m_pActiveShell->getIDocumentDrawModelAccess();
if (const SwDrawModel* pModel = rIDDMA.GetDrawModel())
{
if (const SdrPage* pPage = pModel->GetPage(0))
{
if (pPage->GetObjCount())
{
std::vector<const SdrObject*> aSdrObjectArr;
for (const rtl::Reference<SdrObject>& pObject : *pPage)
{
if (pObject && !pObject->GetName().isEmpty() &&
rIDDMA.IsVisibleLayerId(pObject->GetLayer()))
aSdrObjectArr.push_back(pObject.get());
}
BringDrawingObjectsToAttention(aSdrObjectArr);
}
}
}
}
else if (nType == ContentTypeId::TEXTFIELD)
{
std::vector<const SwTextAttr*> aTextAttrArr;
const auto nCount = pCntType->GetMemberCount();
for (size_t i = 0; i < nCount; i++)
{
const SwTextFieldContent* pTextFieldCnt =
static_cast<const SwTextFieldContent*>(pCntType->GetMember(i));
if (pTextFieldCnt && !pTextFieldCnt->IsInvisible())
if (const SwFormatField* pFormatField = pTextFieldCnt->GetFormatField())
if (const SwTextAttr* pTextAttr = pFormatField->GetTextField())
aTextAttrArr.push_back(pTextAttr);
}
BringTextFieldsToAttention(aTextAttrArr);
}
else if (nType == ContentTypeId::FOOTNOTE || nType == ContentTypeId::ENDNOTE)
{
std::vector<const SwTextAttr*> aTextAttrArr;
const auto nCount = pCntType->GetMemberCount();
for (size_t i = 0; i < nCount; i++)
{
const SwTextFootnoteContent* pTextFootnoteCnt =
static_cast<const SwTextFootnoteContent*>(pCntType->GetMember(i));
if (pTextFootnoteCnt && !pTextFootnoteCnt->IsInvisible())
if (const SwTextAttr* pTextAttr = pTextFootnoteCnt->GetTextFootnote())
aTextAttrArr.push_back(pTextAttr);
}
BringFootnotesToAttention(aTextAttrArr);
}
}
}
}
static void lcl_CalcOverlayRanges(const SwTextFrame* pStartFrame, const SwTextFrame* pEndFrame,
const SwPosition& aStartPos, const SwPosition& aEndPos,
std::vector<basegfx::B2DRange>& aRanges)
{
if (pStartFrame && pEndFrame)
{
SwRect aStartCharRect;
pStartFrame->GetCharRect(aStartCharRect, aStartPos);
SwRect aEndCharRect;
pEndFrame->GetCharRect(aEndCharRect, aEndPos);
if (aStartCharRect.Top() == aEndCharRect.Top())
{
// single line range
aRanges.emplace_back(aStartCharRect.Left(), aStartCharRect.Top(),
aEndCharRect.Right() + 1, aEndCharRect.Bottom() + 1);
}
else
{
// multi line range
SwRect aFrameRect = pStartFrame->getFrameArea();
aRanges.emplace_back(aStartCharRect.Left(), aStartCharRect.Top(),
aFrameRect.Right(), aStartCharRect.Bottom() + 1);
if (aStartCharRect.Bottom() + 1 != aEndCharRect.Top())
aRanges.emplace_back(aFrameRect.Left(), aStartCharRect.Bottom() + 1,
aFrameRect.Right(), aEndCharRect.Top() + 1);
aRanges.emplace_back(aFrameRect.Left(), aEndCharRect.Top() + 1,
aEndCharRect.Right() + 1, aEndCharRect.Bottom() + 1);
}
}
}
void SwContentTree::BringFramesToAttention(const std::vector<const SwFrameFormat*>& rFrameFormats)
{
std::vector<basegfx::B2DRange> aRanges;
for (const SwFrameFormat* pFrameFormat : rFrameFormats)
{
if (!pFrameFormat)
continue;
SwRect aFrameRect = pFrameFormat->FindLayoutRect();
if (!aFrameRect.IsEmpty())
aRanges.emplace_back(aFrameRect.Left(), aFrameRect.Top(), aFrameRect.Right(),
aFrameRect.Bottom());
}
OverlayObject(std::move(aRanges));
}
void SwContentTree::BringBookmarksToAttention(const std::vector<OUString>& rNames)
{
std::vector<basegfx::B2DRange> aRanges;
IDocumentMarkAccess* const pMarkAccess = m_pActiveShell->getIDocumentMarkAccess();
for (const auto& rName : rNames)
{
IDocumentMarkAccess::const_iterator_t ppBkmk = pMarkAccess->findBookmark(rName);
if (ppBkmk == pMarkAccess->getBookmarksEnd())
continue;
SwPosition aMarkStart = (*ppBkmk)->GetMarkStart();
const SwTextNode* pMarkStartTextNode = aMarkStart.GetNode().GetTextNode();
if (!pMarkStartTextNode)
continue;
const SwTextFrame* pMarkStartFrame = static_cast<const SwTextFrame*>(
pMarkStartTextNode->getLayoutFrame(m_pActiveShell->GetLayout()));
if (!pMarkStartFrame)
continue;
SwPosition aMarkEnd = (*ppBkmk)->GetMarkEnd();
const SwTextNode* pMarkEndTextNode = aMarkEnd.GetNode().GetTextNode();
if (!pMarkEndTextNode)
continue;
const SwTextFrame* pMarkEndFrame = static_cast<const SwTextFrame*>(
pMarkEndTextNode->getLayoutFrame(m_pActiveShell->GetLayout()));
if (!pMarkEndFrame)
continue;
// adjust span when mark start equals mark end
if (aMarkStart == aMarkEnd)
{
if (aMarkEnd.GetContentIndex() < pMarkEndTextNode->Len() - 1)
aMarkEnd.AdjustContent(+1);
else if (aMarkStart.GetContentIndex() > 0)
aMarkStart.AdjustContent(-1);
}
lcl_CalcOverlayRanges(pMarkStartFrame, pMarkEndFrame, aMarkStart, aMarkEnd, aRanges);
}
OverlayObject(std::move(aRanges));
}
void SwContentTree::BringTypesWithFlowFramesToAttention(const std::vector<const SwNode*>& rNodes,
const bool bIncludeTopMargin)
{
std::vector<basegfx::B2DRange> aRanges;
for (const auto* pNode : rNodes)
{
if (!pNode)
continue;
const SwFrame* pFrame;
if (pNode->IsContentNode() || pNode->IsTableNode())
{
if (pNode->IsContentNode())
pFrame = pNode->GetContentNode()->getLayoutFrame(m_pActiveShell->GetLayout());
else // table node
{
SwNode2Layout aTmp(*pNode, pNode->GetIndex() - 1);
pFrame = aTmp.NextFrame();
}
while (pFrame)
{
const SwRect& rFrameRect = pFrame->getFrameArea();
if (!rFrameRect.IsEmpty())
aRanges.emplace_back(rFrameRect.Left(), bIncludeTopMargin ? rFrameRect.Top() :
rFrameRect.Top() + pFrame->GetTopMargin(),
rFrameRect.Right(), rFrameRect.Bottom());
if (!pFrame->IsFlowFrame())
break;
const SwFlowFrame *pFollow = SwFlowFrame::CastFlowFrame(pFrame)->GetFollow();
if (!pFollow)
break;
pFrame = &pFollow->GetFrame();
}
}
else if (pNode->IsSectionNode())
{
const SwNode* pEndOfSectionNode = pNode->EndOfSectionNode();
SwNodeIndex aIdx(*pNode);
while (&aIdx.GetNode() != pEndOfSectionNode)
{
if (aIdx.GetNode().IsContentNode())
{
if ((pFrame = aIdx.GetNode().GetContentNode()->
getLayoutFrame(m_pActiveShell->GetLayout())))
{
if (pFrame->IsInSct())
pFrame = pFrame->FindSctFrame();
if (pFrame)
{
const SwRect& rFrameRect = pFrame->getFrameArea();
if (!rFrameRect.IsEmpty())
aRanges.emplace_back(rFrameRect.Left(), rFrameRect.Top(),
rFrameRect.Right(), rFrameRect.Bottom());
}
}
++aIdx;
while (!aIdx.GetNode().IsEndNode() && !aIdx.GetNode().IsSectionNode())
++aIdx;
continue;
}
if (!aIdx.GetNode().IsSectionNode())
{
++aIdx;
continue;
}
SwNode2Layout aTmp(aIdx.GetNode(), aIdx.GetNode().GetIndex() - 1);
pFrame = aTmp.NextFrame();
if (pFrame)
{
if (!pFrame->getFrameArea().IsEmpty())
{
const SwRect& rFrameRect = pFrame->getFrameArea();
aRanges.emplace_back(rFrameRect.Left(), rFrameRect.Top(),
rFrameRect.Right(), rFrameRect.Bottom());
}
if (pFrame->IsSctFrame())
{
const SwSectionFrame* pSectionFrame
= static_cast<const SwSectionFrame*>(pFrame);
if (pSectionFrame->HasFollow())
{
const SwFlowFrame *pFollow
= SwFlowFrame::CastFlowFrame(pSectionFrame)->GetFollow();
while (pFollow)
{
pFrame = &pFollow->GetFrame();
if (!pFrame->getFrameArea().IsEmpty())
{
const SwRect& rFrameRect = pFrame->getFrameArea();
aRanges.emplace_back(rFrameRect.Left(), rFrameRect.Top(),
rFrameRect.Right(), rFrameRect.Bottom());
}
pFollow = SwFlowFrame::CastFlowFrame(pFrame)->GetFollow();
}
}
}
}
++aIdx;
while (!aIdx.GetNode().IsEndNode() && !aIdx.GetNode().IsSectionNode())
++aIdx;
}
// Remove nested sections. This wouldn't be needed if the overlay wasn't invert type.
auto end = aRanges.end();
for (auto it = aRanges.begin(); it != end; ++it)
end = std::remove_if(it + 1, end, [&it](auto itt){ return it->isInside(itt); });
aRanges.erase(end, aRanges.end());
}
}
OverlayObject(std::move(aRanges));
}
void SwContentTree::BringURLFieldsToAttention(const SwGetINetAttrs& rINetAttrsArr)
{
std::vector<basegfx::B2DRange> aRanges;
for (const auto& r : rINetAttrsArr)
{
const SwTextNode& rTextNode = r.rINetAttr.GetTextNode();
if (SwTextFrame* pFrame = static_cast<SwTextFrame*>(
rTextNode.getLayoutFrame(m_pActiveShell->GetLayout())))
{
auto nStart = r.rINetAttr.GetStart();
auto nEnd = r.rINetAttr.GetAnyEnd();
SwPosition aStartPos(rTextNode, nStart), aEndPos(rTextNode, nEnd);
lcl_CalcOverlayRanges(pFrame, pFrame, aStartPos, aEndPos, aRanges);
}
}
OverlayObject(std::move(aRanges));
}
void SwContentTree::BringReferencesToAttention(std::vector<const SwTextAttr*>& rTextAttrsArr)
{
std::vector<basegfx::B2DRange> aRanges;
for (const SwTextAttr* p : rTextAttrsArr)
{
if (!p)
continue;
const SwTextRefMark* pTextRefMark = p->GetRefMark().GetTextRefMark();
if (!pTextRefMark)
continue;
const SwTextNode& rTextNode = pTextRefMark->GetTextNode();
if (SwTextFrame* pFrame = static_cast<SwTextFrame*>(
rTextNode.getLayoutFrame(m_pActiveShell->GetLayout())))
{
auto nStart = p->GetStart();
auto nEnd = p->GetAnyEnd();
SwPosition aStartPos(rTextNode, nStart), aEndPos(rTextNode, nEnd);
lcl_CalcOverlayRanges(pFrame, pFrame, aStartPos, aEndPos, aRanges);
}
}
OverlayObject(std::move(aRanges));
}
void SwContentTree::BringPostItFieldsToAttention(std::vector<const SwTextAttr*>& rTextAttrsArr)
{
std::vector<basegfx::B2DRange> aRanges;
for (const SwTextAttr* p : rTextAttrsArr)
{
if (!p)
continue;
const SwTextField* pTextField = p->GetFormatField().GetTextField();
if (!pTextField)
continue;
// use as a fallback when there is no mark
SwTextNode& rTextNode = pTextField->GetTextNode();
if (!rTextNode.getLayoutFrame(m_pActiveShell->GetLayout()))
continue;
assert(dynamic_cast<const SwTextAnnotationField*>(pTextField));
const SwTextAnnotationField* pTextAnnotationField =
static_cast<const SwTextAnnotationField*>(pTextField);
const ::sw::mark::IMark* pAnnotationMark = pTextAnnotationField->GetAnnotationMark();
const SwPosition aMarkStart = pAnnotationMark ? pAnnotationMark->GetMarkStart()
: SwPosition(rTextNode, p->GetStart());
const SwPosition aMarkEnd = pAnnotationMark ? pAnnotationMark->GetMarkEnd()
: SwPosition(rTextNode, p->GetAnyEnd());
const SwTextFrame* pMarkStartFrame = static_cast<SwTextFrame*>(
aMarkStart.GetNode().GetTextNode()->getLayoutFrame(m_pActiveShell->GetLayout()));
const SwTextFrame* pMarkEndFrame = static_cast<SwTextFrame*>(
aMarkEnd.GetNode().GetTextNode()->getLayoutFrame(m_pActiveShell->GetLayout()));
if (!pMarkStartFrame || !pMarkEndFrame)
continue;
lcl_CalcOverlayRanges(pMarkStartFrame, pMarkEndFrame, aMarkStart,
aMarkEnd, aRanges);
}
OverlayObject(std::move(aRanges));
}
void SwContentTree::BringFootnotesToAttention(std::vector<const SwTextAttr*>& rTextAttrsArr)
{
std::vector<basegfx::B2DRange> aRanges;
for (const SwTextAttr* p : rTextAttrsArr)
{
if (!p)
continue;
const SwTextFootnote* pTextFootnote = p->GetFootnote().GetTextFootnote();
if (!pTextFootnote)
continue;
const SwTextNode& rTextNode = pTextFootnote->GetTextNode();
if (SwTextFrame* pFrame = static_cast<SwTextFrame*>(
rTextNode.getLayoutFrame(m_pActiveShell->GetLayout())))
{
auto nStart = p->GetStart();
auto nEnd = nStart + 1;
SwPosition aStartPos(rTextNode, nStart), aEndPos(rTextNode, nEnd);
lcl_CalcOverlayRanges(pFrame, pFrame, aStartPos, aEndPos, aRanges);
}
}
OverlayObject(std::move(aRanges));
}
void SwContentTree::BringDrawingObjectsToAttention(std::vector<const SdrObject*>& rDrawingObjectsArr)
{
std::vector<basegfx::B2DRange> aRanges;
for (const SdrObject* pObject : rDrawingObjectsArr)
{
if (pObject)
{
tools::Rectangle aRect(pObject->GetLogicRect());
if (!aRect.IsEmpty())
aRanges.emplace_back(aRect.Left(), aRect.Top(), aRect.Right(), aRect.Bottom());
}
}
OverlayObject(std::move(aRanges));
}
void SwContentTree::BringTextFieldsToAttention(std::vector<const SwTextAttr*>& rTextAttrsArr)
{
std::vector<basegfx::B2DRange> aRanges;
std::shared_ptr<SwPaM> pPamForTextField;
for (const SwTextAttr* p : rTextAttrsArr)
{
if (!p)
continue;
const SwTextField* pTextField = p->GetFormatField().GetTextField();
if (!pTextField)
continue;
if (SwTextFrame* pFrame = static_cast<SwTextFrame*>(
pTextField->GetTextNode().getLayoutFrame(m_pActiveShell->GetLayout())))
{
SwTextField::GetPamForTextField(*pTextField, pPamForTextField);
if (!pPamForTextField)
continue;
SwPosition aStartPos(*pPamForTextField->GetMark());
SwPosition aEndPos(*pPamForTextField->GetPoint());
lcl_CalcOverlayRanges(pFrame, pFrame, aStartPos, aEndPos, aRanges);
}
}
OverlayObject(std::move(aRanges));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|