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
|
/* -*- 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 <config_features.h>
#include <config_fuzzers.h>
#include <sal/config.h>
#include <hintids.hxx>
#include <comphelper/servicehelper.hxx>
#include <svl/languageoptions.hxx>
#include <sfx2/linkmgr.hxx>
#include <sfx2/htmlmode.hxx>
#include <svx/imapdlg.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/request.hxx>
#include <svl/whiter.hxx>
#include <svl/visitem.hxx>
#include <editeng/langitem.hxx>
#include <svx/clipfmtitem.hxx>
#include <svx/contdlg.hxx>
#include <vcl/graph.hxx>
#include <vcl/inputctx.hxx>
#include <svl/slstitm.hxx>
#include <svl/ptitem.hxx>
#include <svl/stritem.hxx>
#include <editeng/colritem.hxx>
#include <editeng/fhgtitem.hxx>
#include <editeng/fontitem.hxx>
#include <editeng/shaditem.hxx>
#include <editeng/boxitem.hxx>
#include <editeng/brushitem.hxx>
#include <editeng/opaqitem.hxx>
#include <editeng/sizeitem.hxx>
#include <svx/flagsdef.hxx>
#include <editeng/scripttypeitem.hxx>
#include <sfx2/objface.hxx>
#include <fmturl.hxx>
#include <fmthdft.hxx>
#include <fmtclds.hxx>
#include <docsh.hxx>
#include <wrtsh.hxx>
#include <view.hxx>
#include <swmodule.hxx>
#include <swundo.hxx>
#include <fldbas.hxx>
#include <uitool.hxx>
#include <basesh.hxx>
#include <viewopt.hxx>
#include <fontcfg.hxx>
#include <fmtsrnd.hxx>
#include <fldmgr.hxx>
#include <frmmgr.hxx>
#include <tablemgr.hxx>
#include <mdiexp.hxx>
#include <swdtflvr.hxx>
#include <pagedesc.hxx>
#include <fmtcol.hxx>
#include <edtwin.hxx>
#include <tblafmt.hxx>
#include <swwait.hxx>
#include <cmdid.h>
#include <strings.hrc>
#include <unotxdoc.hxx>
#include <doc.hxx>
#include <drawdoc.hxx>
#include <IDocumentSettingAccess.hxx>
#include <IDocumentDrawModelAccess.hxx>
#include <IDocumentUndoRedo.hxx>
#include <ThemeColorChanger.hxx>
#include <swabstdlg.hxx>
#include <modcfg.hxx>
#include <svx/fmshell.hxx>
#include <SwRewriter.hxx>
#include <GraphicSizeCheck.hxx>
#include <svx/galleryitem.hxx>
#include <svx/theme/ThemeColorPaletteManager.hxx>
#include <sfx2/devtools/DevelopmentToolChildWindow.hxx>
#include <com/sun/star/gallery/GalleryItemType.hpp>
#include <com/sun/star/beans/PropertyValues.hpp>
#include <memory>
#include <svx/unobrushitemhelper.hxx>
#include <svx/dialog/ThemeDialog.hxx>
#include <comphelper/scopeguard.hxx>
#include <comphelper/lok.hxx>
#include <sfx2/lokhelper.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <osl/diagnose.h>
#include <svx/svxdlg.hxx>
#include <comphelper/sequenceashashmap.hxx>
#include <shellres.hxx>
#include <UndoTable.hxx>
#include <ndtxt.hxx>
#include <UndoManager.hxx>
#include <fmtrfmrk.hxx>
#include <txtrfmrk.hxx>
#include <translatehelper.hxx>
FlyMode SwBaseShell::s_eFrameMode = FLY_DRAG_END;
// These variables keep the state of Gallery (slot SID_GALLERY_BG_BRUSH)
// detected by GetGalleryState() for the subsequent ExecuteGallery() call.
static sal_uInt8 nParagraphPos;
static sal_uInt8 nGraphicPos;
static sal_uInt8 nOlePos;
static sal_uInt8 nFramePos;
static sal_uInt8 nTablePos;
static sal_uInt8 nTableRowPos;
static sal_uInt8 nTableCellPos;
static sal_uInt8 nPagePos;
static sal_uInt8 nHeaderPos;
static sal_uInt8 nFooterPos;
#define ShellClass_SwBaseShell
#include <sfx2/msg.hxx>
#include <swslots.hxx>
#include <AccessibilityCheck.hxx>
namespace
{
SvxContourDlg* GetContourDlg(SwView const &rView)
{
SfxChildWindow *pWnd = rView.GetViewFrame().GetChildWindow(SvxContourDlgChildWindow::GetChildWindowId());
return pWnd ? static_cast<SvxContourDlg*>(pWnd->GetController().get()) : nullptr;
}
SvxIMapDlg* GetIMapDlg(SwView const &rView)
{
SfxChildWindow* pWnd = rView.GetViewFrame().GetChildWindow(SvxIMapDlgChildWindow::GetChildWindowId());
return pWnd ? static_cast<SvxIMapDlg*>(pWnd->GetController().get()) : nullptr;
}
}
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::lang;
SFX_IMPL_SUPERCLASS_INTERFACE(SwBaseShell, SfxShell)
void SwBaseShell::InitInterface_Impl()
{
GetStaticInterface()->RegisterChildWindow(SvxIMapDlgChildWindow::GetChildWindowId());
GetStaticInterface()->RegisterChildWindow(SvxContourDlgChildWindow::GetChildWindowId());
GetStaticInterface()->RegisterChildWindow(DevelopmentToolChildWindow::GetChildWindowId());
}
static void lcl_UpdateIMapDlg( SwWrtShell& rSh )
{
Graphic aGrf( rSh.GetIMapGraphic() );
GraphicType nGrfType = aGrf.GetType();
void* pEditObj = GraphicType::NONE != nGrfType && GraphicType::Default != nGrfType
? rSh.GetIMapInventor() : nullptr;
TargetList aList;
SfxFrame::GetDefaultTargetList(aList);
SfxItemSetFixed<RES_URL, RES_URL> aSet( rSh.GetAttrPool() );
rSh.GetFlyFrameAttr( aSet );
const SwFormatURL &rURL = aSet.Get( RES_URL );
SvxIMapDlgChildWindow::UpdateIMapDlg(
aGrf, rURL.GetMap(), &aList, pEditObj );
}
static bool lcl_UpdateContourDlg( SwWrtShell &rSh, SelectionType nSel )
{
Graphic aGraf( rSh.GetIMapGraphic() );
GraphicType nGrfType = aGraf.GetType();
bool bRet = GraphicType::NONE != nGrfType && GraphicType::Default != nGrfType;
if( bRet )
{
OUString aGrfName;
if ( nSel & SelectionType::Graphic )
rSh.GetGrfNms( &aGrfName, nullptr );
SvxContourDlg *pDlg = GetContourDlg(rSh.GetView());
if (pDlg)
{
pDlg->Update(aGraf, !aGrfName.isEmpty(),
rSh.GetGraphicPolygon(), rSh.GetIMapInventor());
}
}
return bRet;
}
void SwBaseShell::ExecDelete(SfxRequest &rReq)
{
SwWrtShell &rSh = GetShell();
SwEditWin& rTmpEditWin = GetView().GetEditWin();
switch(rReq.GetSlot())
{
case SID_DELETE:
if (rSh.GetViewOptions()->IsShowOutlineContentVisibilityButton())
{
// Disallow if the cursor is at the end of a paragraph and the document model
// node at this position is an outline node with folded content or the next node
// is an outline node with folded content.
if (rSh.IsEndPara())
{
SwNodeIndex aIdx(rSh.GetCursor()->GetPointNode());
if (aIdx.GetNode().IsTextNode())
{
bool bVisible = true;
aIdx.GetNode().GetTextNode()->GetAttrOutlineContentVisible(bVisible);
if (!bVisible)
break;
++aIdx;
if (aIdx.GetNode().IsTextNode())
{
bVisible = true;
aIdx.GetNode().GetTextNode()->GetAttrOutlineContentVisible(bVisible);
if (!bVisible)
break;
}
}
}
}
rSh.DelRight();
break;
case FN_BACKSPACE:
if (rSh.GetViewOptions()->IsShowOutlineContentVisibilityButton())
{
// Disallow if the cursor is at the start of a paragraph and the document model
// node at this position is an outline node with folded content or the previous
// node is a content node without a layout frame.
if (rSh.IsSttPara())
{
SwNodeIndex aIdx(rSh.GetCursor()->GetPointNode());
if (aIdx.GetNode().IsTextNode())
{
bool bVisible = true;
aIdx.GetNode().GetTextNode()->GetAttrOutlineContentVisible(bVisible);
if (!bVisible)
break;
--aIdx;
if (aIdx.GetNode().IsContentNode() &&
!aIdx.GetNode().GetContentNode()->getLayoutFrame(rSh.GetLayout()))
break;
}
}
}
if( rSh.IsNoNum() )
{
rSh.SttCursorMove();
bool bLeft = rSh.Left( SwCursorSkipMode::Chars, true, 1, false );
if( bLeft )
{
rSh.DelLeft();
}
else
// JP 15.07.96: If it no longer goes forward, cancel
// the numbering. For example at the beginning
// of a doc, frame, table or an area.
rSh.DelNumRules();
rSh.EndCursorMove();
break;
}
[[fallthrough]]; // otherwise call DelLeft
case FN_SHIFT_BACKSPACE:
rSh.DelLeft();
break;
default:
OSL_FAIL("wrong Dispatcher");
return;
}
rReq.Done();
//#i42732# - notify the edit window that from now on we do not use the input language
rTmpEditWin.SetUseInputLanguage( false );
}
void SwBaseShell::ExecClpbrd(SfxRequest &rReq)
{
// Attention: At risk of suicide!
// After paste, paste special the shell can be destroy.
SwWrtShell &rSh = GetShell();
sal_uInt16 nId = rReq.GetSlot();
bool bIgnore = false;
PasteTableType ePasteTable = PasteTableType::PASTE_DEFAULT;
switch( nId )
{
case SID_CUT:
case SID_COPY:
m_rView.GetEditWin().FlushInBuffer();
if ( rSh.HasSelection() )
{
rtl::Reference<SwTransferable> pTransfer = new SwTransferable( rSh );
if ( nId == SID_CUT && FlyProtectFlags::NONE == rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent) )
pTransfer->Cut();
else
{
const bool bLockedView = rSh.IsViewLocked();
rSh.LockView( true ); //lock visible section
pTransfer->Copy();
rSh.LockView( bLockedView );
}
break;
}
return;
case FN_PASTE_NESTED_TABLE:
case FN_TABLE_PASTE_ROW_BEFORE:
case FN_TABLE_PASTE_COL_BEFORE:
switch ( nId )
{
case FN_PASTE_NESTED_TABLE:
ePasteTable = PasteTableType::PASTE_TABLE;
break;
case FN_TABLE_PASTE_ROW_BEFORE:
ePasteTable = PasteTableType::PASTE_ROW;
break;
case FN_TABLE_PASTE_COL_BEFORE:
ePasteTable = PasteTableType::PASTE_COLUMN;
break;
default:
;
}
[[fallthrough]];
case SID_PASTE:
{
TransferableDataHelper aDataHelper(
TransferableDataHelper::CreateFromSystemClipboard( &rSh.GetView().GetEditWin() ) );
if( aDataHelper.GetXTransferable().is()
&& SwTransferable::IsPaste( rSh, aDataHelper ) )
{
// Temporary variables, because the shell could already be
// destroyed after the paste.
SwView* pView = &m_rView;
RndStdIds nAnchorType = RndStdIds::FLY_AT_PARA;
const SfxUInt16Item* pAnchorType = rReq.GetArg<SfxUInt16Item>(FN_PARAM_1);
if (pAnchorType)
nAnchorType = static_cast<RndStdIds>(pAnchorType->GetValue());
bool bIgnoreComments = false;
const SfxBoolItem* pIgnoreComments = rReq.GetArg<SfxBoolItem>(FN_PARAM_2);
if (pIgnoreComments)
bIgnoreComments = pIgnoreComments->GetValue();
SwTransferable::Paste(rSh, aDataHelper, nAnchorType, bIgnoreComments, ePasteTable);
if( rSh.IsFrameSelected() || rSh.IsObjSelected() )
rSh.EnterSelFrameMode();
pView->AttrChangedNotify(nullptr);
// Fold pasted outlines that have outline content visible attribute false
MakeAllOutlineContentTemporarilyVisible a(rSh.GetDoc());
}
else
return;
}
break;
case SID_CLIPBOARD_FORMAT_ITEMS:
{
const SfxItemSet* pArgs = rReq.GetArgs();
const SfxPoolItem* pFormat;
if( pArgs && SfxItemState::SET == pArgs->GetItemState( nId, false, &pFormat ) )
{
TransferableDataHelper aDataHelper(
TransferableDataHelper::CreateFromSystemClipboard(
&rSh.GetView().GetEditWin()) );
if( aDataHelper.GetXTransferable().is()
/*&& SwTransferable::IsPaste( rSh, aDataHelper )*/ )
{
// Temporary variables, because the shell could already be
// destroyed after the paste.
SwView* pView = &m_rView;
SwTransferable::PasteFormat( rSh, aDataHelper,
static_cast<SotClipboardFormatId>(static_cast<const SfxUInt32Item*>(pFormat)->GetValue()) );
//Done() has to be called before the shell has been removed
rReq.Done();
bIgnore = true;
if( rSh.IsFrameSelected() || rSh.IsObjSelected())
rSh.EnterSelFrameMode();
pView->AttrChangedNotify(nullptr);
// Fold pasted outlines that have outline content visible attribute false
MakeAllOutlineContentTemporarilyVisible a(rSh.GetDoc());
}
}
}
break;
case SID_PASTE_UNFORMATTED:
{
TransferableDataHelper aDataHelper(
TransferableDataHelper::CreateFromSystemClipboard( &rSh.GetView().GetEditWin()) );
if( aDataHelper.GetXTransferable().is()
&& SwTransferable::IsPaste( rSh, aDataHelper ) )
{
// Temporary variables, because the shell could already be
// destroyed after the paste.
SwView* pView = &m_rView;
rReq.Ignore();
bIgnore = true;
if(SwTransferable::PasteUnformatted( rSh, aDataHelper ))
{
SfxViewFrame& rViewFrame = pView->GetViewFrame();
uno::Reference< frame::XDispatchRecorder > xRecorder =
rViewFrame.GetBindings().GetRecorder();
if(xRecorder.is()) {
SfxRequest aReq(rViewFrame, SID_CLIPBOARD_FORMAT_ITEMS);
aReq.AppendItem( SfxUInt32Item( SID_CLIPBOARD_FORMAT_ITEMS, static_cast<sal_uInt32>(SotClipboardFormatId::STRING) ) );
aReq.Done();
}
}
if (rSh.IsFrameSelected() || rSh.IsObjSelected())
rSh.EnterSelFrameMode();
pView->AttrChangedNotify(nullptr);
// Fold pasted outlines that have outline content visible attribute false
MakeAllOutlineContentTemporarilyVisible a(rSh.GetDoc());
}
else
return;
}
break;
case SID_PASTE_SPECIAL:
{
std::shared_ptr<TransferableDataHelper> aDataHelper =
std::make_shared<TransferableDataHelper>(TransferableDataHelper::CreateFromSystemClipboard( &rSh.GetView().GetEditWin()));
if( aDataHelper->GetXTransferable().is()
&& SwTransferable::IsPaste( rSh, *aDataHelper )
&& !rSh.CursorInsideInputField() )
{
rReq.Ignore();
bIgnore = true;
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
VclPtr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( rReq.GetFrameWeld() ));
// Prepare the dialog
SwTransferable::PrePasteSpecial(rSh, *aDataHelper, pDlg);
pDlg->PreGetFormat(*aDataHelper);
pDlg->StartExecuteAsync([aDataHelper, pDlg, &rSh, this](sal_Int32 nResult){
if (nResult == RET_OK)
{
// Temporary variables, because the shell could already be
// destroyed after the paste.
SwView* pView = &m_rView;
bool bRet = false;
SotClipboardFormatId nFormatId = pDlg->GetFormatOnly();
if( nFormatId != SotClipboardFormatId::NONE )
bRet = SwTransferable::PasteFormat( rSh, *aDataHelper, nFormatId );
if (bRet)
{
SfxViewFrame& rViewFrame = pView->GetViewFrame();
uno::Reference< frame::XDispatchRecorder > xRecorder =
rViewFrame.GetBindings().GetRecorder();
if(xRecorder.is()) {
SfxRequest aReq(rViewFrame, SID_CLIPBOARD_FORMAT_ITEMS);
aReq.AppendItem( SfxUInt32Item( SID_CLIPBOARD_FORMAT_ITEMS, static_cast<sal_uInt32>(nFormatId) ) );
aReq.Done();
}
}
if (rSh.IsFrameSelected() || rSh.IsObjSelected())
rSh.EnterSelFrameMode();
pView->AttrChangedNotify(nullptr);
// Fold pasted outlines that have outline content visible attribute false
MakeAllOutlineContentTemporarilyVisible a(rSh.GetDoc());
}
pDlg->disposeOnce();
});
}
else
return;
}
break;
default:
OSL_FAIL("wrong Dispatcher");
return;
}
if(!bIgnore)
rReq.Done();
}
// ClipBoard state
void SwBaseShell::StateClpbrd(SfxItemSet &rSet)
{
SwWrtShell &rSh = GetShell();
SfxWhichIter aIter(rSet);
const bool bCopy = rSh.HasSelection();
sal_uInt16 nWhich = aIter.FirstWhich();
while(nWhich)
{
switch(nWhich)
{
case SID_CUT:
if( FlyProtectFlags::NONE != rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent ) )
{
rSet.DisableItem( nWhich );
break;
}
[[fallthrough]];
case SID_COPY:
if( !bCopy || GetObjectShell()->isContentExtractionLocked())
rSet.DisableItem( nWhich );
break;
case FN_PASTE_NESTED_TABLE:
case FN_TABLE_PASTE_ROW_BEFORE:
case FN_TABLE_PASTE_COL_BEFORE:
if( !rSh.IsCursorInTable()
|| !GetView().IsPasteSpecialAllowed()
|| rSh.CursorInsideInputField()
// disable if not a native Writer table and not a spreadsheet format
|| !GetView().IsPasteSpreadsheet(rSh.GetTableCopied()) )
{
rSet.DisableItem( nWhich );
}
break;
case SID_PASTE:
if( !GetView().IsPasteAllowed() )
{
rSet.DisableItem( nWhich );
}
break;
case SID_PASTE_SPECIAL:
if( !GetView().IsPasteSpecialAllowed()
|| rSh.CursorInsideInputField() )
{
rSet.DisableItem( nWhich );
}
break;
case SID_PASTE_UNFORMATTED:
if( !GetView().IsPasteSpecialAllowed() )
{
rSet.DisableItem( nWhich );
}
break;
case SID_CLIPBOARD_FORMAT_ITEMS:
{
TransferableDataHelper aDataHelper(
TransferableDataHelper::CreateFromSystemClipboard(
&rSh.GetView().GetEditWin()) );
SvxClipboardFormatItem aFormatItem( SID_CLIPBOARD_FORMAT_ITEMS );
SwTransferable::FillClipFormatItem( rSh, aDataHelper, aFormatItem );
rSet.Put( aFormatItem );
}
break;
}
nWhich = aIter.NextWhich();
}
}
// Perform undo
void SwBaseShell::ExecUndo(SfxRequest &rReq)
{
MakeAllOutlineContentTemporarilyVisible a(GetShell().GetDoc(), true);
SwWrtShell &rWrtShell = GetShell();
SwUndoId nUndoId(SwUndoId::EMPTY);
sal_uInt16 nId = rReq.GetSlot(), nCnt = 1;
const SfxItemSet* pArgs = rReq.GetArgs();
const SfxPoolItem* pItem;
if( pArgs && SfxItemState::SET == pArgs->GetItemState( nId, false, &pItem ))
nCnt = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
// Repair mode: allow undo/redo of all undo actions, even if access would
// be limited based on the view shell ID.
bool bRepair = false;
const SfxBoolItem* pRepairItem;
if (pArgs && (pRepairItem = pArgs->GetItemIfSet(SID_REPAIRPACKAGE, false)))
bRepair = pRepairItem->GetValue();
// #i106349#: save pointer: undo/redo may delete the shell, i.e., this!
SfxViewFrame& rViewFrame( GetView().GetViewFrame() );
IDocumentUndoRedo& rUndoRedo = rWrtShell.GetIDocumentUndoRedo();
bool bWasRepair = rUndoRedo.DoesRepair();
rUndoRedo.DoRepair(bRepair);
comphelper::ScopeGuard aGuard([&rUndoRedo, bWasRepair]()
{
rUndoRedo.DoRepair(bWasRepair);
});
switch( nId )
{
case SID_UNDO:
if (rUndoRedo.GetLastUndoInfo(nullptr, &nUndoId, &rWrtShell.GetView()))
{
for (SwViewShell& rShell : rWrtShell.GetRingContainer())
rShell.LockPaint(LockPaintReason::Undo);
sal_uInt16 nUndoOffset = 0;
if (comphelper::LibreOfficeKit::isActive() && !bRepair && nCnt == 1)
{
sw::UndoManager& rManager = rWrtShell.GetDoc()->GetUndoManager();
const SfxUndoAction* pAction = rManager.GetUndoAction();
SwView& rView = rWrtShell.GetView();
ViewShellId nViewShellId = rView.GetViewShellId();
sal_uInt16 nOffset = 0;
if (pAction->GetViewShellId() != nViewShellId
&& rManager.IsViewUndoActionIndependent(&rView, nOffset))
{
// Execute the undo with an offset: don't undo the top action, but an
// earlier one, since it's independent and that belongs to our view.
nUndoOffset += nOffset;
}
}
rWrtShell.Do(SwWrtShell::UNDO, nCnt, nUndoOffset);
for (SwViewShell& rShell : rWrtShell.GetRingContainer())
rShell.UnlockPaint();
// tdf#141613 FIXME: Disable redoing header/footer changes for now.
// The proper solution would be to write a SwUndoHeaderFooter class
// to represent the addition of a header or footer to the current page.
if (nUndoId == SwUndoId::HEADER_FOOTER)
rUndoRedo.ClearRedo();
}
break;
case SID_REDO:
if (rUndoRedo.GetFirstRedoInfo(nullptr, &nUndoId, &rWrtShell.GetView()))
{
for (SwViewShell& rShell : rWrtShell.GetRingContainer())
rShell.LockPaint(LockPaintReason::Redo);
rWrtShell.Do( SwWrtShell::REDO, nCnt );
for (SwViewShell& rShell : rWrtShell.GetRingContainer())
rShell.UnlockPaint();
}
break;
case SID_REPEAT:
rWrtShell.Do( SwWrtShell::REPEAT );
break;
default:
OSL_FAIL("wrong Dispatcher");
}
if (nUndoId == SwUndoId::CONFLICT)
{
rReq.SetReturnValue( SfxUInt32Item(nId, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
}
rViewFrame.GetBindings().InvalidateAll(false);
}
// State of undo
void SwBaseShell::StateUndo(SfxItemSet &rSet)
{
SwUndoId nUndoId(SwUndoId::EMPTY);
SwWrtShell &rSh = GetShell();
SfxWhichIter aIter(rSet);
sal_uInt16 nWhich = aIter.FirstWhich();
while(nWhich)
{
switch(nWhich)
{
case SID_UNDO:
{
if (rSh.GetLastUndoInfo(nullptr, &nUndoId, &rSh.GetView()))
{
rSet.Put( SfxStringItem(nWhich,
rSh.GetDoString(SwWrtShell::UNDO)));
}
else if (nUndoId == SwUndoId::CONFLICT)
{
rSet.Put( SfxUInt32Item(nWhich, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
}
else
rSet.DisableItem(nWhich);
break;
}
case SID_REDO:
{
if (rSh.GetFirstRedoInfo(nullptr, &nUndoId, &rSh.GetView()))
{
rSet.Put(SfxStringItem(nWhich,
rSh.GetDoString(SwWrtShell::REDO)));
}
else if (nUndoId == SwUndoId::CONFLICT)
{
rSet.Put( SfxInt32Item(nWhich, static_cast<sal_uInt32>(SID_REPAIRPACKAGE)) );
}
else
rSet.DisableItem(nWhich);
break;
}
case SID_REPEAT:
{ // Repeat is only possible if no REDO is possible - UI-Restriction
if ((!rSh.GetFirstRedoInfo(nullptr, nullptr)) &&
!rSh.IsSelFrameMode() &&
(SwUndoId::EMPTY != rSh.GetRepeatInfo(nullptr)))
{
rSet.Put(SfxStringItem(nWhich, rSh.GetRepeatString()));
}
else
rSet.DisableItem(nWhich);
break;
}
case SID_GETUNDOSTRINGS:
if (rSh.GetLastUndoInfo(nullptr, nullptr))
{
SfxStringListItem aStrLst( nWhich );
rSh.GetDoStrings( SwWrtShell::UNDO, aStrLst );
rSet.Put( aStrLst );
}
else
rSet.DisableItem( nWhich );
break;
case SID_GETREDOSTRINGS:
if (rSh.GetFirstRedoInfo(nullptr, nullptr))
{
SfxStringListItem aStrLst( nWhich );
rSh.GetDoStrings( SwWrtShell::REDO, aStrLst );
rSet.Put( aStrLst );
}
else
rSet.DisableItem( nWhich );
break;
}
nWhich = aIter.NextWhich();
}
}
namespace
{
/// Searches for the specified field type and field name prefix and update the matching fields to
/// have the provided new name and content.
bool UpdateFieldContents(SfxRequest& rReq, SwWrtShell& rWrtSh)
{
const SfxStringItem* pTypeName = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
if (!pTypeName || pTypeName->GetValue() != "SetRef")
{
// This is implemented so far only for reference marks.
return false;
}
const SfxStringItem* pNamePrefix = rReq.GetArg<SfxStringItem>(FN_PARAM_2);
if (!pNamePrefix)
{
return false;
}
const OUString& rNamePrefix = pNamePrefix->GetValue();
const SfxUnoAnyItem* pFields = rReq.GetArg<SfxUnoAnyItem>(FN_PARAM_3);
if (!pFields)
{
return false;
}
uno::Sequence<beans::PropertyValues> aFields;
pFields->GetValue() >>= aFields;
SwDoc* pDoc = rWrtSh.GetDoc();
pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::UPDATE_FIELDS, nullptr);
rWrtSh.StartAction();
std::vector<const SwFormatRefMark*> aRefMarks;
for (sal_uInt16 i = 0; i < pDoc->GetRefMarks(); ++i)
{
aRefMarks.push_back(pDoc->GetRefMark(i));
}
std::sort(aRefMarks.begin(), aRefMarks.end(),
[](const SwFormatRefMark* pMark1, const SwFormatRefMark* pMark2) -> bool {
const SwTextRefMark* pTextRefMark1 = pMark1->GetTextRefMark();
const SwTextRefMark* pTextRefMark2 = pMark2->GetTextRefMark();
SwPosition aPos1(pTextRefMark1->GetTextNode(), pTextRefMark1->GetStart());
SwPosition aPos2(pTextRefMark2->GetTextNode(), pTextRefMark2->GetStart());
return aPos1 < aPos2;
});
sal_uInt16 nFieldIndex = 0;
for (auto& pIntermediateRefMark : aRefMarks)
{
auto pRefMark = const_cast<SwFormatRefMark*>(pIntermediateRefMark);
if (!pRefMark->GetRefName().startsWith(rNamePrefix))
{
continue;
}
if (nFieldIndex >= aFields.getLength())
{
break;
}
comphelper::SequenceAsHashMap aMap(aFields[nFieldIndex++]);
auto aName = aMap["Name"].get<OUString>();
pRefMark->GetRefName() = aName;
OUString aContent = aMap["Content"].get<OUString>();
auto pTextRefMark = const_cast<SwTextRefMark*>(pRefMark->GetTextRefMark());
pTextRefMark->UpdateFieldContent(pDoc, rWrtSh, aContent);
}
rWrtSh.EndAction();
pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::UPDATE_FIELDS, nullptr);
return true;
}
/// Searches for the specified field type and field name prefix under cursor and update the matching
/// field to have the provided new name and content.
void UpdateFieldContent(SfxRequest& rReq, SwWrtShell& rWrtSh)
{
const SfxStringItem* pTypeName = rReq.GetArg<SfxStringItem>(FN_PARAM_1);
if (!pTypeName || pTypeName->GetValue() != "SetRef")
{
// This is implemented so far only for reference marks.
return;
}
const SfxStringItem* pNamePrefix = rReq.GetArg<SfxStringItem>(FN_PARAM_2);
if (!pNamePrefix)
{
return;
}
const OUString& rNamePrefix = pNamePrefix->GetValue();
const SfxUnoAnyItem* pField = rReq.GetArg<SfxUnoAnyItem>(FN_PARAM_3);
if (!pField)
{
return;
}
uno::Sequence<beans::PropertyValue> aField;
pField->GetValue() >>= aField;
SwPosition& rCursor = *rWrtSh.GetCursor()->GetPoint();
SwTextNode* pTextNode = rCursor.GetNode().GetTextNode();
std::vector<SwTextAttr*> aAttrs
= pTextNode->GetTextAttrsAt(rCursor.GetContentIndex(), RES_TXTATR_REFMARK);
if (aAttrs.empty())
{
return;
}
auto& rRefmark = const_cast<SwFormatRefMark&>(aAttrs[0]->GetRefMark());
if (!rRefmark.GetRefName().startsWith(rNamePrefix))
{
return;
}
SwDoc* pDoc = rWrtSh.GetDoc();
SwRewriter aRewriter;
aRewriter.AddRule(UndoArg1, rRefmark.GetRefName());
pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::UPDATE_FIELD, &aRewriter);
rWrtSh.StartAction();
comphelper::ScopeGuard g(
[&rWrtSh, &aRewriter]
{
rWrtSh.EndAction();
rWrtSh.GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::UPDATE_FIELD, &aRewriter);
});
comphelper::SequenceAsHashMap aMap(aField);
auto aName = aMap["Name"].get<OUString>();
rRefmark.GetRefName() = aName;
OUString aContent = aMap["Content"].get<OUString>();
auto pTextRefMark = const_cast<SwTextRefMark*>(rRefmark.GetTextRefMark());
pTextRefMark->UpdateFieldContent(pDoc, rWrtSh, aContent);
}
}
// Evaluate respectively dispatching the slot Id
void SwBaseShell::Execute(SfxRequest &rReq)
{
const SfxPoolItem *pItem;
SwWrtShell &rSh = GetShell();
const SfxItemSet* pArgs = rReq.GetArgs();
bool bMore = false;
sal_uInt16 nSlot = rReq.GetSlot();
switch(nSlot)
{
case FN_REPAGINATE:
{
Reference < XModel > xModel = GetView().GetDocShell()->GetModel();
auto pDoc = comphelper::getFromUnoTunnel<SwXTextDocument>(xModel);
pDoc->NotifyRefreshListeners();
rSh.CalcLayout();
}
break;
case FN_UPDATE_FIELDS:
{
if (UpdateFieldContents(rReq, rSh))
{
// Parameters indicated that the name / content of fields has to be updated to
// the provided values, don't do an actual fields update.
break;
}
rSh.UpdateDocStat();
rSh.EndAllTableBoxEdit();
rSh.SwViewShell::UpdateFields(true);
if( rSh.IsCursorInTable() )
{
if( !rSh.IsTableComplexForChart() )
SwTableFUNC( &rSh ).UpdateChart();
rSh.ClearTableBoxContent();
rSh.SaveTableBoxContent();
}
}
break;
case FN_UPDATE_FIELD:
{
UpdateFieldContent(rReq, rSh);
}
break;
case FN_UPDATE_CHARTS:
{
SwWait aWait( *m_rView.GetDocShell(), true );
rSh.UpdateAllCharts();
}
break;
case FN_UPDATE_ALL:
{
comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer
= GetObjectShell()->getEmbeddedObjectContainer();
rEmbeddedObjectContainer.setUserAllowsLinkUpdate(true);
SwView& rTempView = GetView();
rSh.EnterStdMode();
if( !rSh.GetLinkManager().GetLinks().empty() )
{
rSh.StartAllAction();
rSh.GetLinkManager().UpdateAllLinks( false, true, nullptr );
rSh.EndAllAction();
}
SfxDispatcher &rDis = *rTempView.GetViewFrame().GetDispatcher();
rDis.Execute( FN_UPDATE_FIELDS );
rDis.Execute( FN_UPDATE_TOX );
rDis.Execute( FN_UPDATE_CHARTS );
rSh.Reformat();
rSh.UpdateOleObjectPreviews();
}
break;
case FN_UPDATE_INPUTFIELDS:
rSh.UpdateInputFields();
break;
case FN_PREV_BOOKMARK:
rReq.SetReturnValue(SfxBoolItem( nSlot, rSh.GoPrevBookmark()));
break;
case FN_NEXT_BOOKMARK:
rReq.SetReturnValue(SfxBoolItem( nSlot, rSh.GoNextBookmark()));
break;
case FN_GOTO_NEXT_MARK:
case FN_GOTO_PREV_MARK:
{
SwFieldMgr aFieldMgr;
SwFieldType* pFieldType = aFieldMgr.GetFieldType(SwFieldIds::JumpEdit);
if (pFieldType)
{
if (rSh.IsSelFrameMode())
{
rSh.UnSelectFrame();
rSh.LeaveSelFrameMode();
}
if (rSh.HasMark())
{
SwMvContext aMvContext(&rSh);
if (rSh.IsCursorPtAtEnd())
rSh.SwapPam();
rSh.ClearMark();
rSh.EndSelect();
}
bool bRet = rSh.MoveFieldType( pFieldType, nSlot == FN_GOTO_NEXT_MARK );
SwField* pCurField = bRet ? rSh.GetCurField() : nullptr;
if (pCurField)
rSh.ClickToField(*pCurField, /*bExecHyperlinks=*/false);
rReq.SetReturnValue(SfxBoolItem( nSlot, bRet));
}
}
break;
case FN_START_DOC_DIRECT:
case FN_END_DOC_DIRECT:
{
if (rSh.IsSelFrameMode())
{
rSh.UnSelectFrame();
rSh.LeaveSelFrameMode();
}
rSh.EnterStdMode();
nSlot == FN_START_DOC_DIRECT ?
rSh.SttEndDoc(true) :
rSh.SttEndDoc(false);
}
break;
case FN_GOTO_PREV_OBJ:
case FN_GOTO_NEXT_OBJ:
{
bool bSuccess = rSh.GotoObj( nSlot == FN_GOTO_NEXT_OBJ );
rReq.SetReturnValue(SfxBoolItem(nSlot, bSuccess));
if (bSuccess && !rSh.IsSelFrameMode())
{
rSh.HideCursor();
rSh.EnterSelFrameMode();
GetView().AttrChangedNotify(nullptr);
}
}
break;
case SID_GALLERY_FORMATS:
{
const SvxGalleryItem* pGalleryItem = SfxItemSet::GetItem<SvxGalleryItem>(pArgs, SID_GALLERY_FORMATS, false);
if ( !pGalleryItem )
break;
const SelectionType nSelType = rSh.GetSelectionType();
sal_Int8 nGalleryItemType( pGalleryItem->GetType() );
if ( (!rSh.IsSelFrameMode() || nSelType & SelectionType::Graphic) &&
nGalleryItemType == css::gallery::GalleryItemType::GRAPHIC )
{
SwWait aWait( *m_rView.GetDocShell(), true );
OUString aGrfName, aFltName;
const Graphic aGrf( pGalleryItem->GetGraphic() );
if ( nSelType & SelectionType::Graphic )
rSh.ReRead( aGrfName, aFltName, &aGrf );
else
rSh.InsertGraphic( aGrfName, aFltName, aGrf );
GetView().GetEditWin().GrabFocus();
}
else if(!rSh.IsSelFrameMode() &&
nGalleryItemType == css::gallery::GalleryItemType::MEDIA )
{
const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, pGalleryItem->GetURL() );
GetView().GetViewFrame().GetDispatcher()->ExecuteList(
SID_INSERT_AVMEDIA, SfxCallMode::SYNCHRON,
{ &aMediaURLItem });
}
}
break;
case FN_PAGE_STYLE_SET_COLS:
{
if (pArgs)
{
// Determine the current PageDescriptor and fill the set with that.
const size_t nCurIdx = rSh.GetCurPageDesc();
SwPageDesc aPageDesc(rSh.GetPageDesc(nCurIdx));
SwFrameFormat &rFormat = aPageDesc.GetMaster();
SwFormatCol aFormatCol = rFormat.GetCol();
sal_uInt16 nCount;
if(SfxItemState::SET == pArgs->GetItemState(nSlot))
nCount = static_cast<const SfxUInt16Item &>(pArgs->Get(nSlot)).GetValue();
else
nCount = pArgs->Get(SID_ATTR_COLUMNS).GetValue();
sal_uInt16 nGutterWidth = DEF_GUTTER_WIDTH;
aFormatCol.Init(nCount ? nCount : 1, nGutterWidth, USHRT_MAX);
aFormatCol.SetWishWidth(USHRT_MAX);
aFormatCol.SetGutterWidth(nGutterWidth, USHRT_MAX);
rFormat.SetFormatAttr(aFormatCol);
rSh.ChgPageDesc(nCurIdx, aPageDesc);
}
else
GetView().GetViewFrame().GetDispatcher()->Execute(FN_FORMAT_PAGE_COLUMN_DLG);
}
break;
case FN_CONVERT_TABLE_TO_TEXT:
case FN_CONVERT_TEXT_TO_TABLE:
case FN_CONVERT_TEXT_TABLE:
{
sal_Unicode cDelim = 0;
bool bToTable = false;
if( nSlot == FN_CONVERT_TEXT_TO_TABLE ||
( nSlot == FN_CONVERT_TEXT_TABLE && nullptr == rSh.GetTableFormat() ))
bToTable = true;
SwInsertTableOptions aInsTableOpts( SwInsertTableFlags::All, 1 );
SwTableAutoFormat const* pTAFormat = nullptr;
std::unique_ptr<SwTableAutoFormatTable> pAutoFormatTable;
bool bDeleteFormat = true;
if(pArgs && SfxItemState::SET == pArgs->GetItemState( FN_PARAM_1, true, &pItem))
{
aInsTableOpts.mnInsMode = SwInsertTableFlags::NONE;
// Delimiter
OUString sDelim = static_cast< const SfxStringItem* >(pItem)->GetValue();
if(!sDelim.isEmpty())
cDelim = sDelim[0];
// AutoFormat
if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_2, true, &pItem))
{
OUString sAutoFormat = static_cast< const SfxStringItem* >(pItem)->GetValue();
pAutoFormatTable.reset(new SwTableAutoFormatTable);
pAutoFormatTable->Load();
for( sal_uInt16 i = 0, nCount = pAutoFormatTable->size(); i < nCount; i++ )
{
SwTableAutoFormat const*const pFormat = &(*pAutoFormatTable)[ i ];
if( pFormat->GetName() == sAutoFormat )
{
pTAFormat = pFormat;
bDeleteFormat = false;
break;
}
}
}
//WithHeader
if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_3, true, &pItem) &&
static_cast< const SfxBoolItem* >(pItem)->GetValue())
aInsTableOpts.mnInsMode |= SwInsertTableFlags::Headline;
// RepeatHeaderLines
if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_4, true, &pItem))
aInsTableOpts.mnRowsToRepeat =
o3tl::narrowing<sal_uInt16>(static_cast< const SfxInt16Item* >(pItem)->GetValue());
//WithBorder
if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_5, true, &pItem) &&
static_cast< const SfxBoolItem* >(pItem)->GetValue())
aInsTableOpts.mnInsMode |= SwInsertTableFlags::DefaultBorder;
//DontSplitTable
if(SfxItemState::SET == pArgs->GetItemState( FN_PARAM_6, true, &pItem) &&
!static_cast< const SfxBoolItem* >(pItem)->GetValue() )
aInsTableOpts.mnInsMode |= SwInsertTableFlags::SplitLayout;
}
else
{
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
ScopedVclPtr<AbstractSwConvertTableDlg> pDlg(pFact->CreateSwConvertTableDlg(GetView(), bToTable));
if( RET_OK == pDlg->Execute() )
{
pDlg->GetValues( cDelim, aInsTableOpts, pTAFormat );
}
}
if( cDelim )
{
//Shell change!
SwView& rSaveView = m_rView;
bool bInserted = false;
//recording:
SfxViewFrame& rViewFrame = GetView().GetViewFrame();
if (SfxRequest::HasMacroRecorder(rViewFrame))
{
SfxRequest aReq(rViewFrame, nSlot);
aReq.AppendItem( SfxStringItem( FN_PARAM_1, OUString(cDelim) ));
if(bToTable)
{
if(pTAFormat)
aReq.AppendItem( SfxStringItem( FN_PARAM_2, pTAFormat->GetName()));
aReq.AppendItem( SfxBoolItem ( FN_PARAM_3, bool(aInsTableOpts.mnInsMode & SwInsertTableFlags::Headline)));
aReq.AppendItem( SfxInt16Item( FN_PARAM_4, static_cast<short>(aInsTableOpts.mnRowsToRepeat) ));
aReq.AppendItem( SfxBoolItem ( FN_PARAM_5, bool(aInsTableOpts.mnInsMode & SwInsertTableFlags::DefaultBorder) ));
aReq.AppendItem( SfxBoolItem ( FN_PARAM_6, !(aInsTableOpts.mnInsMode & SwInsertTableFlags::SplitLayout)));
}
aReq.Done();
}
if( !bToTable )
rSh.TableToText( cDelim );
else
{
bInserted = rSh.TextToTable( aInsTableOpts, cDelim, pTAFormat );
}
rSh.EnterStdMode();
if( bInserted )
rSaveView.AutoCaption( TABLE_CAP );
}
if(bDeleteFormat)
delete pTAFormat;
}
break;
case SID_STYLE_WATERCAN:
case SID_STYLE_UPDATE_BY_EXAMPLE:
case SID_STYLE_NEW_BY_EXAMPLE:
case SID_STYLE_APPLY:
{
ShellMode eMode = GetView().GetShellMode();
if ( ShellMode::Draw != eMode &&
ShellMode::DrawForm != eMode &&
ShellMode::DrawText != eMode &&
ShellMode::Bezier != eMode )
{
// oj #107754#
if ( SID_STYLE_WATERCAN == nSlot )
{
const bool bLockedView = rSh.IsViewLocked();
rSh.LockView( true ); //lock visible section
GetView().GetDocShell()->ExecStyleSheet(rReq);
rSh.LockView( bLockedView );
}
else
// Will be recorded from the DocShell
GetView().GetDocShell()->ExecStyleSheet(rReq);
}
}
break;
case SID_CLASSIFICATION_APPLY:
{
GetView().GetDocShell()->Execute(rReq);
}
break;
case SID_CLASSIFICATION_DIALOG:
{
GetView().GetDocShell()->Execute(rReq);
}
break;
case SID_PARAGRAPH_SIGN_CLASSIFY_DLG:
{
GetView().GetDocShell()->Execute(rReq);
}
break;
case SID_WATERMARK:
{
GetView().GetDocShell()->Execute(rReq);
}
break;
case FN_ESCAPE:
GetView().ExecuteSlot(rReq);
break;
case SID_IMAP:
{
sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
SfxViewFrame& rVFrame = GetView().GetViewFrame();
rVFrame.ToggleChildWindow( nId );
rVFrame.GetBindings().Invalidate( SID_IMAP );
if ( rVFrame.HasChildWindow( nId ) && rSh.IsFrameSelected() )
lcl_UpdateIMapDlg( rSh );
}
break;
case SID_IMAP_EXEC:
{
SvxIMapDlg* pDlg = GetIMapDlg(GetView());
// Check, if the allocation is useful or allowed at all.
if ( rSh.IsFrameSelected() &&
pDlg->GetEditingObject() == rSh.GetIMapInventor() )
{
SfxItemSetFixed<RES_URL, RES_URL> aSet( rSh.GetAttrPool() );
rSh.GetFlyFrameAttr( aSet );
SwFormatURL aURL( aSet.Get( RES_URL ) );
aURL.SetMap( &pDlg->GetImageMap() );
aSet.Put( aURL );
rSh.SetFlyFrameAttr( aSet );
}
}
break;
case FN_SET_TRACKED_CHANGES_IN_TEXT:
case FN_SET_TRACKED_DELETIONS_IN_MARGIN:
case FN_SET_TRACKED_INSERTIONS_IN_MARGIN:
{
SwViewOption aViewOption = *rSh.GetViewOptions();
bool bAllInText = FN_SET_TRACKED_CHANGES_IN_TEXT == nSlot;
aViewOption.SetShowChangesInMargin( !bAllInText );
if ( !bAllInText )
aViewOption.SetShowChangesInMargin2( FN_SET_TRACKED_INSERTIONS_IN_MARGIN == nSlot );
rSh.ApplyViewOptions( aViewOption );
// tdf#140982 restore annotation ranges stored in temporary bookmarks
// (only remove temporary bookmarks during file saving to avoid possible
// conflict with lazy deletion of the bookmarks of the moved tracked deletions)
if ( bAllInText || FN_SET_TRACKED_INSERTIONS_IN_MARGIN == nSlot )
rSh.GetDoc()->getIDocumentMarkAccess()->restoreAnnotationMarks(false);
}
break;
case SID_CONTOUR_DLG:
{
sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
SfxViewFrame& rVFrame = GetView().GetViewFrame();
rVFrame.ToggleChildWindow( nId );
rVFrame.GetBindings().Invalidate( SID_CONTOUR_DLG );
SelectionType nSel = rSh.GetSelectionType();
if ( rVFrame.HasChildWindow( nId ) &&
(nSel & (SelectionType::Graphic|SelectionType::Ole)) )
{
lcl_UpdateContourDlg( rSh, nSel );
}
}
break;
case SID_CONTOUR_EXEC:
{
SvxContourDlg *pDlg = GetContourDlg(GetView());
// Check, if the allocation is useful or allowed at all.
SelectionType nSel = rSh.GetSelectionType();
if ( nSel & (SelectionType::Graphic|SelectionType::Ole) )
{
if (pDlg && pDlg->GetEditingObject() == rSh.GetIMapInventor())
{
rSh.StartAction();
SfxItemSetFixed<RES_SURROUND, RES_SURROUND> aSet( rSh.GetAttrPool() );
rSh.GetFlyFrameAttr( aSet );
SwFormatSurround aSur( aSet.Get( RES_SURROUND ) );
if ( !aSur.IsContour() )
{
aSur.SetContour( true );
if ( aSur.GetSurround() == css::text::WrapTextMode_NONE )
aSur.SetSurround( css::text::WrapTextMode_PARALLEL );
aSet.Put( aSur );
rSh.SetFlyFrameAttr( aSet );
}
const tools::PolyPolygon aPoly( pDlg->GetPolyPolygon() );
rSh.SetGraphicPolygon( &aPoly );
if ( pDlg->IsGraphicChanged() )
rSh.ReRead( OUString(), OUString(), &pDlg->GetGraphic());
rSh.EndAction();
}
}
}
break;
case FN_FRAME_TO_ANCHOR:
{
rSh.GotoFlyAnchor();
rSh.EnterStdMode();
rSh.CallChgLnk();
}
break;
case FN_TOOL_ANCHOR_PAGE:
case FN_TOOL_ANCHOR_PARAGRAPH:
case FN_TOOL_ANCHOR_CHAR:
case FN_TOOL_ANCHOR_AT_CHAR:
case FN_TOOL_ANCHOR_FRAME:
{
RndStdIds eSet = nSlot == FN_TOOL_ANCHOR_PAGE
? RndStdIds::FLY_AT_PAGE
: nSlot == FN_TOOL_ANCHOR_PARAGRAPH
? RndStdIds::FLY_AT_PARA
: nSlot == FN_TOOL_ANCHOR_FRAME
? RndStdIds::FLY_AT_FLY
: nSlot == FN_TOOL_ANCHOR_CHAR
? RndStdIds::FLY_AS_CHAR
: RndStdIds::FLY_AT_CHAR;
rSh.StartUndo();
if (rSh.IsObjSelected())
rSh.ChgAnchor(eSet);
else if (rSh.IsFrameSelected())
{
SwFormatAnchor aAnc(eSet, eSet == RndStdIds::FLY_AT_PAGE ? rSh.GetPhyPageNum() : 0);
SfxItemSet aSet(SwFEShell::makeItemSetFromFormatAnchor(GetPool(), aAnc));
rSh.SetFlyFrameAttr(aSet);
}
// if new anchor is 'as char' and it is a Math object and the usual
// pre-conditions are met then align the formula to the baseline of the text
const uno::Reference < embed::XEmbeddedObject > xObj( rSh.GetOleRef() );
const bool bDoMathBaselineAlignment = xObj.is() && SotExchange::IsMath( xObj->getClassID() )
&& RndStdIds::FLY_AS_CHAR == eSet && rSh.GetDoc()->getIDocumentSettingAccess().get( DocumentSettingId::MATH_BASELINE_ALIGNMENT );
if (bDoMathBaselineAlignment)
rSh.AlignFormulaToBaseline( xObj );
sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
if( nHtmlMode )
{
SfxItemSetFixed<RES_SURROUND, RES_HORI_ORIENT> aSet(GetPool());
rSh.GetFlyFrameAttr(aSet);
const SwFormatSurround& rSurround = aSet.Get(RES_SURROUND);
const SwFormatVertOrient& rVert = aSet.Get(RES_VERT_ORIENT);
const SwFormatHoriOrient& rHori = aSet.Get(RES_HORI_ORIENT);
sal_Int16 eVOrient = rVert.GetVertOrient();
sal_Int16 eHOrient = rHori.GetHoriOrient();
css::text::WrapTextMode eSurround = rSurround.GetSurround();
switch( eSet )
{
case RndStdIds::FLY_AT_FLY:
case RndStdIds::FLY_AT_PAGE:
//Wrap through, left or from left, top, from top
if(eSurround != css::text::WrapTextMode_THROUGH)
aSet.Put(SwFormatSurround(css::text::WrapTextMode_THROUGH));
if( eVOrient != text::VertOrientation::TOP && eVOrient != text::VertOrientation::NONE)
aSet.Put(SwFormatVertOrient(0, text::VertOrientation::TOP));
if (eHOrient != text::HoriOrientation::NONE && eHOrient != text::HoriOrientation::LEFT)
aSet.Put(SwFormatHoriOrient(0, text::HoriOrientation::LEFT));
break;
case RndStdIds::FLY_AT_PARA:
// left, from left, right, top, no wrap, wrap left and right
if (eSurround != css::text::WrapTextMode_LEFT && eSurround != css::text::WrapTextMode_RIGHT)
aSet.Put(SwFormatSurround(css::text::WrapTextMode_LEFT));
if( eVOrient != text::VertOrientation::TOP)
aSet.Put(SwFormatVertOrient(0, text::VertOrientation::TOP));
if (eHOrient != text::HoriOrientation::NONE && eHOrient != text::HoriOrientation::LEFT && eHOrient != text::HoriOrientation::RIGHT)
aSet.Put(SwFormatHoriOrient(0, text::HoriOrientation::LEFT));
break;
case RndStdIds::FLY_AT_CHAR:
// left, from left, right, top, wrap through
if(eSurround != css::text::WrapTextMode_THROUGH)
aSet.Put(SwFormatSurround(css::text::WrapTextMode_THROUGH));
if( eVOrient != text::VertOrientation::TOP)
aSet.Put(SwFormatVertOrient(0, text::VertOrientation::TOP));
if (eHOrient != text::HoriOrientation::NONE && eHOrient != text::HoriOrientation::LEFT && eHOrient != text::HoriOrientation::RIGHT)
aSet.Put(SwFormatHoriOrient(0, text::HoriOrientation::LEFT));
break;
default:
;
}
if( aSet.Count() )
rSh.SetFlyFrameAttr( aSet );
}
rSh.EndUndo();
GetView().GetViewFrame().GetBindings().Invalidate( SID_ANCHOR_MENU );
}
break;
case FN_FRAME_NOWRAP:
case FN_FRAME_WRAP:
case FN_FRAME_WRAP_IDEAL:
case FN_FRAME_WRAPTHRU:
case FN_FRAME_WRAPTHRU_TRANSP:
case FN_FRAME_WRAPTHRU_TOGGLE:
case FN_FRAME_WRAP_CONTOUR:
case FN_WRAP_ANCHOR_ONLY:
case FN_FRAME_WRAP_LEFT:
case FN_FRAME_WRAP_RIGHT:
SetWrapMode( nSlot );
break;
case FN_UPDATE_ALL_LINKS:
{
if( !rSh.GetLinkManager().GetLinks().empty() )
{
rSh.EnterStdMode();
rSh.StartAllAction();
rSh.GetLinkManager().UpdateAllLinks( false, false, nullptr );
rSh.EndAllAction();
}
}
break;
case FN_XFORMS_DESIGN_MODE:
if (pArgs && pArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET)
{
if (const SfxBoolItem* pBoolItem = dynamic_cast<const SfxBoolItem*>(pItem))
{
bool bDesignMode = pBoolItem->GetValue();
// set from design mode
OSL_ENSURE( GetView().GetFormShell() != nullptr, "form shell?" );
SfxRequest aReq(GetView().GetViewFrame(), SID_FM_DESIGN_MODE);
aReq.AppendItem( SfxBoolItem( SID_FM_DESIGN_MODE, bDesignMode ) );
GetView().GetFormShell()->Execute( aReq );
aReq.Done();
// also set suitable view options
SwViewOption aViewOption = *rSh.GetViewOptions();
aViewOption.SetFormView( ! bDesignMode );
rSh.ApplyViewOptions( aViewOption );
}
}
break;
default:
bMore = true;
}
if(!bMore || !pArgs)
return;
pItem = nullptr;
pArgs->GetItemState(GetPool().GetWhich(nSlot), false, &pItem);
if(!pItem)
return;
switch(nSlot)
{
case SID_ATTR_BRUSH:
case SID_ATTR_BORDER_SHADOW:
case RES_SHADOW:
{
rSh.StartAllAction();
// Table cell(s) selected?
if ( rSh.IsTableMode() )
{
SwFrameFormat *pFormat = rSh.GetTableFormat();
pFormat->SetFormatAttr( *pItem );
}
else if ( rSh.IsFrameSelected() )
{
// Set border attributes via Frame-Manager.
SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
aMgr.SetAttrSet( *pArgs );
aMgr.UpdateFlyFrame();
}
else
{
rSh.SetAttrSet( *pArgs );
}
rSh.EndAllAction();
}
break;
case FN_PAGE_STYLE_SET_LR_MARGIN:
case FN_PAGE_STYLE_SET_UL_MARGIN:
case FN_PAGE_STYLE_SET_NUMBER_FORMAT:
case FN_PAGE_STYLE_SET_PAPER_SIZE:
case FN_PAGE_STYLE_SET_PAPER_BIN:
{
OSL_FAIL("not implemented");
}
break;
case SID_ATTR_BORDER_OUTER:
{
// Table cell(s) selected?
if ( rSh.IsTableMode() )
{
// Set border attributes Get/SetTabBorders()
rSh.SetTabBorders(*pArgs);
}
else if ( rSh.IsFrameSelected() )
{
// Set border attributes via Frame-Manager.
SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
aMgr.SetAttrSet(*pArgs);
aMgr.UpdateFlyFrame();
}
else
{
// Set border attributes via shell quite normally.
rSh.SetAttrItem( *pItem );
}
}
break;
default:
OSL_FAIL("wrong Dispatcher");
}
}
// Here the state for SID_IMAP / SID_CONTOUR will be handled
// until the swapping of the graphic is finished.
IMPL_LINK_NOARG(SwBaseShell, GraphicArrivedHdl, SwCursorShell&, void)
{
SwWrtShell &rSh = GetShell();
if (CNT_GRF != rSh.SwEditShell::GetCntType())
return;
GraphicType const nGrfType(rSh.GetGraphicType());
if (GraphicType::NONE == nGrfType || m_aGrfUpdateSlots.empty())
return;
bool bProtect = FlyProtectFlags::NONE != rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent);
SfxViewFrame& rVFrame = GetView().GetViewFrame();
for( const auto nSlot : m_aGrfUpdateSlots )
{
bool bSetState = false;
bool bState = false;
switch( nSlot )
{
case SID_IMAP:
case SID_IMAP_EXEC:
{
sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
SfxChildWindow *pChildWindow = rVFrame.HasChildWindow(nId) ?
rVFrame.GetChildWindow(nId) : nullptr;
SvxIMapDlg *pDlg = pChildWindow ?
static_cast<SvxIMapDlg*>(pChildWindow->GetController().get()) : nullptr;
if( pDlg && ( SID_IMAP_EXEC == nSlot ||
( SID_IMAP == nSlot && !bProtect)) &&
pDlg->GetEditingObject() != rSh.GetIMapInventor())
lcl_UpdateIMapDlg( rSh );
if( !bProtect && SID_IMAP == nSlot )
{
bSetState = true;
bState = nullptr != pDlg;
}
}
break;
case SID_CONTOUR_DLG:
if( !bProtect )
{
sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
SfxChildWindow *pChildWindow = rVFrame.HasChildWindow(nId) ?
rVFrame.GetChildWindow(nId) : nullptr;
SvxIMapDlg *pDlg = pChildWindow ?
static_cast<SvxIMapDlg*>(pChildWindow->GetController().get()) : nullptr;
if( pDlg && pDlg->GetEditingObject() !=
rSh.GetIMapInventor() )
lcl_UpdateContourDlg( rSh, SelectionType::Graphic );
bSetState = true;
bState = nullptr != pDlg;
}
break;
case FN_FRAME_WRAP_CONTOUR:
if( !bProtect )
{
SfxItemSetFixed<RES_SURROUND, RES_SURROUND> aSet(GetPool());
rSh.GetFlyFrameAttr(aSet);
const SwFormatSurround& rWrap = aSet.Get(RES_SURROUND);
bSetState = true;
bState = rWrap.IsContour();
}
break;
case SID_GRFFILTER:
case SID_GRFFILTER_INVERT:
case SID_GRFFILTER_SMOOTH:
case SID_GRFFILTER_SHARPEN:
case SID_GRFFILTER_REMOVENOISE:
case SID_GRFFILTER_SOBEL:
case SID_GRFFILTER_MOSAIC:
case SID_GRFFILTER_EMBOSS:
case SID_GRFFILTER_POSTER:
case SID_GRFFILTER_POPART:
case SID_GRFFILTER_SEPIA:
case SID_GRFFILTER_SOLARIZE:
bSetState = bState = GraphicType::Bitmap == nGrfType;
break;
}
if( bSetState )
{
SfxBoolItem aBool( nSlot, bState );
if( m_pGetStateSet )
m_pGetStateSet->Put( aBool );
else
rVFrame.GetBindings().SetState( aBool );
}
}
m_aGrfUpdateSlots.clear();
}
void SwBaseShell::GetState( SfxItemSet &rSet )
{
SwWrtShell &rSh = GetShell();
SfxViewFrame& rVFrame = GetView().GetViewFrame();
SfxWhichIter aIter( rSet );
sal_uInt16 nWhich = aIter.FirstWhich();
m_pGetStateSet = &rSet;
while ( nWhich )
{
switch ( nWhich )
{
case SID_GALLERY_FORMATS:
if ( rSh.IsObjSelected() ||
(rSh.IsSelFrameMode() &&
!(rSh.GetSelectionType() & SelectionType::Graphic)) )
rSet.DisableItem( nWhich );
break;
case SID_GALLERY_ENABLE_ADDCOPY:
// #108230# allow copy from gallery in Writer AND Writer/Web!
rSet.Put( SfxBoolItem( SID_GALLERY_ENABLE_ADDCOPY, true ) );
break;
case FN_EDIT_REGION:
if( !rSh.IsAnySectionInDoc() )
rSet.DisableItem(nWhich);
break;
case FN_EDIT_CURRENT_REGION:
//tdf#112808 if cursor is in an index, don't show the edit section.
if( !rSh.GetCurrSection() ||
(rSh.GetCurrSection()->GetType() != SectionType::Content &&
rSh.GetCurrSection()->GetType() != SectionType::FileLink ))
{
rSet.DisableItem(nWhich);
}
break;
case FN_INSERT_REGION:
if( rSh.CursorInsideInputField()
|| rSh.IsSelFrameMode()
|| !rSh.IsInsRegionAvailable() )
{
rSet.DisableItem( nWhich );
}
break;
case FN_CONVERT_TABLE_TO_TEXT:
{
FrameTypeFlags eFrameType = rSh.GetFrameType(nullptr,true);
if( (eFrameType & FrameTypeFlags::FOOTNOTE) ||
!rSh.GetTableFormat() )
rSet.DisableItem( nWhich );
}
break;
case FN_CONVERT_TEXT_TO_TABLE:
{
FrameTypeFlags eFrameType = rSh.GetFrameType(nullptr,true);
if( (eFrameType & FrameTypeFlags::FOOTNOTE) ||
!rSh.IsTextToTableAvailable() )
rSet.DisableItem( nWhich );
}
break;
case FN_CONVERT_TEXT_TABLE:
{
FrameTypeFlags eFrameType = rSh.GetFrameType(nullptr,true);
if( (eFrameType & FrameTypeFlags::FOOTNOTE) ||
(!rSh.GetTableFormat() && !rSh.IsTextToTableAvailable() ) )
rSet.DisableItem( nWhich );
}
break;
case RES_SHADOW:
{
SfxItemSetFixed<RES_SHADOW, RES_SHADOW> aSet( rSh.GetAttrPool());
// Table cell(s) selected?
if ( rSh.IsTableMode() )
{
SwFrameFormat *pFormat = rSh.GetTableFormat();
aSet.Put(pFormat->GetFormatAttr( nWhich ));
}
else if( rSh.IsFrameSelected() )
{
SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
aSet.Put( aMgr.GetAttrSet() );
}
else
rSh.GetCurAttr( aSet );
const SvxShadowItem& rShItem = static_cast<const SvxShadowItem&>(aSet.Get(nWhich));
rSet.Put(rShItem);
}
break;
case SID_IMAP:
{
// #i59688#
// Improve efficiency:
// If selected object is protected, item has to disabled.
const bool bProtect = FlyProtectFlags::NONE != rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent);
if ( bProtect )
{
rSet.DisableItem( nWhich );
}
else
{
const sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
const bool bHas = rVFrame.HasChildWindow( nId );
const bool bFrameSel = rSh.IsFrameSelected();
const bool bIsGraphicSelection =
rSh.GetSelectionType() == SelectionType::Graphic;
// #i59688#
// Avoid unnecessary loading of selected graphic.
// The graphic is only needed, if the dialog is open.
// If the swapping of the graphic is finished, the status
// must be determined asynchronously, until this the slot
// will be disabled.
if ( bHas && bIsGraphicSelection && rSh.IsLinkedGrfSwapOut() )
{
if( AddGrfUpdateSlot( nWhich ))
rSh.GetGraphic(false); // start the loading
}
else
{
if ( !bHas &&
( !bFrameSel ||
( bIsGraphicSelection &&
rSh.GetGraphicType() == GraphicType::NONE ) ) )
{
rSet.DisableItem( nWhich );
}
else
{
SfxBoolItem aBool(nWhich, bHas);
if ( bHas && bFrameSel )
lcl_UpdateIMapDlg( rSh );
rSet.Put(aBool);
}
}
}
}
break;
case SID_IMAP_EXEC:
{
bool bDisable = false;
if( !rSh.IsFrameSelected())
bDisable = true;
sal_uInt16 nId = SvxIMapDlgChildWindow::GetChildWindowId();
if(!bDisable && rVFrame.HasChildWindow( nId ))
{
if(rSh.GetSelectionType() == SelectionType::Graphic
&& rSh.IsLinkedGrfSwapOut())
{
if( AddGrfUpdateSlot( nWhich ))
rSh.GetGraphic(false); // start the loading
}
else
{
SvxIMapDlg *pDlg = GetIMapDlg(GetView());
if (pDlg && pDlg->GetEditingObject() != rSh.GetIMapInventor())
lcl_UpdateIMapDlg( rSh );
}
}
rSet.Put(SfxBoolItem(nWhich, bDisable));
}
break;
case FN_BACKSPACE:
case SID_DELETE:
if ( ( rSh.HasReadonlySel() && !rSh.CursorInsideInputField() )
|| rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE )
{
rSet.DisableItem( nWhich );
}
break;
case SID_CONTOUR_DLG:
{
bool bParentCntProt = FlyProtectFlags::NONE != rSh.IsSelObjProtected(FlyProtectFlags::Content|FlyProtectFlags::Parent );
if( bParentCntProt || 0 != (HTMLMODE_ON & ::GetHtmlMode(
GetView().GetDocShell() )) )
rSet.DisableItem( nWhich );
else
{
sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
bool bHas = GetView().GetViewFrame().HasChildWindow( nId );
SelectionType nSel = rSh.GetSelectionType();
bool bOk(nSel & (SelectionType::Graphic|SelectionType::Ole));
bool bDisable = false;
if( !bHas && !bOk )
bDisable = true;
// #i59688#
// Avoid unnecessary loading of selected graphic.
// The graphic is only needed, if the dialog is open.
// If the swapping of the graphic is finished, the status
// must be determined asynchronously, until this the slot
// will be disabled.
else if ( bHas && (nSel & SelectionType::Graphic) &&
rSh.IsLinkedGrfSwapOut() )
{
if( AddGrfUpdateSlot( nWhich ))
rSh.GetGraphic(false); // start the loading
// #i75481#
bDisable = true;
}
else if( bHas && bOk )
bDisable = !lcl_UpdateContourDlg( rSh, nSel );
else if( bOk )
{
// #i75481#
// apply fix #i59688# only for selected graphics
if ( nSel & SelectionType::Graphic )
bDisable = GraphicType::NONE == rSh.GetGraphicType();
else
bDisable = GraphicType::NONE == rSh.GetIMapGraphic().GetType();
}
if( bDisable )
rSet.DisableItem( nWhich );
else
rSet.Put( SfxBoolItem(nWhich, bHas) );
}
}
break;
case SID_CONTOUR_EXEC:
{
bool bDisable = false;
SelectionType nSel = rSh.GetSelectionType();
if( !(nSel & (SelectionType::Graphic|SelectionType::Ole)) )
bDisable = true;
sal_uInt16 nId = SvxContourDlgChildWindow::GetChildWindowId();
if( !bDisable && GetView().GetViewFrame().HasChildWindow( nId ))
{
SvxContourDlg *pDlg = GetContourDlg(GetView());
if (pDlg && pDlg->GetEditingObject() != rSh.GetIMapInventor())
bDisable = true;
}
rSet.Put(SfxBoolItem(nWhich, bDisable));
}
break;
case SID_ANCHOR_MENU:
case FN_TOOL_ANCHOR_PAGE:
case FN_TOOL_ANCHOR_PARAGRAPH:
case FN_TOOL_ANCHOR_CHAR:
case FN_TOOL_ANCHOR_AT_CHAR:
case FN_TOOL_ANCHOR_FRAME:
{
bool bObj = 0 != rSh.IsObjSelected();
bool bParentCntProt = rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE;
if( !bParentCntProt && (bObj || rSh.IsFrameSelected()))
{
SfxItemSetFixed<RES_ANCHOR, RES_ANCHOR> aSet(GetPool());
if(bObj)
rSh.GetObjAttr(aSet);
else
rSh.GetFlyFrameAttr(aSet);
RndStdIds eSet = aSet.Get(RES_ANCHOR).GetAnchorId();
const bool bSet =
((nWhich == FN_TOOL_ANCHOR_PAGE) &&
(eSet == RndStdIds::FLY_AT_PAGE))
|| ((nWhich == FN_TOOL_ANCHOR_PARAGRAPH) &&
(eSet == RndStdIds::FLY_AT_PARA))
|| ((nWhich == FN_TOOL_ANCHOR_FRAME) &&
(eSet == RndStdIds::FLY_AT_FLY))
|| ((nWhich == FN_TOOL_ANCHOR_AT_CHAR) &&
(eSet == RndStdIds::FLY_AT_CHAR))
|| ((nWhich == FN_TOOL_ANCHOR_CHAR) &&
(eSet == RndStdIds::FLY_AS_CHAR));
if( nWhich == FN_TOOL_ANCHOR_FRAME && !rSh.IsFlyInFly() )
rSet.DisableItem(nWhich);
else if(nWhich != SID_ANCHOR_MENU)
rSet.Put(SfxBoolItem(nWhich, bSet));
if (comphelper::LibreOfficeKit::isActive())
{
if (nWhich == FN_TOOL_ANCHOR_PAGE || nWhich == FN_TOOL_ANCHOR_FRAME)
{
rSet.DisableItem(nWhich);
}
}
}
else
rSet.DisableItem( nWhich );
}
break;
case FN_FRAME_NOWRAP:
case FN_FRAME_WRAP:
case FN_FRAME_WRAP_IDEAL:
case FN_FRAME_WRAPTHRU:
case FN_FRAME_WRAPTHRU_TRANSP:
case FN_FRAME_WRAPTHRU_TOGGLE:
case FN_FRAME_WRAP_CONTOUR:
case FN_WRAP_ANCHOR_ONLY:
case FN_FRAME_WRAP_LEFT:
case FN_FRAME_WRAP_RIGHT:
{
bool bObj = 0 != rSh.IsObjSelected();
bool bParentCntProt = rSh.IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE;
if( !bParentCntProt && (bObj || rSh.IsFrameSelected()))
{
SfxItemSetFixed<RES_OPAQUE, RES_ANCHOR> aSet(GetPool());
RndStdIds nAnchorType;
if(bObj)
{
rSh.GetObjAttr(aSet);
nAnchorType = rSh.GetAnchorId();
}
else
{
rSh.GetFlyFrameAttr(aSet);
nAnchorType = aSet.Get(RES_ANCHOR).GetAnchorId();
}
const SwFormatSurround& rWrap = aSet.Get(RES_SURROUND);
const SvxOpaqueItem& rOpaque = aSet.Get(RES_OPAQUE);
bool bOpaque = rOpaque.GetValue();
css::text::WrapTextMode nSurround = rWrap.GetSurround();
bool bSet = false;
bool bDisable =
(nAnchorType == RndStdIds::UNKNOWN) || (nAnchorType == RndStdIds::FLY_AS_CHAR);
const bool bHtmlMode =
0 != ::GetHtmlMode(GetView().GetDocShell());
switch( nWhich )
{
case FN_FRAME_NOWRAP:
bDisable |=
( (nAnchorType != RndStdIds::FLY_AT_PARA)
&& (nAnchorType != RndStdIds::FLY_AT_CHAR)
&& (nAnchorType != RndStdIds::FLY_AT_PAGE));
bSet = nSurround == css::text::WrapTextMode_NONE;
break;
case FN_FRAME_WRAP:
bDisable |= bHtmlMode;
bSet = nSurround == css::text::WrapTextMode_PARALLEL;
break;
case FN_FRAME_WRAP_IDEAL:
bDisable |= bHtmlMode;
bSet = nSurround == css::text::WrapTextMode_DYNAMIC;
break;
case FN_FRAME_WRAPTHRU:
bDisable |= (bHtmlMode ||
( (nAnchorType != RndStdIds::FLY_AT_PARA)
&& (nAnchorType != RndStdIds::FLY_AT_CHAR)
&& (nAnchorType != RndStdIds::FLY_AT_PAGE)));
if(bObj)
bSet = nSurround == css::text::WrapTextMode_THROUGH && rSh.GetLayerId();
else
bSet = nSurround == css::text::WrapTextMode_THROUGH && bOpaque;
break;
case FN_FRAME_WRAPTHRU_TRANSP:
case FN_FRAME_WRAPTHRU_TOGGLE:
bDisable |= bHtmlMode;
if(bObj)
bSet = nSurround == css::text::WrapTextMode_THROUGH && !rSh.GetLayerId();
else
bSet = nSurround == css::text::WrapTextMode_THROUGH && !bOpaque;
break;
case FN_FRAME_WRAP_CONTOUR:
bDisable |= bHtmlMode;
//no contour available when no wrap or wrap through is set
bDisable |= (nSurround == css::text::WrapTextMode_NONE || nSurround == css::text::WrapTextMode_THROUGH);
if( !bDisable )
{
SelectionType nSel = rSh.GetSelectionType();
if( (nSel & SelectionType::Graphic) &&
rSh.IsLinkedGrfSwapOut())
{
if( AddGrfUpdateSlot( nWhich ))
rSh.GetGraphic(false); // start the loading
}
else if( rSh.IsFrameSelected() )
{
// #i102253# applied patch from OD (see task)
bDisable =
nSel & SelectionType::Frame ||
GraphicType::NONE == rSh.GetIMapGraphic().GetType();
}
}
bSet = !bDisable && rWrap.IsContour();
break;
case FN_WRAP_ANCHOR_ONLY:
bDisable |= (bHtmlMode ||
(nAnchorType != RndStdIds::FLY_AT_PARA));
bSet = rWrap.IsAnchorOnly();
break;
case FN_FRAME_WRAP_LEFT:
bSet = nSurround == css::text::WrapTextMode_LEFT;
break;
case FN_FRAME_WRAP_RIGHT:
bSet = nSurround == css::text::WrapTextMode_RIGHT;
break;
}
if(bDisable)
rSet.DisableItem(nWhich);
else
rSet.Put(SfxBoolItem(nWhich, bSet));
}
else
rSet.DisableItem(nWhich);
}
break;
case FN_UPDATE_CHARTS:
if( !rSh.HasCharts() )
rSet.DisableItem( nWhich );
break;
case FN_UPDATE_ALL_LINKS:
if ( rSh.GetLinkManager().GetLinks().empty() )
rSet.DisableItem(nWhich);
break;
case FN_XFORMS_DESIGN_MODE:
// enable if in XForms document
if( rSh.GetDoc()->isXForms() )
{
// determine current state from view options
bool bValue = ! rSh.GetViewOptions()->IsFormView();
rSet.Put( SfxBoolItem( nWhich, bValue ) );
}
else
rSet.Put( SfxVisibilityItem( nWhich, false ) );
break;
case SID_GRAPHIC_SIZE_CHECK:
{
sal_Int32 nDPI = rSh.GetDoc()->getIDocumentSettingAccess().getImagePreferredDPI();
if (nDPI <= 0)
rSet.DisableItem(nWhich);
}
break;
case SID_THEME_DIALOG:
{
bool bDisable = true;
auto* pDocument = rSh.GetDoc();
auto* pDocumentShell = pDocument->GetDocShell();
if (pDocumentShell)
{
SdrModel* pModel = pDocument->getIDocumentDrawModelAccess().GetDrawModel();
if (pModel)
{
auto const& pTheme = pModel->getTheme();
if (pTheme)
bDisable = false;
}
}
if (bDisable)
rSet.DisableItem(nWhich);
}
break;
}
nWhich = aIter.NextWhich();
}
m_pGetStateSet = nullptr;
}
// Disable the slots with this status method
void SwBaseShell::StateDisableItems( SfxItemSet &rSet )
{
SfxWhichIter aIter(rSet);
sal_uInt16 nWhich = aIter.FirstWhich();
while (nWhich)
{
rSet.DisableItem( nWhich );
nWhich = aIter.NextWhich();
}
}
// Disable the slots with this status method
void SwBaseShell::StateStyle( SfxItemSet &rSet )
{
bool bParentCntProt = GetShell().IsSelObjProtected( FlyProtectFlags::Content|FlyProtectFlags::Parent ) != FlyProtectFlags::NONE;
ShellMode eMode = GetView().GetShellMode();
if ( bParentCntProt ||
ShellMode::Draw == eMode ||
ShellMode::DrawForm == eMode ||
ShellMode::DrawText == eMode ||
ShellMode::Bezier == eMode )
{
SfxWhichIter aIter( rSet );
sal_uInt16 nWhich = aIter.FirstWhich();
while ( nWhich )
{
rSet.DisableItem( nWhich );
nWhich = aIter.NextWhich();
}
}
else
GetView().GetDocShell()->StateStyleSheet(rSet, &GetShell());
}
void SwBaseShell::SetWrapMode( sal_uInt16 nSlot )
{
SwWrtShell &rSh = GetShell();
bool bObj = 0 != rSh.IsObjSelected();
if( !bObj && !rSh.IsFrameSelected())
return;
SfxItemSetFixed<RES_OPAQUE, RES_SURROUND> aSet(GetPool());
if(bObj)
rSh.GetObjAttr(aSet);
else
rSh.GetFlyFrameAttr(aSet);
SwFormatSurround aWrap( aSet.Get(RES_SURROUND) );
css::text::WrapTextMode nOldSurround(aWrap.GetSurround());
css::text::WrapTextMode nSurround = css::text::WrapTextMode_PARALLEL;
switch (nSlot)
{
case FN_FRAME_NOWRAP:
nSurround = css::text::WrapTextMode_NONE;
if (aWrap.IsContour())
aWrap.SetContour(false);
break;
case FN_FRAME_WRAP_IDEAL:
nSurround = css::text::WrapTextMode_DYNAMIC;
break;
case FN_WRAP_ANCHOR_ONLY:
aWrap.SetAnchorOnly(!aWrap.IsAnchorOnly());
// keep previous wrapping
// switch to wrap css::text::WrapTextMode_PARALLEL, if previous wrap is css::text::WrapTextMode_NONE
if ( nOldSurround != css::text::WrapTextMode_NONE )
{
nSurround = nOldSurround;
}
break;
case FN_FRAME_WRAP_CONTOUR:
aWrap.SetContour(!aWrap.IsContour());
// Contour is meaningless in no-wrap or wrap-through context. Otherwise keep existing wrap.
if ( !aWrap.IsContour() ||
( nOldSurround != css::text::WrapTextMode_NONE &&
nOldSurround != css::text::WrapTextMode_THROUGH ) )
{
nSurround = nOldSurround;
}
break;
case FN_FRAME_WRAPTHRU_TRANSP:
case FN_FRAME_WRAPTHRU_TOGGLE:
if (aWrap.IsContour())
aWrap.SetContour(false);
[[fallthrough]];
case FN_FRAME_WRAPTHRU:
nSurround = css::text::WrapTextMode_THROUGH;
break;
case FN_FRAME_WRAP_LEFT:
nSurround = css::text::WrapTextMode_LEFT;
break;
case FN_FRAME_WRAP_RIGHT:
nSurround = css::text::WrapTextMode_RIGHT;
break;
default:
break;
}
aWrap.SetSurround(nSurround);
if (nSlot != FN_FRAME_WRAP_CONTOUR)
{
// Defaulting the contour wrap on draw objects.
if (bObj && nOldSurround != nSurround &&
(nOldSurround == css::text::WrapTextMode_NONE || nOldSurround == css::text::WrapTextMode_THROUGH))
{
aWrap.SetContour(true);
}
}
aSet.Put( aWrap );
bool bOpaque = nSlot != FN_FRAME_WRAPTHRU_TRANSP && nSlot != FN_FRAME_WRAPTHRU_TOGGLE;
if( nSlot == FN_FRAME_WRAPTHRU_TOGGLE )
{
if( bObj )
bOpaque = !rSh.GetLayerId();
else
{
const SvxOpaqueItem& aOpaque( aSet.Get(RES_OPAQUE) );
bOpaque = !aOpaque.GetValue();
}
}
aSet.Put(SvxOpaqueItem(RES_OPAQUE, bOpaque ));
if(bObj)
{
rSh.SetObjAttr(aSet);
if ( bOpaque )
rSh.SelectionToHeaven();
else
rSh.SelectionToHell();
}
else
rSh.SetFlyFrameAttr(aSet);
}
//Force update of the status line
void SwBaseShell::SetFrameMode(FlyMode eMode, SwWrtShell *pSh )
{
s_eFrameMode = eMode;
SfxBindings &rBnd = pSh->GetView().GetViewFrame().GetBindings();
if( eMode == FLY_DRAG || pSh->IsFrameSelected() || pSh->IsObjSelected() )
{
const SfxPointItem aTmp1( SID_ATTR_POSITION, pSh->GetAnchorObjDiff());
const SvxSizeItem aTmp2( SID_ATTR_SIZE, pSh->GetObjSize());
rBnd.SetState( aTmp1 );
rBnd.SetState( aTmp2 );
}
else if( eMode == FLY_DRAG_END )
{
static sal_uInt16 aInval[] =
{
SID_ATTR_POSITION, SID_ATTR_SIZE, 0
};
rBnd.Invalidate(aInval);
}
}
SwBaseShell::SwBaseShell(SwView& rVw) :
SfxShell( &rVw ),
m_rView(rVw),
m_pGetStateSet(nullptr)
{
SwWrtShell& rWrtSh = m_rView.GetWrtShell();
SetPool(&rWrtSh.GetAttrPool());
SetName("Base");
rWrtSh.SetGrfArrivedLnk( LINK( this, SwBaseShell, GraphicArrivedHdl));
}
SwBaseShell::~SwBaseShell()
{
if( m_rView.GetCurShell() == this )
m_rView.ResetSubShell();
Link<SwCursorShell&,void> aTmp( LINK( this, SwBaseShell, GraphicArrivedHdl));
if( aTmp == m_rView.GetWrtShell().GetGrfArrivedLnk() )
m_rView.GetWrtShell().SetGrfArrivedLnk( Link<SwCursorShell&,void>() );
}
void SwBaseShell::ExecTextCtrl( SfxRequest& rReq )
{
const SfxItemSet *pArgs = rReq.GetArgs();
const sal_uInt16 nSlot = rReq.GetSlot();
if( pArgs)
{
SwWrtShell &rSh = GetShell();
std::unique_ptr<SvxScriptSetItem> pSSetItem;
SfxItemPool& rPool = rSh.GetAttrPool();
sal_uInt16 nWhich = rPool.GetWhich( nSlot );
SvtScriptType nScripts = SvtScriptType::LATIN | SvtScriptType::ASIAN | SvtScriptType::COMPLEX;
SfxItemSetFixed<RES_CHRATR_FONTSIZE, RES_CHRATR_FONTSIZE,
RES_CHRATR_CJK_FONTSIZE, RES_CHRATR_CJK_FONTSIZE,
RES_CHRATR_CTL_FONTSIZE, RES_CHRATR_CTL_FONTSIZE>
aHeightSet( GetPool() );
switch( nSlot )
{
case SID_ATTR_CHAR_FONT:
{
nScripts = rSh.GetScriptType();
// #i42732# input language should be preferred over
// current cursor position to detect script type
if(!rSh.HasSelection())
{
LanguageType nInputLang = GetView().GetEditWin().GetInputLanguage();
if(nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
nScripts = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
}
[[fallthrough]];
}
case SID_ATTR_CHAR_POSTURE:
case SID_ATTR_CHAR_WEIGHT:
{
pSSetItem.reset(new SvxScriptSetItem( nSlot, rPool ));
pSSetItem->PutItemForScriptType( nScripts, pArgs->Get( nWhich ));
pArgs = &pSSetItem->GetItemSet();
}
break;
case SID_ATTR_CHAR_FONTHEIGHT:
{
if(rSh.HasSelection())
{
pSSetItem.reset(new SvxScriptSetItem( nSlot, rPool ));
pSSetItem->PutItemForScriptType( nScripts, pArgs->Get( nWhich ));
pArgs = &pSSetItem->GetItemSet();
}
else
{
nScripts = rSh.GetScriptType();
LanguageType nInputLang = GetView().GetEditWin().GetInputLanguage();
if(nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
nScripts = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
sal_uInt32 nHeight = static_cast< const SvxFontHeightItem& >(pArgs->Get( nWhich )).GetHeight();
SwStdFontConfig* pStdFont = SW_MOD()->GetStdFontConfig();
SfxItemSetFixed<RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE>
aLangSet( GetPool() );
rSh.GetCurAttr( aLangSet );
sal_Int32 nWesternSize =
pStdFont->GetFontHeight(FONT_STANDARD, FONT_GROUP_DEFAULT,
aLangSet.Get( RES_CHRATR_LANGUAGE).GetLanguage());
sal_Int32 nCJKSize =
pStdFont->GetFontHeight(FONT_STANDARD, FONT_GROUP_CJK,
aLangSet.Get( RES_CHRATR_CJK_LANGUAGE).GetLanguage());
sal_Int32 nCTLSize =
pStdFont->GetFontHeight(FONT_STANDARD, FONT_GROUP_CTL,
aLangSet.Get( RES_CHRATR_CTL_LANGUAGE).GetLanguage());
switch(nScripts)
{
case SvtScriptType::LATIN:
nCJKSize = nHeight * nCJKSize / nWesternSize;
nCTLSize = nHeight * nCTLSize / nWesternSize;
nWesternSize = static_cast<sal_Int32>(nHeight);
break;
case SvtScriptType::ASIAN:
nCTLSize = nHeight* nCTLSize / nCJKSize;
nWesternSize = nHeight * nWesternSize / nCJKSize;
nCJKSize = static_cast<sal_Int32>(nHeight);
break;
case SvtScriptType::COMPLEX:
nCJKSize = nHeight * nCJKSize / nCTLSize;
nWesternSize = nHeight * nWesternSize / nCTLSize;
nCTLSize = static_cast<sal_Int32>(nHeight);
break;
default: break;
}
aHeightSet.Put( SvxFontHeightItem( static_cast<sal_uInt32>(nWesternSize), 100, RES_CHRATR_FONTSIZE ));
aHeightSet.Put( SvxFontHeightItem( static_cast<sal_uInt32>(nCJKSize), 100, RES_CHRATR_CJK_FONTSIZE ));
aHeightSet.Put( SvxFontHeightItem( static_cast<sal_uInt32>(nCTLSize), 100, RES_CHRATR_CTL_FONTSIZE ));
pArgs = &aHeightSet;
}
}
break;
}
if( pArgs )
{
bool bAuto = false;
if ( !isCHRATR(nWhich) ||
( rSh.HasSelection() && rSh.IsSelFullPara() ) )
{
SwTextFormatColl * pColl = rSh.GetCurTextFormatColl();
if ( pColl && pColl->IsAutoUpdateOnDirectFormat() )
{
rSh.AutoUpdatePara( pColl, *pArgs );
bAuto = true;
}
}
if (!bAuto)
{
rSh.SetAttrSet( *pArgs );
}
}
}
else
{
if (nSlot == SID_ATTR_CHAR_KERNING)
GetView().GetViewFrame().GetDispatcher()->Execute(SID_CHAR_DLG_POSITION);
else if (nSlot == SID_ATTR_CHAR_COLOR)
GetView().GetViewFrame().GetDispatcher()->Execute(SID_CHAR_DLG_EFFECT);
else
GetView().GetViewFrame().GetDispatcher()->Execute(SID_CHAR_DLG);
}
rReq.Done();
}
void SwBaseShell::GetTextCtrlState( SfxItemSet& rSet )
{
SwWrtShell &rSh = GetShell();
rSh.GetCurAttr( rSet );
}
void SwBaseShell::GetTextFontCtrlState( SfxItemSet& rSet )
{
SwWrtShell &rSh = GetShell();
bool bFirst = true;
std::optional<SfxItemSet> pFntCoreSet;
SvtScriptType nScriptType = SvtScriptType::LATIN;
SfxWhichIter aIter( rSet );
sal_uInt16 nWhich = aIter.FirstWhich();
while( nWhich )
{
switch( nWhich )
{
case RES_CHRATR_FONT:
case RES_CHRATR_FONTSIZE:
case RES_CHRATR_WEIGHT:
case RES_CHRATR_POSTURE:
{
if( !pFntCoreSet )
{
pFntCoreSet.emplace( *rSet.GetPool(),
svl::Items<RES_CHRATR_BEGIN, RES_CHRATR_END-1> );
rSh.GetCurAttr( *pFntCoreSet );
nScriptType = rSh.GetScriptType();
// #i42732# input language should be preferred over
// current cursor position to detect script type
SwEditWin& rEditWin = GetView().GetEditWin();
if( rEditWin.IsUseInputLanguage() )
{
if(!rSh.HasSelection() && (
nWhich == RES_CHRATR_FONT ||
nWhich == RES_CHRATR_FONTSIZE ))
{
LanguageType nInputLang = rEditWin.GetInputLanguage();
if(nInputLang != LANGUAGE_DONTKNOW && nInputLang != LANGUAGE_SYSTEM)
nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nInputLang );
}
}
}
SfxItemPool& rPool = *rSet.GetPool();
SvxScriptSetItem aSetItem( rPool.GetSlotId( nWhich ), rPool );
aSetItem.GetItemSet().Put( *pFntCoreSet, false );
const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScriptType );
if( pI )
{
rSet.Put( pI->CloneSetWhich(nWhich) );
}
else
rSet.InvalidateItem( nWhich );
// Set input context of the SwEditWin according to the selected font and script type
if(RES_CHRATR_FONT == nWhich)
{
vcl::Font aFont;
if (const SvxFontItem* pFontItem = dynamic_cast<const SvxFontItem*>(pI))
{
aFont.SetFamilyName(pFontItem->GetFamilyName());
aFont.SetStyleName(pFontItem->GetStyleName());
aFont.SetFamily(pFontItem->GetFamily());
aFont.SetPitch(pFontItem->GetPitch());
aFont.SetCharSet(pFontItem->GetCharSet());
}
bool bVertical = rSh.IsInVerticalText();
aFont.SetOrientation(Degree10(bVertical ? 2700 : 0));
aFont.SetVertical(bVertical);
GetView().GetEditWin().SetInputContext( InputContext( aFont, InputContextFlags::Text |
InputContextFlags::ExtText ) );
}
}
break;
default:
if( bFirst )
{
rSh.GetCurAttr( rSet );
bFirst = false;
}
}
nWhich = aIter.NextWhich();
}
}
void SwBaseShell::GetBckColState(SfxItemSet &rSet)
{
SwWrtShell &rSh = GetShell();
SfxWhichIter aIter(rSet);
sal_uInt16 nWhich(aIter.FirstWhich());
SelectionType nSelType(rSh.GetSelectionType());
std::unique_ptr<SvxBrushItem> aBrushItem(std::make_unique<SvxBrushItem>(RES_BACKGROUND));
if( nWhich == SID_TABLE_CELL_BACKGROUND_COLOR )
{
rSh.GetBoxBackground( aBrushItem );
}
else
{
// Adapt to new DrawingLayer FillStyle; use a parent which has XFILL_NONE set
SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST> aCoreSet(GetPool());
aCoreSet.SetParent(&GetView().GetDocShell()->GetDoc()->GetDfltFrameFormat()->GetAttrSet());
if(nSelType & SelectionType::Graphic || SelectionType::Frame & nSelType)
{
rSh.GetFlyFrameAttr(aCoreSet);
}
else
{
rSh.GetCurAttr(aCoreSet);
}
aBrushItem = getSvxBrushItemFromSourceSet(aCoreSet, RES_BACKGROUND);
}
while(nWhich)
{
switch(nWhich)
{
case SID_BACKGROUND_COLOR:
case SID_TABLE_CELL_BACKGROUND_COLOR:
{
SvxColorItem aColorItem(aBrushItem->GetColor(), aBrushItem->getComplexColor(), nWhich);
rSet.Put(aColorItem);
break;
}
case SID_ATTR_BRUSH:
case RES_BACKGROUND:
{
// if this was intended to have a independent copy of the Item to be set
// this is not needed due to the ItemSet/Pool cloning Items which get set anyways.
// Keeping code as reference - it may have had other reasons I do notz see (?!?)
// std::unique_ptr<SfxPoolItem> pNewItem(aBrushItem.CloneSetWhich(GetPool().GetWhich(nWhich)));
rSet.Put(*aBrushItem);
break;
}
}
nWhich = aIter.NextWhich();
}
}
void SwBaseShell::ExecBckCol(SfxRequest& rReq)
{
SwWrtShell &rSh = GetShell();
SelectionType nSelType(rSh.GetSelectionType());
const SfxItemSet* pArgs = rReq.GetArgs();
sal_uInt16 nSlot(rReq.GetSlot());
if (!pArgs && nSlot != SID_BACKGROUND_COLOR && nSlot != SID_TABLE_CELL_BACKGROUND_COLOR)
{
return;
}
std::unique_ptr<SvxBrushItem> aBrushItem(std::make_unique<SvxBrushItem>(RES_BACKGROUND));
if ( nSlot == SID_TABLE_CELL_BACKGROUND_COLOR )
{
rSh.GetBoxBackground( aBrushItem );
}
else
{
// Adapt to new DrawingLayer FillStyle; use a parent which has XFILL_NONE set
SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST> aCoreSet(GetPool());
aCoreSet.SetParent(&GetView().GetDocShell()->GetDoc()->GetDfltFrameFormat()->GetAttrSet());
if((SelectionType::Frame & nSelType) || (SelectionType::Graphic & nSelType))
{
rSh.GetFlyFrameAttr(aCoreSet);
}
else
{
rSh.GetCurAttr(aCoreSet);
}
aBrushItem = getSvxBrushItemFromSourceSet(aCoreSet, RES_BACKGROUND);
}
switch(nSlot)
{
case SID_BACKGROUND_COLOR:
case SID_TABLE_CELL_BACKGROUND_COLOR:
{
bool bIsTransparent = false;
aBrushItem->SetGraphicPos(GPOS_NONE);
sal_uInt16 nSlotId = (nSlot == SID_BACKGROUND_COLOR) ? SID_BACKGROUND_COLOR : SID_TABLE_CELL_BACKGROUND_COLOR;
if (pArgs)
{
const SvxColorItem& rNewColorItem = static_cast<const SvxColorItem&>(pArgs->Get(nSlotId));
aBrushItem->SetColor(rNewColorItem.GetValue());
aBrushItem->setComplexColor(rNewColorItem.getComplexColor());
GetView().GetViewFrame().GetBindings().SetState(rNewColorItem);
}
else
{
bIsTransparent = true;
}
if (bIsTransparent)
{
aBrushItem->SetColor(COL_TRANSPARENT);
rReq.AppendItem(SvxColorItem(COL_TRANSPARENT,nSlot));
}
break;
}
case SID_ATTR_BRUSH:
case RES_BACKGROUND:
{
assert(pArgs && "only SID_BACKGROUND_COLOR can have !pArgs, checked at entry");
aBrushItem.reset(static_cast<SvxBrushItem*>(pArgs->Get(GetPool().GetWhich(nSlot)).Clone()));
break;
}
default:
{
rReq.Ignore();
OSL_FAIL("unknown message in ExecuteAttr!" );
return;
}
}
if ( nSlot == SID_TABLE_CELL_BACKGROUND_COLOR )
{
rSh.SetBoxBackground( *aBrushItem );
}
else
{
// Adapt to new DrawingLayer FillStyle; use a parent which has XFILL_NONE set
SfxItemSetFixed<XATTR_FILL_FIRST, XATTR_FILL_LAST> aCoreSet(GetPool());
aCoreSet.SetParent(&GetView().GetDocShell()->GetDoc()->GetDfltFrameFormat()->GetAttrSet());
setSvxBrushItemAsFillAttributesToTargetSet(*aBrushItem, aCoreSet);
if((SelectionType::Frame & nSelType) || (SelectionType::Graphic & nSelType))
{
// Template autoupdate
SwFrameFormat* pFormat = rSh.GetSelectedFrameFormat();
if(pFormat && pFormat->IsAutoUpdateOnDirectFormat())
{
rSh.AutoUpdateFrame(pFormat, aCoreSet);
}
else
{
rSh.SetFlyFrameAttr(aCoreSet);
}
}
else
{
SwTextFormatColl* pColl = rSh.GetCurTextFormatColl();
if(pColl && pColl->IsAutoUpdateOnDirectFormat())
{
rSh.AutoUpdatePara(pColl, aCoreSet);
}
else
{
rSh.SetAttrSet(aCoreSet);
}
}
}
rReq.Done();
}
void SwBaseShell::GetBorderState(SfxItemSet &rSet)
{
SwWrtShell &rSh = GetShell();
// Table cell(s) selected?
bool bPrepare = true;
bool bTableMode = rSh.IsTableMode();
if ( bTableMode )
{
SfxItemSetFixed<RES_BOX, RES_BOX,
SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER> aCoreSet( GetPool() );
SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
aCoreSet.Put( aBoxInfo );
rSh.GetTabBorders( aCoreSet );
rSet.Put( aCoreSet );
}
else if ( rSh.IsFrameSelected() )
{
SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
rSet.Put( aMgr.GetAttrSet() );
bPrepare = false;
}
else
// Get border attributes via shell quite normal
rSh.GetCurAttr( rSet );
if ( bPrepare )
::PrepareBoxInfo( rSet, rSh );
// Switch the border toolbox controller mode
rSet.Put( SfxBoolItem( SID_BORDER_REDUCED_MODE, !bTableMode ));
}
void SwBaseShell::ExecDlg(SfxRequest &rReq)
{
SwWrtShell &rSh = GetShell();
weld::Window* pMDI = GetView().GetFrameWeld();
// So that from the basic no dialogues for the background views are called:
bool bBackground = (&GetView() != GetActiveView());
const SfxPoolItem* pItem = nullptr;
const SfxItemSet* pArgs = rReq.GetArgs();
sal_uInt16 nSlot = rReq.GetSlot();
const SfxItemSet* pOutSet = nullptr;
bool bDone = false;
if(pArgs)
pArgs->GetItemState( GetPool().GetWhich(nSlot), false, &pItem );
switch ( nSlot )
{
case FN_FORMAT_TITLEPAGE_DLG:
{
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateTitlePageDlg(pMDI));
VclAbstractDialog::AsyncContext aContext;
aContext.maEndDialogFn = [](sal_Int32){};
pDlg->StartExecuteAsync(aContext);
}
break;
case FN_FORMAT_PAGE_DLG:
case FN_FORMAT_PAGE_COLUMN_DLG:
case FN_FORMAT_PAGE_SETTING_DLG:
case FN_FORMAT_PAGE_AREA_DLG:
{
if( !bBackground )
{
const size_t nCurIdx = rSh.GetCurPageDesc();
const SwPageDesc& rPageDesc = rSh.GetPageDesc( nCurIdx );
// Temporary view, because the shell does not need to be valid after the dialog
// for example disable header
SwView& rTempView = GetView();
OUString sPageId;
switch (nSlot)
{
case FN_FORMAT_PAGE_COLUMN_DLG:
sPageId = "columns";
break;
case FN_FORMAT_PAGE_SETTING_DLG:
sPageId = "page";
break;
case FN_FORMAT_PAGE_AREA_DLG:
sPageId = "area";
break;
case FN_FORMAT_PAGE_DLG:
if (pItem)
sPageId = static_cast<const SfxStringItem*>(pItem)->GetValue();
break;
}
rTempView.GetDocShell()->FormatPage(rReq.GetFrameWeld(), rPageDesc.GetName(), sPageId, rSh, &rReq);
rTempView.InvalidateRulerPos();
bDone = true; // FormatPage() takes care of calling Done()
}
}
break;
case FN_FORMAT_BORDER_DLG:
{
SfxItemSetFixed<RES_BOX , RES_SHADOW,
SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER> aSet( rSh.GetAttrPool() );
ScopedVclPtr<SfxAbstractDialog> pDlg;
// Table cell(s) selected?
if ( rSh.IsTableMode() )
{
// Set border attributes Get/SetTabBorders()
::PrepareBoxInfo( aSet, rSh );
rSh.GetTabBorders( aSet );
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
pDlg.disposeAndReset(pFact->CreateSwBorderDlg(pMDI, aSet, SwBorderModes::TABLE));
if ( pDlg->Execute() == RET_OK )
{
rSh.SetTabBorders( *pDlg->GetOutputItemSet() );
pOutSet = pDlg->GetOutputItemSet();
}
}
else if ( rSh.IsFrameSelected() )
{
// Set border attributes via Frame-Manager
SwFlyFrameAttrMgr aMgr( false, &rSh, Frmmgr_Type::NONE, nullptr );
aSet.Put( aMgr.GetAttrSet() );
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
pDlg.disposeAndReset(pFact->CreateSwBorderDlg(pMDI, aSet, SwBorderModes::FRAME));
if ( pDlg->Execute() == RET_OK )
{
aMgr.SetAttrSet( *pDlg->GetOutputItemSet() );
aMgr.UpdateFlyFrame();
pOutSet = pDlg->GetOutputItemSet();
}
}
else
{
// Set border attributes via Shell quite normal
rSh.GetCurAttr( aSet );
::PrepareBoxInfo( aSet, rSh );
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
pDlg.disposeAndReset(pFact->CreateSwBorderDlg(pMDI, aSet, SwBorderModes::PARA));
if ( pDlg->Execute() == RET_OK )
{
rSh.SetAttrSet( *pDlg->GetOutputItemSet() );
pOutSet = pDlg->GetOutputItemSet();
}
}
if(pOutSet)
{
rReq.Done(*pOutSet);
bDone = true;
}
}
break;
case FN_FORMAT_BACKGROUND_DLG:
{
SfxItemSetFixed<RES_BACKGROUND, RES_BACKGROUND,
XATTR_FILL_FIRST, XATTR_FILL_LAST> aSet( rSh.GetAttrPool() );
ScopedVclPtr<SfxAbstractDialog> pDlg;
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
// Table cell(s) selected?
if ( rSh.IsTableMode() )
{
// Get background attributes of the table and put it in the set
// tdf#144843 calling GetBoxBackground *requires* an incarnation to be handed over
std::unique_ptr<SvxBrushItem> aBrush(std::make_unique<SvxBrushItem>(RES_BACKGROUND));
rSh.GetBoxBackground( aBrush );
pDlg.disposeAndReset(pFact->CreateSwBackgroundDialog(pMDI, aSet));
aSet.Put( std::move(aBrush) );
if ( pDlg->Execute() == RET_OK )
{
rSh.SetBoxBackground( pDlg->GetOutputItemSet()->Get( RES_BACKGROUND ) );
pOutSet = pDlg->GetOutputItemSet();
}
}
else if ( rSh.IsFrameSelected() )
{
rSh.GetFlyFrameAttr( aSet );
pDlg.disposeAndReset(pFact->CreateSwBackgroundDialog(pMDI, aSet));
if ( pDlg->Execute() == RET_OK )
{
rSh.SetFlyFrameAttr(const_cast<SfxItemSet &>(*pDlg->GetOutputItemSet()) );
pOutSet = pDlg->GetOutputItemSet();
}
}
else
{
// Set border attributes Umrandungsattribute with the shell quite normal.
rSh.GetCurAttr( aSet );
pDlg.disposeAndReset(pFact->CreateSwBackgroundDialog(pMDI, aSet));
if ( pDlg->Execute() == RET_OK )
{
rSh.SetAttrSet( *pDlg->GetOutputItemSet() );
pOutSet = pDlg->GetOutputItemSet();
}
}
if(pOutSet)
{
rReq.Done(*pOutSet);
bDone = true;
}
}
break;
case SID_GRAPHIC_SIZE_CHECK:
{
sw::GraphicSizeCheckGUIResult aResult(rSh.GetDoc());
svx::GenericCheckDialog aDialog(pMDI, aResult);
aDialog.run();
}
break;
case SID_THEME_DIALOG:
{
auto* pDocument = rSh.GetDoc();
auto* pDocumentShell = pDocument->GetDocShell();
if (pDocumentShell)
{
SdrModel* pModel = pDocument->getIDocumentDrawModelAccess().GetDrawModel();
auto const& pTheme = pModel->getTheme();
if (pTheme)
{
std::shared_ptr<svx::IThemeColorChanger> pChanger(new sw::ThemeColorChanger(pDocumentShell));
auto pDialog = std::make_shared<svx::ThemeDialog>(pMDI, pTheme.get());
weld::DialogController::runAsync(pDialog, [pDialog, pChanger](sal_uInt32 nResult) {
if (RET_OK != nResult)
return;
auto pColorSet = pDialog->getCurrentColorSet();
if (pColorSet)
{
pChanger->apply(pColorSet);
if (comphelper::LibreOfficeKit::isActive())
{
svx::ThemeColorPaletteManager aManager(pColorSet);
SfxLokHelper::notifyAllViews(LOK_CALLBACK_COLOR_PALETTES, aManager.generateJSON());
}
}
});
}
}
}
break;
default:OSL_FAIL("wrong Dispatcher (basesh.cxx)");
}
if(!bDone)
rReq.Done();
}
SwWrtShell& SwBaseShell::GetShell()
{
return m_rView.GetWrtShell();
}
SwWrtShell* SwBaseShell::GetShellPtr()
{
return m_rView.GetWrtShellPtr();
}
static void EndUndo(SwWrtShell& rSh)
{
SwRewriter aRewriter;
if (rSh.GetTableFormat())
{
aRewriter.AddRule(UndoArg1, SwResId(STR_START_QUOTE));
aRewriter.AddRule(UndoArg2, rSh.GetTableFormat()->GetName());
aRewriter.AddRule(UndoArg3, SwResId(STR_END_QUOTE));
}
rSh.EndUndo(SwUndoId::INSTABLE, &aRewriter); // If possible change the Shell
}
static void InsertTableImpl(SwWrtShell& rSh,
SwView &rTempView,
const OUString& aTableName,
sal_uInt16 nRows,
sal_uInt16 nCols,
SwInsertTableOptions aInsTableOpts,
const OUString& aAutoName,
const std::unique_ptr<SwTableAutoFormat>& pTAFormat)
{
rSh.StartUndo(SwUndoId::INSTABLE);
rSh.StartAllAction();
if( rSh.HasSelection() )
rSh.DelRight();
rSh.InsertTable( aInsTableOpts, nRows, nCols, pTAFormat.get() );
rSh.MoveTable( GotoPrevTable, fnTableStart );
if( !aTableName.isEmpty() && !rSh.GetTableStyle( aTableName ) )
rSh.GetTableFormat()->SetFormatName( aTableName );
if( pTAFormat != nullptr && !aAutoName.isEmpty()
&& aAutoName != SwViewShell::GetShellRes()->aStrNone )
{
SwTableNode* pTableNode = const_cast<SwTableNode*>( rSh.IsCursorInTable() );
if ( pTableNode )
{
pTableNode->GetTable().SetTableStyleName( aAutoName );
SwUndoTableAutoFormat* pUndo = new SwUndoTableAutoFormat( *pTableNode, *pTAFormat );
if ( pUndo )
rSh.GetIDocumentUndoRedo().AppendUndo( std::unique_ptr<SwUndo>(pUndo) );
}
}
rSh.EndAllAction();
rTempView.AutoCaption(TABLE_CAP);
}
void SwBaseShell::InsertTable( SfxRequest& _rRequest )
{
const SfxItemSet* pArgs = _rRequest.GetArgs();
SwWrtShell& rSh = GetShell();
if ( rSh.GetFrameType( nullptr, true ) & FrameTypeFlags::FOOTNOTE )
return;
SwView &rTempView = GetView(); // Because GetView() does not work after the shell exchange
bool bHTMLMode = 0 != (::GetHtmlMode(rTempView.GetDocShell())&HTMLMODE_ON);
bool bCallEndUndo = false;
if( !pArgs && rSh.IsSelection() && !rSh.IsInClickToEdit() &&
!rSh.IsTableMode() )
{
const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
SwInsertTableOptions aInsTableOpts = pModOpt->GetInsTableFlags(bHTMLMode);
rSh.StartUndo(SwUndoId::INSTABLE);
bCallEndUndo = true;
bool bInserted = rSh.TextToTable( aInsTableOpts, '\t' );
rSh.EnterStdMode();
if (bInserted)
rTempView.AutoCaption(TABLE_CAP);
_rRequest.Done();
}
else
{
sal_uInt16 nColsIn = 0;
sal_uInt16 nRowsIn = 0;
SwInsertTableOptions aInsTableOptsIn( SwInsertTableFlags::All, 1 );
OUString aTableNameIn;
OUString aAutoNameIn;
std::unique_ptr<SwTableAutoFormat> pTAFormatIn;
if( pArgs && pArgs->Count() >= 2 )
{
const SfxStringItem* pName = _rRequest.GetArg<SfxStringItem>(FN_INSERT_TABLE);
const SfxUInt16Item* pCols = _rRequest.GetArg<SfxUInt16Item>(SID_ATTR_TABLE_COLUMN);
const SfxUInt16Item* pRows = _rRequest.GetArg<SfxUInt16Item>(SID_ATTR_TABLE_ROW);
const SfxInt32Item* pFlags = _rRequest.GetArg<SfxInt32Item>(FN_PARAM_1);
const SfxStringItem* pAuto = _rRequest.GetArg<SfxStringItem>(FN_PARAM_2);
if ( pName )
aTableNameIn = pName->GetValue();
if ( pCols )
nColsIn = pCols->GetValue();
if ( pRows )
nRowsIn = pRows->GetValue();
if ( pAuto )
{
aAutoNameIn = pAuto->GetValue();
if ( !aAutoNameIn.isEmpty() )
{
SwTableAutoFormatTable aTableTable;
aTableTable.Load();
for ( size_t n=0; n<aTableTable.size(); n++ )
{
if ( aTableTable[n].GetName() == aAutoNameIn )
{
pTAFormatIn.reset(new SwTableAutoFormat( aTableTable[n] ));
break;
}
}
}
}
if ( pFlags )
aInsTableOptsIn.mnInsMode = static_cast<SwInsertTableFlags>(pFlags->GetValue());
else
{
const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
aInsTableOptsIn = pModOpt->GetInsTableFlags(bHTMLMode);
}
}
if( !nColsIn || !nRowsIn )
{
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
std::shared_ptr<AbstractInsTableDlg> pAbstractDialog(pFact->CreateInsTableDlg(rTempView));
std::shared_ptr<weld::DialogController> pDialogController(pAbstractDialog->getDialogController());
weld::DialogController::runAsync(pDialogController,
[pAbstractDialog, &rSh, &rTempView, aTableNameIn, nRowsIn, nColsIn, aInsTableOptsIn, aAutoNameIn] (sal_Int32 nResult) {
if( RET_OK == nResult )
{
sal_uInt16 nCols = nColsIn;
sal_uInt16 nRows = nRowsIn;
SwInsertTableOptions aInsTableOpts = aInsTableOptsIn;
OUString aTableName = aTableNameIn;
OUString aAutoName = aAutoNameIn;
std::unique_ptr<SwTableAutoFormat> pTAFormat;
pAbstractDialog->GetValues( aTableName, nRows, nCols, aInsTableOpts, aAutoName, pTAFormat );
if( nCols && nRows )
{
InsertTableImpl( rSh, rTempView, aTableName, nRows, nCols, aInsTableOpts, aAutoName, pTAFormat );
EndUndo(rSh);
}
}
}
);
}
else
{
// record before shell change
_rRequest.AppendItem( SfxStringItem( FN_INSERT_TABLE, aTableNameIn ) );
if ( !aAutoNameIn.isEmpty() )
_rRequest.AppendItem( SfxStringItem( FN_PARAM_2, aAutoNameIn ) );
_rRequest.AppendItem( SfxUInt16Item( SID_ATTR_TABLE_COLUMN, nColsIn ) );
_rRequest.AppendItem( SfxUInt16Item( SID_ATTR_TABLE_ROW, nRowsIn ) );
_rRequest.AppendItem( SfxInt32Item( FN_PARAM_1, static_cast<sal_Int32>(aInsTableOptsIn.mnInsMode) ) );
_rRequest.Done();
InsertTableImpl( rSh, rTempView, aTableNameIn, nRowsIn, nColsIn, aInsTableOptsIn, aAutoNameIn, pTAFormatIn );
bCallEndUndo = true;
}
}
if( bCallEndUndo )
EndUndo(rSh);
}
void SwBaseShell::GetGalleryState( SfxItemSet &rSet )
{
SwWrtShell &rSh = GetShell();
SfxWhichIter aIter( rSet );
sal_uInt16 nWhich = aIter.FirstWhich();
switch ( nWhich )
{
case SID_GALLERY_BG_BRUSH:
{
SelectionType nSel = rSh.GetSelectionType();
SfxStringListItem aLst( nWhich );
std::vector<OUString> &rLst = aLst.GetList();
nParagraphPos = nGraphicPos = nOlePos = nFramePos = nTablePos =
nTableRowPos = nTableCellPos = nPagePos =
nHeaderPos = nFooterPos = 0;
sal_uInt8 nPos = 1;
rLst.push_back( SwResId( STR_SWBG_PAGE ) );
nPagePos = nPos++;
sal_uInt16 nHtmlMode = ::GetHtmlMode(GetView().GetDocShell());
bool bHtmlMode = 0 != (nHtmlMode & HTMLMODE_ON);
if ( (!bHtmlMode || (nHtmlMode & HTMLMODE_FULL_STYLES)) &&
(nSel & SelectionType::Text) )
{
rLst.push_back( SwResId( STR_SWBG_PARAGRAPH ) );
nParagraphPos = nPos++;
}
if ( (!bHtmlMode || (nHtmlMode & HTMLMODE_SOME_STYLES)) &&
nSel & (SelectionType::Table|SelectionType::TableCell) )
{
rLst.push_back( SwResId( STR_SWBG_TABLE ) );
nTablePos = nPos++;
if(!bHtmlMode)
{
rLst.push_back( SwResId( STR_SWBG_TABLE_ROW ) );
nTableRowPos = nPos++;
}
rLst.push_back( SwResId( STR_SWBG_TABLE_CELL) );
nTableCellPos = nPos++;
}
if(!bHtmlMode)
{
if ( nSel & SelectionType::Frame )
{
rLst.push_back( SwResId( STR_SWBG_FRAME ) );
nFramePos = nPos++;
}
if ( nSel & SelectionType::Graphic )
{
rLst.push_back( SwResId( STR_SWBG_GRAPHIC ) );
nGraphicPos = nPos++;
}
if ( nSel & SelectionType::Ole )
{
rLst.push_back( SwResId( STR_SWBG_OLE ) );
nOlePos = nPos++;
}
const FrameTypeFlags nType = rSh.GetFrameType(nullptr,true);
if ( nType & FrameTypeFlags::HEADER )
{
rLst.push_back( SwResId( STR_SWBG_HEADER ) );
nHeaderPos = nPos++;
}
if ( nType & FrameTypeFlags::FOOTER )
{
rLst.push_back( SwResId( STR_SWBG_FOOTER ) );
nFooterPos = nPos;
}
}
if ( rLst.empty() )
rSet.DisableItem( nWhich );
else
rSet.Put( aLst );
break;
}
}
}
void SwBaseShell::ExecuteGallery(SfxRequest &rReq)
{
SwWrtShell &rSh = GetShell();
rSh.StartAction();
const SfxItemSet* pArgs = rReq.GetArgs();
sal_uInt16 nSlot = rReq.GetSlot();
switch(nSlot)
{
case SID_GALLERY_BG_BRUSH:
{
if ( !pArgs )
break;
SelectionType nSel = rSh.GetSelectionType();
if ( nSel & SelectionType::DrawObjectEditMode )
break;
const SfxUInt16Item* pPos = rReq.GetArg<SfxUInt16Item>(SID_GALLERY_BG_POS);
const SvxBrushItem* pBrush = rReq.GetArg<SvxBrushItem>(SID_GALLERY_BG_BRUSH);
if ( !pPos || !pBrush )
break;
sal_uInt8 nPos = pPos->GetValue();
++nPos;
SvxBrushItem aBrush( *pBrush );
aBrush.SetWhich( RES_BACKGROUND );
if ( nPos == nParagraphPos )
rSh.SetAttrItem( aBrush );
else if ( nPos == nTablePos )
rSh.SetTabBackground( aBrush );
else if ( nPos == nTableRowPos )
rSh.SetRowBackground( aBrush );
else if ( nPos == nTableCellPos )
rSh.SetBoxBackground( aBrush );
else if ( nPos == nFramePos || nPos == nGraphicPos || nPos == nOlePos )
{
SfxItemSetFixed<RES_BACKGROUND, RES_BACKGROUND> aCoreSet(GetPool());
aCoreSet.Put( aBrush );
rSh.SetFlyFrameAttr( aCoreSet );
}
else if ( nPos == nPagePos || nPos == nHeaderPos || nPos == nFooterPos )
{
sal_uInt16 nDesc = rSh.GetCurPageDesc();
SwPageDesc aDesc( rSh.GetPageDesc( nDesc ) );
if ( nPos == nPagePos )
aDesc.GetMaster().SetFormatAttr( aBrush );
else if ( nPos == nHeaderPos )
{
SwFormatHeader aHead( aDesc.GetMaster().GetHeader() );
aHead.GetHeaderFormat()->SetFormatAttr( aBrush );
aDesc.GetMaster().SetFormatAttr( aHead );
}
else if ( nPos == nFooterPos )
{
SwFormatFooter aFoot( aDesc.GetMaster().GetFooter() );
aFoot.GetFooterFormat()->SetFormatAttr( aBrush );
aDesc.GetMaster().SetFormatAttr( aFoot );
}
rSh.ChgPageDesc( nDesc, aDesc );
}
break;
}
}
rSh.EndAction();
rReq.Done();
}
void SwBaseShell::ExecField( SfxRequest const & rReq )
{
sal_uInt16 nSlot = rReq.GetSlot();
switch( nSlot )
{
#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
case FN_CHANGE_DBFIELD:
{
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSwChangeDBDlg(GetView()));
pDlg->Execute();
}
break;
#endif
default:
OSL_FAIL("wrong dispatcher");
}
}
std::shared_ptr<std::vector<std::unique_ptr<SwPaM>>> SwBaseShell::CopyPaMRing(SwPaM& rOrig)
{
auto vCursors = std::make_shared<std::vector<std::unique_ptr<SwPaM>>>();
vCursors->emplace_back(std::make_unique<SwPaM>(rOrig, nullptr));
for (auto& rCursor : rOrig.GetRingContainer())
{
if (&rCursor != &rOrig)
vCursors->emplace_back(std::make_unique<SwPaM>(rCursor, vCursors->front().get()));
}
return vCursors;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|