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
|
/* -*- 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 <hintids.hxx>
#include <svx/strings.hrc>
#include <svx/sdrobjectfilter.hxx>
#include <svx/svddrgmt.hxx>
#include <svx/svditer.hxx>
#include <svx/svdobj.hxx>
#include <svx/svdouno.hxx>
#include <svx/svdogrp.hxx>
#include <svx/svdocirc.hxx>
#include <svx/svdopath.hxx>
#include <svx/sxciaitm.hxx>
#include <svx/svdocapt.hxx>
#include <svx/xlnwtit.hxx>
#include <svx/xlnstwit.hxx>
#include <svx/xlnedwit.hxx>
#include <svx/xlnedit.hxx>
#include <svx/xlnstit.hxx>
#include <svx/svdomeas.hxx>
#include <svx/sdtagitm.hxx>
#include <svx/sdtacitm.hxx>
#include <svx/sdtaaitm.hxx>
#include <editeng/opaqitem.hxx>
#include <editeng/protitem.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdpagv.hxx>
#include <svx/dialmgr.hxx>
#include <tools/globname.hxx>
#include <sot/exchange.hxx>
#include <IDocumentDrawModelAccess.hxx>
#include <IDocumentSettingAccess.hxx>
#include <DocumentSettingManager.hxx>
#include <IDocumentState.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <drawdoc.hxx>
#include <textboxhelper.hxx>
#include <frmfmt.hxx>
#include <frmatr.hxx>
#include <frmtool.hxx>
#include <fmtfsize.hxx>
#include <fmtanchr.hxx>
#include <fmtornt.hxx>
#include <fmtsrnd.hxx>
#include <fmtcntnt.hxx>
#include <fmtflcnt.hxx>
#include <fmtcnct.hxx>
#include <swmodule.hxx>
#include <fesh.hxx>
#include <rootfrm.hxx>
#include <pagefrm.hxx>
#include <sectfrm.hxx>
#include <doc.hxx>
#include <IDocumentUndoRedo.hxx>
#include <dview.hxx>
#include <dflyobj.hxx>
#include <dcontact.hxx>
#include <viewimp.hxx>
#include <flyfrm.hxx>
#include <pam.hxx>
#include <ndole.hxx>
#include <ndgrf.hxx>
#include <ndtxt.hxx>
#include <viewopt.hxx>
#include <swundo.hxx>
#include <notxtfrm.hxx>
#include <txtfrm.hxx>
#include <mdiexp.hxx>
#include <sortedobjs.hxx>
#include <HandleAnchorNodeChg.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <comphelper/lok.hxx>
#include <sfx2/lokhelper.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <calbck.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <svx/svxids.hrc>
#include <com/sun/star/embed/EmbedMisc.hpp>
#include <com/sun/star/embed/Aspects.hpp>
#include <com/sun/star/embed/XEmbeddedObject.hpp>
#include <svx/srchdlg.hxx>
#define SCROLLVAL 75
using namespace com::sun::star;
/**
* set line starts and ends for the object to be created
*/
namespace {
::basegfx::B2DPolyPolygon getPolygon(const char* pResId, const SdrModel& rModel)
{
::basegfx::B2DPolyPolygon aRetval;
XLineEndListRef pLineEndList(rModel.GetLineEndList());
if( pLineEndList.is() )
{
OUString aArrowName( SvxResId(pResId) );
long nCount = pLineEndList->Count();
long nIndex;
for( nIndex = 0; nIndex < nCount; nIndex++ )
{
const XLineEndEntry* pEntry = pLineEndList->GetLineEnd(nIndex);
if( pEntry->GetName() == aArrowName )
{
aRetval = pEntry->GetLineEnd();
break;
}
}
}
return aRetval;
}
}
SwFlyFrame *GetFlyFromMarked( const SdrMarkList *pLst, SwViewShell *pSh )
{
if ( !pLst )
pLst = pSh->HasDrawView() ? &pSh->Imp()->GetDrawView()->GetMarkedObjectList():nullptr;
if ( pLst && pLst->GetMarkCount() == 1 )
{
SdrObject *pO = pLst->GetMark( 0 )->GetMarkedSdrObj();
if (SwVirtFlyDrawObj* pVirtO = dynamic_cast<SwVirtFlyDrawObj*>(pO))
return pVirtO->GetFlyFrame();
}
return nullptr;
}
static void lcl_GrabCursor( SwFEShell* pSh, SwFlyFrame* pOldSelFly)
{
const SwFrameFormat *pFlyFormat = pSh->SelFlyGrabCursor();
if( pFlyFormat && !pSh->ActionPend() &&
(!pOldSelFly || pOldSelFly->GetFormat() != pFlyFormat) )
{
// now call set macro if applicable
pSh->GetFlyMacroLnk().Call( static_cast<const SwFlyFrameFormat*>(pFlyFormat) );
// if a dialog was started inside a macro, then
// MouseButtonUp arrives at macro and not to us. Therefore
// flag is always set here and will never be switched to
// respective Shell !!!!!!!
g_bNoInterrupt = false;
}
else if( !pFlyFormat || RES_DRAWFRMFMT == pFlyFormat->Which() )
{
// --> assure consistent cursor
pSh->KillPams();
pSh->ClearMark();
pSh->SetCursor( pSh->Imp()->GetDrawView()->GetAllMarkedRect().TopLeft(), true);
}
}
bool SwFEShell::SelectObj( const Point& rPt, sal_uInt8 nFlag, SdrObject *pObj )
{
SwDrawView *pDView = Imp()->GetDrawView();
if(!pDView)
return false;
SET_CURR_SHELL( this );
StartAction(); // action is necessary to assure only one AttrChgdNotify
// (e.g. due to Unmark->MarkListHasChgd) arrives
const SdrMarkList &rMrkList = pDView->GetMarkedObjectList();
const bool bHadSelection = rMrkList.GetMarkCount();
const bool bAddSelect = 0 != (SW_ADD_SELECT & nFlag);
const bool bEnterGroup = 0 != (SW_ENTER_GROUP & nFlag);
SwFlyFrame* pOldSelFly = nullptr;
const Point aOldPos( pDView->GetAllMarkedRect().TopLeft() );
if( bHadSelection )
{
// call Unmark when !bAddSelect or if fly was selected
bool bUnmark = !bAddSelect;
if ( rMrkList.GetMarkCount() == 1 )
{
// if fly was selected, deselect it first
pOldSelFly = ::GetFlyFromMarked( &rMrkList, this );
if ( pOldSelFly )
{
const sal_uInt16 nType = GetCntType();
if( nType != CNT_TXT || (SW_LEAVE_FRAME & nFlag) ||
( pOldSelFly->GetFormat()->GetProtect().IsContentProtected()
&& !IsReadOnlyAvailable() ))
{
// If a fly is deselected, which contains graphic, OLE or
// otherwise, the cursor should be removed from it.
// Similar if a fly with protected content is deselected.
// For simplicity we put the cursor next to the upper-left
// corner.
Point aPt( pOldSelFly->getFrameArea().Pos() );
aPt.setX(aPt.getX() - 1);
bool bUnLockView = !IsViewLocked();
LockView( true );
SetCursor( aPt, true );
if( bUnLockView )
LockView( false );
}
if ( nType & CNT_GRF &&
static_cast<SwNoTextFrame*>(pOldSelFly->Lower())->HasAnimation() )
{
GetWin()->Invalidate( pOldSelFly->getFrameArea().SVRect() );
}
// Cancel crop mode
if ( SdrDragMode::Crop == GetDragMode() )
SetDragMode( SdrDragMode::Move );
bUnmark = true;
}
}
if ( bUnmark )
{
pDView->UnmarkAll();
if (pOldSelFly)
pOldSelFly->SelectionHasChanged(this);
}
}
else
{
KillPams();
ClearMark();
}
if ( pObj )
{
OSL_ENSURE( !bEnterGroup, "SW_ENTER_GROUP is not supported" );
pDView->MarkObj( pObj, Imp()->GetPageView() );
}
else
{
// tolerance limit of Drawing-SS
const auto nHdlSizePixel = Imp()->GetDrawView()->GetMarkHdlSizePixel();
const short nMinMove = static_cast<short>(GetOut()->PixelToLogic(Size(nHdlSizePixel/2, 0)).Width());
pDView->MarkObj( rPt, nMinMove, bAddSelect, bEnterGroup );
}
const bool bRet = 0 != rMrkList.GetMarkCount();
if ( rMrkList.GetMarkCount() > 1 )
{
// It sucks if Drawing objects were selected and now
// additionally a fly is selected.
for ( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
{
SdrObject *pTmpObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
bool bForget = dynamic_cast<const SwVirtFlyDrawObj*>( pTmpObj) != nullptr;
if( bForget )
{
pDView->UnmarkAll();
pDView->MarkObj( pTmpObj, Imp()->GetPageView(), bAddSelect, bEnterGroup );
break;
}
}
}
if ( rMrkList.GetMarkCount() == 1 )
{
SwFlyFrame *pSelFly = ::GetFlyFromMarked( &rMrkList, this );
if (pSelFly)
pSelFly->SelectionHasChanged(this);
}
if (!(nFlag & SW_ALLOW_TEXTBOX))
{
// If the fly frame is a textbox of a shape, then select the shape instead.
for (size_t i = 0; i < rMrkList.GetMarkCount(); ++i)
{
SdrObject* pObject = rMrkList.GetMark(i)->GetMarkedSdrObj();
SwFrameFormat* pFormat = GetUserCall(pObject)->GetFormat();
if (SwFrameFormat* pShapeFormat = SwTextBoxHelper::getOtherTextBoxFormat(pFormat, RES_FLYFRMFMT))
{
SdrObject* pShape = pShapeFormat->FindSdrObject();
pDView->UnmarkAll();
pDView->MarkObj(pShape, Imp()->GetPageView(), bAddSelect, bEnterGroup);
break;
}
}
}
if ( bRet )
{
::lcl_GrabCursor(this, pOldSelFly);
if ( GetCntType() & CNT_GRF )
{
const SwFlyFrame *pTmp = GetFlyFromMarked( &rMrkList, this );
OSL_ENSURE( pTmp, "Graphic without Fly" );
if ( static_cast<const SwNoTextFrame*>(pTmp->Lower())->HasAnimation() )
static_cast<const SwNoTextFrame*>(pTmp->Lower())->StopAnimation( GetOut() );
}
}
else if ( !pOldSelFly && bHadSelection )
SetCursor( aOldPos, true);
if( bRet || !bHadSelection )
CallChgLnk();
// update status line
::FrameNotify( this, bRet ? FLY_DRAG_START : FLY_DRAG_END );
EndAction();
return bRet;
}
/*
* Description: MoveAnchor( nDir ) looked for an another Anchor for
* the selected drawing object (or fly frame) in the given direction.
* An object "as character" doesn't moves anyway.
* A page bounded object could move to the previous/next page with up/down,
* an object bounded "at paragraph" moves to the previous/next paragraph, too.
* An object bounded "at character" moves to the previous/next paragraph
* with up/down and to the previous/next character with left/right.
* If the anchor for at paragraph/character bounded objects has vertical or
* right_to_left text direction, the directions for up/down/left/right will
* interpreted accordingly.
* An object bounded "at fly" takes the center of the actual anchor and looks
* for the nearest fly frame in the given direction.
*/
static bool LessX( Point const & aPt1, Point const & aPt2, bool bOld )
{
return aPt1.getX() < aPt2.getX()
|| ( aPt1.getX() == aPt2.getX()
&& ( aPt1.getY() < aPt2.getY()
|| ( aPt1.getY() == aPt2.getY() && bOld ) ) );
}
static bool LessY( Point const & aPt1, Point const & aPt2, bool bOld )
{
return aPt1.getY() < aPt2.getY()
|| ( aPt1.getY() == aPt2.getY()
&& ( aPt1.getX() < aPt2.getX()
|| ( aPt1.getX() == aPt2.getX() && bOld ) ) );
}
bool SwFEShell::MoveAnchor( SwMove nDir )
{
if (!Imp()->GetDrawView())
return false;
const SdrMarkList& pMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
if (1 != pMrkList.GetMarkCount())
return false;
SwFrame* pOld;
SwFlyFrame* pFly = nullptr;
SdrObject *pObj = pMrkList.GetMark( 0 )->GetMarkedSdrObj();
if (SwVirtFlyDrawObj* pVirtO = dynamic_cast<SwVirtFlyDrawObj*>(pObj))
{
pFly = pVirtO->GetFlyFrame();
pOld = pFly->AnchorFrame();
}
else
pOld = static_cast<SwDrawContact*>(GetUserCall(pObj))->GetAnchorFrame( pObj );
bool bRet = false;
if( pOld )
{
SwFrame* pNew = pOld;
// #i28701#
SwAnchoredObject* pAnchoredObj = ::GetUserCall( pObj )->GetAnchoredObj( pObj );
SwFrameFormat& rFormat = pAnchoredObj->GetFrameFormat();
SwFormatAnchor aAnch( rFormat.GetAnchor() );
RndStdIds nAnchorId = aAnch.GetAnchorId();
if ( RndStdIds::FLY_AS_CHAR == nAnchorId )
return false;
if( pOld->IsVertical() )
{
if( pOld->IsTextFrame() )
{
switch( nDir ) {
case SwMove::UP: nDir = SwMove::LEFT; break;
case SwMove::DOWN: nDir = SwMove::RIGHT; break;
case SwMove::LEFT: nDir = SwMove::DOWN; break;
case SwMove::RIGHT: nDir = SwMove::UP; break;
}
if( pOld->IsRightToLeft() )
{
if( nDir == SwMove::LEFT )
nDir = SwMove::RIGHT;
else if( nDir == SwMove::RIGHT )
nDir = SwMove::LEFT;
}
}
}
switch ( nAnchorId ) {
case RndStdIds::FLY_AT_PAGE:
{
OSL_ENSURE( pOld->IsPageFrame(), "Wrong anchor, page expected." );
if( SwMove::UP == nDir )
pNew = pOld->GetPrev();
else if( SwMove::DOWN == nDir )
pNew = pOld->GetNext();
if( pNew && pNew != pOld )
{
aAnch.SetPageNum( static_cast<SwPageFrame*>(pNew)->GetPhyPageNum() );
bRet = true;
}
break;
}
case RndStdIds::FLY_AT_CHAR:
{
OSL_ENSURE(pOld->IsTextFrame(), "Wrong anchor, text frame expected.");
if( SwMove::LEFT == nDir || SwMove::RIGHT == nDir )
{
SwPosition pos = *aAnch.GetContentAnchor();
SwTextFrame *const pOldFrame(static_cast<SwTextFrame*>(pOld));
TextFrameIndex const nAct(pOldFrame->MapModelToViewPos(pos));
if( SwMove::LEFT == nDir )
{
bRet = true;
if( nAct )
{
pos = pOldFrame->MapViewToModelPos(nAct - TextFrameIndex(1));
}
else
nDir = SwMove::UP;
}
else
{
TextFrameIndex const nMax(pOldFrame->GetText().getLength());
if( nAct < nMax )
{
bRet = true;
pos = pOldFrame->MapViewToModelPos(nAct + TextFrameIndex(1));
}
else
nDir = SwMove::DOWN;
}
if( pos != *aAnch.GetContentAnchor())
aAnch.SetAnchor( &pos );
}
[[fallthrough]];
}
case RndStdIds::FLY_AT_PARA:
{
OSL_ENSURE(pOld->IsTextFrame(), "Wrong anchor, text frame expected.");
if( SwMove::UP == nDir )
pNew = pOld->FindPrev();
else if( SwMove::DOWN == nDir )
pNew = pOld->FindNext();
if( pNew && pNew != pOld && pNew->IsContentFrame() )
{
SwTextFrame *const pNewFrame(static_cast<SwTextFrame*>(pNew));
SwPosition const pos = pNewFrame->MapViewToModelPos(
TextFrameIndex(
(bRet && pNewFrame->GetText().getLength() != 0)
? pNewFrame->GetText().getLength() - 1
: 0));
aAnch.SetAnchor( &pos );
bRet = true;
}
else if( SwMove::UP == nDir || SwMove::DOWN == nDir )
bRet = false;
break;
}
case RndStdIds::FLY_AT_FLY:
{
OSL_ENSURE( pOld->IsFlyFrame(), "Wrong anchor, fly frame expected.");
SwPageFrame* pPage = pOld->FindPageFrame();
OSL_ENSURE( pPage, "Where's my page?" );
SwFlyFrame* pNewFly = nullptr;
if( pPage->GetSortedObjs() )
{
bool bOld = false;
Point aCenter( pOld->getFrameArea().Left() + pOld->getFrameArea().Width()/2,
pOld->getFrameArea().Top() + pOld->getFrameArea().Height()/2 );
Point aBest;
for(SwAnchoredObject* pAnchObj : *pPage->GetSortedObjs())
{
if( dynamic_cast<const SwFlyFrame*>( pAnchObj) != nullptr )
{
SwFlyFrame* pTmp = static_cast<SwFlyFrame*>(pAnchObj);
if( pTmp == pOld )
bOld = true;
else
{
const SwFlyFrame* pCheck = pFly ? pTmp : nullptr;
while( pCheck )
{
if( pCheck == pFly )
break;
const SwFrame *pNxt = pCheck->GetAnchorFrame();
pCheck = pNxt ? pNxt->FindFlyFrame() : nullptr;
}
if( pCheck || pTmp->IsProtected() )
continue;
Point aNew( pTmp->getFrameArea().Left() +
pTmp->getFrameArea().Width()/2,
pTmp->getFrameArea().Top() +
pTmp->getFrameArea().Height()/2 );
bool bAccept = false;
switch( nDir ) {
case SwMove::RIGHT:
{
bAccept = LessX( aCenter, aNew, bOld )
&& ( !pNewFly ||
LessX( aNew, aBest, false ) );
break;
}
case SwMove::LEFT:
{
bAccept = LessX( aNew, aCenter, !bOld )
&& ( !pNewFly ||
LessX( aBest, aNew, true ) );
break;
}
case SwMove::UP:
{
bAccept = LessY( aNew, aCenter, !bOld )
&& ( !pNewFly ||
LessY( aBest, aNew, true ) );
break;
}
case SwMove::DOWN:
{
bAccept = LessY( aCenter, aNew, bOld )
&& ( !pNewFly ||
LessY( aNew, aBest, false ) );
break;
}
}
if( bAccept )
{
pNewFly = pTmp;
aBest = aNew;
}
}
}
}
}
if( pNewFly )
{
SwPosition aPos( *pNewFly->GetFormat()->
GetContent().GetContentIdx());
aAnch.SetAnchor( &aPos );
bRet = true;
}
break;
}
default: break;
}
if( bRet )
{
StartAllAction();
// --> handle change of anchor node:
// if count of the anchor frame also change, the fly frames have to be
// re-created. Thus, delete all fly frames except the <this> before the
// anchor attribute is change and re-create them afterwards.
{
std::unique_ptr<SwHandleAnchorNodeChg, o3tl::default_delete<SwHandleAnchorNodeChg>> pHandleAnchorNodeChg;
SwFlyFrameFormat* pFlyFrameFormat( dynamic_cast<SwFlyFrameFormat*>(&rFormat) );
if ( pFlyFrameFormat )
{
pHandleAnchorNodeChg.reset(
new SwHandleAnchorNodeChg( *pFlyFrameFormat, aAnch ));
}
rFormat.GetDoc()->SetAttr( aAnch, rFormat );
}
// #i28701# - no call of method
// <CheckCharRectAndTopOfLine()> for to-character anchored
// Writer fly frame needed. This method call can cause a
// format of the anchor frame, which is no longer intended.
// Instead clear the anchor character rectangle and
// the top of line values for all to-character anchored objects.
pAnchoredObj->ClearCharRectAndTopOfLine();
EndAllAction();
}
}
return bRet;
}
const SdrMarkList* SwFEShell::GetMarkList_() const
{
const SdrMarkList* pMarkList = nullptr;
if( Imp()->GetDrawView() != nullptr )
pMarkList = &Imp()->GetDrawView()->GetMarkedObjectList();
return pMarkList;
}
FrameTypeFlags SwFEShell::GetSelFrameType() const
{
FrameTypeFlags eType;
// get marked frame list, and check if anything is selected
const SdrMarkList* pMarkList = GetMarkList_();
if( pMarkList == nullptr || pMarkList->GetMarkCount() == 0 )
eType = FrameTypeFlags::NONE;
else
{
// obtain marked item as fly frame; if no fly frame, it must
// be a draw object
const SwFlyFrame* pFly = ::GetFlyFromMarked(pMarkList, const_cast<SwFEShell*>(this));
if ( pFly != nullptr )
{
if( pFly->IsFlyLayFrame() )
eType = FrameTypeFlags::FLY_FREE;
else if( pFly->IsFlyAtContentFrame() )
eType = FrameTypeFlags::FLY_ATCNT;
else
{
OSL_ENSURE( pFly->IsFlyInContentFrame(), "New frametype?" );
eType = FrameTypeFlags::FLY_INCNT;
}
}
else
eType = FrameTypeFlags::DRAWOBJ;
}
return eType;
}
// does the draw selection contain a control?
bool SwFEShell::IsSelContainsControl() const
{
bool bRet = false;
// basically, copy the mechanism from GetSelFrameType(), but call
// CheckControl... if you get a drawing object
const SdrMarkList* pMarkList = GetMarkList_();
if( pMarkList != nullptr && pMarkList->GetMarkCount() == 1 )
{
// if we have one marked object, get the SdrObject and check
// whether it contains a control
const SdrObject* pSdrObject = pMarkList->GetMark( 0 )->GetMarkedSdrObj();
bRet = pSdrObject && ::CheckControlLayer( pSdrObject );
}
return bRet;
}
void SwFEShell::ScrollTo( const Point &rPt )
{
const SwRect aRect( rPt, rPt );
if ( IsScrollMDI( this, aRect ) &&
(!Imp()->GetDrawView()->GetMarkedObjectList().GetMarkCount() ||
Imp()->IsDragPossible( rPt )) )
{
ScrollMDI( this, aRect, SCROLLVAL, SCROLLVAL );
}
}
void SwFEShell::SetDragMode( SdrDragMode eDragMode )
{
if ( Imp()->HasDrawView() )
Imp()->GetDrawView()->SetDragMode( eDragMode );
}
SdrDragMode SwFEShell::GetDragMode() const
{
SdrDragMode nRet = SdrDragMode(0);
if ( Imp()->HasDrawView() )
{
nRet = Imp()->GetDrawView()->GetDragMode();
}
return nRet;
}
void SwFEShell::StartCropImage()
{
if ( !Imp()->HasDrawView() )
{
return;
}
SdrView *pView = Imp()->GetDrawView();
if (!pView) return;
const SdrMarkList &rMarkList = pView->GetMarkedObjectList();
if( 0 == rMarkList.GetMarkCount() ) {
// No object selected
return;
}
// If more than a single SwVirtFlyDrawObj is selected, select only the first SwVirtFlyDrawObj
if ( rMarkList.GetMarkCount() > 1 )
{
for ( size_t i = 0; i < rMarkList.GetMarkCount(); ++i )
{
SdrObject *pTmpObj = rMarkList.GetMark( i )->GetMarkedSdrObj();
bool bForget = dynamic_cast<const SwVirtFlyDrawObj*>( pTmpObj) != nullptr;
if( bForget )
{
pView->UnmarkAll();
pView->MarkObj( pTmpObj, Imp()->GetPageView() );
break;
}
}
}
// Activate CROP mode
pView->SetEditMode( SdrViewEditMode::Edit );
SetDragMode( SdrDragMode::Crop );
}
void SwFEShell::BeginDrag( const Point* pPt, bool bIsShift)
{
SdrView *pView = Imp()->GetDrawView();
if ( pView && pView->AreObjectsMarked() )
{
m_pChainFrom.reset();
m_pChainTo.reset();
SdrHdl* pHdl = pView->PickHandle( *pPt );
if (pView->BegDragObj( *pPt, nullptr, pHdl ))
pView->GetDragMethod()->SetShiftPressed( bIsShift );
::FrameNotify( this );
}
}
void SwFEShell::Drag( const Point *pPt, bool )
{
OSL_ENSURE( Imp()->HasDrawView(), "Drag without DrawView?" );
if ( HasDrawViewDrag() )
{
ScrollTo( *pPt );
Imp()->GetDrawView()->MovDragObj( *pPt );
Imp()->GetDrawView()->ShowDragAnchor();
::FrameNotify( this );
}
}
void SwFEShell::EndDrag()
{
OSL_ENSURE( Imp()->HasDrawView(), "EndDrag without DrawView?" );
SdrView *pView = Imp()->GetDrawView();
if ( pView->IsDragObj() )
{
for(SwViewShell& rSh : GetRingContainer())
rSh.StartAction();
StartUndo( SwUndoId::START );
// #50778# Bug during dragging: In StartAction a HideShowXor is called.
// In EndDragObj() this is reversed, for no reason and even wrong.
// To restore consistency we should bring up the Xor again.
// Reanimation from the hack #50778 to fix bug #97057
// May be not the best solution, but the one with lowest risc at the moment.
// pView->ShowShownXor( GetOut() );
pView->EndDragObj();
// DrawUndo on to flyframes are not stored
// The flys change the flag.
GetDoc()->GetIDocumentUndoRedo().DoDrawUndo(true);
ChgAnchor( RndStdIds::FLY_AT_PARA, true );
EndUndo( SwUndoId::END );
for(SwViewShell& rSh : GetRingContainer())
{
rSh.EndAction();
if( dynamic_cast<const SwCursorShell *>(&rSh) != nullptr )
static_cast<SwCursorShell*>(&rSh)->CallChgLnk();
}
GetDoc()->getIDocumentState().SetModified();
::FrameNotify( this );
}
}
void SwFEShell::BreakDrag()
{
OSL_ENSURE( Imp()->HasDrawView(), "BreakDrag without DrawView?" );
if( HasDrawViewDrag() )
Imp()->GetDrawView()->BrkDragObj();
SetChainMarker();
}
// If a fly is selected, pulls the crsr in the first ContentFrame
const SwFrameFormat* SwFEShell::SelFlyGrabCursor()
{
if ( Imp()->HasDrawView() )
{
const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
SwFlyFrame *pFly = ::GetFlyFromMarked( &rMrkList, this );
if( pFly )
{
SwContentFrame *pCFrame = pFly->ContainsContent();
if ( pCFrame )
{
// --> assure, that the cursor is consistent.
KillPams();
ClearMark();
SwPaM *pCursor = GetCursor();
if (pCFrame->IsTextFrame())
{
*pCursor->GetPoint() = static_cast<SwTextFrame *>(pCFrame)
->MapViewToModelPos(TextFrameIndex(0));
}
else
{
assert(pCFrame->IsNoTextFrame());
SwContentNode *const pCNode = static_cast<SwNoTextFrame *>(pCFrame)->GetNode();
pCursor->GetPoint()->nNode = *pCNode;
pCursor->GetPoint()->nContent.Assign( pCNode, 0 );
}
SwRect& rChrRect = const_cast<SwRect&>(GetCharRect());
rChrRect = pFly->getFramePrintArea();
rChrRect.Pos() += pFly->getFrameArea().Pos();
GetCursorDocPos() = rChrRect.Pos();
}
return pFly->GetFormat();
}
}
return nullptr;
}
// Selection to above/below (Z-Order)
static void lcl_NotifyNeighbours( const SdrMarkList *pLst )
{
// Rules for evasion have changed.
// 1. The environment of the fly and everything inside should be notified
// 2. The content of the frame itself has to be notified
// 3. Frames displaced by the frame have to be notified
// 4. Also Drawing objects can displace frames
for( size_t j = 0; j < pLst->GetMarkCount(); ++j )
{
SwPageFrame *pPage;
bool bCheckNeighbours = false;
sal_Int16 aHori = text::HoriOrientation::NONE;
SwRect aRect;
SdrObject *pO = pLst->GetMark( j )->GetMarkedSdrObj();
if (SwVirtFlyDrawObj* pVirtO = dynamic_cast<SwVirtFlyDrawObj*>(pO))
{
SwFlyFrame *pFly = pVirtO->GetFlyFrame();
const SwFormatHoriOrient &rHori = pFly->GetFormat()->GetHoriOrient();
aHori = rHori.GetHoriOrient();
if( text::HoriOrientation::NONE != aHori && text::HoriOrientation::CENTER != aHori &&
pFly->IsFlyAtContentFrame() )
{
bCheckNeighbours = true;
pFly->InvalidatePos();
SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*pFly);
aFrm.Pos().AdjustY(1 );
}
pPage = pFly->FindPageFrame();
aRect = pFly->getFrameArea();
}
else
{
SwFrame* pAnch = static_cast<SwDrawContact*>( GetUserCall(pO) )->GetAnchorFrame( pO );
if( !pAnch )
continue;
pPage = pAnch->FindPageFrame();
// #i68520# - naming changed
aRect = GetBoundRectOfAnchoredObj( pO );
}
const size_t nCount = pPage->GetSortedObjs() ? pPage->GetSortedObjs()->size() : 0;
for ( size_t i = 0; i < nCount; ++i )
{
SwAnchoredObject* pAnchoredObj = (*pPage->GetSortedObjs())[i];
if ( dynamic_cast<const SwFlyFrame*>( pAnchoredObj) == nullptr )
continue;
SwFlyFrame* pAct = static_cast<SwFlyFrame*>(pAnchoredObj);
SwRect aTmpCalcPnt( pAct->getFramePrintArea() );
aTmpCalcPnt += pAct->getFrameArea().Pos();
if ( aRect.IsOver( aTmpCalcPnt ) )
{
SwContentFrame *pCnt = pAct->ContainsContent();
while ( pCnt )
{
aTmpCalcPnt = pCnt->getFramePrintArea();
aTmpCalcPnt += pCnt->getFrameArea().Pos();
if ( aRect.IsOver( aTmpCalcPnt ) )
static_cast<SwFrame*>(pCnt)->Prepare( PrepareHint::FlyFrameAttributesChanged );
pCnt = pCnt->GetNextContentFrame();
}
}
if ( bCheckNeighbours && pAct->IsFlyAtContentFrame() )
{
const SwFormatHoriOrient &rH = pAct->GetFormat()->GetHoriOrient();
if ( rH.GetHoriOrient() == aHori &&
pAct->getFrameArea().Top() <= aRect.Bottom() &&
pAct->getFrameArea().Bottom() >= aRect.Top() )
{
pAct->InvalidatePos();
SwFrameAreaDefinition::FrameAreaWriteAccess aFrm(*pAct);
aFrm.Pos().AdjustY(1 );
}
}
}
}
}
void SwFEShell::SetLineEnds(SfxItemSet& rAttr, SdrObject const & rObj, sal_uInt16 nSlotId)
{
SdrModel& rModel(rObj.getSdrModelFromSdrObject());
if ( !(nSlotId == SID_LINE_ARROW_START ||
nSlotId == SID_LINE_ARROW_END ||
nSlotId == SID_LINE_ARROWS ||
nSlotId == SID_LINE_ARROW_CIRCLE ||
nSlotId == SID_LINE_CIRCLE_ARROW ||
nSlotId == SID_LINE_ARROW_SQUARE ||
nSlotId == SID_LINE_SQUARE_ARROW ||
nSlotId == SID_DRAW_MEASURELINE) )
return;
// set attributes of line start and ends
// arrowhead
::basegfx::B2DPolyPolygon aArrow( getPolygon( RID_SVXSTR_ARROW, rModel ) );
if( !aArrow.count() )
{
::basegfx::B2DPolygon aNewArrow;
aNewArrow.append(::basegfx::B2DPoint(10.0, 0.0));
aNewArrow.append(::basegfx::B2DPoint(0.0, 30.0));
aNewArrow.append(::basegfx::B2DPoint(20.0, 30.0));
aNewArrow.setClosed(true);
aArrow.append(aNewArrow);
}
// Circles
::basegfx::B2DPolyPolygon aCircle( getPolygon( RID_SVXSTR_CIRCLE, rModel ) );
if( !aCircle.count() )
{
::basegfx::B2DPolygon aNewCircle = ::basegfx::utils::createPolygonFromEllipse(::basegfx::B2DPoint(0.0, 0.0), 250.0, 250.0);
aNewCircle.setClosed(true);
aCircle.append(aNewCircle);
}
// Square
::basegfx::B2DPolyPolygon aSquare( getPolygon( RID_SVXSTR_SQUARE, rModel ) );
if( !aSquare.count() )
{
::basegfx::B2DPolygon aNewSquare;
aNewSquare.append(::basegfx::B2DPoint(0.0, 0.0));
aNewSquare.append(::basegfx::B2DPoint(10.0, 0.0));
aNewSquare.append(::basegfx::B2DPoint(10.0, 10.0));
aNewSquare.append(::basegfx::B2DPoint(0.0, 10.0));
aNewSquare.setClosed(true);
aSquare.append(aNewSquare);
}
SfxItemSet aSet( rModel.GetItemPool() );
long nWidth = 100; // (1/100th mm)
// determine line width and calculate with it the line end width
if( aSet.GetItemState( XATTR_LINEWIDTH ) != SfxItemState::DONTCARE )
{
long nValue = aSet.Get( XATTR_LINEWIDTH ).GetValue();
if( nValue > 0 )
nWidth = nValue * 3;
}
switch (nSlotId)
{
case SID_LINE_ARROWS:
case SID_DRAW_MEASURELINE:
{
// connector with arrow ends
rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
rAttr.Put(XLineStartWidthItem(nWidth));
rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
rAttr.Put(XLineEndWidthItem(nWidth));
}
break;
case SID_LINE_ARROW_START:
case SID_LINE_ARROW_CIRCLE:
case SID_LINE_ARROW_SQUARE:
{
// connector with arrow start
rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
rAttr.Put(XLineStartWidthItem(nWidth));
}
break;
case SID_LINE_ARROW_END:
case SID_LINE_CIRCLE_ARROW:
case SID_LINE_SQUARE_ARROW:
{
// connector with arrow end
rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW), aArrow));
rAttr.Put(XLineEndWidthItem(nWidth));
}
break;
}
// and again, for the still missing ends
switch (nSlotId)
{
case SID_LINE_CIRCLE_ARROW:
{
// circle start
rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_CIRCLE), aCircle));
rAttr.Put(XLineStartWidthItem(nWidth));
}
break;
case SID_LINE_ARROW_SQUARE:
{
// square end
rAttr.Put(XLineEndItem(SvxResId(RID_SVXSTR_SQUARE), aSquare));
rAttr.Put(XLineEndWidthItem(nWidth));
}
break;
case SID_LINE_SQUARE_ARROW:
{
// square start
rAttr.Put(XLineStartItem(SvxResId(RID_SVXSTR_SQUARE), aSquare));
rAttr.Put(XLineStartWidthItem(nWidth));
}
break;
}
}
void SwFEShell::SelectionToTop( bool bTop )
{
OSL_ENSURE( Imp()->HasDrawView(), "SelectionToTop without DrawView?" );
const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
OSL_ENSURE( rMrkList.GetMarkCount(), "No object selected." );
SwFlyFrame *pFly = ::GetFlyFromMarked( &rMrkList, this );
if ( pFly && pFly->IsFlyInContentFrame() )
return;
StartAllAction();
if ( bTop )
Imp()->GetDrawView()->PutMarkedToTop();
else
Imp()->GetDrawView()->MovMarkedToTop();
::lcl_NotifyNeighbours( &rMrkList );
GetDoc()->getIDocumentState().SetModified();
EndAllAction();
}
void SwFEShell::SelectionToBottom( bool bBottom )
{
OSL_ENSURE( Imp()->HasDrawView(), "SelectionToBottom without DrawView?" );
const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
OSL_ENSURE( rMrkList.GetMarkCount(), "No object selected." );
SwFlyFrame *pFly = ::GetFlyFromMarked( &rMrkList, this );
if ( pFly && pFly->IsFlyInContentFrame() )
return;
StartAllAction();
if ( bBottom )
Imp()->GetDrawView()->PutMarkedToBtm();
else
Imp()->GetDrawView()->MovMarkedToBtm();
::lcl_NotifyNeighbours( &rMrkList );
GetDoc()->getIDocumentState().SetModified();
EndAllAction();
}
// Object above/below the document? 2 Controls, 1 Heaven, 0 Hell,
// SDRLAYER_NOTFOUND Ambiguous
SdrLayerID SwFEShell::GetLayerId() const
{
if ( !Imp()->HasDrawView() )
return SDRLAYER_NOTFOUND;
SdrLayerID nRet = SDRLAYER_NOTFOUND;
const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
for ( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
{
const SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
if( !pObj )
continue;
if ( nRet == SDRLAYER_NOTFOUND )
nRet = pObj->GetLayer();
else if ( nRet != pObj->GetLayer() )
{
return SDRLAYER_NOTFOUND;
}
}
return nRet;
}
// Object above/below the document
// Note: only visible objects can be marked. Thus, objects with invisible
// layer IDs have not to be considered.
// If <SwFEShell> exists, layout exists!!
void SwFEShell::ChangeOpaque( SdrLayerID nLayerId )
{
if ( Imp()->HasDrawView() )
{
const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
const IDocumentDrawModelAccess& rIDDMA = getIDocumentDrawModelAccess();
// correct type of <nControls>
for ( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
{
SdrObject* pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
if( !pObj )
continue;
// or group objects containing controls.
// --> #i113730#
// consider that a member of a drawing group has been selected.
const SwContact* pContact = ::GetUserCall( pObj );
OSL_ENSURE( pContact && pContact->GetMaster(), "<SwFEShell::ChangeOpaque(..)> - missing contact or missing master object at contact!" );
const bool bControlObj = ( pContact && pContact->GetMaster() )
? ::CheckControlLayer( pContact->GetMaster() )
: ::CheckControlLayer( pObj );
if ( !bControlObj && pObj->GetLayer() != nLayerId )
{
pObj->SetLayer( nLayerId );
InvalidateWindows( SwRect( pObj->GetCurrentBoundRect() ) );
if (SwVirtFlyDrawObj* pVirtO = dynamic_cast<SwVirtFlyDrawObj*>(pObj))
{
SwFormat *pFormat = pVirtO->GetFlyFrame()->GetFormat();
SvxOpaqueItem aOpa( pFormat->GetOpaque() );
aOpa.SetValue( nLayerId == rIDDMA.GetHellId() );
pFormat->SetFormatAttr( aOpa );
}
}
}
GetDoc()->getIDocumentState().SetModified();
}
}
void SwFEShell::SelectionToHeaven()
{
ChangeOpaque( getIDocumentDrawModelAccess().GetHeavenId() );
}
void SwFEShell::SelectionToHell()
{
ChangeOpaque( getIDocumentDrawModelAccess().GetHellId() );
}
size_t SwFEShell::IsObjSelected() const
{
if ( IsFrameSelected() || !Imp()->HasDrawView() )
return 0;
return Imp()->GetDrawView()->GetMarkedObjectList().GetMarkCount();
}
bool SwFEShell::IsFrameSelected() const
{
if ( !Imp()->HasDrawView() )
return false;
else
return nullptr != ::GetFlyFromMarked( &Imp()->GetDrawView()->GetMarkedObjectList(),
const_cast<SwFEShell*>(this) );
}
bool SwFEShell::IsObjSelected( const SdrObject& rObj ) const
{
if ( IsFrameSelected() || !Imp()->HasDrawView() )
return false;
else
return Imp()->GetDrawView()->IsObjMarked( &rObj );
}
bool SwFEShell::IsRotationOfSwGrfNodePossible() const
{
// RotGrfFlyFrame: check if RotationMode is possible
const SdrView *pSdrView = Imp()->GetDrawView();
if(pSdrView)
{
const SdrMarkList& rList(pSdrView->GetMarkedObjectList());
if(1 == rList.GetMarkCount())
{
const SwVirtFlyDrawObj* pVirtFlyDraw(dynamic_cast< const SwVirtFlyDrawObj* >(rList.GetMark(0)->GetMarkedSdrObj()));
if(nullptr != pVirtFlyDraw)
{
return pVirtFlyDraw->ContainsSwGrfNode();
}
}
}
return false;
}
bool SwFEShell::IsObjSameLevelWithMarked(const SdrObject* pObj) const
{
if (pObj)
{
const SdrMarkList& aMarkList = Imp()->GetDrawView()->GetMarkedObjectList();
if (aMarkList.GetMarkCount() == 0)
{
return true;
}
SdrMark* pM=aMarkList.GetMark(0);
if (pM)
{
SdrObject* pMarkObj = pM->GetMarkedSdrObj();
if (pMarkObj && pMarkObj->getParentSdrObjectFromSdrObject() == pObj->getParentSdrObjectFromSdrObject())
return true;
}
}
return false;
}
void SwFEShell::EndTextEdit()
{
// Terminate the TextEditMode. If required (default if the object
// does not contain any more text and does not carry attributes) the object
// is deleted. All other objects marked are preserved.
OSL_ENSURE( Imp()->HasDrawView() && Imp()->GetDrawView()->IsTextEdit(),
"EndTextEdit a no Object" );
StartAllAction();
SdrView *pView = Imp()->GetDrawView();
SdrObject *pObj = pView->GetTextEditObject();
SdrObjUserCall* pUserCall;
if( nullptr != ( pUserCall = GetUserCall(pObj) ) )
{
SdrObject *pTmp = static_cast<SwContact*>(pUserCall)->GetMaster();
if( !pTmp )
pTmp = pObj;
pUserCall->Changed( *pTmp, SdrUserCallType::Resize, pTmp->GetLastBoundRect() );
}
if ( !pObj->getParentSdrObjectFromSdrObject() )
{
if ( SdrEndTextEditKind::ShouldBeDeleted == pView->SdrEndTextEdit(true) )
{
if ( pView->GetMarkedObjectList().GetMarkCount() > 1 )
{
SdrMarkList aSave( pView->GetMarkedObjectList() );
aSave.DeleteMark( aSave.FindObject( pObj ) );
if ( aSave.GetMarkCount() )
{
pView->UnmarkAll();
pView->MarkObj( pObj, Imp()->GetPageView() );
}
DelSelectedObj();
for ( size_t i = 0; i < aSave.GetMarkCount(); ++i )
pView->MarkObj( aSave.GetMark( i )->GetMarkedSdrObj(), Imp()->GetPageView() );
}
else
DelSelectedObj();
}
}
else
pView->SdrEndTextEdit();
if (comphelper::LibreOfficeKit::isActive())
SfxLokHelper::notifyOtherViews(GetSfxViewShell(), LOK_CALLBACK_VIEW_LOCK, "rectangle", "EMPTY");
EndAllAction();
}
bool SwFEShell::IsInsideSelectedObj( const Point &rPt )
{
if( Imp()->HasDrawView() )
{
SwDrawView *pDView = Imp()->GetDrawView();
if( pDView->GetMarkedObjectList().GetMarkCount() &&
pDView->IsMarkedObjHit( rPt ) )
{
return true;
}
}
return false;
}
bool SwFEShell::IsObjSelectable( const Point& rPt )
{
SET_CURR_SHELL(this);
SwDrawView *pDView = Imp()->GetDrawView();
bool bRet = false;
if( pDView )
{
SdrPageView* pPV;
const auto nOld = pDView->GetHitTolerancePixel();
pDView->SetHitTolerancePixel( pDView->GetMarkHdlSizePixel()/2 );
bRet = pDView->PickObj(rPt, pDView->getHitTolLog(), pPV, SdrSearchOptions::PICKMARKABLE) != nullptr;
pDView->SetHitTolerancePixel( nOld );
}
return bRet;
}
SdrObject* SwFEShell::GetObjAt( const Point& rPt )
{
SdrObject* pRet = nullptr;
SET_CURR_SHELL(this);
SwDrawView *pDView = Imp()->GetDrawView();
if( pDView )
{
SdrPageView* pPV;
const auto nOld = pDView->GetHitTolerancePixel();
pDView->SetHitTolerancePixel( pDView->GetMarkHdlSizePixel()/2 );
pRet = pDView->PickObj(rPt, pDView->getHitTolLog(), pPV, SdrSearchOptions::PICKMARKABLE);
pDView->SetHitTolerancePixel( nOld );
}
return pRet;
}
// Test if there is an object at that position and if it should be selected.
bool SwFEShell::ShouldObjectBeSelected(const Point& rPt)
{
SET_CURR_SHELL(this);
SwDrawView *pDrawView = Imp()->GetDrawView();
bool bRet(false);
if(pDrawView)
{
SdrPageView* pPV;
const auto nOld(pDrawView->GetHitTolerancePixel());
pDrawView->SetHitTolerancePixel(pDrawView->GetMarkHdlSizePixel()/2);
SdrObject* pObj = pDrawView->PickObj(rPt, pDrawView->getHitTolLog(), pPV, SdrSearchOptions::PICKMARKABLE);
pDrawView->SetHitTolerancePixel(nOld);
if (pObj)
{
bRet = true;
const IDocumentDrawModelAccess& rIDDMA = getIDocumentDrawModelAccess();
// #i89920#
// Do not select object in background which is overlapping this text
// at the given position.
bool bObjInBackground( false );
{
if ( pObj->GetLayer() == rIDDMA.GetHellId() )
{
const SwAnchoredObject* pAnchoredObj = ::GetUserCall( pObj )->GetAnchoredObj( pObj );
const SwFrameFormat& rFormat = pAnchoredObj->GetFrameFormat();
const SwFormatSurround& rSurround = rFormat.GetSurround();
if ( rSurround.GetSurround() == css::text::WrapTextMode_THROUGH )
{
bObjInBackground = true;
}
}
}
if ( bObjInBackground )
{
const SwPageFrame* pPageFrame = GetLayout()->GetPageAtPos( rPt );
if( pPageFrame )
{
const SwContentFrame* pContentFrame( pPageFrame->ContainsContent() );
while ( pContentFrame )
{
if ( pContentFrame->UnionFrame().IsInside( rPt ) )
{
const SwTextFrame* pTextFrame =
dynamic_cast<const SwTextFrame*>(pContentFrame);
if ( pTextFrame )
{
SwPosition aPos(GetDoc()->GetNodes());
Point aTmpPt( rPt );
if (pTextFrame->GetKeyCursorOfst(&aPos, aTmpPt))
{
SwRect aCursorCharRect;
if (pTextFrame->GetCharRect(aCursorCharRect,
aPos))
{
if ( aCursorCharRect.IsOver( SwRect( pObj->GetLastBoundRect() ) ) )
{
bRet = false;
}
}
}
}
else
{
bRet = false;
}
break;
}
pContentFrame = pContentFrame->GetNextContentFrame();
}
}
}
// Don't select header / footer objects in body edition and vice-versa
SwContact* pContact = static_cast<SwContact*>(pObj->GetUserCall());
if (pContact && !pContact->ObjAnchoredAtPage() )
{
const SwPosition& rPos = pContact->GetContentAnchor();
bool bInHdrFtr = GetDoc()->IsInHeaderFooter( rPos.nNode );
if (IsHeaderFooterEdit() != bInHdrFtr)
{
bRet = false;
}
}
if ( bRet )
{
const SdrPage* pPage = rIDDMA.GetDrawModel()->GetPage(0);
for(size_t a = pObj->GetOrdNum()+1; bRet && a < pPage->GetObjCount(); ++a)
{
SdrObject *pCandidate = pPage->GetObj(a);
SwVirtFlyDrawObj* pDrawObj = dynamic_cast<SwVirtFlyDrawObj*>(pCandidate);
if (pDrawObj && pDrawObj->GetCurrentBoundRect().IsInside(rPt))
{
bRet = false;
}
}
}
}
}
return bRet;
}
/*
* If an object was selected, we assume its upper-left corner
* otherwise the middle of the current CharRects.
* Does the object include a control or groups,
* which comprise only controls
*/
static bool lcl_IsControlGroup( const SdrObject *pObj )
{
bool bRet = false;
if(dynamic_cast<const SdrUnoObj*>( pObj) != nullptr)
bRet = true;
else if( auto pObjGroup = dynamic_cast<const SdrObjGroup*>( pObj) )
{
bRet = true;
const SdrObjList *pLst = pObjGroup->GetSubList();
for ( size_t i = 0; i < pLst->GetObjCount(); ++i )
if( !::lcl_IsControlGroup( pLst->GetObj( i ) ) )
return false;
}
return bRet;
}
namespace
{
class MarkableObjectsOnly : public svx::ISdrObjectFilter
{
public:
explicit MarkableObjectsOnly( SdrPageView* i_pPV )
:m_pPV( i_pPV )
{
}
virtual bool includeObject( const SdrObject& i_rObject ) const override
{
return m_pPV && m_pPV->GetView().IsObjMarkable( &i_rObject, m_pPV );
}
private:
SdrPageView* m_pPV;
};
}
const SdrObject* SwFEShell::GetBestObject( bool bNext, GotoObjFlags eType, bool bFlat, const svx::ISdrObjectFilter* pFilter )
{
if( !Imp()->HasDrawView() )
return nullptr;
const SdrObject *pBest = nullptr,
*pTop = nullptr;
const long nTmp = bNext ? LONG_MAX : 0;
Point aBestPos( nTmp, nTmp );
Point aTopPos( nTmp, nTmp );
Point aCurPos;
Point aPos;
bool bNoDraw((GotoObjFlags::DrawAny & eType) == GotoObjFlags::NONE);
bool bNoFly((GotoObjFlags::FlyAny & eType) == GotoObjFlags::NONE);
if( !bNoFly && bNoDraw )
{
SwFlyFrame *pFly = GetCurrFrame( false )->FindFlyFrame();
if( pFly )
pBest = pFly->GetVirtDrawObj();
}
const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
SdrPageView* pPV = Imp()->GetDrawView()->GetSdrPageView();
MarkableObjectsOnly aDefaultFilter( pPV );
if ( !pFilter )
pFilter = &aDefaultFilter;
if( !pBest || rMrkList.GetMarkCount() == 1 )
{
// Determine starting point
SdrObjList* pList = nullptr;
if ( rMrkList.GetMarkCount() )
{
const SdrObject* pStartObj = rMrkList.GetMark(0)->GetMarkedSdrObj();
if( auto pVirtFlyDrawObj = dynamic_cast<const SwVirtFlyDrawObj*>( pStartObj) )
aPos = pVirtFlyDrawObj->GetFlyFrame()->getFrameArea().Pos();
else
aPos = pStartObj->GetSnapRect().TopLeft();
// If an object inside a group is selected, we want to
// iterate over the group members.
if ( ! pStartObj->GetUserCall() )
pList = pStartObj->getParentSdrObjListFromSdrObject();
}
else
{
// If no object is selected, we check if we just entered a group.
// In this case we want to iterate over the group members.
aPos = GetCharRect().Center();
const SdrObject* pStartObj = pPV ? pPV->GetCurrentGroup() : nullptr;
if ( dynamic_cast<const SdrObjGroup*>( pStartObj) )
pList = pStartObj->GetSubList();
}
if ( ! pList )
{
// Here we are if
// A No object has been selected and no group has been entered or
// B An object has been selected and it is not inside a group
pList = getIDocumentDrawModelAccess().GetDrawModel()->GetPage( 0 );
}
OSL_ENSURE( pList, "No object list to iterate" );
SdrObjListIter aObjIter( pList, bFlat ? SdrIterMode::Flat : SdrIterMode::DeepNoGroups );
while ( aObjIter.IsMore() )
{
SdrObject* pObj = aObjIter.Next();
SwVirtFlyDrawObj *pVirtO = dynamic_cast<SwVirtFlyDrawObj*>(pObj);
if( ( bNoFly && pVirtO ) ||
( bNoDraw && !pVirtO ) ||
// Ignore TextBoxes of draw shapes here, so that
// SwFEShell::SelectObj() won't jump back on this list, meaning
// we never jump to the next draw shape.
(pVirtO && pVirtO->IsTextBox()) ||
( eType == GotoObjFlags::DrawSimple && lcl_IsControlGroup( pObj ) ) ||
( eType == GotoObjFlags::DrawControl && !lcl_IsControlGroup( pObj ) ) ||
!pFilter->includeObject( *pObj ) )
continue;
if (pVirtO)
{
SwFlyFrame *pFly = pVirtO->GetFlyFrame();
if( GotoObjFlags::FlyAny != ( GotoObjFlags::FlyAny & eType ) )
{
switch ( eType )
{
case GotoObjFlags::FlyFrame:
if ( pFly->Lower() && pFly->Lower()->IsNoTextFrame() )
continue;
break;
case GotoObjFlags::FlyGrf:
if ( pFly->Lower() &&
(!pFly->Lower()->IsNoTextFrame() ||
!static_cast<SwNoTextFrame*>(pFly->Lower())->GetNode()->GetGrfNode()))
continue;
break;
case GotoObjFlags::FlyOLE:
if ( pFly->Lower() &&
(!pFly->Lower()->IsNoTextFrame() ||
!static_cast<SwNoTextFrame*>(pFly->Lower())->GetNode()->GetOLENode()))
continue;
break;
default: break;
}
}
aCurPos = pFly->getFrameArea().Pos();
}
else
aCurPos = pObj->GetSnapRect().TopLeft();
// Special case if another object is on same Y.
if( aCurPos != aPos && // only when it is not me
aCurPos.getY() == aPos.getY() && // Y positions equal
(bNext? (aCurPos.getX() > aPos.getX()) : // lies next to me
(aCurPos.getX() < aPos.getX())) ) // " reverse
{
aBestPos = Point( nTmp, nTmp );
SdrObjListIter aTmpIter( pList, bFlat ? SdrIterMode::Flat : SdrIterMode::DeepNoGroups );
while ( aTmpIter.IsMore() )
{
SdrObject* pTmpObj = aTmpIter.Next();
pVirtO = dynamic_cast<SwVirtFlyDrawObj*>(pTmpObj);
if( ( bNoFly && pVirtO ) || ( bNoDraw && !pVirtO ) )
continue;
if (pVirtO)
{
aCurPos = pVirtO->GetFlyFrame()->getFrameArea().Pos();
}
else
aCurPos = pTmpObj->GetCurrentBoundRect().TopLeft();
if( aCurPos != aPos && aCurPos.Y() == aPos.Y() &&
(bNext? (aCurPos.getX() > aPos.getX()) : // lies next to me
(aCurPos.getX() < aPos.getX())) && // " reverse
(bNext? (aCurPos.getX() < aBestPos.getX()) : // better as best
(aCurPos.getX() > aBestPos.getX())) ) // " reverse
{
aBestPos = aCurPos;
pBest = pTmpObj;
}
}
break;
}
if( (
(bNext? (aPos.getY() < aCurPos.getY()) : // only below me
(aPos.getY() > aCurPos.getY())) && // " reverse
(bNext? (aBestPos.getY() > aCurPos.getY()) : // closer below
(aBestPos.getY() < aCurPos.getY()))
) || // " reverse
(aBestPos.getY() == aCurPos.getY() &&
(bNext? (aBestPos.getX() > aCurPos.getX()) : // further left
(aBestPos.getX() < aCurPos.getX())))) // " reverse
{
aBestPos = aCurPos;
pBest = pObj;
}
if( (bNext? (aTopPos.getY() > aCurPos.getY()) : // higher as best
(aTopPos.getY() < aCurPos.getY())) || // " reverse
(aTopPos.getY() == aCurPos.getY() &&
(bNext? (aTopPos.getX() > aCurPos.getX()) : // further left
(aTopPos.getX() < aCurPos.getX())))) // " reverse
{
aTopPos = aCurPos;
pTop = pObj;
}
}
// unfortunately nothing found
if( bNext ? (aBestPos.getX() == LONG_MAX) : (aBestPos.getX() == 0) )
{
pBest = pTop;
SvxSearchDialogWrapper::SetSearchLabel( bNext ? SearchLabel::EndWrapped : SearchLabel::StartWrapped );
}
}
return pBest;
}
bool SwFEShell::GotoObj( bool bNext, GotoObjFlags eType )
{
SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::Empty );
const SdrObject* pBest = GetBestObject( bNext, eType );
if ( !pBest )
{
SvxSearchDialogWrapper::SetSearchLabel( SearchLabel::NavElementNotFound );
return false;
}
const SwVirtFlyDrawObj *pVirtO = dynamic_cast<const SwVirtFlyDrawObj*>(pBest);
if (pVirtO)
{
const SwRect& rFrame = pVirtO->GetFlyFrame()->getFrameArea();
SelectObj( rFrame.Pos(), 0, const_cast<SdrObject*>(pBest) );
if( !ActionPend() )
MakeVisible( rFrame );
}
else
{
SelectObj( Point(), 0, const_cast<SdrObject*>(pBest) );
if( !ActionPend() )
MakeVisible( pBest->GetCurrentBoundRect() );
}
CallChgLnk();
return true;
}
bool SwFEShell::BeginCreate( sal_uInt16 /*SdrObjKind ?*/ eSdrObjectKind, const Point &rPos )
{
bool bRet = false;
if ( !Imp()->HasDrawView() )
Imp()->MakeDrawView();
if ( GetPageNumber( rPos ) )
{
Imp()->GetDrawView()->SetCurrentObj( eSdrObjectKind );
if ( eSdrObjectKind == OBJ_CAPTION )
bRet = Imp()->GetDrawView()->BegCreateCaptionObj(
rPos, Size( lMinBorder - MINFLY, lMinBorder - MINFLY ),
GetOut() );
else
bRet = Imp()->GetDrawView()->BegCreateObj( rPos, GetOut() );
}
if ( bRet )
{
::FrameNotify( this, FLY_DRAG_START );
}
return bRet;
}
bool SwFEShell::BeginCreate( sal_uInt16 /*SdrObjKind ?*/ eSdrObjectKind, SdrInventor eObjInventor,
const Point &rPos )
{
bool bRet = false;
if ( !Imp()->HasDrawView() )
Imp()->MakeDrawView();
if ( GetPageNumber( rPos ) )
{
Imp()->GetDrawView()->SetCurrentObj( eSdrObjectKind, eObjInventor );
bRet = Imp()->GetDrawView()->BegCreateObj( rPos, GetOut() );
}
if ( bRet )
::FrameNotify( this, FLY_DRAG_START );
return bRet;
}
void SwFEShell::MoveCreate( const Point &rPos )
{
OSL_ENSURE( Imp()->HasDrawView(), "MoveCreate without DrawView?" );
if ( GetPageNumber( rPos ) )
{
ScrollTo( rPos );
Imp()->GetDrawView()->MovCreateObj( rPos );
::FrameNotify( this );
}
}
bool SwFEShell::EndCreate( SdrCreateCmd eSdrCreateCmd )
{
// To assure undo-object from the DrawEngine is not stored,
// (we create our own undo-object!), temporarily switch-off Undo
OSL_ENSURE( Imp()->HasDrawView(), "EndCreate without DrawView?" );
if( !Imp()->GetDrawView()->IsGroupEntered() )
{
GetDoc()->GetIDocumentUndoRedo().DoDrawUndo(false);
}
bool bCreate = Imp()->GetDrawView()->EndCreateObj( eSdrCreateCmd );
GetDoc()->GetIDocumentUndoRedo().DoDrawUndo(true);
if ( !bCreate )
{
::FrameNotify( this, FLY_DRAG_END );
return false;
}
if ( eSdrCreateCmd == SdrCreateCmd::NextPoint )
{
::FrameNotify( this );
return true;
}
return ImpEndCreate();
}
bool SwFEShell::ImpEndCreate()
{
OSL_ENSURE( Imp()->GetDrawView()->GetMarkedObjectList().GetMarkCount() == 1,
"New object not selected." );
SdrObject& rSdrObj = *Imp()->GetDrawView()->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj();
if( rSdrObj.GetSnapRect().IsEmpty() )
{
// preferably we forget the object, only gives problems
Imp()->GetDrawView()->DeleteMarked();
Imp()->GetDrawView()->UnmarkAll();
::FrameNotify( this, FLY_DRAG_END );
return false;
}
if( rSdrObj.getParentSdrObjectFromSdrObject() )
{
Point aTmpPos( rSdrObj.GetSnapRect().TopLeft() );
Point aNewAnchor( rSdrObj.getParentSdrObjectFromSdrObject()->GetAnchorPos() );
// OD 2004-04-05 #i26791# - direct object positioning for group members
rSdrObj.NbcSetRelativePos( aTmpPos - aNewAnchor );
rSdrObj.NbcSetAnchorPos( aNewAnchor );
::FrameNotify( this );
return true;
}
LockPaint();
StartAllAction();
Imp()->GetDrawView()->UnmarkAll();
const tools::Rectangle &rBound = rSdrObj.GetSnapRect();
Point aPt( rBound.TopRight() );
// alien identifier should end up on defaults
// duplications possible!!
sal_uInt16 nIdent = SdrInventor::Default == rSdrObj.GetObjInventor()
? rSdrObj.GetObjIdentifier()
: 0xFFFF;
// default for controls character bound, otherwise paragraph bound.
SwFormatAnchor aAnch;
const SwFrame *pAnch = nullptr;
bool bCharBound = false;
if( dynamic_cast<const SdrUnoObj*>( &rSdrObj) != nullptr )
{
SwPosition aPos( GetDoc()->GetNodes() );
SwCursorMoveState aState( CursorMoveState::SetOnlyText );
Point aPoint( aPt.getX(), aPt.getY() + rBound.GetHeight()/2 );
GetLayout()->GetModelPositionForViewPoint( &aPos, aPoint, &aState );
// characterbinding not allowed in readonly-content
if( !aPos.nNode.GetNode().IsProtect() )
{
std::pair<Point, bool> const tmp(aPoint, true);
pAnch = aPos.nNode.GetNode().GetContentNode()->getLayoutFrame(GetLayout(), &aPos, &tmp);
SwRect aTmp;
pAnch->GetCharRect( aTmp, aPos );
// The crsr should not be too far away
bCharBound = true;
tools::Rectangle aRect( aTmp.SVRect() );
aRect.AdjustLeft( -(MM50*2) );
aRect.AdjustTop( -(MM50*2) );
aRect.AdjustRight(MM50*2 );
aRect.AdjustBottom(MM50*2 );
if( !aRect.IsOver( rBound ) && !::GetHtmlMode( GetDoc()->GetDocShell() ))
bCharBound = false;
// anchor in header/footer also not allowed.
if( bCharBound )
bCharBound = !GetDoc()->IsInHeaderFooter( aPos.nNode );
if( bCharBound )
{
aAnch.SetType( RndStdIds::FLY_AS_CHAR );
aAnch.SetAnchor( &aPos );
}
}
}
if( !bCharBound )
{
// allow native drawing objects in header/footer.
// Thus, set <bBodyOnly> to <false> for these objects using value
// of <nIdent> - value <0xFFFF> indicates control objects, which aren't
// allowed in header/footer.
//bool bBodyOnly = OBJ_NONE != nIdent;
bool bBodyOnly = 0xFFFF == nIdent;
bool bAtPage = false;
const SwFrame* pPage = nullptr;
SwCursorMoveState aState( CursorMoveState::SetOnlyText );
Point aPoint( aPt );
SwPosition aPos( GetDoc()->GetNodes() );
GetLayout()->GetModelPositionForViewPoint( &aPos, aPoint, &aState );
// do not set in ReadnOnly-content
if (aPos.nNode.GetNode().IsProtect())
{
// then only page bound. Or should we
// search the next not-readonly position?
bAtPage = true;
}
SwContentNode* pCNode = aPos.nNode.GetNode().GetContentNode();
std::pair<Point, bool> const tmp(aPoint, false);
pAnch = pCNode ? pCNode->getLayoutFrame(GetLayout(), nullptr, &tmp) : nullptr;
if (!pAnch)
{
// Hidden content. Anchor to the page instead
bAtPage = true;
}
if( !bAtPage )
{
const SwFlyFrame *pTmp = pAnch->FindFlyFrame();
if( pTmp )
{
const SwFrame* pTmpFrame = pAnch;
SwRect aBound( rBound );
while( pTmp )
{
if( pTmp->getFrameArea().IsInside( aBound ) )
{
if( !bBodyOnly || !pTmp->FindFooterOrHeader() )
pPage = pTmpFrame;
break;
}
pTmp = pTmp->GetAnchorFrame()
? pTmp->GetAnchorFrame()->FindFlyFrame()
: nullptr;
pTmpFrame = pTmp;
}
}
if( !pPage )
pPage = pAnch->FindPageFrame();
// Always via FindAnchor, to assure the frame will be bound
// to the previous. With GetCrsOfst we can also reach the next. THIS IS WRONG.
pAnch = ::FindAnchor( pPage, aPt, bBodyOnly );
if (pAnch->IsTextFrame())
{
std::pair<SwTextNode const*, sal_Int32> const pos(
static_cast<SwTextFrame const*>(pAnch)->MapViewToModel(TextFrameIndex(0)));
aPos.nNode = *pos.first;
}
else
{
aPos.nNode = *static_cast<const SwNoTextFrame*>(pAnch)->GetNode();
}
// do not set in ReadnOnly-content
if( aPos.nNode.GetNode().IsProtect() )
// then only page bound. Or should we
// search the next not-readonly position?
bAtPage = true;
else
{
aAnch.SetType( RndStdIds::FLY_AT_PARA );
aAnch.SetAnchor( &aPos );
}
}
if( bAtPage )
{
pPage = pAnch ? pAnch->FindPageFrame() : GetLayout()->GetPageAtPos(aPoint);
aAnch.SetType( RndStdIds::FLY_AT_PAGE );
aAnch.SetPageNum( pPage->GetPhyPageNum() );
pAnch = pPage; // page becomes an anchor
}
}
SfxItemSet aSet( GetDoc()->GetAttrPool(), svl::Items<RES_FRM_SIZE, RES_FRM_SIZE,
RES_SURROUND, RES_ANCHOR>{} );
aSet.Put( aAnch );
// OD 2004-03-30 #i26791# - determine relative object position
SwTwips nXOffset;
SwTwips nYOffset = rBound.Top() - pAnch->getFrameArea().Top();
{
if( pAnch->IsVertical() )
{
nXOffset = nYOffset;
nYOffset = pAnch->getFrameArea().Left()+pAnch->getFrameArea().Width()-rBound.Right();
}
else if( pAnch->IsRightToLeft() )
nXOffset = pAnch->getFrameArea().Left()+pAnch->getFrameArea().Width()-rBound.Right();
else
nXOffset = rBound.Left() - pAnch->getFrameArea().Left();
if (pAnch->IsTextFrame())
{
const SwTextFrame* pTmp = static_cast<const SwTextFrame*>(pAnch);
if (pTmp->IsFollow())
{
do {
pTmp = pTmp->FindMaster();
OSL_ENSURE(pTmp, "Where's my Master?");
// OD 2004-03-30 #i26791# - correction: add frame area height
// of master frames.
nYOffset += pTmp->IsVertical() ?
pTmp->getFrameArea().Width() : pTmp->getFrameArea().Height();
} while (pTmp->IsFollow());
}
nYOffset -= pTmp->GetBaseVertOffsetForFly(false);
}
}
if( OBJ_NONE == nIdent )
{
// For OBJ_NONE a fly is inserted.
const long nWidth = rBound.Right() - rBound.Left();
const long nHeight= rBound.Bottom() - rBound.Top();
aSet.Put( SwFormatFrameSize( SwFrameSize::Minimum, std::max( nWidth, long(MINFLY) ),
std::max( nHeight, long(MINFLY) )));
SwFormatHoriOrient aHori( nXOffset, text::HoriOrientation::NONE, text::RelOrientation::FRAME );
SwFormatVertOrient aVert( nYOffset, text::VertOrientation::NONE, text::RelOrientation::FRAME );
aSet.Put( SwFormatSurround( css::text::WrapTextMode_PARALLEL ) );
aSet.Put( aHori );
aSet.Put( aVert );
// Quickly store the square
const SwRect aFlyRect( rBound );
// Throw away generated object, now the fly can nicely
// via the available SS be generated.
GetDoc()->GetIDocumentUndoRedo().DoDrawUndo(false); // see above
// #i52858# - method name changed
SdrPage *pPg = getIDocumentDrawModelAccess().GetOrCreateDrawModel()->GetPage( 0 );
if( !pPg )
{
SdrModel* pTmpSdrModel = getIDocumentDrawModelAccess().GetDrawModel();
pPg = pTmpSdrModel->AllocPage( false );
pTmpSdrModel->InsertPage( pPg );
}
pPg->RecalcObjOrdNums();
SdrObject* pRemovedObject = pPg->RemoveObject( rSdrObj.GetOrdNumDirect() );
SdrObject::Free( pRemovedObject );
GetDoc()->GetIDocumentUndoRedo().DoDrawUndo(true);
SwFlyFrame* pFlyFrame;
if( NewFlyFrame( aSet, true ) &&
::GetHtmlMode( GetDoc()->GetDocShell() ) &&
nullptr != ( pFlyFrame = GetSelectedFlyFrame() ))
{
SfxItemSet aHtmlSet( GetDoc()->GetAttrPool(), svl::Items<RES_VERT_ORIENT, RES_HORI_ORIENT>{} );
// horizontal orientation:
const bool bLeftFrame = aFlyRect.Left() <
pAnch->getFrameArea().Left() + pAnch->getFramePrintArea().Left(),
bLeftPrt = aFlyRect.Left() + aFlyRect.Width() <
pAnch->getFrameArea().Left() + pAnch->getFramePrintArea().Width()/2;
if( bLeftFrame || bLeftPrt )
{
aHori.SetHoriOrient( text::HoriOrientation::LEFT );
aHori.SetRelationOrient( bLeftFrame ? text::RelOrientation::FRAME : text::RelOrientation::PRINT_AREA );
}
else
{
const bool bRightFrame = aFlyRect.Left() >
pAnch->getFrameArea().Left() + pAnch->getFramePrintArea().Width();
aHori.SetHoriOrient( text::HoriOrientation::RIGHT );
aHori.SetRelationOrient( bRightFrame ? text::RelOrientation::FRAME : text::RelOrientation::PRINT_AREA );
}
aHtmlSet.Put( aHori );
aVert.SetVertOrient( text::VertOrientation::TOP );
aVert.SetRelationOrient( text::RelOrientation::PRINT_AREA );
aHtmlSet.Put( aVert );
GetDoc()->SetAttr( aHtmlSet, *pFlyFrame->GetFormat() );
}
}
else
{
if (rSdrObj.GetName().isEmpty())
{
bool bRestore = GetDoc()->GetIDocumentUndoRedo().DoesDrawUndo();
GetDoc()->GetIDocumentUndoRedo().DoDrawUndo(false);
rSdrObj.SetName(GetUniqueShapeName());
GetDoc()->GetIDocumentUndoRedo().DoDrawUndo(bRestore);
}
Point aRelNullPt;
if( OBJ_CAPTION == nIdent )
aRelNullPt = static_cast<SdrCaptionObj&>(rSdrObj).GetTailPos();
else
aRelNullPt = rBound.TopLeft();
aSet.Put( aAnch );
aSet.Put( SwFormatSurround( css::text::WrapTextMode_THROUGH ) );
// OD 2004-03-30 #i26791# - set horizontal position
SwFormatHoriOrient aHori( nXOffset, text::HoriOrientation::NONE, text::RelOrientation::FRAME );
aSet.Put( aHori );
// OD 2004-03-30 #i26791# - set vertical position
if( pAnch->IsTextFrame() && static_cast<const SwTextFrame*>(pAnch)->IsFollow() )
{
const SwTextFrame* pTmp = static_cast<const SwTextFrame*>(pAnch);
do {
pTmp = pTmp->FindMaster();
assert(pTmp && "Where's my Master?");
nYOffset += pTmp->IsVertical() ?
pTmp->getFramePrintArea().Width() : pTmp->getFramePrintArea().Height();
} while ( pTmp->IsFollow() );
}
SwFormatVertOrient aVert( nYOffset, text::VertOrientation::NONE, text::RelOrientation::FRAME );
aSet.Put( aVert );
SwDrawFrameFormat* pFormat = static_cast<SwDrawFrameFormat*>(getIDocumentLayoutAccess().MakeLayoutFormat( RndStdIds::DRAW_OBJECT, &aSet ));
// #i36010# - set layout direction of the position
pFormat->SetPositionLayoutDir(
text::PositionLayoutDir::PositionInLayoutDirOfAnchor );
// #i44344#, #i44681# - positioning attributes already set
pFormat->PosAttrSet();
pFormat->SetName(rSdrObj.GetName());
SwDrawContact *pContact = new SwDrawContact( pFormat, &rSdrObj );
// #i35635#
pContact->MoveObjToVisibleLayer( &rSdrObj );
if( bCharBound )
{
OSL_ENSURE( aAnch.GetAnchorId() == RndStdIds::FLY_AS_CHAR, "wrong AnchorType" );
SwTextNode *pNd = aAnch.GetContentAnchor()->nNode.GetNode().GetTextNode();
SwFormatFlyCnt aFormat( pFormat );
pNd->InsertItem(aFormat,
aAnch.GetContentAnchor()->nContent.GetIndex(), 0 );
SwFormatVertOrient aVertical( pFormat->GetVertOrient() );
aVertical.SetVertOrient( text::VertOrientation::LINE_CENTER );
pFormat->SetFormatAttr( aVertical );
}
if( pAnch->IsTextFrame() && static_cast<const SwTextFrame*>(pAnch)->IsFollow() )
{
const SwTextFrame* pTmp = static_cast<const SwTextFrame*>(pAnch);
do {
pTmp = pTmp->FindMaster();
OSL_ENSURE( pTmp, "Where's my Master?" );
} while( pTmp->IsFollow() );
pAnch = pTmp;
}
pContact->ConnectToLayout();
// mark object at frame the object is inserted at.
{
SdrObject* pMarkObj = pContact->GetDrawObjectByAnchorFrame( *pAnch );
if ( pMarkObj )
{
Imp()->GetDrawView()->MarkObj( pMarkObj, Imp()->GetPageView() );
}
else
{
Imp()->GetDrawView()->MarkObj( &rSdrObj, Imp()->GetPageView() );
}
}
}
GetDoc()->getIDocumentState().SetModified();
KillPams();
EndAllActionAndCall();
UnlockPaint();
return true;
}
void SwFEShell::BreakCreate()
{
OSL_ENSURE( Imp()->HasDrawView(), "BreakCreate without DrawView?" );
Imp()->GetDrawView()->BrkCreateObj();
::FrameNotify( this, FLY_DRAG_END );
}
bool SwFEShell::IsDrawCreate() const
{
return Imp()->HasDrawView() && Imp()->GetDrawView()->IsCreateObj();
}
bool SwFEShell::BeginMark( const Point &rPos )
{
if ( !Imp()->HasDrawView() )
Imp()->MakeDrawView();
if ( GetPageNumber( rPos ) )
{
SwDrawView* pDView = Imp()->GetDrawView();
if (pDView->HasMarkablePoints())
return pDView->BegMarkPoints( rPos );
else
{
pDView->BegMarkObj( rPos );
return true;
}
}
else
return false;
}
void SwFEShell::MoveMark( const Point &rPos )
{
OSL_ENSURE( Imp()->HasDrawView(), "MoveMark without DrawView?" );
if ( GetPageNumber( rPos ) )
{
ScrollTo( rPos );
SwDrawView* pDView = Imp()->GetDrawView();
if (pDView->IsInsObjPoint())
pDView->MovInsObjPoint( rPos );
else if (pDView->IsMarkPoints())
pDView->MovMarkPoints( rPos );
else
pDView->MovAction( rPos );
}
}
bool SwFEShell::EndMark()
{
bool bRet = false;
OSL_ENSURE( Imp()->HasDrawView(), "EndMark without DrawView?" );
if (Imp()->GetDrawView()->IsMarkObj())
{
bRet = Imp()->GetDrawView()->EndMarkObj();
if ( bRet )
{
bool bShowHdl = false;
SwDrawView* pDView = Imp()->GetDrawView();
// frames are not selected this way, except when
// it is only one frame
SdrMarkList &rMrkList = const_cast<SdrMarkList&>(pDView->GetMarkedObjectList());
SwFlyFrame* pOldSelFly = ::GetFlyFromMarked( &rMrkList, this );
if ( rMrkList.GetMarkCount() > 1 )
for ( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
{
SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
if( dynamic_cast<const SwVirtFlyDrawObj*>( pObj) != nullptr )
{
if ( !bShowHdl )
{
bShowHdl = true;
}
rMrkList.DeleteMark( i );
--i; // no exceptions
}
}
if( bShowHdl )
{
pDView->MarkListHasChanged();
pDView->AdjustMarkHdl();
}
if ( rMrkList.GetMarkCount() )
::lcl_GrabCursor(this, pOldSelFly);
else
bRet = false;
}
if ( bRet )
::FrameNotify( this, FLY_DRAG_START );
}
else
{
if (Imp()->GetDrawView()->IsMarkPoints())
bRet = Imp()->GetDrawView()->EndMarkPoints();
}
SetChainMarker();
return bRet;
}
RndStdIds SwFEShell::GetAnchorId() const
{
RndStdIds nRet = RndStdIds(SHRT_MAX);
if ( Imp()->HasDrawView() )
{
const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
for ( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
{
SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
if ( dynamic_cast<const SwVirtFlyDrawObj*>( pObj) != nullptr )
{
nRet = RndStdIds::UNKNOWN;
break;
}
SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
RndStdIds nId = pContact->GetFormat()->GetAnchor().GetAnchorId();
if ( nRet == RndStdIds(SHRT_MAX) )
nRet = nId;
else if ( nRet != nId )
{
nRet = RndStdIds::UNKNOWN;
break;
}
}
}
if ( nRet == RndStdIds(SHRT_MAX) )
nRet = RndStdIds::UNKNOWN;
return nRet;
}
void SwFEShell::ChgAnchor( RndStdIds eAnchorId, bool bSameOnly, bool bPosCorr )
{
OSL_ENSURE( Imp()->HasDrawView(), "ChgAnchor without DrawView?" );
const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
if( rMrkList.GetMarkCount() &&
!rMrkList.GetMark( 0 )->GetMarkedSdrObj()->getParentSdrObjectFromSdrObject() )
{
StartAllAction();
if( GetDoc()->ChgAnchor( rMrkList, eAnchorId, bSameOnly, bPosCorr ))
Imp()->GetDrawView()->UnmarkAll();
EndAllAction();
::FrameNotify( this );
}
}
void SwFEShell::DelSelectedObj()
{
OSL_ENSURE( Imp()->HasDrawView(), "DelSelectedObj(), no DrawView available" );
if ( Imp()->HasDrawView() )
{
StartAllAction();
Imp()->GetDrawView()->DeleteMarked();
EndAllAction();
::FrameNotify( this, FLY_DRAG_END );
}
}
// For the statusline to request the current conditions
Size SwFEShell::GetObjSize() const
{
tools::Rectangle aRect;
if ( Imp()->HasDrawView() )
{
if ( Imp()->GetDrawView()->IsAction() )
Imp()->GetDrawView()->TakeActionRect( aRect );
else
aRect = Imp()->GetDrawView()->GetAllMarkedRect();
}
return aRect.GetSize();
}
Point SwFEShell::GetAnchorObjDiff() const
{
const SdrView *pView = Imp()->GetDrawView();
OSL_ENSURE( pView, "GetAnchorObjDiff without DrawView?" );
tools::Rectangle aRect;
if ( Imp()->GetDrawView()->IsAction() )
Imp()->GetDrawView()->TakeActionRect( aRect );
else
aRect = Imp()->GetDrawView()->GetAllMarkedRect();
Point aRet( aRect.TopLeft() );
if ( IsFrameSelected() )
{
SwFlyFrame *pFly = GetSelectedFlyFrame();
aRet -= pFly->GetAnchorFrame()->getFrameArea().Pos();
}
else
{
const SdrObject *pObj = pView->GetMarkedObjectList().GetMarkCount() == 1 ?
pView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj() : nullptr;
if ( pObj )
aRet -= pObj->GetAnchorPos();
}
return aRet;
}
Point SwFEShell::GetObjAbsPos() const
{
OSL_ENSURE( Imp()->GetDrawView(), "GetObjAbsPos() without DrawView?" );
return Imp()->GetDrawView()->GetDragStat().GetActionRect().TopLeft();
}
bool SwFEShell::IsGroupSelected()
{
if ( IsObjSelected() )
{
const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
for ( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
{
SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
// consider 'virtual' drawing objects.
// Thus, use corresponding method instead of checking type.
if ( pObj->IsGroupObject() &&
// --> #i38505# No ungroup allowed for 3d objects
!pObj->Is3DObj() &&
RndStdIds::FLY_AS_CHAR != static_cast<SwDrawContact*>(GetUserCall(pObj))->
GetFormat()->GetAnchor().GetAnchorId() )
{
return true;
}
}
}
return false;
}
namespace
{
bool HasSuitableGroupingAnchor(const SdrObject* pObj)
{
bool bSuitable = true;
SwFrameFormat* pFrameFormat(::FindFrameFormat(const_cast<SdrObject*>(pObj)));
if (!pFrameFormat)
{
OSL_FAIL( "<HasSuitableGroupingAnchor> - missing frame format" );
bSuitable = false;
}
else if (RndStdIds::FLY_AS_CHAR == pFrameFormat->GetAnchor().GetAnchorId())
{
bSuitable = false;
}
return bSuitable;
}
}
// Change return type.
// Adjustments for drawing objects in header/footer:
// allow group, only if all selected objects are in the same header/footer
// or not in header/footer.
bool SwFEShell::IsGroupAllowed() const
{
bool bIsGroupAllowed = false;
if ( IsObjSelected() > 1 )
{
bIsGroupAllowed = true;
const SdrObject* pUpGroup = nullptr;
const SwFrame* pHeaderFooterFrame = nullptr;
const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
for ( size_t i = 0; bIsGroupAllowed && i < rMrkList.GetMarkCount(); ++i )
{
const SdrObject* pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
if ( i )
bIsGroupAllowed = pObj->getParentSdrObjectFromSdrObject() == pUpGroup;
else
pUpGroup = pObj->getParentSdrObjectFromSdrObject();
if ( bIsGroupAllowed )
bIsGroupAllowed = HasSuitableGroupingAnchor(pObj);
// check, if all selected objects are in the
// same header/footer or not in header/footer.
if ( bIsGroupAllowed )
{
const SwFrame* pAnchorFrame = nullptr;
if ( auto pVirtFlyDrawObj = dynamic_cast<const SwVirtFlyDrawObj*>( pObj) )
{
const SwFlyFrame* pFlyFrame = pVirtFlyDrawObj->GetFlyFrame();
if ( pFlyFrame )
{
pAnchorFrame = pFlyFrame->GetAnchorFrame();
}
}
else
{
SwDrawContact* pDrawContact = static_cast<SwDrawContact*>(GetUserCall( pObj ));
if ( pDrawContact )
{
pAnchorFrame = pDrawContact->GetAnchorFrame( pObj );
}
}
if ( pAnchorFrame )
{
if ( i )
{
bIsGroupAllowed =
( pAnchorFrame->FindFooterOrHeader() == pHeaderFooterFrame );
}
else
{
pHeaderFooterFrame = pAnchorFrame->FindFooterOrHeader();
}
}
}
}
}
return bIsGroupAllowed;
}
bool SwFEShell::IsUnGroupAllowed() const
{
bool bIsUnGroupAllowed = false;
const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
for (size_t i = 0; i < rMrkList.GetMarkCount(); ++i)
{
const SdrObject* pObj = rMrkList.GetMark(i)->GetMarkedSdrObj();
bIsUnGroupAllowed = HasSuitableGroupingAnchor(pObj);
if (!bIsUnGroupAllowed)
break;
}
return bIsUnGroupAllowed;
}
// The group gets the anchor and the contactobject of the first in the selection
void SwFEShell::GroupSelection()
{
if ( IsGroupAllowed() )
{
StartAllAction();
StartUndo( SwUndoId::START );
GetDoc()->GroupSelection( *Imp()->GetDrawView() );
EndUndo( SwUndoId::END );
EndAllAction();
}
}
// The individual objects get a copy of the anchor and the contactobject of the group
void SwFEShell::UnGroupSelection()
{
if ( IsGroupSelected() )
{
StartAllAction();
StartUndo( SwUndoId::START );
GetDoc()->UnGroupSelection( *Imp()->GetDrawView() );
EndUndo( SwUndoId::END );
EndAllAction();
}
}
void SwFEShell::MirrorSelection( bool bHorizontal )
{
SdrView *pView = Imp()->GetDrawView();
if ( IsObjSelected() && pView->IsMirrorAllowed() )
{
if ( bHorizontal )
pView->MirrorAllMarkedHorizontal();
else
pView->MirrorAllMarkedVertical();
}
}
// jump to named frame (Graphic/OLE)
bool SwFEShell::GotoFly( const OUString& rName, FlyCntType eType, bool bSelFrame )
{
bool bRet = false;
static SwNodeType const aChkArr[ 4 ] = {
/* FLYCNTTYPE_ALL */ SwNodeType::NONE,
/* FLYCNTTYPE_FRM */ SwNodeType::Text,
/* FLYCNTTYPE_GRF */ SwNodeType::Grf,
/* FLYCNTTYPE_OLE */ SwNodeType::Ole
};
const SwFlyFrameFormat* pFlyFormat = mxDoc->FindFlyByName( rName, aChkArr[ eType]);
if( pFlyFormat )
{
SET_CURR_SHELL( this );
SwFlyFrame* pFrame = SwIterator<SwFlyFrame,SwFormat>( *pFlyFormat ).First();
if( pFrame )
{
if( bSelFrame )
{
// first make visible, to get a11y events in proper order
if (!ActionPend())
MakeVisible( pFrame->getFrameArea() );
SelectObj( pFrame->getFrameArea().Pos(), 0, pFrame->GetVirtDrawObj() );
}
else
{
SwContentFrame *pCFrame = pFrame->ContainsContent();
if ( pCFrame )
{
ClearMark();
SwPaM* pCursor = GetCursor();
if (pCFrame->IsTextFrame())
{
*pCursor->GetPoint() = static_cast<SwTextFrame *>(pCFrame)
->MapViewToModelPos(TextFrameIndex(0));
}
else
{
assert(pCFrame->IsNoTextFrame());
SwContentNode *const pCNode = static_cast<SwNoTextFrame *>(pCFrame)->GetNode();
pCursor->GetPoint()->nNode = *pCNode;
pCursor->GetPoint()->nContent.Assign( pCNode, 0 );
}
SwRect& rChrRect = const_cast<SwRect&>(GetCharRect());
rChrRect = pFrame->getFramePrintArea();
rChrRect.Pos() += pFrame->getFrameArea().Pos();
GetCursorDocPos() = rChrRect.Pos();
}
}
bRet = true;
}
}
return bRet;
}
size_t SwFEShell::GetFlyCount( FlyCntType eType, bool bIgnoreTextBoxes ) const
{
return GetDoc()->GetFlyCount(eType, bIgnoreTextBoxes);
}
const SwFrameFormat* SwFEShell::GetFlyNum(size_t nIdx, FlyCntType eType, bool bIgnoreTextBoxes ) const
{
return GetDoc()->GetFlyNum(nIdx, eType, bIgnoreTextBoxes);
}
std::vector<SwFrameFormat const*> SwFEShell::GetFlyFrameFormats(
FlyCntType const eType, bool const bIgnoreTextBoxes)
{
return GetDoc()->GetFlyFrameFormats(eType, bIgnoreTextBoxes);
}
// show the current selected object
void SwFEShell::MakeSelVisible()
{
if ( Imp()->HasDrawView() &&
Imp()->GetDrawView()->GetMarkedObjectList().GetMarkCount() )
{
GetCurrFrame(); // just to trigger formatting in case the selected object is not formatted.
MakeVisible( Imp()->GetDrawView()->GetAllMarkedRect() );
}
else
SwCursorShell::MakeSelVisible();
}
// how is the selected object protected?
FlyProtectFlags SwFEShell::IsSelObjProtected( FlyProtectFlags eType ) const
{
FlyProtectFlags nChk = FlyProtectFlags::NONE;
const bool bParent(eType & FlyProtectFlags::Parent);
if( Imp()->HasDrawView() )
{
const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
for( size_t i = rMrkList.GetMarkCount(); i; )
{
SdrObject *pObj = rMrkList.GetMark( --i )->GetMarkedSdrObj();
if( !bParent )
{
nChk |= ( pObj->IsMoveProtect() ? FlyProtectFlags::Pos : FlyProtectFlags::NONE ) |
( pObj->IsResizeProtect()? FlyProtectFlags::Size : FlyProtectFlags::NONE );
if (SwVirtFlyDrawObj* pVirtO = dynamic_cast<SwVirtFlyDrawObj*>(pObj))
{
SwFlyFrame *pFly = pVirtO->GetFlyFrame();
if ( (FlyProtectFlags::Content & eType) && pFly->GetFormat()->GetProtect().IsContentProtected() )
nChk |= FlyProtectFlags::Content;
if ( pFly->Lower() && pFly->Lower()->IsNoTextFrame() )
{
SwOLENode *pNd = static_cast<SwNoTextFrame*>(pFly->Lower())->GetNode()->GetOLENode();
uno::Reference < embed::XEmbeddedObject > xObj( pNd ? pNd->GetOLEObj().GetOleRef() : nullptr );
if ( xObj.is() )
{
// TODO/LATER: use correct aspect
const bool bNeverResize = (embed::EmbedMisc::EMBED_NEVERRESIZE & xObj->getStatus( embed::Aspects::MSOLE_CONTENT ));
if ( ( (FlyProtectFlags::Content & eType) || (FlyProtectFlags::Size & eType) ) && bNeverResize )
{
nChk |= FlyProtectFlags::Size;
nChk |= FlyProtectFlags::Fixed;
}
// set FlyProtectFlags::Pos if it is a Math object anchored 'as char' and baseline alignment is activated
const bool bProtectMathPos = SotExchange::IsMath( xObj->getClassID() )
&& RndStdIds::FLY_AS_CHAR == pFly->GetFormat()->GetAnchor().GetAnchorId()
&& mxDoc->GetDocumentSettingManager().get( DocumentSettingId::MATH_BASELINE_ALIGNMENT );
if ((FlyProtectFlags::Pos & eType) && bProtectMathPos)
nChk |= FlyProtectFlags::Pos;
}
}
}
nChk &= eType;
if( nChk == eType )
return eType;
}
const SwFrame* pAnch;
if (SwVirtFlyDrawObj* pVirtO = dynamic_cast<SwVirtFlyDrawObj*>(pObj))
pAnch = pVirtO->GetFlyFrame()->GetAnchorFrame();
else
{
SwDrawContact* pTmp = static_cast<SwDrawContact*>(GetUserCall(pObj));
pAnch = pTmp ? pTmp->GetAnchorFrame( pObj ) : nullptr;
}
if( pAnch && pAnch->IsProtected() )
return eType;
}
}
return nChk;
}
bool SwFEShell::GetObjAttr( SfxItemSet &rSet ) const
{
if ( !IsObjSelected() )
return false;
const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
for ( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
{
SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
// --> make code robust
OSL_ENSURE( pContact, "<SwFEShell::GetObjAttr(..)> - missing <pContact>." );
if ( pContact )
{
if ( i )
rSet.MergeValues( pContact->GetFormat()->GetAttrSet() );
else
rSet.Put( pContact->GetFormat()->GetAttrSet() );
}
}
return true;
}
void SwFEShell::SetObjAttr( const SfxItemSet& rSet )
{
SET_CURR_SHELL( this );
if ( !rSet.Count() )
{
OSL_ENSURE( false, "SetObjAttr, empty set." );
return;
}
StartAllAction();
StartUndo( SwUndoId::INSATTR );
const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
for ( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
{
SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
SwDrawContact *pContact = static_cast<SwDrawContact*>(GetUserCall(pObj));
GetDoc()->SetAttr( rSet, *pContact->GetFormat() );
}
EndUndo( SwUndoId::INSATTR );
EndAllActionAndCall();
GetDoc()->getIDocumentState().SetModified();
}
bool SwFEShell::IsAlignPossible() const
{
return Imp()->GetDrawView()->IsAlignPossible();
}
void SwFEShell::CheckUnboundObjects()
{
SET_CURR_SHELL( this );
const SdrMarkList &rMrkList = Imp()->GetDrawView()->GetMarkedObjectList();
for ( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
{
SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
if ( !GetUserCall(pObj) )
{
const tools::Rectangle &rBound = pObj->GetSnapRect();
const Point aPt( rBound.TopLeft() );
const SwFrame *pPage = GetLayout()->Lower();
const SwFrame *pLast = pPage;
while ( pPage && !pPage->getFrameArea().IsInside( aPt ) )
{
if ( aPt.Y() > pPage->getFrameArea().Bottom() )
pLast = pPage;
pPage = pPage->GetNext();
}
if ( !pPage )
pPage = pLast;
OSL_ENSURE( pPage, "Page not found." );
// Alien identifier should roll into the default,
// Duplications are possible!!
sal_uInt16 nIdent =
Imp()->GetDrawView()->GetCurrentObjInventor() == SdrInventor::Default ?
Imp()->GetDrawView()->GetCurrentObjIdentifier() : 0xFFFF;
SwFormatAnchor aAnch;
{
const SwContentFrame *const pAnch = ::FindAnchor(pPage, aPt, true);
SwPosition aPos( pAnch->IsTextFrame()
? *static_cast<SwTextFrame const*>(pAnch)->GetTextNodeForParaProps()
: *static_cast<SwNoTextFrame const*>(pAnch)->GetNode() );
aAnch.SetType( RndStdIds::FLY_AT_PARA );
aAnch.SetAnchor( &aPos );
const_cast<SwRect&>(GetCharRect()).Pos() = aPt;
}
// First the action here, to assure GetCharRect delivers current values.
StartAllAction();
SfxItemSet aSet( GetAttrPool(), svl::Items<RES_FRM_SIZE, RES_FRM_SIZE,
RES_SURROUND, RES_ANCHOR>{} );
aSet.Put( aAnch );
Point aRelNullPt;
if( OBJ_CAPTION == nIdent )
aRelNullPt = static_cast<SdrCaptionObj*>(pObj)->GetTailPos();
else
aRelNullPt = rBound.TopLeft();
aSet.Put( aAnch );
aSet.Put( SwFormatSurround( css::text::WrapTextMode_THROUGH ) );
SwFrameFormat* pFormat = getIDocumentLayoutAccess().MakeLayoutFormat( RndStdIds::DRAW_OBJECT, &aSet );
SwDrawContact *pContact = new SwDrawContact(
static_cast<SwDrawFrameFormat*>(pFormat), pObj );
// #i35635#
pContact->MoveObjToVisibleLayer( pObj );
pContact->ConnectToLayout();
EndAllAction();
}
}
}
void SwFEShell::SetCalcFieldValueHdl(Outliner* pOutliner)
{
GetDoc()->SetCalcFieldValueHdl(pOutliner);
}
SwChainRet SwFEShell::Chainable( SwRect &rRect, const SwFrameFormat &rSource,
const Point &rPt ) const
{
rRect.Clear();
// The source is not allowed to have a follow.
const SwFormatChain &rChain = rSource.GetChain();
if ( rChain.GetNext() )
return SwChainRet::SOURCE_CHAINED;
SwChainRet nRet = SwChainRet::NOT_FOUND;
if( Imp()->HasDrawView() )
{
SdrPageView* pPView;
SwDrawView *pDView = const_cast<SwDrawView*>(Imp()->GetDrawView());
const auto nOld = pDView->GetHitTolerancePixel();
pDView->SetHitTolerancePixel( 0 );
SdrObject* pObj = pDView->PickObj(rPt, pDView->getHitTolLog(), pPView, SdrSearchOptions::PICKMARKABLE);
SwVirtFlyDrawObj* pDrawObj = dynamic_cast<SwVirtFlyDrawObj*>(pObj);
if (pDrawObj)
{
SwFlyFrame *pFly = pDrawObj->GetFlyFrame();
rRect = pFly->getFrameArea();
// Target and source should not be equal and the list
// should not be cyclic
SwFrameFormat *pFormat = pFly->GetFormat();
nRet = GetDoc()->Chainable(rSource, *pFormat);
}
pDView->SetHitTolerancePixel( nOld );
}
return nRet;
}
void SwFEShell::Chain( SwFrameFormat &rSource, const SwFrameFormat &rDest )
{
GetDoc()->Chain(rSource, rDest);
}
SwChainRet SwFEShell::Chain( SwFrameFormat &rSource, const Point &rPt )
{
SwRect aDummy;
SwChainRet nErr = Chainable( aDummy, rSource, rPt );
if ( nErr == SwChainRet::OK )
{
StartAllAction();
SdrPageView* pPView;
SwDrawView *pDView = Imp()->GetDrawView();
const auto nOld = pDView->GetHitTolerancePixel();
pDView->SetHitTolerancePixel( 0 );
SdrObject* pObj = pDView->PickObj(rPt, pDView->getHitTolLog(), pPView, SdrSearchOptions::PICKMARKABLE);
pDView->SetHitTolerancePixel( nOld );
SwFlyFrame *pFly = static_cast<SwVirtFlyDrawObj*>(pObj)->GetFlyFrame();
SwFlyFrameFormat *pFormat = pFly->GetFormat();
GetDoc()->Chain(rSource, *pFormat);
EndAllAction();
SetChainMarker();
}
return nErr;
}
void SwFEShell::Unchain( SwFrameFormat &rFormat )
{
StartAllAction();
GetDoc()->Unchain(rFormat);
EndAllAction();
}
void SwFEShell::HideChainMarker()
{
m_pChainFrom.reset();
m_pChainTo.reset();
}
void SwFEShell::SetChainMarker()
{
bool bDelFrom = true,
bDelTo = true;
if ( IsFrameSelected() )
{
SwFlyFrame *pFly = GetSelectedFlyFrame();
if ( pFly->GetPrevLink() )
{
bDelFrom = false;
const SwFrame *pPre = pFly->GetPrevLink();
Point aStart( pPre->getFrameArea().Right(), pPre->getFrameArea().Bottom());
Point aEnd(pFly->getFrameArea().Pos());
if (!m_pChainFrom)
{
m_pChainFrom.reset(
new SdrDropMarkerOverlay( *GetDrawView(), aStart, aEnd ));
}
}
if ( pFly->GetNextLink() )
{
bDelTo = false;
const SwFlyFrame *pNxt = pFly->GetNextLink();
Point aStart( pFly->getFrameArea().Right(), pFly->getFrameArea().Bottom());
Point aEnd(pNxt->getFrameArea().Pos());
if (!m_pChainTo)
{
m_pChainTo.reset(
new SdrDropMarkerOverlay( *GetDrawView(), aStart, aEnd ));
}
}
}
if ( bDelFrom )
{
m_pChainFrom.reset();
}
if ( bDelTo )
{
m_pChainTo.reset();
}
}
long SwFEShell::GetSectionWidth( SwFormat const & rFormat ) const
{
SwFrame *pFrame = GetCurrFrame();
// Is the cursor at this moment in a SectionFrame?
if( pFrame && pFrame->IsInSct() )
{
SwSectionFrame* pSect = pFrame->FindSctFrame();
do
{
// Is it the right one?
if( pSect->KnowsFormat( rFormat ) )
return pSect->getFrameArea().Width();
// for nested areas
pSect = pSect->GetUpper()->FindSctFrame();
}
while( pSect );
}
SwIterator<SwSectionFrame,SwFormat> aIter( rFormat );
for ( SwSectionFrame* pSct = aIter.First(); pSct; pSct = aIter.Next() )
{
if( !pSct->IsFollow() )
{
return pSct->getFrameArea().Width();
}
}
return 0;
}
void SwFEShell::CreateDefaultShape( sal_uInt16 /*SdrObjKind ?*/ eSdrObjectKind, const tools::Rectangle& rRect,
sal_uInt16 nSlotId)
{
SdrView* pDrawView = GetDrawView();
SdrModel* pDrawModel = pDrawView->GetModel();
SdrObject* pObj = SdrObjFactory::MakeNewObject(
*pDrawModel,
SdrInventor::Default,
eSdrObjectKind);
if(pObj)
{
tools::Rectangle aRect(rRect);
if(OBJ_CARC == eSdrObjectKind || OBJ_CCUT == eSdrObjectKind)
{
// force quadratic
if(aRect.GetWidth() > aRect.GetHeight())
{
aRect = tools::Rectangle(
Point(aRect.Left() + ((aRect.GetWidth() - aRect.GetHeight()) / 2), aRect.Top()),
Size(aRect.GetHeight(), aRect.GetHeight()));
}
else
{
aRect = tools::Rectangle(
Point(aRect.Left(), aRect.Top() + ((aRect.GetHeight() - aRect.GetWidth()) / 2)),
Size(aRect.GetWidth(), aRect.GetWidth()));
}
}
pObj->SetLogicRect(aRect);
Point aStart = aRect.TopLeft();
Point aEnd = aRect.BottomRight();
if(dynamic_cast<const SdrCircObj*>( pObj) != nullptr)
{
SfxItemSet aAttr(pDrawModel->GetItemPool());
aAttr.Put(makeSdrCircStartAngleItem(9000));
aAttr.Put(makeSdrCircEndAngleItem(0));
pObj->SetMergedItemSet(aAttr);
}
else if(dynamic_cast<const SdrPathObj*>( pObj) != nullptr)
{
basegfx::B2DPolyPolygon aPoly;
switch(eSdrObjectKind)
{
case OBJ_PATHLINE:
case OBJ_PATHFILL:
{
basegfx::B2DPolygon aInnerPoly;
aInnerPoly.append(basegfx::B2DPoint(aRect.Left(), aRect.Bottom()));
const basegfx::B2DPoint aCenterBottom(aRect.Center().getX(), aRect.Bottom());
aInnerPoly.appendBezierSegment(
aCenterBottom,
aCenterBottom,
basegfx::B2DPoint(aRect.Center().getX(), aRect.Center().getY()));
const basegfx::B2DPoint aCenterTop(aRect.Center().getX(), aRect.Top());
aInnerPoly.appendBezierSegment(
aCenterTop,
aCenterTop,
basegfx::B2DPoint(aRect.Right(), aRect.Top()));
aInnerPoly.setClosed(true);
aPoly.append(aInnerPoly);
}
break;
case OBJ_FREELINE:
case OBJ_FREEFILL:
{
basegfx::B2DPolygon aInnerPoly;
aInnerPoly.append(basegfx::B2DPoint(aRect.Left(), aRect.Bottom()));
aInnerPoly.appendBezierSegment(
basegfx::B2DPoint(aRect.Left(), aRect.Top()),
basegfx::B2DPoint(aRect.Center().getX(), aRect.Top()),
basegfx::B2DPoint(aRect.Center().getX(), aRect.Center().getY()));
aInnerPoly.appendBezierSegment(
basegfx::B2DPoint(aRect.Center().getX(), aRect.Bottom()),
basegfx::B2DPoint(aRect.Right(), aRect.Bottom()),
basegfx::B2DPoint(aRect.Right(), aRect.Top()));
aInnerPoly.append(basegfx::B2DPoint(aRect.Right(), aRect.Bottom()));
aInnerPoly.setClosed(true);
aPoly.append(aInnerPoly);
}
break;
case OBJ_POLY:
case OBJ_PLIN:
{
basegfx::B2DPolygon aInnerPoly;
sal_Int32 nWdt(aRect.GetWidth());
sal_Int32 nHgt(aRect.GetHeight());
aInnerPoly.append(basegfx::B2DPoint(aRect.Left(), aRect.Bottom()));
aInnerPoly.append(basegfx::B2DPoint(aRect.Left() + (nWdt * 30) / 100, aRect.Top() + (nHgt * 70) / 100));
aInnerPoly.append(basegfx::B2DPoint(aRect.Left(), aRect.Top() + (nHgt * 15) / 100));
aInnerPoly.append(basegfx::B2DPoint(aRect.Left() + (nWdt * 65) / 100, aRect.Top()));
aInnerPoly.append(basegfx::B2DPoint(aRect.Left() + nWdt, aRect.Top() + (nHgt * 30) / 100));
aInnerPoly.append(basegfx::B2DPoint(aRect.Left() + (nWdt * 80) / 100, aRect.Top() + (nHgt * 50) / 100));
aInnerPoly.append(basegfx::B2DPoint(aRect.Left() + (nWdt * 80) / 100, aRect.Top() + (nHgt * 75) / 100));
aInnerPoly.append(basegfx::B2DPoint(aRect.Bottom(), aRect.Right()));
if(OBJ_PLIN == eSdrObjectKind)
{
aInnerPoly.append(basegfx::B2DPoint(aRect.Center().getX(), aRect.Bottom()));
}
else
{
aInnerPoly.setClosed(true);
}
aPoly.append(aInnerPoly);
}
break;
case OBJ_LINE :
{
sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
basegfx::B2DPolygon aTempPoly;
aTempPoly.append(basegfx::B2DPoint(aRect.TopLeft().getX(), nYMiddle));
aTempPoly.append(basegfx::B2DPoint(aRect.BottomRight().getX(), nYMiddle));
aPoly.append(aTempPoly);
SfxItemSet aAttr(pObj->getSdrModelFromSdrObject().GetItemPool());
SetLineEnds(aAttr, *pObj, nSlotId);
pObj->SetMergedItemSet(aAttr);
}
break;
}
static_cast<SdrPathObj*>(pObj)->SetPathPoly(aPoly);
}
else if(dynamic_cast<const SdrMeasureObj*>( pObj) != nullptr)
{
sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
static_cast<SdrMeasureObj*>(pObj)->SetPoint(Point(aStart.X(), nYMiddle), 0);
static_cast<SdrMeasureObj*>(pObj)->SetPoint(Point(aEnd.X(), nYMiddle), 1);
SfxItemSet aAttr(pObj->getSdrModelFromSdrObject().GetItemPool());
SetLineEnds(aAttr, *pObj, nSlotId);
pObj->SetMergedItemSet(aAttr);
}
else if(dynamic_cast<const SdrCaptionObj*>( pObj) != nullptr)
{
bool bVerticalText = ( SID_DRAW_TEXT_VERTICAL == nSlotId ||
SID_DRAW_CAPTION_VERTICAL == nSlotId );
static_cast<SdrTextObj*>(pObj)->SetVerticalWriting(bVerticalText);
if(bVerticalText)
{
SfxItemSet aSet(pObj->GetMergedItemSet());
aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
pObj->SetMergedItemSet(aSet);
}
static_cast<SdrCaptionObj*>(pObj)->SetLogicRect(aRect);
static_cast<SdrCaptionObj*>(pObj)->SetTailPos(
aRect.TopLeft() - Point(aRect.GetWidth() / 2, aRect.GetHeight() / 2));
}
else if(dynamic_cast<const SdrTextObj*>( pObj) != nullptr)
{
SdrTextObj* pText = static_cast<SdrTextObj*>(pObj);
pText->SetLogicRect(aRect);
bool bVertical = (SID_DRAW_TEXT_VERTICAL == nSlotId);
bool bMarquee = (SID_DRAW_TEXT_MARQUEE == nSlotId);
pText->SetVerticalWriting(bVertical);
if(bVertical)
{
SfxItemSet aSet(pDrawModel->GetItemPool());
aSet.Put(makeSdrTextAutoGrowWidthItem(true));
aSet.Put(makeSdrTextAutoGrowHeightItem(false));
aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_TOP));
aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
pText->SetMergedItemSet(aSet);
}
if(bMarquee)
{
SfxItemSet aSet(pDrawModel->GetItemPool(), svl::Items<SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST>{});
aSet.Put( makeSdrTextAutoGrowWidthItem( false ) );
aSet.Put( makeSdrTextAutoGrowHeightItem( false ) );
aSet.Put( SdrTextAniKindItem( SdrTextAniKind::Slide ) );
aSet.Put( SdrTextAniDirectionItem( SdrTextAniDirection::Left ) );
aSet.Put( SdrTextAniCountItem( 1 ) );
aSet.Put( SdrTextAniAmountItem( static_cast<sal_Int16>(GetWin()->PixelToLogic(Size(2,1)).Width())) );
pObj->SetMergedItemSetAndBroadcast(aSet);
}
}
SdrPageView* pPageView = pDrawView->GetSdrPageView();
SdrCreateView::SetupObjLayer(pPageView, pDrawView->GetActiveLayer(), pObj);
// switch undo off or this combined with ImpEndCreate will cause two undos
// see comment made in SwFEShell::EndCreate (we create our own undo-object!)
const bool bUndo(GetDoc()->GetIDocumentUndoRedo().DoesUndo());
GetDoc()->GetIDocumentUndoRedo().DoUndo(false);
pDrawView->InsertObjectAtView(pObj, *pPageView);
GetDoc()->GetIDocumentUndoRedo().DoUndo(bUndo);
}
ImpEndCreate();
}
/** SwFEShell::GetShapeBackgrd
method determines background color of the page the selected drawing
object is on and returns this color.
If no color is found, because no drawing object is selected or ...,
color COL_BLACK (default color on constructing object of class Color)
is returned.
@returns an object of class Color
*/
Color SwFEShell::GetShapeBackgrd() const
{
Color aRetColor;
// check, if a draw view exists
OSL_ENSURE( Imp()->GetDrawView(), "wrong usage of SwFEShell::GetShapeBackgrd - no draw view!");
if( Imp()->GetDrawView() )
{
// determine list of selected objects
const SdrMarkList* pMrkList = &Imp()->GetDrawView()->GetMarkedObjectList();
// check, if exactly one object is selected.
OSL_ENSURE( pMrkList->GetMarkCount() == 1, "wrong usage of SwFEShell::GetShapeBackgrd - no selected object!");
if ( pMrkList->GetMarkCount() == 1)
{
// get selected object
const SdrObject *pSdrObj = pMrkList->GetMark( 0 )->GetMarkedSdrObj();
// check, if selected object is a shape (drawing object)
OSL_ENSURE( dynamic_cast<const SwVirtFlyDrawObj*>( pSdrObj) == nullptr, "wrong usage of SwFEShell::GetShapeBackgrd - selected object is not a drawing object!");
if ( dynamic_cast<const SwVirtFlyDrawObj*>( pSdrObj) == nullptr )
{
// determine page frame of the frame the shape is anchored.
const SwFrame* pAnchorFrame =
static_cast<SwDrawContact*>(GetUserCall(pSdrObj))->GetAnchorFrame( pSdrObj );
OSL_ENSURE( pAnchorFrame, "inconsistent model - no anchor at shape!");
if ( pAnchorFrame )
{
const SwPageFrame* pPageFrame = pAnchorFrame->FindPageFrame();
OSL_ENSURE( pPageFrame, "inconsistent model - no page!");
if ( pPageFrame )
{
aRetColor = pPageFrame->GetDrawBackgrdColor();
}
}
}
}
}
return aRetColor;
}
/** Is default horizontal text direction for selected drawing object right-to-left
Because drawing objects only painted for each page only, the default
horizontal text direction of a drawing object is given by the corresponding
page property.
@returns boolean, indicating, if the horizontal text direction of the
page, the selected drawing object is on, is right-to-left.
*/
bool SwFEShell::IsShapeDefaultHoriTextDirR2L() const
{
bool bRet = false;
// check, if a draw view exists
OSL_ENSURE( Imp()->GetDrawView(), "wrong usage of SwFEShell::GetShapeBackgrd - no draw view!");
if( Imp()->GetDrawView() )
{
// determine list of selected objects
const SdrMarkList* pMrkList = &Imp()->GetDrawView()->GetMarkedObjectList();
// check, if exactly one object is selected.
OSL_ENSURE( pMrkList->GetMarkCount() == 1, "wrong usage of SwFEShell::GetShapeBackgrd - no selected object!");
if ( pMrkList->GetMarkCount() == 1)
{
// get selected object
const SdrObject *pSdrObj = pMrkList->GetMark( 0 )->GetMarkedSdrObj();
// check, if selected object is a shape (drawing object)
OSL_ENSURE( dynamic_cast<const SwVirtFlyDrawObj*>( pSdrObj) == nullptr, "wrong usage of SwFEShell::GetShapeBackgrd - selected object is not a drawing object!");
if ( dynamic_cast<const SwVirtFlyDrawObj*>( pSdrObj) == nullptr )
{
// determine page frame of the frame the shape is anchored.
const SwFrame* pAnchorFrame =
static_cast<SwDrawContact*>(GetUserCall(pSdrObj))->GetAnchorFrame( pSdrObj );
OSL_ENSURE( pAnchorFrame, "inconsistent model - no anchor at shape!");
if ( pAnchorFrame )
{
const SwPageFrame* pPageFrame = pAnchorFrame->FindPageFrame();
OSL_ENSURE( pPageFrame, "inconsistent model - no page!");
if ( pPageFrame )
{
bRet = pPageFrame->IsRightToLeft();
}
}
}
}
}
return bRet;
}
Point SwFEShell::GetRelativePagePosition(const Point& rDocPos)
{
Point aRet(-1, -1);
const SwFrame *pPage = GetLayout()->Lower();
while ( pPage && !pPage->getFrameArea().IsInside( rDocPos ) )
{
pPage = pPage->GetNext();
}
if(pPage)
{
aRet = rDocPos - pPage->getFrameArea().TopLeft();
}
return aRet;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|