1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194 | /* -*- 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 <tuple>
#include <utility>
#include <memory>
#include <vector>
#include <algorithm>
#include <o3tl/any.hxx>
#include <o3tl/safeint.hxx>
#include <svx/svxids.hrc>
#include <editeng/memberids.h>
#include <float.h>
#include <swtypes.hxx>
#include <cmdid.h>
#include <unocoll.hxx>
#include <unomid.h>
#include <unomap.hxx>
#include <unotbl.hxx>
#include <section.hxx>
#include <unocrsr.hxx>
#include <hints.hxx>
#include <swtblfmt.hxx>
#include <doc.hxx>
#include <IDocumentUndoRedo.hxx>
#include <IDocumentContentOperations.hxx>
#include <IDocumentFieldsAccess.hxx>
#include <IDocumentState.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <shellres.hxx>
#include <docary.hxx>
#include <ndole.hxx>
#include <ndtxt.hxx>
#include <frame.hxx>
#include <vcl/svapp.hxx>
#include <fmtfsize.hxx>
#include <tblafmt.hxx>
#include <tabcol.hxx>
#include <cellatr.hxx>
#include <fmtpdsc.hxx>
#include <pagedesc.hxx>
#include <viewsh.hxx>
#include <rootfrm.hxx>
#include <tabfrm.hxx>
#include <redline.hxx>
#include <unoport.hxx>
#include <unocrsrhelper.hxx>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <com/sun/star/text/WrapTextMode.hpp>
#include <com/sun/star/text/TextContentAnchorType.hpp>
#include <com/sun/star/text/TableColumnSeparator.hpp>
#include <com/sun/star/text/VertOrientation.hpp>
#include <com/sun/star/text/XTextSection.hpp>
#include <com/sun/star/table/TableBorder.hpp>
#include <com/sun/star/table/TableBorder2.hpp>
#include <com/sun/star/table/BorderLine2.hpp>
#include <com/sun/star/table/TableBorderDistances.hpp>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/chart/XChartDataChangeEventListener.hpp>
#include <com/sun/star/chart/ChartDataChangeEvent.hpp>
#include <com/sun/star/table/CellContentType.hpp>
#include <unotextrange.hxx>
#include <unotextcursor.hxx>
#include <unoparagraph.hxx>
#include <svl/zforlist.hxx>
#include <editeng/formatbreakitem.hxx>
#include <editeng/shaditem.hxx>
#include <editeng/lrspitem.hxx>
#include <editeng/ulspitem.hxx>
#include <fmtornt.hxx>
#include <editeng/keepitem.hxx>
#include <fmtlsplt.hxx>
#include <swundo.hxx>
#include <osl/mutex.hxx>
#include <SwStyleNameMapper.hxx>
#include <frmatr.hxx>
#include <sortopt.hxx>
#include <rtl/math.hxx>
#include <sal/log.hxx>
#include <editeng/frmdiritem.hxx>
#include <comphelper/interfacecontainer2.hxx>
#include <comphelper/servicehelper.hxx>
#include <comphelper/string.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <comphelper/sequence.hxx>
#include <comphelper/sequenceashashmap.hxx>
#include <swtable.hxx>
#include <docsh.hxx>
#include <fesh.hxx>
#include <itabenum.hxx>
#include <poolfmt.hxx>
#include <frameformats.hxx>
using namespace ::com::sun::star;
using ::editeng::SvxBorderLine;
namespace
{
template<typename Tcoretype, typename Tunotype>
struct FindUnoInstanceHint final : SfxHint
{
FindUnoInstanceHint(Tcoretype* pCore) : m_pCore(pCore), m_pResult(nullptr) {};<--- Struct 'FindUnoInstanceHint < SwTableBox , SwXCell >' has a constructor with 1 argument that is not explicit. [+]Struct 'FindUnoInstanceHint < SwTableBox , SwXCell >' has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided. <--- Struct 'FindUnoInstanceHint < SwTableLine , SwXTextTableRow >' has a constructor with 1 argument that is not explicit. [+]Struct 'FindUnoInstanceHint < SwTableLine , SwXTextTableRow >' has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided.
const Tcoretype* const m_pCore;
mutable Tunotype* m_pResult;
};
SwFrameFormat* lcl_EnsureCoreConnected(SwFrameFormat* pFormat, cppu::OWeakObject* pObject)
{
if(!pFormat)
throw uno::RuntimeException("Lost connection to core objects", pObject);
return pFormat;
}
SwTable* lcl_EnsureTableNotComplex(SwTable* pTable, cppu::OWeakObject* pObject)
{
if(pTable->IsTableComplex())
throw uno::RuntimeException("Table too complex", pObject);
return pTable;
}
chart::ChartDataChangeEvent createChartEvent(uno::Reference<uno::XInterface> const& xSource)
{
//TODO: find appropriate settings of the Event
chart::ChartDataChangeEvent event;
event.Source = xSource;
event.Type = chart::ChartDataChangeType_ALL;
event.StartColumn = 0;
event.EndColumn = 1;
event.StartRow = 0;
event.EndRow = 1;
return event;
}
void lcl_SendChartEvent(
uno::Reference<uno::XInterface> const& xSource,
::comphelper::OInterfaceContainerHelper2& rListeners)
{
rListeners.notifyEach(
&chart::XChartDataChangeEventListener::chartDataChanged,
createChartEvent(xSource));
}
void lcl_SendChartEvent(
uno::Reference<uno::XInterface> const& xSource,
::cppu::OMultiTypeInterfaceContainerHelper const& rListeners)
{
auto pContainer(rListeners.getContainer(cppu::UnoType<chart::XChartDataChangeEventListener>::get()));
if (pContainer)
pContainer->notifyEach(
&chart::XChartDataChangeEventListener::chartDataChanged,
createChartEvent(xSource));
}
}
#define UNO_TABLE_COLUMN_SUM 10000
static bool lcl_LineToSvxLine(const table::BorderLine& rLine, SvxBorderLine& rSvxLine)
{
rSvxLine.SetColor(Color(rLine.Color));
rSvxLine.GuessLinesWidths( SvxBorderLineStyle::NONE,
convertMm100ToTwip( rLine.OuterLineWidth ),
convertMm100ToTwip( rLine.InnerLineWidth ),
convertMm100ToTwip( rLine.LineDistance ) );
return rLine.InnerLineWidth > 0 || rLine.OuterLineWidth > 0;
}
/// @throws lang::IllegalArgumentException
/// @throws uno::RuntimeException
static void lcl_SetSpecialProperty(SwFrameFormat* pFormat,
const SfxItemPropertySimpleEntry* pEntry,
const uno::Any& aValue)
{
// special treatment for "non-items"
switch(pEntry->nWID)
{
case FN_TABLE_HEADLINE_REPEAT:
case FN_TABLE_HEADLINE_COUNT:
{
SwTable* pTable = SwTable::FindTable( pFormat );
UnoActionContext aAction(pFormat->GetDoc());
if( pEntry->nWID == FN_TABLE_HEADLINE_REPEAT)
{
pFormat->GetDoc()->SetRowsToRepeat( *pTable, aValue.get<bool>() ? 1 : 0 );
}
else
{
sal_Int32 nRepeat = 0;
aValue >>= nRepeat;
if( nRepeat >= 0 && nRepeat < SAL_MAX_UINT16 )
pFormat->GetDoc()->SetRowsToRepeat( *pTable, static_cast<sal_uInt16>(nRepeat) );
}
}
break;
case FN_TABLE_IS_RELATIVE_WIDTH:
case FN_TABLE_WIDTH:
case FN_TABLE_RELATIVE_WIDTH:
{
SwFormatFrameSize aSz( pFormat->GetFrameSize() );
if(FN_TABLE_WIDTH == pEntry->nWID)
{
sal_Int32 nWidth = 0;
aValue >>= nWidth;
aSz.SetWidthPercent(0);
aSz.SetWidth ( convertMm100ToTwip ( nWidth ) );
}
else if(FN_TABLE_RELATIVE_WIDTH == pEntry->nWID)
{
sal_Int16 nSet = 0;<--- Assignment 'nSet=0', assigned value is 0
aValue >>= nSet;
if(nSet && nSet <=100)<--- Condition 'nSet' is always false
aSz.SetWidthPercent( static_cast<sal_uInt8>(nSet) );
}
else if(FN_TABLE_IS_RELATIVE_WIDTH == pEntry->nWID)
{
if(!aValue.get<bool>())
aSz.SetWidthPercent(0);
else
{
lang::IllegalArgumentException aExcept;
aExcept.Message = "relative width cannot be switched on with this property";
throw aExcept;
}
}
pFormat->GetDoc()->SetAttr(aSz, *pFormat);
}
break;
case RES_PAGEDESC:
{
OUString sPageStyle;
aValue >>= sPageStyle;
const SwPageDesc* pDesc = nullptr;
if (!sPageStyle.isEmpty())
{
SwStyleNameMapper::FillUIName(sPageStyle, sPageStyle, SwGetPoolIdFromName::PageDesc);
pDesc = SwPageDesc::GetByName(*pFormat->GetDoc(), sPageStyle);
}
SwFormatPageDesc aDesc( pDesc );
pFormat->GetDoc()->SetAttr(aDesc, *pFormat);
}
break;
default:
throw lang::IllegalArgumentException();
}
}
static uno::Any lcl_GetSpecialProperty(SwFrameFormat* pFormat, const SfxItemPropertySimpleEntry* pEntry )
{
switch(pEntry->nWID)
{
case FN_TABLE_HEADLINE_REPEAT:
case FN_TABLE_HEADLINE_COUNT:
{
SwTable* pTable = SwTable::FindTable( pFormat );
const sal_uInt16 nRepeat = pTable->GetRowsToRepeat();
if(pEntry->nWID == FN_TABLE_HEADLINE_REPEAT)
return uno::makeAny<bool>(nRepeat > 0);
return uno::makeAny<sal_Int32>(nRepeat);
}
case FN_TABLE_WIDTH:
case FN_TABLE_IS_RELATIVE_WIDTH:
case FN_TABLE_RELATIVE_WIDTH:
{
uno::Any aRet;
const SwFormatFrameSize& rSz = pFormat->GetFrameSize();
if(FN_TABLE_WIDTH == pEntry->nWID)
rSz.QueryValue(aRet, MID_FRMSIZE_WIDTH|CONVERT_TWIPS);
else if(FN_TABLE_RELATIVE_WIDTH == pEntry->nWID)
rSz.QueryValue(aRet, MID_FRMSIZE_REL_WIDTH);
else
aRet <<= (0 != rSz.GetWidthPercent());
return aRet;
}
case RES_PAGEDESC:
{
const SfxItemSet& rSet = pFormat->GetAttrSet();
const SfxPoolItem* pItem;
if(SfxItemState::SET == rSet.GetItemState(RES_PAGEDESC, false, &pItem))
{
const SwPageDesc* pDsc = static_cast<const SwFormatPageDesc*>(pItem)->GetPageDesc();
if(pDsc)
return uno::makeAny<OUString>(SwStyleNameMapper::GetProgName(pDsc->GetName(), SwGetPoolIdFromName::PageDesc ));
}
return uno::makeAny(OUString());
}
case RES_ANCHOR:
return uno::makeAny(text::TextContentAnchorType_AT_PARAGRAPH);
case FN_UNO_ANCHOR_TYPES:
{
uno::Sequence<text::TextContentAnchorType> aTypes{text::TextContentAnchorType_AT_PARAGRAPH};
return uno::makeAny(aTypes);
}
case FN_UNO_WRAP :
return uno::makeAny(text::WrapTextMode_NONE);
case FN_PARAM_LINK_DISPLAY_NAME :
return uno::makeAny(pFormat->GetName());
case FN_UNO_REDLINE_NODE_START:
case FN_UNO_REDLINE_NODE_END:
{
SwTable* pTable = SwTable::FindTable( pFormat );
SwNode* pTableNode = pTable->GetTableNode();
if(FN_UNO_REDLINE_NODE_END == pEntry->nWID)
pTableNode = pTableNode->EndOfSectionNode();
for(const SwRangeRedline* pRedline : pFormat->GetDoc()->getIDocumentRedlineAccess().GetRedlineTable())
{
const SwNode& rRedPointNode = pRedline->GetNode();
const SwNode& rRedMarkNode = pRedline->GetNode(false);
if(&rRedPointNode == pTableNode || &rRedMarkNode == pTableNode)
{
const SwNode& rStartOfRedline = SwNodeIndex(rRedPointNode) <= SwNodeIndex(rRedMarkNode) ?
rRedPointNode : rRedMarkNode;
bool bIsStart = &rStartOfRedline == pTableNode;
return uno::makeAny(SwXRedlinePortion::CreateRedlineProperties(*pRedline, bIsStart));
}
}
}
}
return uno::Any();
}
/** get position of a cell with a given name
*
* If everything was OK, the indices for column and row are changed (both >= 0).
* In case of errors, at least one of them is < 0.
*
* Also since the implementations of tables does not really have columns using
* this function is appropriate only for tables that are not complex (i.e.
* where IsTableComplex() returns false).
*
* @param rCellName e.g. A1..Z1, a1..z1, AA1..AZ1, Aa1..Az1, BA1..BZ1, Ba1..Bz1, ...
* @param [IN,OUT] o_rColumn (0-based)
* @param [IN,OUT] o_rRow (0-based)
*/
//TODO: potential for throwing proper exceptions instead of having every caller to check for errors
void SwXTextTable::GetCellPosition(const OUString& rCellName, sal_Int32& o_rColumn, sal_Int32& o_rRow)
{
o_rColumn = o_rRow = -1; // default return values indicating failure
const sal_Int32 nLen = rCellName.getLength();
if(!nLen)
{
SAL_WARN("sw.uno", "failed to get column or row index");
return;
}
sal_Int32 nRowPos = 0;
while (nRowPos<nLen)
{
if (rCellName[nRowPos]>='0' && rCellName[nRowPos]<='9')
{
break;
}
++nRowPos;
}
if (nRowPos>0 && nRowPos<nLen)
{
sal_Int32 nColIdx = 0;
for (sal_Int32 i = 0; i < nRowPos; ++i)
{
nColIdx *= 52;
if (i < nRowPos - 1)
++nColIdx;
const sal_Unicode cChar = rCellName[i];
if ('A' <= cChar && cChar <= 'Z')
nColIdx += cChar - 'A';
else if ('a' <= cChar && cChar <= 'z')
nColIdx += 26 + cChar - 'a';
else
{
nColIdx = -1; // sth failed
break;
}
}
o_rColumn = nColIdx;
o_rRow = rCellName.copy(nRowPos).toInt32() - 1; // - 1 because indices ought to be 0 based
}
}
/** compare position of two cells (check rows first)
*
* @note this function probably also make sense only
* for cell names of non-complex tables
*
* @param rCellName1 e.g. "A1" (non-empty string with valid cell name)
* @param rCellName2 e.g. "A1" (non-empty string with valid cell name)
* @return -1 if cell_1 < cell_2; 0 if both cells are equal; +1 if cell_1 > cell_2
*/
int sw_CompareCellsByRowFirst( const OUString &rCellName1, const OUString &rCellName2 )
{
sal_Int32 nCol1 = -1, nRow1 = -1, nCol2 = -1, nRow2 = -1;
SwXTextTable::GetCellPosition( rCellName1, nCol1, nRow1 );
SwXTextTable::GetCellPosition( rCellName2, nCol2, nRow2 );
if (nRow1 < nRow2 || (nRow1 == nRow2 && nCol1 < nCol2))
return -1;
else if (nCol1 == nCol2 && nRow1 == nRow2)
return 0;
else
return +1;
}
/** compare position of two cells (check columns first)
*
* @note this function probably also make sense only
* for cell names of non-complex tables
*
* @param rCellName1 e.g. "A1" (non-empty string with valid cell name)
* @param rCellName2 e.g. "A1" (non-empty string with valid cell name)
* @return -1 if cell_1 < cell_2; 0 if both cells are equal; +1 if cell_1 > cell_2
*/
int sw_CompareCellsByColFirst( const OUString &rCellName1, const OUString &rCellName2 )
{
sal_Int32 nCol1 = -1, nRow1 = -1, nCol2 = -1, nRow2 = -1;
SwXTextTable::GetCellPosition( rCellName1, nCol1, nRow1 );
SwXTextTable::GetCellPosition( rCellName2, nCol2, nRow2 );
if (nCol1 < nCol2 || (nCol1 == nCol2 && nRow1 < nRow2))
return -1;
else if (nRow1 == nRow2 && nCol1 == nCol2)
return 0;
else
return +1;
}
/** compare position of two cell ranges
*
* @note this function probably also make sense only
* for cell names of non-complex tables
*
* @param rRange1StartCell e.g. "A1" (non-empty string with valid cell name)
* @param rRange1EndCell e.g. "A1" (non-empty string with valid cell name)
* @param rRange2StartCell e.g. "A1" (non-empty string with valid cell name)
* @param rRange2EndCell e.g. "A1" (non-empty string with valid cell name)
* @param bCmpColsFirst if <true> position in columns will be compared first before rows
*
* @return -1 if cell_range_1 < cell_range_2; 0 if both cell ranges are equal; +1 if cell_range_1 > cell_range_2
*/
int sw_CompareCellRanges(
const OUString &rRange1StartCell, const OUString &rRange1EndCell,
const OUString &rRange2StartCell, const OUString &rRange2EndCell,
bool bCmpColsFirst )
{
int (*pCompareCells)( const OUString &, const OUString & ) =
bCmpColsFirst ? &sw_CompareCellsByColFirst : &sw_CompareCellsByRowFirst;
int nCmpResStartCells = pCompareCells( rRange1StartCell, rRange2StartCell );
if ((-1 == nCmpResStartCells ) ||
( 0 == nCmpResStartCells &&
-1 == pCompareCells( rRange1EndCell, rRange2EndCell ) ))
return -1;
else if (0 == nCmpResStartCells &&
0 == pCompareCells( rRange1EndCell, rRange2EndCell ))
return 0;
else
return +1;
}
/** get cell name at a specified coordinate
*
* @param nColumn column index (0-based)
* @param nRow row index (0-based)
* @return the cell name
*/
OUString sw_GetCellName( sal_Int32 nColumn, sal_Int32 nRow )
{
if (nColumn < 0 || nRow < 0)
return OUString();
OUString sCellName;
sw_GetTableBoxColStr( static_cast< sal_uInt16 >(nColumn), sCellName );
return sCellName + OUString::number( nRow + 1 );
}
/** Find the top left or bottom right corner box in given table.
Consider nested lines when finding the box.
@param rTableLines the table
@param i_bTopLeft if true, find top left box, otherwise find bottom
right box
*/
static const SwTableBox* lcl_FindCornerTableBox(const SwTableLines& rTableLines, const bool i_bTopLeft)
{
const SwTableLines* pLines(&rTableLines);
while(true)
{
assert(!pLines->empty());
if(pLines->empty())
return nullptr;
const SwTableLine* pLine(i_bTopLeft ? pLines->front() : pLines->back());
assert(pLine);
const SwTableBoxes& rBoxes(pLine->GetTabBoxes());
assert(rBoxes.size() != 0);
const SwTableBox* pBox = i_bTopLeft ? rBoxes.front() : rBoxes.back();
assert(pBox);
if (pBox->GetSttNd())
return pBox;
pLines = &pBox->GetTabLines();
}
}
/** cleanup order in a range
*
* Sorts the input to a uniform format. I.e. for the four possible representation
* A1:C5, C5:A1, A5:C1, C1:A5
* the result will be always A1:C5.
*
* @param [IN,OUT] rCell1 cell name (will be modified to upper-left corner), e.g. "A1" (non-empty string with valid cell name)
* @param [IN,OUT] rCell2 cell name (will be modified to lower-right corner), e.g. "A1" (non-empty string with valid cell name)
*/
void sw_NormalizeRange(OUString &rCell1, OUString &rCell2)
{
sal_Int32 nCol1 = -1, nRow1 = -1, nCol2 = -1, nRow2 = -1;
SwXTextTable::GetCellPosition( rCell1, nCol1, nRow1 );
SwXTextTable::GetCellPosition( rCell2, nCol2, nRow2 );
if (nCol2 < nCol1 || nRow2 < nRow1)
{
rCell1 = sw_GetCellName( std::min(nCol1, nCol2), std::min(nRow1, nRow2) );
rCell2 = sw_GetCellName( std::max(nCol1, nCol2), std::max(nRow1, nRow2) );
}
}
void SwRangeDescriptor::Normalize()
{
if (nTop > nBottom)
std::swap(nBottom, nTop);
if (nLeft > nRight)
std::swap(nLeft, nRight);
}
static SwXCell* lcl_CreateXCell(SwFrameFormat* pFormat, sal_Int32 nColumn, sal_Int32 nRow)
{
const OUString sCellName = sw_GetCellName(nColumn, nRow);
SwTable* pTable = SwTable::FindTable(pFormat);
SwTableBox* pBox = const_cast<SwTableBox*>(pTable->GetTableBox(sCellName));
if(!pBox)
return nullptr;
return SwXCell::CreateXCell(pFormat, pBox, pTable);
}
static void lcl_InspectLines(SwTableLines& rLines, std::vector<OUString>& rAllNames)<--- Parameter 'rLines' can be declared with const
{
for(auto pLine : rLines)
{
for(auto pBox : pLine->GetTabBoxes())
{
if(!pBox->GetName().isEmpty() && pBox->getRowSpan() > 0)
rAllNames.push_back(pBox->GetName());
SwTableLines& rBoxLines = pBox->GetTabLines();
if(!rBoxLines.empty())
lcl_InspectLines(rBoxLines, rAllNames);
}
}
}
static bool lcl_FormatTable(SwFrameFormat const * pTableFormat)
{
bool bHasFrames = false;
SwIterator<SwFrame,SwFormat> aIter( *pTableFormat );
for(SwFrame* pFrame = aIter.First(); pFrame; pFrame = aIter.Next())
{
vcl::RenderContext* pRenderContext = pFrame->getRootFrame()->GetCurrShell()->GetOut();
// mba: no TYPEINFO for SwTabFrame
if(!pFrame->IsTabFrame())
continue;
DisableCallbackAction a(*pFrame->getRootFrame());
SwTabFrame* pTabFrame = static_cast<SwTabFrame*>(pFrame);
if(pTabFrame->isFrameAreaDefinitionValid())
pTabFrame->InvalidatePos();
pTabFrame->SetONECalcLowers();
pTabFrame->Calc(pRenderContext);
bHasFrames = true;
}
return bHasFrames;
}
static void lcl_CursorSelect(SwPaM& rCursor, bool bExpand)
{
if(bExpand)
{
if(!rCursor.HasMark())
rCursor.SetMark();
}
else if(rCursor.HasMark())
rCursor.DeleteMark();
}
static void lcl_GetTableSeparators(uno::Any& rRet, SwTable const * pTable, SwTableBox const * pBox, bool bRow)
{
SwTabCols aCols;
aCols.SetLeftMin ( 0 );
aCols.SetLeft ( 0 );
aCols.SetRight ( UNO_TABLE_COLUMN_SUM );
aCols.SetRightMax( UNO_TABLE_COLUMN_SUM );
pTable->GetTabCols( aCols, pBox, false, bRow );
const size_t nSepCount = aCols.Count();
uno::Sequence< text::TableColumnSeparator> aColSeq(nSepCount);
text::TableColumnSeparator* pArray = aColSeq.getArray();
bool bError = false;
for(size_t i = 0; i < nSepCount; ++i)
{
pArray[i].Position = static_cast< sal_Int16 >(aCols[i]);
pArray[i].IsVisible = !aCols.IsHidden(i);
if(!bRow && !pArray[i].IsVisible)
{
bError = true;
break;
}
}
if(!bError)
rRet <<= aColSeq;
}
static void lcl_SetTableSeparators(const uno::Any& rVal, SwTable* pTable, SwTableBox const * pBox, bool bRow, SwDoc* pDoc)
{
SwTabCols aOldCols;
aOldCols.SetLeftMin ( 0 );
aOldCols.SetLeft ( 0 );
aOldCols.SetRight ( UNO_TABLE_COLUMN_SUM );
aOldCols.SetRightMax( UNO_TABLE_COLUMN_SUM );
pTable->GetTabCols( aOldCols, pBox, false, bRow );
const size_t nOldCount = aOldCols.Count();
// there is no use in setting tab cols if there is only one column
if( !nOldCount )
return;
auto pSepSeq =
o3tl::tryAccess<uno::Sequence<text::TableColumnSeparator>>(rVal);
if(!pSepSeq || static_cast<size_t>(pSepSeq->getLength()) != nOldCount)
return;
SwTabCols aCols(aOldCols);
const text::TableColumnSeparator* pArray = pSepSeq->getConstArray();
long nLastValue = 0;
//sal_Int32 nTableWidth = aCols.GetRight() - aCols.GetLeft();
for(size_t i = 0; i < nOldCount; ++i)
{
aCols[i] = pArray[i].Position;
if(bool(pArray[i].IsVisible) == aCols.IsHidden(i) ||
(!bRow && aCols.IsHidden(i)) ||
aCols[i] < nLastValue ||
UNO_TABLE_COLUMN_SUM < aCols[i] )
return; // probably this should assert()
nLastValue = aCols[i];
}
pDoc->SetTabCols(*pTable, aCols, aOldCols, pBox, bRow );
}
/* non UNO function call to set string in SwXCell */
void sw_setString( SwXCell &rCell, const OUString &rText,
bool bKeepNumberFormat = false )
{
if(rCell.IsValid())
{
SwFrameFormat* pBoxFormat = rCell.m_pBox->ClaimFrameFormat();
pBoxFormat->LockModify();
pBoxFormat->ResetFormatAttr( RES_BOXATR_FORMULA );
pBoxFormat->ResetFormatAttr( RES_BOXATR_VALUE );
if (!bKeepNumberFormat)
pBoxFormat->SetFormatAttr( SwTableBoxNumFormat(/*default Text*/) );
pBoxFormat->UnlockModify();
}
rCell.SwXText::setString(rText);
}
/* non UNO function call to set value in SwXCell */
void sw_setValue( SwXCell &rCell, double nVal )
{
if(!rCell.IsValid())
return;
// first this text (maybe) needs to be deleted
sal_uLong nNdPos = rCell.m_pBox->IsValidNumTextNd();
if(ULONG_MAX != nNdPos)
sw_setString( rCell, OUString(), true ); // true == keep number format
SwDoc* pDoc = rCell.GetDoc();
UnoActionContext aAction(pDoc);
SwFrameFormat* pBoxFormat = rCell.m_pBox->ClaimFrameFormat();
SfxItemSet aSet(pDoc->GetAttrPool(), svl::Items<RES_BOXATR_FORMAT, RES_BOXATR_VALUE>{});
const SfxPoolItem* pItem;
//!! do we need to set a new number format? Yes, if
// - there is no current number format
// - the current number format is not a number format according to the number formatter, but rather a text format
if(SfxItemState::SET != pBoxFormat->GetAttrSet().GetItemState(RES_BOXATR_FORMAT, true, &pItem)
|| pDoc->GetNumberFormatter()->IsTextFormat(static_cast<const SwTableBoxNumFormat*>(pItem)->GetValue()))
{
aSet.Put(SwTableBoxNumFormat(0));
}
SwTableBoxValue aVal(nVal);
aSet.Put(aVal);
pDoc->SetTableBoxFormulaAttrs( *rCell.m_pBox, aSet );
// update table
SwTableFormulaUpdate aTableUpdate( SwTable::FindTable( rCell.GetFrameFormat() ));
pDoc->getIDocumentFieldsAccess().UpdateTableFields( &aTableUpdate );
}
SwXCell::SwXCell(SwFrameFormat* pTableFormat, SwTableBox* pBx, size_t const nPos) :
SwXText(pTableFormat->GetDoc(), CursorType::TableText),
m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TABLE_CELL)),
m_pBox(pBx),
m_pStartNode(nullptr),
m_pTableFormat(pTableFormat),
m_nFndPos(nPos)
{
StartListening(pTableFormat->GetNotifier());
}
SwXCell::SwXCell(SwFrameFormat* pTableFormat, const SwStartNode& rStartNode) :
SwXText(pTableFormat->GetDoc(), CursorType::TableText),
m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TABLE_CELL)),
m_pBox(nullptr),
m_pStartNode(&rStartNode),
m_pTableFormat(pTableFormat),
m_nFndPos(NOTFOUND)
{
StartListening(pTableFormat->GetNotifier());
}
SwXCell::~SwXCell()
{
SolarMutexGuard aGuard;
EndListeningAll();
}
namespace
{
class theSwXCellUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXCellUnoTunnelId > {};
}
const uno::Sequence< sal_Int8 > & SwXCell::getUnoTunnelId()
{
return theSwXCellUnoTunnelId::get().getSeq();
}
sal_Int64 SAL_CALL SwXCell::getSomething( const uno::Sequence< sal_Int8 >& rId )
{
if( isUnoTunnelId<SwXCell>(rId) )
{
return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
}
else
return SwXText::getSomething(rId);
}
uno::Sequence< uno::Type > SAL_CALL SwXCell::getTypes( )
{
return comphelper::concatSequences(
SwXCellBaseClass::getTypes(),
SwXText::getTypes()
);
}
uno::Sequence< sal_Int8 > SAL_CALL SwXCell::getImplementationId( )
{
return css::uno::Sequence<sal_Int8>();
}
void SAL_CALL SwXCell::acquire( ) throw()
{
SwXCellBaseClass::acquire();
}
void SAL_CALL SwXCell::release( ) throw()
{
SolarMutexGuard aGuard;
SwXCellBaseClass::release();
}
uno::Any SAL_CALL SwXCell::queryInterface( const uno::Type& aType )
{
uno::Any aRet = SwXCellBaseClass::queryInterface(aType);
if(aRet.getValueType() == cppu::UnoType<void>::get())
aRet = SwXText::queryInterface(aType);
return aRet;
}
const SwStartNode *SwXCell::GetStartNode() const
{
const SwStartNode* pSttNd = nullptr;
if( m_pStartNode || IsValid() )
pSttNd = m_pStartNode ? m_pStartNode : m_pBox->GetSttNd();
return pSttNd;
}
uno::Reference< text::XTextCursor >
SwXCell::CreateCursor()
{
return createTextCursor();
}
bool SwXCell::IsValid() const
{
// FIXME: this is now a const method, to make SwXText::IsValid invisible
// but the const_cast here are still ridiculous. TODO: find a better way.
SwFrameFormat* pTableFormat = m_pBox ? GetFrameFormat() : nullptr;
if(!pTableFormat)
{
const_cast<SwXCell*>(this)->m_pBox = nullptr;
}
else
{
SwTable* pTable = SwTable::FindTable( pTableFormat );
SwTableBox const*const pFoundBox =
const_cast<SwXCell*>(this)->FindBox(pTable, m_pBox);
if (!pFoundBox)
{
const_cast<SwXCell*>(this)->m_pBox = nullptr;
}
}
return nullptr != m_pBox;
}
OUString SwXCell::getFormula()
{
SolarMutexGuard aGuard;
if(!IsValid())
return OUString();
SwTableBoxFormula aFormula( m_pBox->GetFrameFormat()->GetTableBoxFormula() );
SwTable* pTable = SwTable::FindTable( GetFrameFormat() );
aFormula.PtrToBoxNm( pTable );
return aFormula.GetFormula();
}
///@see sw_setValue (TODO: seems to be copy and paste programming here)
void SwXCell::setFormula(const OUString& rFormula)
{
SolarMutexGuard aGuard;
if(!IsValid())
return;
// first this text (maybe) needs to be deleted
sal_uInt32 nNdPos = m_pBox->IsValidNumTextNd();
if(USHRT_MAX == nNdPos)
sw_setString( *this, OUString(), true );
OUString sFormula(comphelper::string::stripStart(rFormula, ' '));
if( !sFormula.isEmpty() && '=' == sFormula[0] )
sFormula = sFormula.copy( 1 );
SwTableBoxFormula aFormula( sFormula );
SwDoc* pMyDoc = GetDoc();
UnoActionContext aAction(pMyDoc);
SfxItemSet aSet(pMyDoc->GetAttrPool(), svl::Items<RES_BOXATR_FORMAT, RES_BOXATR_FORMULA>{});
const SfxPoolItem* pItem;
SwFrameFormat* pBoxFormat = m_pBox->GetFrameFormat();
if(SfxItemState::SET != pBoxFormat->GetAttrSet().GetItemState(RES_BOXATR_FORMAT, true, &pItem)
|| pMyDoc->GetNumberFormatter()->IsTextFormat(static_cast<const SwTableBoxNumFormat*>(pItem)->GetValue()))
{
aSet.Put(SwTableBoxNumFormat(0));
}
aSet.Put(aFormula);
GetDoc()->SetTableBoxFormulaAttrs( *m_pBox, aSet );
// update table
SwTableFormulaUpdate aTableUpdate( SwTable::FindTable( GetFrameFormat() ));
pMyDoc->getIDocumentFieldsAccess().UpdateTableFields( &aTableUpdate );
}
double SwXCell::getValue()
{
SolarMutexGuard aGuard;
// #i112652# a table cell may contain NaN as a value, do not filter that
double fRet;
if(IsValid() && !getString().isEmpty())
fRet = m_pBox->GetFrameFormat()->GetTableBoxValue().GetValue();
else
::rtl::math::setNan( &fRet );
return fRet;
}
void SwXCell::setValue(double rValue)
{
SolarMutexGuard aGuard;
sw_setValue( *this, rValue );
}
table::CellContentType SwXCell::getType()
{
SolarMutexGuard aGuard;
table::CellContentType nRes = table::CellContentType_EMPTY;
sal_uInt32 nNdPos = m_pBox->IsFormulaOrValueBox();
switch (nNdPos)
{
case 0 : nRes = table::CellContentType_TEXT; break;
case USHRT_MAX : nRes = table::CellContentType_EMPTY; break;
case RES_BOXATR_VALUE : nRes = table::CellContentType_VALUE; break;
case RES_BOXATR_FORMULA : nRes = table::CellContentType_FORMULA; break;
default :
OSL_FAIL( "unexpected case" );
}
return nRes;
}
void SwXCell::setString(const OUString& aString)
{
SolarMutexGuard aGuard;
sw_setString( *this, aString );
}
sal_Int32 SwXCell::getError()
{
SolarMutexGuard aGuard;
OUString sContent = getString();
return sal_Int32(sContent == SwViewShell::GetShellRes()->aCalc_Error);
}
uno::Reference<text::XTextCursor> SwXCell::createTextCursor()
{
SolarMutexGuard aGuard;
if(!m_pStartNode && !IsValid())
throw uno::RuntimeException();
const SwStartNode* pSttNd = m_pStartNode ? m_pStartNode : m_pBox->GetSttNd();
SwPosition aPos(*pSttNd);
SwXTextCursor* const pXCursor =
new SwXTextCursor(*GetDoc(), this, CursorType::TableText, aPos);
auto& rUnoCursor(pXCursor->GetCursor());
rUnoCursor.Move(fnMoveForward, GoInNode);
return static_cast<text::XWordCursor*>(pXCursor);
}
uno::Reference<text::XTextCursor> SwXCell::createTextCursorByRange(const uno::Reference< text::XTextRange > & xTextPosition)
{
SolarMutexGuard aGuard;
SwUnoInternalPaM aPam(*GetDoc());
if((!m_pStartNode && !IsValid()) || !::sw::XTextRangeToSwPaM(aPam, xTextPosition))
throw uno::RuntimeException();
const SwStartNode* pSttNd = m_pStartNode ? m_pStartNode : m_pBox->GetSttNd();
// skip sections
SwStartNode* p1 = aPam.GetNode().StartOfSectionNode();
while(p1->IsSectionNode())
p1 = p1->StartOfSectionNode();
if( p1 != pSttNd )
return nullptr;
return static_cast<text::XWordCursor*>(
new SwXTextCursor(*GetDoc(), this, CursorType::TableText,
*aPam.GetPoint(), aPam.GetMark()));
}
uno::Reference< beans::XPropertySetInfo > SwXCell::getPropertySetInfo()
{
static uno::Reference< beans::XPropertySetInfo > xRef = m_pPropSet->getPropertySetInfo();
return xRef;
}
void SwXCell::setPropertyValue(const OUString& rPropertyName, const uno::Any& aValue)
{
SolarMutexGuard aGuard;
if(!IsValid())
return;
// Hack to support hidden property to transfer textDirection
if(rPropertyName == "FRMDirection")
{
SvxFrameDirectionItem aItem(SvxFrameDirection::Environment, RES_FRAMEDIR);
aItem.PutValue(aValue, 0);
m_pBox->GetFrameFormat()->SetFormatAttr(aItem);
}
else if(rPropertyName == "TableRedlineParams")
{
// Get the table row properties
uno::Sequence<beans::PropertyValue> tableCellProperties = aValue.get< uno::Sequence< beans::PropertyValue > >();
comphelper::SequenceAsHashMap aPropMap(tableCellProperties);
OUString sRedlineType;
if(!(aPropMap.getValue("RedlineType") >>= sRedlineType))
throw beans::UnknownPropertyException("No redline type property: ", static_cast<cppu::OWeakObject*>(this));
// Create a 'Table Cell Redline' object
SwUnoCursorHelper::makeTableCellRedline(*m_pBox, sRedlineType, tableCellProperties);
}
else
{
auto pEntry(m_pPropSet->getPropertyMap().getByName(rPropertyName));
if ( !pEntry )
{
// not a table property: ignore it, if it is a paragraph/character property
const SfxItemPropertySet& rParaPropSet = *aSwMapProvider.GetPropertySet(PROPERTY_MAP_PARAGRAPH);
pEntry = rParaPropSet.getPropertyMap().getByName(rPropertyName);
if ( pEntry )
return;
}
if(!pEntry)
throw beans::UnknownPropertyException(rPropertyName, static_cast<cppu::OWeakObject*>(this));
if(pEntry->nWID != FN_UNO_CELL_ROW_SPAN)
{
SwFrameFormat* pBoxFormat = m_pBox->ClaimFrameFormat();
SwAttrSet aSet(pBoxFormat->GetAttrSet());
m_pPropSet->setPropertyValue(rPropertyName, aValue, aSet);
pBoxFormat->GetDoc()->SetAttr(aSet, *pBoxFormat);
}
else if(aValue.isExtractableTo(cppu::UnoType<sal_Int32>::get()))
m_pBox->setRowSpan(aValue.get<sal_Int32>());
}
}
uno::Any SwXCell::getPropertyValue(const OUString& rPropertyName)
{
SolarMutexGuard aGuard;
if(!IsValid())
return uno::Any();
auto pEntry(m_pPropSet->getPropertyMap().getByName(rPropertyName));
if(!pEntry)
throw beans::UnknownPropertyException(rPropertyName, static_cast<cppu::OWeakObject*>(this));
switch(pEntry->nWID)
{
case FN_UNO_CELL_ROW_SPAN:
return uno::makeAny(m_pBox->getRowSpan());
break;
case FN_UNO_TEXT_SECTION:
{
SwFrameFormat* pTableFormat = GetFrameFormat();
SwTable* pTable = SwTable::FindTable(pTableFormat);
SwTableNode* pTableNode = pTable->GetTableNode();
SwSectionNode* pSectionNode = pTableNode->FindSectionNode();
if(!pSectionNode)
return uno::Any();
SwSection& rSect = pSectionNode->GetSection();
return uno::makeAny(SwXTextSections::GetObject(*rSect.GetFormat()));
}
break;
case FN_UNO_CELL_NAME:
return uno::makeAny(m_pBox->GetName());
break;
case FN_UNO_REDLINE_NODE_START:
case FN_UNO_REDLINE_NODE_END:
{
//redline can only be returned if it's a living object
return SwXText::getPropertyValue(rPropertyName);
}
break;
case FN_UNO_PARENT_TEXT:
{
if (!m_xParentText.is())
{
const SwStartNode* pSttNd = m_pBox->GetSttNd();
if (!pSttNd)
return uno::Any();
const SwTableNode* pTableNode = pSttNd->FindTableNode();
if (!pTableNode)
return uno::Any();
SwPosition aPos(*pTableNode);
SwDoc* pDoc = aPos.GetDoc();
if (!pDoc)
return uno::Any();
m_xParentText = sw::CreateParentXText(*pDoc, aPos);
}
return uno::makeAny(m_xParentText);
}
break;
default:
{
const SwAttrSet& rSet = m_pBox->GetFrameFormat()->GetAttrSet();
uno::Any aResult;
m_pPropSet->getPropertyValue(rPropertyName, rSet, aResult);
return aResult;
}
}
}
void SwXCell::addPropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/)
{ throw uno::RuntimeException("not implemented", static_cast<cppu::OWeakObject*>(this)); };
void SwXCell::removePropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/)
{ throw uno::RuntimeException("not implemented", static_cast<cppu::OWeakObject*>(this)); };
void SwXCell::addVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/)
{ throw uno::RuntimeException("not implemented", static_cast<cppu::OWeakObject*>(this)); };
void SwXCell::removeVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/)
{ throw uno::RuntimeException("not implemented", static_cast<cppu::OWeakObject*>(this)); };
uno::Reference<container::XEnumeration> SwXCell::createEnumeration()
{
SolarMutexGuard aGuard;
if(!IsValid())
return uno::Reference<container::XEnumeration>();
const SwStartNode* pSttNd = m_pBox->GetSttNd();
SwPosition aPos(*pSttNd);
auto pUnoCursor(GetDoc()->CreateUnoCursor(aPos));
pUnoCursor->Move(fnMoveForward, GoInNode);
// remember table and start node for later travelling
// (used in export of tables in tables)
SwTable const*const pTable(&pSttNd->FindTableNode()->GetTable());
return SwXParagraphEnumeration::Create(this, pUnoCursor, CursorType::TableText, pSttNd, pTable);
}
uno::Type SAL_CALL SwXCell::getElementType()
{
return cppu::UnoType<text::XTextRange>::get();
}
sal_Bool SwXCell::hasElements()
{
return true;
}
void SwXCell::Notify(const SfxHint& rHint)
{
if(rHint.GetId() == SfxHintId::Dying)
{
m_pTableFormat = nullptr;
}
else if(auto pFindHint = dynamic_cast<const FindUnoInstanceHint<SwTableBox, SwXCell>*>(&rHint))
{
if(!pFindHint->m_pResult && pFindHint->m_pCore == GetTableBox())
pFindHint->m_pResult = this;
}
}
SwXCell* SwXCell::CreateXCell(SwFrameFormat* pTableFormat, SwTableBox* pBox, SwTable *pTable )
{
if(!pTableFormat || !pBox)
return nullptr;
if(!pTable)
pTable = SwTable::FindTable(pTableFormat);
SwTableSortBoxes::const_iterator it = pTable->GetTabSortBoxes().find(pBox);
if(it == pTable->GetTabSortBoxes().end())
return nullptr;
size_t const nPos = it - pTable->GetTabSortBoxes().begin();
FindUnoInstanceHint<SwTableBox, SwXCell> aHint{pBox};
pTableFormat->GetNotifier().Broadcast(aHint);
return aHint.m_pResult ? aHint.m_pResult : new SwXCell(pTableFormat, pBox, nPos);
}
/** search if a box exists in a table
*
* @param pTable the table to search in
* @param pBox2 box model to find
* @return the box if existent in pTable, 0 (!!!) if not found
*/
SwTableBox* SwXCell::FindBox(SwTable* pTable, SwTableBox* pBox2)
{
// check if nFndPos happens to point to the right table box
if( m_nFndPos < pTable->GetTabSortBoxes().size() &&
pBox2 == pTable->GetTabSortBoxes()[ m_nFndPos ] )
return pBox2;
// if not, seek the entry (and return, if successful)
SwTableSortBoxes::const_iterator it = pTable->GetTabSortBoxes().find( pBox2 );
if( it != pTable->GetTabSortBoxes().end() )
{
m_nFndPos = it - pTable->GetTabSortBoxes().begin();
return pBox2;
}
// box not found: reset nFndPos pointer
m_nFndPos = NOTFOUND;
return nullptr;
}
double SwXCell::GetForcedNumericalValue() const
{
if(table::CellContentType_TEXT != const_cast<SwXCell*>(this)->getType())
return getValue();
// now we'll try to get a useful numerical value
// from the text in the cell...
sal_uInt32 nFIndex;
SvNumberFormatter* pNumFormatter(const_cast<SvNumberFormatter*>(GetDoc()->GetNumberFormatter()));
// look for SwTableBoxNumFormat value in parents as well
const SfxPoolItem* pItem;
auto pBoxFormat(GetTableBox()->GetFrameFormat());
SfxItemState eState = pBoxFormat->GetAttrSet().GetItemState(RES_BOXATR_FORMAT, true, &pItem);
if (eState == SfxItemState::SET)
{
// please note that the language of the numberformat
// is implicitly coded into the below value as well
nFIndex = static_cast<const SwTableBoxNumFormat*>(pItem)->GetValue();
// since the current value indicates a text format but the call
// to 'IsNumberFormat' below won't work for text formats
// we need to get rid of the part that indicates the text format.
// According to ER this can be done like this:
nFIndex -= (nFIndex % SV_COUNTRY_LANGUAGE_OFFSET);
}
else
{
// system language is probably not the best possible choice
// but since we have to guess anyway (because the language of at
// the text is NOT the one used for the number format!)
// it is at least conform to what is used in
// SwTableShell::Execute when
// SID_ATTR_NUMBERFORMAT_VALUE is set...
LanguageType eLang = LANGUAGE_SYSTEM;
nFIndex = pNumFormatter->GetStandardIndex( eLang );
}
double fTmp;
if (!const_cast<SwDoc*>(GetDoc())->IsNumberFormat(const_cast<SwXCell*>(this)->getString(), nFIndex, fTmp))
::rtl::math::setNan(&fTmp);
return fTmp;
}
uno::Any SwXCell::GetAny() const
{
if(!m_pBox)
throw uno::RuntimeException();
// check if table box value item is set
auto pBoxFormat(m_pBox->GetFrameFormat());
const bool bIsNum = pBoxFormat->GetItemState(RES_BOXATR_VALUE, false) == SfxItemState::SET;
return bIsNum ? uno::makeAny(getValue()) : uno::makeAny(const_cast<SwXCell*>(this)->getString());
}
OUString SwXCell::getImplementationName()
{ return "SwXCell"; }
sal_Bool SwXCell::supportsService(const OUString& rServiceName)
{ return cppu::supportsService(this, rServiceName); }
uno::Sequence< OUString > SwXCell::getSupportedServiceNames()
{ return {"com.sun.star.text.CellProperties"}; }
OUString SwXTextTableRow::getImplementationName()
{ return "SwXTextTableRow"; }
sal_Bool SwXTextTableRow::supportsService(const OUString& rServiceName)
{ return cppu::supportsService(this, rServiceName); }
uno::Sequence< OUString > SwXTextTableRow::getSupportedServiceNames()
{ return {"com.sun.star.text.TextTableRow"}; }
SwXTextTableRow::SwXTextTableRow(SwFrameFormat* pFormat, SwTableLine* pLn) :
m_pFormat(pFormat),
pLine(pLn),
m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_TABLE_ROW))
{
StartListening(m_pFormat->GetNotifier());
}
SwXTextTableRow::~SwXTextTableRow()
{
SolarMutexGuard aGuard;
EndListeningAll();
}
uno::Reference< beans::XPropertySetInfo > SwXTextTableRow::getPropertySetInfo()
{
static uno::Reference<beans::XPropertySetInfo> xRef = m_pPropSet->getPropertySetInfo();
return xRef;
}
void SwXTextTableRow::setPropertyValue(const OUString& rPropertyName, const uno::Any& aValue)
{
SolarMutexGuard aGuard;
SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this));
SwTable* pTable = SwTable::FindTable( pFormat );
SwTableLine* pLn = SwXTextTableRow::FindLine(pTable, pLine);
if(pLn)
{
// Check for a specific property
if ( rPropertyName == "TableRedlineParams" )
{
// Get the table row properties
uno::Sequence< beans::PropertyValue > tableRowProperties = aValue.get< uno::Sequence< beans::PropertyValue > >();
comphelper::SequenceAsHashMap aPropMap( tableRowProperties );
OUString sRedlineType;
if( !(aPropMap.getValue("RedlineType") >>= sRedlineType) )
{
throw beans::UnknownPropertyException("No redline type property: ", static_cast < cppu::OWeakObject * > ( this ) );
}
// Create a 'Table Row Redline' object
SwUnoCursorHelper::makeTableRowRedline( *pLn, sRedlineType, tableRowProperties);
}
else
{
const SfxItemPropertySimpleEntry* pEntry =
m_pPropSet->getPropertyMap().getByName(rPropertyName);
SwDoc* pDoc = pFormat->GetDoc();
if (!pEntry)
throw beans::UnknownPropertyException("Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
throw beans::PropertyVetoException("Property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
switch(pEntry->nWID)
{
case FN_UNO_ROW_HEIGHT:
case FN_UNO_ROW_AUTO_HEIGHT:
{
SwFormatFrameSize aFrameSize(pLn->GetFrameFormat()->GetFrameSize());
if(FN_UNO_ROW_AUTO_HEIGHT== pEntry->nWID)
{
bool bSet = *o3tl::doAccess<bool>(aValue);
aFrameSize.SetHeightSizeType(bSet ? SwFrameSize::Variable : SwFrameSize::Fixed);
}
else
{
sal_Int32 nHeight = 0;
aValue >>= nHeight;
Size aSz(aFrameSize.GetSize());
aSz.setHeight( convertMm100ToTwip(nHeight) );
aFrameSize.SetSize(aSz);
}
pDoc->SetAttr(aFrameSize, *pLn->ClaimFrameFormat());
}
break;
case FN_UNO_TABLE_COLUMN_SEPARATORS:
{
UnoActionContext aContext(pDoc);
SwTable* pTable2 = SwTable::FindTable( pFormat );
lcl_SetTableSeparators(aValue, pTable2, pLine->GetTabBoxes()[0], true, pDoc);
}
break;
default:
{
SwFrameFormat* pLnFormat = pLn->ClaimFrameFormat();
SwAttrSet aSet(pLnFormat->GetAttrSet());
m_pPropSet->setPropertyValue(*pEntry, aValue, aSet);
pDoc->SetAttr(aSet, *pLnFormat);
}
}
}
}
}
uno::Any SwXTextTableRow::getPropertyValue(const OUString& rPropertyName)
{
SolarMutexGuard aGuard;
uno::Any aRet;
SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this));
SwTable* pTable = SwTable::FindTable( pFormat );
SwTableLine* pLn = SwXTextTableRow::FindLine(pTable, pLine);
if(pLn)
{
const SfxItemPropertySimpleEntry* pEntry =
m_pPropSet->getPropertyMap().getByName(rPropertyName);
if (!pEntry)
throw beans::UnknownPropertyException("Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
switch(pEntry->nWID)
{
case FN_UNO_ROW_HEIGHT:
case FN_UNO_ROW_AUTO_HEIGHT:
{
const SwFormatFrameSize& rSize = pLn->GetFrameFormat()->GetFrameSize();
if(FN_UNO_ROW_AUTO_HEIGHT== pEntry->nWID)
{
aRet <<= SwFrameSize::Variable == rSize.GetHeightSizeType();
}
else
aRet <<= static_cast<sal_Int32>(convertTwipToMm100(rSize.GetSize().Height()));
}
break;
case FN_UNO_TABLE_COLUMN_SEPARATORS:
{
lcl_GetTableSeparators(aRet, pTable, pLine->GetTabBoxes()[0], true);
}
break;
default:
{
const SwAttrSet& rSet = pLn->GetFrameFormat()->GetAttrSet();
m_pPropSet->getPropertyValue(*pEntry, rSet, aRet);
}
}
}
return aRet;
}
void SwXTextTableRow::addPropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/)
{ throw uno::RuntimeException("not implemented", static_cast<cppu::OWeakObject*>(this)); };
void SwXTextTableRow::removePropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/)
{ throw uno::RuntimeException("not implemented", static_cast<cppu::OWeakObject*>(this)); };
void SwXTextTableRow::addVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/)
{ throw uno::RuntimeException("not implemented", static_cast<cppu::OWeakObject*>(this)); };
void SwXTextTableRow::removeVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/)
{ throw uno::RuntimeException("not implemented", static_cast<cppu::OWeakObject*>(this)); };
void SwXTextTableRow::Notify(const SfxHint& rHint)
{
if(rHint.GetId() == SfxHintId::Dying)
{
m_pFormat = nullptr;
} else if(auto pFindHint = dynamic_cast<const FindUnoInstanceHint<SwTableLine, SwXTextTableRow>*>(&rHint))
{
if(!pFindHint->m_pCore && pFindHint->m_pCore == pLine)
pFindHint->m_pResult = this;
}
}
SwTableLine* SwXTextTableRow::FindLine(SwTable* pTable, SwTableLine const * pLine)
{
for(const auto& pCurrentLine : pTable->GetTabLines())
if(pCurrentLine == pLine)<--- Consider using std::find_if algorithm instead of a raw loop.
return pCurrentLine;
return nullptr;
}
// SwXTextTableCursor
OUString SwXTextTableCursor::getImplementationName()
{ return "SwXTextTableCursor"; }
sal_Bool SwXTextTableCursor::supportsService(const OUString& rServiceName)
{ return cppu::supportsService(this, rServiceName); }
void SwXTextTableCursor::acquire() throw()
{
SwXTextTableCursor_Base::acquire();
}
void SwXTextTableCursor::release() throw()
{
SolarMutexGuard aGuard;
SwXTextTableCursor_Base::release();
}
css::uno::Any SAL_CALL
SwXTextTableCursor::queryInterface( const css::uno::Type& _rType )
{
css::uno::Any aReturn = SwXTextTableCursor_Base::queryInterface( _rType );
if ( !aReturn.hasValue() )
aReturn = OTextCursorHelper::queryInterface( _rType );
return aReturn;
}
const SwPaM* SwXTextTableCursor::GetPaM() const { return &GetCursor(); }
SwPaM* SwXTextTableCursor::GetPaM() { return &GetCursor(); }
const SwDoc* SwXTextTableCursor::GetDoc() const { return GetFrameFormat()->GetDoc(); }
SwDoc* SwXTextTableCursor::GetDoc() { return GetFrameFormat()->GetDoc(); }
const SwUnoCursor& SwXTextTableCursor::GetCursor() const { return *m_pUnoCursor; }
SwUnoCursor& SwXTextTableCursor::GetCursor() { return *m_pUnoCursor; }
uno::Sequence<OUString> SwXTextTableCursor::getSupportedServiceNames()
{ return {"com.sun.star.text.TextTableCursor"}; }
SwXTextTableCursor::SwXTextTableCursor(SwFrameFormat* pFrameFormat, SwTableBox const* pBox)
: m_pFrameFormat(pFrameFormat)
, m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_TABLE_CURSOR))
{
StartListening(m_pFrameFormat->GetNotifier());
SwDoc* pDoc = m_pFrameFormat->GetDoc();
const SwStartNode* pSttNd = pBox->GetSttNd();
SwPosition aPos(*pSttNd);
m_pUnoCursor = pDoc->CreateUnoCursor(aPos, true);
m_pUnoCursor->Move( fnMoveForward, GoInNode );
SwUnoTableCursor& rTableCursor = dynamic_cast<SwUnoTableCursor&>(*m_pUnoCursor);
rTableCursor.MakeBoxSels();
}
SwXTextTableCursor::SwXTextTableCursor(SwFrameFormat& rTableFormat, const SwTableCursor* pTableSelection)
: m_pFrameFormat(&rTableFormat)
, m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_TABLE_CURSOR))
{
StartListening(m_pFrameFormat->GetNotifier());
m_pUnoCursor = pTableSelection->GetDoc()->CreateUnoCursor(*pTableSelection->GetPoint(), true);
if(pTableSelection->HasMark())
{
m_pUnoCursor->SetMark();
*m_pUnoCursor->GetMark() = *pTableSelection->GetMark();
}
const SwSelBoxes& rBoxes = pTableSelection->GetSelectedBoxes();
SwUnoTableCursor& rTableCursor = dynamic_cast<SwUnoTableCursor&>(*m_pUnoCursor);
for(auto pBox : rBoxes)
rTableCursor.InsertBox(*pBox);
rTableCursor.MakeBoxSels();
}
OUString SwXTextTableCursor::getRangeName()
{
SolarMutexGuard aGuard;
SwUnoCursor& rUnoCursor = GetCursor();
SwUnoTableCursor* pTableCursor = dynamic_cast<SwUnoTableCursor*>(&rUnoCursor);
//!! see also SwChartDataSequence::getSourceRangeRepresentation
if(!pTableCursor)
return OUString();
pTableCursor->MakeBoxSels();
const SwStartNode* pNode = pTableCursor->GetPoint()->nNode.GetNode().FindTableBoxStartNode();
const SwTable* pTable = SwTable::FindTable(GetFrameFormat());
const SwTableBox* pEndBox = pTable->GetTableBox(pNode->GetIndex());
if(pTableCursor->HasMark())
{
pNode = pTableCursor->GetMark()->nNode.GetNode().FindTableBoxStartNode();
const SwTableBox* pStartBox = pTable->GetTableBox(pNode->GetIndex());
if(pEndBox != pStartBox)
{
// need to switch start and end?
if(*pTableCursor->GetPoint() < *pTableCursor->GetMark())
std::swap(pStartBox, pEndBox);
return pStartBox->GetName() + ":" + pEndBox->GetName();
}
}
return pEndBox->GetName();
}
sal_Bool SwXTextTableCursor::gotoCellByName(const OUString& sCellName, sal_Bool bExpand)
{
SolarMutexGuard aGuard;
SwUnoCursor& rUnoCursor = GetCursor();
auto& rTableCursor = dynamic_cast<SwUnoTableCursor&>(rUnoCursor);
lcl_CursorSelect(rTableCursor, bExpand);
return rTableCursor.GotoTableBox(sCellName);
}
sal_Bool SwXTextTableCursor::goLeft(sal_Int16 Count, sal_Bool bExpand)
{
SolarMutexGuard aGuard;
SwUnoCursor& rUnoCursor = GetCursor();
SwUnoTableCursor& rTableCursor = dynamic_cast<SwUnoTableCursor&>(rUnoCursor);
lcl_CursorSelect(rTableCursor, bExpand);
return rTableCursor.Left(Count);
}
sal_Bool SwXTextTableCursor::goRight(sal_Int16 Count, sal_Bool bExpand)
{
SolarMutexGuard aGuard;
SwUnoCursor& rUnoCursor = GetCursor();
SwUnoTableCursor& rTableCursor = dynamic_cast<SwUnoTableCursor&>(rUnoCursor);
lcl_CursorSelect(rTableCursor, bExpand);
return rTableCursor.Right(Count);
}
sal_Bool SwXTextTableCursor::goUp(sal_Int16 Count, sal_Bool bExpand)
{
SolarMutexGuard aGuard;
SwUnoCursor& rUnoCursor = GetCursor();
SwUnoTableCursor& rTableCursor = dynamic_cast<SwUnoTableCursor&>(rUnoCursor);
lcl_CursorSelect(rTableCursor, bExpand);
return rTableCursor.UpDown(true, Count, nullptr, 0,
*rUnoCursor.GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout());
}
sal_Bool SwXTextTableCursor::goDown(sal_Int16 Count, sal_Bool bExpand)
{
SolarMutexGuard aGuard;
SwUnoCursor& rUnoCursor = GetCursor();
SwUnoTableCursor& rTableCursor = dynamic_cast<SwUnoTableCursor&>(rUnoCursor);
lcl_CursorSelect(rTableCursor, bExpand);
return rTableCursor.UpDown(false, Count, nullptr, 0,
*rUnoCursor.GetDoc()->getIDocumentLayoutAccess().GetCurrentLayout());
}
void SwXTextTableCursor::gotoStart(sal_Bool bExpand)
{
SolarMutexGuard aGuard;
SwUnoCursor& rUnoCursor = GetCursor();
SwUnoTableCursor& rTableCursor = dynamic_cast<SwUnoTableCursor&>(rUnoCursor);
lcl_CursorSelect(rTableCursor, bExpand);
rTableCursor.MoveTable(GotoCurrTable, fnTableStart);
}
void SwXTextTableCursor::gotoEnd(sal_Bool bExpand)
{
SolarMutexGuard aGuard;
SwUnoCursor& rUnoCursor = GetCursor();
SwUnoTableCursor& rTableCursor = dynamic_cast<SwUnoTableCursor&>(rUnoCursor);
lcl_CursorSelect(rTableCursor, bExpand);
rTableCursor.MoveTable(GotoCurrTable, fnTableEnd);
}
sal_Bool SwXTextTableCursor::mergeRange()
{
SolarMutexGuard aGuard;
SwUnoCursor& rUnoCursor = GetCursor();
SwUnoTableCursor& rTableCursor = dynamic_cast<SwUnoTableCursor&>(rUnoCursor);
{
// HACK: remove pending actions for selecting old style tables
UnoActionRemoveContext aRemoveContext(rTableCursor);
}
rTableCursor.MakeBoxSels();
bool bResult;
{
UnoActionContext aContext(rUnoCursor.GetDoc());
bResult = TableMergeErr::Ok == rTableCursor.GetDoc()->MergeTable(rTableCursor);
}
if(bResult)
{
size_t nCount = rTableCursor.GetSelectedBoxesCount();
while (nCount--)
rTableCursor.DeleteBox(nCount);
}
rTableCursor.MakeBoxSels();
return bResult;
}
sal_Bool SwXTextTableCursor::splitRange(sal_Int16 Count, sal_Bool Horizontal)
{
SolarMutexGuard aGuard;
if (Count <= 0)
throw uno::RuntimeException("Illegal first argument: needs to be > 0", static_cast<cppu::OWeakObject*>(this));
SwUnoCursor& rUnoCursor = GetCursor();
SwUnoTableCursor& rTableCursor = dynamic_cast<SwUnoTableCursor&>(rUnoCursor);
{
// HACK: remove pending actions for selecting old style tables
UnoActionRemoveContext aRemoveContext(rTableCursor);
}
rTableCursor.MakeBoxSels();
bool bResult;
{
UnoActionContext aContext(rUnoCursor.GetDoc());
bResult = rTableCursor.GetDoc()->SplitTable(rTableCursor.GetSelectedBoxes(), !Horizontal, Count);
}
rTableCursor.MakeBoxSels();
return bResult;
}
uno::Reference< beans::XPropertySetInfo > SwXTextTableCursor::getPropertySetInfo()
{
static uno::Reference< beans::XPropertySetInfo > xRef = m_pPropSet->getPropertySetInfo();
return xRef;
}
void SwXTextTableCursor::setPropertyValue(const OUString& rPropertyName, const uno::Any& aValue)
{
SolarMutexGuard aGuard;
SwUnoCursor& rUnoCursor = GetCursor();
auto pEntry(m_pPropSet->getPropertyMap().getByName(rPropertyName));
if(!pEntry)
throw beans::UnknownPropertyException("Unknown property: " + rPropertyName, static_cast<cppu::OWeakObject*>(this));
if(pEntry->nFlags & beans::PropertyAttribute::READONLY)
throw beans::PropertyVetoException("Property is read-only: " + rPropertyName, static_cast<cppu::OWeakObject*>(this));
{
auto pSttNode = rUnoCursor.GetNode().StartOfSectionNode();
const SwTableNode* pTableNode = pSttNode->FindTableNode();
lcl_FormatTable(pTableNode->GetTable().GetFrameFormat());
}
auto& rTableCursor = dynamic_cast<SwUnoTableCursor&>(rUnoCursor);
rTableCursor.MakeBoxSels();
SwDoc* pDoc = rUnoCursor.GetDoc();
switch(pEntry->nWID)
{
case FN_UNO_TABLE_CELL_BACKGROUND:
{
std::unique_ptr<SfxPoolItem> aBrush(std::make_unique<SvxBrushItem>(RES_BACKGROUND));
SwDoc::GetBoxAttr(rUnoCursor, aBrush);
aBrush->PutValue(aValue, pEntry->nMemberId);
pDoc->SetBoxAttr(rUnoCursor, *aBrush);
}
break;
case RES_BOXATR_FORMAT:
{
SfxUInt32Item aNumberFormat(RES_BOXATR_FORMAT);
aNumberFormat.PutValue(aValue, 0);
pDoc->SetBoxAttr(rUnoCursor, aNumberFormat);
}
break;
case FN_UNO_PARA_STYLE:
SwUnoCursorHelper::SetTextFormatColl(aValue, rUnoCursor);
break;
default:
{
SfxItemSet aItemSet(pDoc->GetAttrPool(), {{pEntry->nWID, pEntry->nWID}});
SwUnoCursorHelper::GetCursorAttr(rTableCursor.GetSelRing(),
aItemSet);
if (!SwUnoCursorHelper::SetCursorPropertyValue(
*pEntry, aValue, rTableCursor.GetSelRing(), aItemSet))
{
m_pPropSet->setPropertyValue(*pEntry, aValue, aItemSet);
}
SwUnoCursorHelper::SetCursorAttr(rTableCursor.GetSelRing(),
aItemSet, SetAttrMode::DEFAULT, true);
}
}
}
uno::Any SwXTextTableCursor::getPropertyValue(const OUString& rPropertyName)
{
SolarMutexGuard aGuard;
SwUnoCursor& rUnoCursor = GetCursor();
{
auto pSttNode = rUnoCursor.GetNode().StartOfSectionNode();
const SwTableNode* pTableNode = pSttNode->FindTableNode();
lcl_FormatTable(pTableNode->GetTable().GetFrameFormat());
}
SwUnoTableCursor& rTableCursor = dynamic_cast<SwUnoTableCursor&>(rUnoCursor);
auto pEntry(m_pPropSet->getPropertyMap().getByName(rPropertyName));
if(!pEntry)
throw beans::UnknownPropertyException("Unknown property: " + rPropertyName, static_cast<cppu::OWeakObject*>(this));
rTableCursor.MakeBoxSels();
uno::Any aResult;
switch(pEntry->nWID)
{
case FN_UNO_TABLE_CELL_BACKGROUND:
{
std::unique_ptr<SfxPoolItem> aBrush(std::make_unique<SvxBrushItem>(RES_BACKGROUND));
if (SwDoc::GetBoxAttr(rUnoCursor, aBrush))
aBrush->QueryValue(aResult, pEntry->nMemberId);
}
break;
case RES_BOXATR_FORMAT:
// TODO: GetAttr for table selections in a Doc is missing
throw uno::RuntimeException("Unknown property: " + rPropertyName, static_cast<cppu::OWeakObject*>(this));
break;
case FN_UNO_PARA_STYLE:
{
auto pFormat(SwUnoCursorHelper::GetCurTextFormatColl(rUnoCursor, false));
if(pFormat)
aResult <<= pFormat->GetName();
}
break;
default:
{
SfxItemSet aSet(rTableCursor.GetDoc()->GetAttrPool(),
svl::Items<RES_CHRATR_BEGIN, RES_FRMATR_END-1,
RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER>{});
SwUnoCursorHelper::GetCursorAttr(rTableCursor.GetSelRing(), aSet);
m_pPropSet->getPropertyValue(*pEntry, aSet, aResult);
}
}
return aResult;
}
void SwXTextTableCursor::addPropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/)
{ throw uno::RuntimeException("not implemented", static_cast<cppu::OWeakObject*>(this)); };
void SwXTextTableCursor::removePropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/)
{ throw uno::RuntimeException("not implemented", static_cast<cppu::OWeakObject*>(this)); };
void SwXTextTableCursor::addVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/)
{ throw uno::RuntimeException("not implemented", static_cast<cppu::OWeakObject*>(this)); };
void SwXTextTableCursor::removeVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/)
{ throw uno::RuntimeException("not implemented", static_cast<cppu::OWeakObject*>(this)); };
void SwXTextTableCursor::Notify( const SfxHint& rHint )
{
if(rHint.GetId() == SfxHintId::Dying)
m_pFrameFormat = nullptr;
}
// SwXTextTable ===========================================================
namespace {
class SwTableProperties_Impl
{
SwUnoCursorHelper::SwAnyMapHelper aAnyMap;
public:
SwTableProperties_Impl();
void SetProperty(sal_uInt16 nWhichId, sal_uInt16 nMemberId, const uno::Any& aVal);
bool GetProperty(sal_uInt16 nWhichId, sal_uInt16 nMemberId, const uno::Any*& rpAny);
void AddItemToSet(SfxItemSet& rSet, std::function<std::unique_ptr<SfxPoolItem>()> aItemFactory,
sal_uInt16 nWhich, std::initializer_list<sal_uInt16> vMember, bool bAddTwips = false);
void ApplyTableAttr(const SwTable& rTable, SwDoc& rDoc);
};
}
SwTableProperties_Impl::SwTableProperties_Impl()
{ }
void SwTableProperties_Impl::SetProperty(sal_uInt16 nWhichId, sal_uInt16 nMemberId, const uno::Any& rVal)
{ aAnyMap.SetValue( nWhichId, nMemberId, rVal ); }
bool SwTableProperties_Impl::GetProperty(sal_uInt16 nWhichId, sal_uInt16 nMemberId, const uno::Any*& rpAny )
{ return aAnyMap.FillValue( nWhichId, nMemberId, rpAny ); }
void SwTableProperties_Impl::AddItemToSet(SfxItemSet& rSet,
std::function<std::unique_ptr<SfxPoolItem>()> aItemFactory,
sal_uInt16 nWhich, std::initializer_list<sal_uInt16> vMember, bool bAddTwips)
{
std::vector< std::pair<sal_uInt16, const uno::Any* > > vMemberAndAny;
for(sal_uInt16 nMember : vMember)
{
const uno::Any* pAny = nullptr;
GetProperty(nWhich, nMember, pAny);
if(pAny)
vMemberAndAny.emplace_back(nMember, pAny);
}
if(!vMemberAndAny.empty())
{
std::unique_ptr<SfxPoolItem> aItem(aItemFactory());
for(const auto& aMemberAndAny : vMemberAndAny)
aItem->PutValue(*aMemberAndAny.second, aMemberAndAny.first | (bAddTwips ? CONVERT_TWIPS : 0) );
rSet.Put(*aItem);
}
}
void SwTableProperties_Impl::ApplyTableAttr(const SwTable& rTable, SwDoc& rDoc)
{
SfxItemSet aSet(
rDoc.GetAttrPool(),
svl::Items<
RES_FRM_SIZE, RES_BREAK,
RES_HORI_ORIENT, RES_HORI_ORIENT,
RES_BACKGROUND, RES_BACKGROUND,
RES_SHADOW, RES_SHADOW,
RES_KEEP, RES_KEEP,
RES_LAYOUT_SPLIT, RES_LAYOUT_SPLIT>{});
const uno::Any* pRepHead;
const SwFrameFormat &rFrameFormat = *rTable.GetFrameFormat();
if(GetProperty(FN_TABLE_HEADLINE_REPEAT, 0xff, pRepHead ))
{
bool bVal(pRepHead->get<bool>());
const_cast<SwTable&>(rTable).SetRowsToRepeat( bVal ? 1 : 0 ); // TODO: MULTIHEADER
}
AddItemToSet(aSet, [&rFrameFormat]() { return rFrameFormat.makeBackgroundBrushItem(); }, RES_BACKGROUND, {
MID_BACK_COLOR,
MID_GRAPHIC_TRANSPARENT,
MID_GRAPHIC_POSITION,
MID_GRAPHIC,
MID_GRAPHIC_FILTER });
bool bPutBreak = true;
const uno::Any* pPage;
if(GetProperty(FN_UNO_PAGE_STYLE, 0, pPage) || GetProperty(RES_PAGEDESC, 0xff, pPage))
{
OUString sPageStyle = pPage->get<OUString>();
if(!sPageStyle.isEmpty())
{
SwStyleNameMapper::FillUIName(sPageStyle, sPageStyle, SwGetPoolIdFromName::PageDesc);
const SwPageDesc* pDesc = SwPageDesc::GetByName(rDoc, sPageStyle);
if(pDesc)
{
SwFormatPageDesc aDesc(pDesc);
const uno::Any* pPgNo;
if(GetProperty(RES_PAGEDESC, MID_PAGEDESC_PAGENUMOFFSET, pPgNo))
{
aDesc.SetNumOffset(pPgNo->get<sal_Int16>());
}
aSet.Put(aDesc);
bPutBreak = false;
}
}
}
if(bPutBreak)
AddItemToSet(aSet, [&rFrameFormat]() { return std::unique_ptr<SfxPoolItem>(rFrameFormat.GetBreak().Clone()); }, RES_BREAK, {0});
AddItemToSet(aSet, [&rFrameFormat]() { return std::unique_ptr<SfxPoolItem>(rFrameFormat.GetShadow().Clone()); }, RES_SHADOW, {0}, true);
AddItemToSet(aSet, [&rFrameFormat]() { return std::unique_ptr<SfxPoolItem>(rFrameFormat.GetKeep().Clone()); }, RES_KEEP, {0});
AddItemToSet(aSet, [&rFrameFormat]() { return std::unique_ptr<SfxPoolItem>(rFrameFormat.GetHoriOrient().Clone()); }, RES_HORI_ORIENT, {MID_HORIORIENT_ORIENT}, true);
const uno::Any* pSzRel(nullptr);
GetProperty(FN_TABLE_IS_RELATIVE_WIDTH, 0xff, pSzRel);
const uno::Any* pRelWidth(nullptr);
GetProperty(FN_TABLE_RELATIVE_WIDTH, 0xff, pRelWidth);
const uno::Any* pWidth(nullptr);
GetProperty(FN_TABLE_WIDTH, 0xff, pWidth);
bool bPutSize = pWidth != nullptr;
SwFormatFrameSize aSz(SwFrameSize::Variable);
if(pWidth)
{
aSz.PutValue(*pWidth, MID_FRMSIZE_WIDTH);
bPutSize = true;
}
if(pSzRel && pSzRel->get<bool>() && pRelWidth)
{
aSz.PutValue(*pRelWidth, MID_FRMSIZE_REL_WIDTH|CONVERT_TWIPS);
bPutSize = true;
}
if(bPutSize)
{
if(!aSz.GetWidth())
aSz.SetWidth(MINLAY);
aSet.Put(aSz);
}
AddItemToSet(aSet, [&rFrameFormat]() { return std::unique_ptr<SfxPoolItem>(rFrameFormat.GetLRSpace().Clone()); }, RES_LR_SPACE, {
MID_L_MARGIN|CONVERT_TWIPS,
MID_R_MARGIN|CONVERT_TWIPS });
AddItemToSet(aSet, [&rFrameFormat]() { return std::unique_ptr<SfxPoolItem>(rFrameFormat.GetULSpace().Clone()); }, RES_UL_SPACE, {
MID_UP_MARGIN|CONVERT_TWIPS,
MID_LO_MARGIN|CONVERT_TWIPS });
const::uno::Any* pSplit(nullptr);
if(GetProperty(RES_LAYOUT_SPLIT, 0, pSplit))
{
SwFormatLayoutSplit aSp(pSplit->get<bool>());
aSet.Put(aSp);
}
if(aSet.Count())
{
rDoc.SetAttr(aSet, *rTable.GetFrameFormat());
}
}
class SwXTextTable::Impl
: public SvtListener
{
private:
SwFrameFormat* m_pFrameFormat;
::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper2
public:
uno::WeakReference<uno::XInterface> m_wThis;
::cppu::OMultiTypeInterfaceContainerHelper m_Listeners;
const SfxItemPropertySet * m_pPropSet;
css::uno::WeakReference<css::table::XTableRows> m_xRows;
css::uno::WeakReference<css::table::XTableColumns> m_xColumns;
bool m_bFirstRowAsLabel;
bool m_bFirstColumnAsLabel;
// Descriptor-interface
std::unique_ptr<SwTableProperties_Impl> m_pTableProps;
OUString m_sTableName;
unsigned short m_nRows;
unsigned short m_nColumns;
explicit Impl(SwFrameFormat* const pFrameFormat)
: m_pFrameFormat(pFrameFormat)
, m_Listeners(m_Mutex)
, m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_TABLE))
, m_bFirstRowAsLabel(false)
, m_bFirstColumnAsLabel(false)
, m_pTableProps(pFrameFormat ? nullptr : new SwTableProperties_Impl)
, m_nRows(pFrameFormat ? 0 : 2)
, m_nColumns(pFrameFormat ? 0 : 2)
{
if(m_pFrameFormat)
StartListening(m_pFrameFormat->GetNotifier());
}
SwFrameFormat* GetFrameFormat() { return m_pFrameFormat; }
void SetFrameFormat(SwFrameFormat& rFrameFormat)
{
EndListeningAll();
m_pFrameFormat = &rFrameFormat;
StartListening(m_pFrameFormat->GetNotifier());
}
bool IsDescriptor() const { return m_pTableProps != nullptr; }
// note: lock mutex before calling this to avoid concurrent update
static std::pair<sal_uInt16, sal_uInt16> ThrowIfComplex(SwXTextTable &rThis)
{
sal_uInt16 const nRowCount(rThis.m_pImpl->GetRowCount());
sal_uInt16 const nColCount(rThis.m_pImpl->GetColumnCount());
if (!nRowCount || !nColCount)
{
throw uno::RuntimeException("Table too complex",
static_cast<cppu::OWeakObject*>(&rThis));
}
return std::make_pair(nRowCount, nColCount);
}
sal_uInt16 GetRowCount();
sal_uInt16 GetColumnCount();
virtual void Notify(const SfxHint&) override;
};
namespace
{
class theSwXTextTableUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXTextTableUnoTunnelId > {};
}
const uno::Sequence< sal_Int8 > & SwXTextTable::getUnoTunnelId()
{ return theSwXTextTableUnoTunnelId::get().getSeq(); }
sal_Int64 SAL_CALL SwXTextTable::getSomething( const uno::Sequence< sal_Int8 >& rId )
{
if(isUnoTunnelId<SwXTextTable>(rId))
{
return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
}
return 0;
}
SwXTextTable::SwXTextTable()
: m_pImpl(new Impl(nullptr))
{
}
SwXTextTable::SwXTextTable(SwFrameFormat& rFrameFormat)
: m_pImpl(new Impl(&rFrameFormat))
{
}
SwXTextTable::~SwXTextTable()
{
}
uno::Reference<text::XTextTable> SwXTextTable::CreateXTextTable(SwFrameFormat* const pFrameFormat)
{
uno::Reference<text::XTextTable> xTable;
if(pFrameFormat)
xTable.set(pFrameFormat->GetXObject(), uno::UNO_QUERY); // cached?
if(xTable.is())
return xTable;
SwXTextTable* const pNew( pFrameFormat ? new SwXTextTable(*pFrameFormat) : new SwXTextTable());
xTable.set(pNew);
if(pFrameFormat)
pFrameFormat->SetXObject(xTable);
// need a permanent Reference to initialize m_wThis
pNew->m_pImpl->m_wThis = xTable;
return xTable;
}
SwFrameFormat* SwXTextTable::GetFrameFormat()
{
return m_pImpl->GetFrameFormat();
}
void SwXTextTable::initialize(sal_Int32 nR, sal_Int32 nC)
{
if (!m_pImpl->IsDescriptor() || nR <= 0 || nC <= 0 || nR >= SAL_MAX_UINT16 || nC >= SAL_MAX_UINT16)
throw uno::RuntimeException();
m_pImpl->m_nRows = static_cast<sal_uInt16>(nR);
m_pImpl->m_nColumns = static_cast<sal_uInt16>(nC);
}
uno::Reference<table::XTableRows> SAL_CALL SwXTextTable::getRows()
{
SolarMutexGuard aGuard;
uno::Reference<table::XTableRows> xResult(m_pImpl->m_xRows);
if(xResult.is())
return xResult;
if(SwFrameFormat* pFormat = GetFrameFormat())
m_pImpl->m_xRows = xResult = new SwXTableRows(*pFormat);
if(!xResult.is())
throw uno::RuntimeException();
return xResult;
}
uno::Reference<table::XTableColumns> SAL_CALL SwXTextTable::getColumns()
{
SolarMutexGuard aGuard;
uno::Reference<table::XTableColumns> xResult(m_pImpl->m_xColumns);
if(xResult.is())
return xResult;
if(SwFrameFormat* pFormat = GetFrameFormat())
m_pImpl->m_xColumns = xResult = new SwXTableColumns(*pFormat);
if(!xResult.is())
throw uno::RuntimeException();
return xResult;
}
uno::Reference<table::XCell> SwXTextTable::getCellByName(const OUString& sCellName)
{
SolarMutexGuard aGuard;
SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this));
SwTable* pTable = SwTable::FindTable(pFormat);
SwTableBox* pBox = const_cast<SwTableBox*>(pTable->GetTableBox(sCellName));
if(!pBox)
return nullptr;
return SwXCell::CreateXCell(pFormat, pBox);
}
uno::Sequence<OUString> SwXTextTable::getCellNames()
{
SolarMutexGuard aGuard;
SwFrameFormat* pFormat(GetFrameFormat());
if(!pFormat)
return {};
SwTable* pTable = SwTable::FindTable(pFormat);
// exists at the table and at all boxes
SwTableLines& rTableLines = pTable->GetTabLines();
std::vector<OUString> aAllNames;
lcl_InspectLines(rTableLines, aAllNames);
return comphelper::containerToSequence(aAllNames);
}
uno::Reference<text::XTextTableCursor> SwXTextTable::createCursorByCellName(const OUString& sCellName)
{
SolarMutexGuard aGuard;
SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this));
SwTable* pTable = SwTable::FindTable(pFormat);
SwTableBox* pBox = const_cast<SwTableBox*>(pTable->GetTableBox(sCellName));
if(!pBox || pBox->getRowSpan() == 0)
throw uno::RuntimeException();
return new SwXTextTableCursor(pFormat, pBox);
}
void SAL_CALL
SwXTextTable::attach(const uno::Reference<text::XTextRange> & xTextRange)
{
SolarMutexGuard aGuard;
// attach() must only be called once
if (!m_pImpl->IsDescriptor()) /* already attached ? */
throw uno::RuntimeException("SwXTextTable: already attached to range.", static_cast<cppu::OWeakObject*>(this));
uno::Reference<XUnoTunnel> xRangeTunnel(xTextRange, uno::UNO_QUERY);
SwXTextRange* pRange(nullptr);
OTextCursorHelper* pCursor(nullptr);
if(xRangeTunnel.is())
{
pRange = reinterpret_cast<SwXTextRange*>(
sal::static_int_cast<sal_IntPtr>(xRangeTunnel->getSomething(SwXTextRange::getUnoTunnelId())));
pCursor = reinterpret_cast<OTextCursorHelper*>(
sal::static_int_cast<sal_IntPtr>(xRangeTunnel->getSomething(OTextCursorHelper::getUnoTunnelId())));
}
SwDoc* pDoc = pRange ? &pRange->GetDoc() : pCursor ? pCursor->GetDoc() : nullptr;
if (!pDoc || !m_pImpl->m_nRows || !m_pImpl->m_nColumns)
throw lang::IllegalArgumentException();
SwUnoInternalPaM aPam(*pDoc);
// this now needs to return TRUE
::sw::XTextRangeToSwPaM(aPam, xTextRange);
{
UnoActionContext aCont(pDoc);
pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::EMPTY, nullptr);
const SwTable* pTable(nullptr);
if( 0 != aPam.Start()->nContent.GetIndex() )
{
pDoc->getIDocumentContentOperations().SplitNode(*aPam.Start(), false);
}
//TODO: if it is the last paragraph than add another one!
if(aPam.HasMark())
{
pDoc->getIDocumentContentOperations().DeleteAndJoin(aPam);
aPam.DeleteMark();
}
pTable = pDoc->InsertTable(SwInsertTableOptions( SwInsertTableFlags::Headline | SwInsertTableFlags::DefaultBorder | SwInsertTableFlags::SplitLayout, 0 ),
*aPam.GetPoint(),
m_pImpl->m_nRows,
m_pImpl->m_nColumns,
text::HoriOrientation::FULL);
if(pTable)
{
// here, the properties of the descriptor need to be analyzed
m_pImpl->m_pTableProps->ApplyTableAttr(*pTable, *pDoc);
SwFrameFormat* pTableFormat(pTable->GetFrameFormat());
lcl_FormatTable(pTableFormat);
m_pImpl->SetFrameFormat(*pTableFormat);
if (!m_pImpl->m_sTableName.isEmpty())
{
sal_uInt16 nIndex = 1;
OUString sTmpNameIndex(m_pImpl->m_sTableName);
while(pDoc->FindTableFormatByName(sTmpNameIndex, true) && nIndex < USHRT_MAX)
{
sTmpNameIndex = m_pImpl->m_sTableName + OUString::number(nIndex++);
}
pDoc->SetTableName( *pTableFormat, sTmpNameIndex);
}
const::uno::Any* pName;
if (m_pImpl->m_pTableProps->GetProperty(FN_UNO_TABLE_NAME, 0, pName))
setName(pName->get<OUString>());
m_pImpl->m_pTableProps.reset();
}
pDoc->GetIDocumentUndoRedo().EndUndo( SwUndoId::END, nullptr );
}
}
uno::Reference<text::XTextRange> SwXTextTable::getAnchor()
{
SolarMutexGuard aGuard;
SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this));
return new SwXTextRange(*pFormat);
}
void SwXTextTable::dispose()
{
SolarMutexGuard aGuard;
SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this));
SwTable* pTable = SwTable::FindTable(pFormat);
SwSelBoxes aSelBoxes;
for(auto& rBox : pTable->GetTabSortBoxes() )
aSelBoxes.insert(rBox);
pFormat->GetDoc()->DeleteRowCol(aSelBoxes);
}
void SAL_CALL SwXTextTable::addEventListener(
const uno::Reference<lang::XEventListener> & xListener)
{
// no need to lock here as m_pImpl is const and container threadsafe
m_pImpl->m_Listeners.addInterface(
cppu::UnoType<lang::XEventListener>::get(), xListener);
}
void SAL_CALL SwXTextTable::removeEventListener(
const uno::Reference< lang::XEventListener > & xListener)
{
// no need to lock here as m_pImpl is const and container threadsafe
m_pImpl->m_Listeners.removeInterface(
cppu::UnoType<lang::XEventListener>::get(), xListener);
}
uno::Reference<table::XCell> SwXTextTable::getCellByPosition(sal_Int32 nColumn, sal_Int32 nRow)
{
SolarMutexGuard aGuard;
SwFrameFormat* pFormat(GetFrameFormat());
// sheet is unimportant
if(nColumn >= 0 && nRow >= 0 && pFormat)
{
auto pXCell = lcl_CreateXCell(pFormat, nColumn, nRow);
if(pXCell)
return pXCell;
}
throw lang::IndexOutOfBoundsException();
}
namespace {
uno::Reference<table::XCellRange> GetRangeByName(
SwFrameFormat* pFormat, SwTable const * pTable,
const OUString& rTLName, const OUString& rBRName,
SwRangeDescriptor const & rDesc)
{
const SwTableBox* pTLBox = pTable->GetTableBox(rTLName);
if(!pTLBox)
return nullptr;
const SwStartNode* pSttNd = pTLBox->GetSttNd();
SwPosition aPos(*pSttNd);
// set cursor to the upper-left cell of the range
auto pUnoCursor(pFormat->GetDoc()->CreateUnoCursor(aPos, true));
pUnoCursor->Move(fnMoveForward, GoInNode);
pUnoCursor->SetRemainInSection(false);
const SwTableBox* pBRBox(pTable->GetTableBox(rBRName));
if(!pBRBox)
return nullptr;
pUnoCursor->SetMark();
pUnoCursor->GetPoint()->nNode = *pBRBox->GetSttNd();
pUnoCursor->Move( fnMoveForward, GoInNode );
SwUnoTableCursor& rCursor = dynamic_cast<SwUnoTableCursor&>(*pUnoCursor);
// HACK: remove pending actions for selecting old style tables
UnoActionRemoveContext aRemoveContext(rCursor);
rCursor.MakeBoxSels();
// pUnoCursor will be provided and will not be deleted
return SwXCellRange::CreateXCellRange(pUnoCursor, *pFormat, rDesc).get();
}
} // namespace
uno::Reference<table::XCellRange> SwXTextTable::getCellRangeByPosition(sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom)
{
SolarMutexGuard aGuard;
SwFrameFormat* pFormat(GetFrameFormat());
if(pFormat &&
nLeft <= nRight && nTop <= nBottom &&
nLeft >= 0 && nRight >= 0 && nTop >= 0 && nBottom >= 0 )
{
SwTable* pTable = SwTable::FindTable(pFormat);
if(!pTable->IsTableComplex())
{
SwRangeDescriptor aDesc;
aDesc.nTop = nTop;
aDesc.nBottom = nBottom;
aDesc.nLeft = nLeft;
aDesc.nRight = nRight;
const OUString sTLName = sw_GetCellName(aDesc.nLeft, aDesc.nTop);
const OUString sBRName = sw_GetCellName(aDesc.nRight, aDesc.nBottom);
// please note that according to the 'if' statement at the begin
// sTLName:sBRName already denotes the normalized range string
return GetRangeByName(pFormat, pTable, sTLName, sBRName, aDesc);
}
}
throw lang::IndexOutOfBoundsException();
}
uno::Reference<table::XCellRange> SwXTextTable::getCellRangeByName(const OUString& sRange)
{
SolarMutexGuard aGuard;
SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this));
SwTable* pTable = lcl_EnsureTableNotComplex(SwTable::FindTable(pFormat), static_cast<cppu::OWeakObject*>(this));
sal_Int32 nPos = 0;
const OUString sTLName(sRange.getToken(0, ':', nPos));
const OUString sBRName(sRange.getToken(0, ':', nPos));
if(sTLName.isEmpty() || sBRName.isEmpty())
throw uno::RuntimeException();
SwRangeDescriptor aDesc;
aDesc.nTop = aDesc.nLeft = aDesc.nBottom = aDesc.nRight = -1;
SwXTextTable::GetCellPosition(sTLName, aDesc.nLeft, aDesc.nTop );
SwXTextTable::GetCellPosition(sBRName, aDesc.nRight, aDesc.nBottom );
// we should normalize the range now (e.g. A5:C1 will become A1:C5)
// since (depending on what is done later) it will be troublesome
// elsewhere when the cursor in the implementation does not
// point to the top-left and bottom-right cells
aDesc.Normalize();
return GetRangeByName(pFormat, pTable, sTLName, sBRName, aDesc);
}
uno::Sequence< uno::Sequence< uno::Any > > SAL_CALL SwXTextTable::getDataArray()
{
SolarMutexGuard aGuard;
std::pair<sal_uInt16, sal_uInt16> const RowsAndColumns(SwXTextTable::Impl::ThrowIfComplex(*this));
uno::Reference<sheet::XCellRangeData> const xAllRange(
getCellRangeByPosition(0, 0, RowsAndColumns.second-1, RowsAndColumns.first-1),
uno::UNO_QUERY_THROW);
return xAllRange->getDataArray();
}
void SAL_CALL SwXTextTable::setDataArray(const uno::Sequence< uno::Sequence< uno::Any > >& rArray)
{
SolarMutexGuard aGuard;
std::pair<sal_uInt16, sal_uInt16> const RowsAndColumns(SwXTextTable::Impl::ThrowIfComplex(*this));
uno::Reference<sheet::XCellRangeData> const xAllRange(
getCellRangeByPosition(0, 0, RowsAndColumns.second-1, RowsAndColumns.first-1),
uno::UNO_QUERY_THROW);
return xAllRange->setDataArray(rArray);
}
uno::Sequence< uno::Sequence< double > > SwXTextTable::getData()
{
SolarMutexGuard aGuard;
std::pair<sal_uInt16, sal_uInt16> const RowsAndColumns(SwXTextTable::Impl::ThrowIfComplex(*this));
uno::Reference<chart::XChartDataArray> const xAllRange(
getCellRangeByPosition(0, 0, RowsAndColumns.second-1, RowsAndColumns.first-1),
uno::UNO_QUERY_THROW);
static_cast<SwXCellRange*>(xAllRange.get())->SetLabels(
m_pImpl->m_bFirstRowAsLabel, m_pImpl->m_bFirstColumnAsLabel);
return xAllRange->getData();
}
void SwXTextTable::setData(const uno::Sequence< uno::Sequence< double > >& rData)
{
SolarMutexGuard aGuard;
std::pair<sal_uInt16, sal_uInt16> const RowsAndColumns(SwXTextTable::Impl::ThrowIfComplex(*this));
uno::Reference<chart::XChartDataArray> const xAllRange(
getCellRangeByPosition(0, 0, RowsAndColumns.second-1, RowsAndColumns.first-1),
uno::UNO_QUERY_THROW);
static_cast<SwXCellRange*>(xAllRange.get())->SetLabels(
m_pImpl->m_bFirstRowAsLabel, m_pImpl->m_bFirstColumnAsLabel);
xAllRange->setData(rData);
// this is rather inconsistent: setData on XTextTable sends events, but e.g. CellRanges do not
lcl_SendChartEvent(*this, m_pImpl->m_Listeners);
}
uno::Sequence<OUString> SwXTextTable::getRowDescriptions()
{
SolarMutexGuard aGuard;
std::pair<sal_uInt16, sal_uInt16> const RowsAndColumns(SwXTextTable::Impl::ThrowIfComplex(*this));
uno::Reference<chart::XChartDataArray> const xAllRange(
getCellRangeByPosition(0, 0, RowsAndColumns.second-1, RowsAndColumns.first-1),
uno::UNO_QUERY_THROW);
static_cast<SwXCellRange*>(xAllRange.get())->SetLabels(
m_pImpl->m_bFirstRowAsLabel, m_pImpl->m_bFirstColumnAsLabel);
return xAllRange->getRowDescriptions();
}
void SwXTextTable::setRowDescriptions(const uno::Sequence<OUString>& rRowDesc)
{
SolarMutexGuard aGuard;
std::pair<sal_uInt16, sal_uInt16> const RowsAndColumns(SwXTextTable::Impl::ThrowIfComplex(*this));
uno::Reference<chart::XChartDataArray> const xAllRange(
getCellRangeByPosition(0, 0, RowsAndColumns.second-1, RowsAndColumns.first-1),
uno::UNO_QUERY_THROW);
static_cast<SwXCellRange*>(xAllRange.get())->SetLabels(
m_pImpl->m_bFirstRowAsLabel, m_pImpl->m_bFirstColumnAsLabel);
xAllRange->setRowDescriptions(rRowDesc);
}
uno::Sequence<OUString> SwXTextTable::getColumnDescriptions()
{
SolarMutexGuard aGuard;
std::pair<sal_uInt16, sal_uInt16> const RowsAndColumns(SwXTextTable::Impl::ThrowIfComplex(*this));
uno::Reference<chart::XChartDataArray> const xAllRange(
getCellRangeByPosition(0, 0, RowsAndColumns.second-1, RowsAndColumns.first-1),
uno::UNO_QUERY_THROW);
static_cast<SwXCellRange*>(xAllRange.get())->SetLabels(
m_pImpl->m_bFirstRowAsLabel, m_pImpl->m_bFirstColumnAsLabel);
return xAllRange->getColumnDescriptions();
}
void SwXTextTable::setColumnDescriptions(const uno::Sequence<OUString>& rColumnDesc)
{
SolarMutexGuard aGuard;
std::pair<sal_uInt16, sal_uInt16> const RowsAndColumns(SwXTextTable::Impl::ThrowIfComplex(*this));
uno::Reference<chart::XChartDataArray> const xAllRange(
getCellRangeByPosition(0, 0, RowsAndColumns.second-1, RowsAndColumns.first-1),
uno::UNO_QUERY_THROW);
static_cast<SwXCellRange*>(xAllRange.get())->SetLabels(
m_pImpl->m_bFirstRowAsLabel, m_pImpl->m_bFirstColumnAsLabel);
return xAllRange->setColumnDescriptions(rColumnDesc);
}
void SAL_CALL SwXTextTable::addChartDataChangeEventListener(
const uno::Reference<chart::XChartDataChangeEventListener> & xListener)
{
// no need to lock here as m_pImpl is const and container threadsafe
m_pImpl->m_Listeners.addInterface(
cppu::UnoType<chart::XChartDataChangeEventListener>::get(), xListener);
}
void SAL_CALL SwXTextTable::removeChartDataChangeEventListener(
const uno::Reference<chart::XChartDataChangeEventListener> & xListener)
{
// no need to lock here as m_pImpl is const and container threadsafe
m_pImpl->m_Listeners.removeInterface(
cppu::UnoType<chart::XChartDataChangeEventListener>::get(), xListener);
}
sal_Bool SwXTextTable::isNotANumber(double nNumber)
{
// We use DBL_MIN because starcalc does (which uses it because chart
// wants it that way!)
return ( nNumber == DBL_MIN );
}
double SwXTextTable::getNotANumber()
{
// We use DBL_MIN because starcalc does (which uses it because chart
// wants it that way!)
return DBL_MIN;
}
uno::Sequence< beans::PropertyValue > SwXTextTable::createSortDescriptor()
{
SolarMutexGuard aGuard;
return SwUnoCursorHelper::CreateSortDescriptor(true);
}
void SwXTextTable::sort(const uno::Sequence< beans::PropertyValue >& rDescriptor)
{
SolarMutexGuard aGuard;
SwSortOptions aSortOpt;
SwFrameFormat* pFormat = GetFrameFormat();
if(pFormat &&
SwUnoCursorHelper::ConvertSortProperties(rDescriptor, aSortOpt))
{
SwTable* pTable = SwTable::FindTable( pFormat );
SwSelBoxes aBoxes;
const SwTableSortBoxes& rTBoxes = pTable->GetTabSortBoxes();
for (size_t n = 0; n < rTBoxes.size(); ++n)
{
SwTableBox* pBox = rTBoxes[ n ];
aBoxes.insert( pBox );
}
UnoActionContext aContext( pFormat->GetDoc() );
pFormat->GetDoc()->SortTable(aBoxes, aSortOpt);
}
}
void SwXTextTable::autoFormat(const OUString& sAutoFormatName)
{
SolarMutexGuard aGuard;
SwFrameFormat* pFormat = lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this));
SwTable* pTable = lcl_EnsureTableNotComplex(SwTable::FindTable(pFormat), static_cast<cppu::OWeakObject*>(this));
SwTableAutoFormatTable aAutoFormatTable;
aAutoFormatTable.Load();
for (size_t i = aAutoFormatTable.size(); i;)
if( sAutoFormatName == aAutoFormatTable[ --i ].GetName() )
{
SwSelBoxes aBoxes;
const SwTableSortBoxes& rTBoxes = pTable->GetTabSortBoxes();
for (size_t n = 0; n < rTBoxes.size(); ++n)
{
SwTableBox* pBox = rTBoxes[ n ];
aBoxes.insert( pBox );
}
UnoActionContext aContext( pFormat->GetDoc() );
pFormat->GetDoc()->SetTableAutoFormat( aBoxes, aAutoFormatTable[i] );
break;
}
}
uno::Reference< beans::XPropertySetInfo > SwXTextTable::getPropertySetInfo()
{
static uno::Reference<beans::XPropertySetInfo> xRef = m_pImpl->m_pPropSet->getPropertySetInfo();
return xRef;
}
void SwXTextTable::setPropertyValue(const OUString& rPropertyName, const uno::Any& aValue)
{
SolarMutexGuard aGuard;
SwFrameFormat* pFormat = GetFrameFormat();
if(!aValue.hasValue())
throw lang::IllegalArgumentException();
const SfxItemPropertySimpleEntry* pEntry =
m_pImpl->m_pPropSet->getPropertyMap().getByName(rPropertyName);
if( !pEntry )
throw lang::IllegalArgumentException();
if(pFormat)
{
if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
throw beans::PropertyVetoException("Property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
if(0xBF == pEntry->nMemberId)
{
lcl_SetSpecialProperty(pFormat, pEntry, aValue);
}
else
{
switch(pEntry->nWID)
{
case FN_UNO_TABLE_NAME :
{
OUString sName;
aValue >>= sName;
setName( sName );
}
break;
case FN_UNO_RANGE_ROW_LABEL:
{
bool bTmp = *o3tl::doAccess<bool>(aValue);
if (m_pImpl->m_bFirstRowAsLabel != bTmp)
{
lcl_SendChartEvent(*this, m_pImpl->m_Listeners);
m_pImpl->m_bFirstRowAsLabel = bTmp;
}
}
break;
case FN_UNO_RANGE_COL_LABEL:
{
bool bTmp = *o3tl::doAccess<bool>(aValue);
if (m_pImpl->m_bFirstColumnAsLabel != bTmp)
{
lcl_SendChartEvent(*this, m_pImpl->m_Listeners);
m_pImpl->m_bFirstColumnAsLabel = bTmp;
}
}
break;
case FN_UNO_TABLE_BORDER:
case FN_UNO_TABLE_BORDER2:
{
table::TableBorder oldBorder;
table::TableBorder2 aBorder;
SvxBorderLine aTopLine;
SvxBorderLine aBottomLine;
SvxBorderLine aLeftLine;
SvxBorderLine aRightLine;
SvxBorderLine aHoriLine;
SvxBorderLine aVertLine;
if (aValue >>= oldBorder)
{
aBorder.IsTopLineValid = oldBorder.IsTopLineValid;
aBorder.IsBottomLineValid = oldBorder.IsBottomLineValid;
aBorder.IsLeftLineValid = oldBorder.IsLeftLineValid;
aBorder.IsRightLineValid = oldBorder.IsRightLineValid;
aBorder.IsHorizontalLineValid = oldBorder.IsHorizontalLineValid;
aBorder.IsVerticalLineValid = oldBorder.IsVerticalLineValid;
aBorder.Distance = oldBorder.Distance;
aBorder.IsDistanceValid = oldBorder.IsDistanceValid;
lcl_LineToSvxLine(
oldBorder.TopLine, aTopLine);
lcl_LineToSvxLine(
oldBorder.BottomLine, aBottomLine);
lcl_LineToSvxLine(
oldBorder.LeftLine, aLeftLine);
lcl_LineToSvxLine(
oldBorder.RightLine, aRightLine);
lcl_LineToSvxLine(
oldBorder.HorizontalLine, aHoriLine);
lcl_LineToSvxLine(
oldBorder.VerticalLine, aVertLine);
}
else if (aValue >>= aBorder)
{
SvxBoxItem::LineToSvxLine(
aBorder.TopLine, aTopLine, true);
SvxBoxItem::LineToSvxLine(
aBorder.BottomLine, aBottomLine, true);
SvxBoxItem::LineToSvxLine(
aBorder.LeftLine, aLeftLine, true);
SvxBoxItem::LineToSvxLine(
aBorder.RightLine, aRightLine, true);
SvxBoxItem::LineToSvxLine(
aBorder.HorizontalLine, aHoriLine, true);
SvxBoxItem::LineToSvxLine(
aBorder.VerticalLine, aVertLine, true);
}
else
{
break; // something else
}
SwDoc* pDoc = pFormat->GetDoc();
if(!lcl_FormatTable(pFormat))
break;
SwTable* pTable = SwTable::FindTable( pFormat );
SwTableLines &rLines = pTable->GetTabLines();
const SwTableBox* pTLBox = lcl_FindCornerTableBox(rLines, true);
const SwStartNode* pSttNd = pTLBox->GetSttNd();
SwPosition aPos(*pSttNd);
// set cursor to top left cell
auto pUnoCursor(pDoc->CreateUnoCursor(aPos, true));
pUnoCursor->Move( fnMoveForward, GoInNode );
pUnoCursor->SetRemainInSection( false );
const SwTableBox* pBRBox = lcl_FindCornerTableBox(rLines, false);
pUnoCursor->SetMark();
pUnoCursor->GetPoint()->nNode = *pBRBox->GetSttNd();
pUnoCursor->Move( fnMoveForward, GoInNode );
SwUnoTableCursor& rCursor = dynamic_cast<SwUnoTableCursor&>(*pUnoCursor);
// HACK: remove pending actions for selecting old style tables
UnoActionRemoveContext aRemoveContext(rCursor);
rCursor.MakeBoxSels();
SfxItemSet aSet(pDoc->GetAttrPool(),
svl::Items<RES_BOX, RES_BOX,
SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER>{});
SvxBoxItem aBox( RES_BOX );
SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
aBox.SetLine(aTopLine.isEmpty() ? nullptr : &aTopLine, SvxBoxItemLine::TOP);
aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::TOP, aBorder.IsTopLineValid);
aBox.SetLine(aBottomLine.isEmpty() ? nullptr : &aBottomLine, SvxBoxItemLine::BOTTOM);
aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::BOTTOM, aBorder.IsBottomLineValid);
aBox.SetLine(aLeftLine.isEmpty() ? nullptr : &aLeftLine, SvxBoxItemLine::LEFT);
aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::LEFT, aBorder.IsLeftLineValid);
aBox.SetLine(aRightLine.isEmpty() ? nullptr : &aRightLine, SvxBoxItemLine::RIGHT);
aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::RIGHT, aBorder.IsRightLineValid);
aBoxInfo.SetLine(aHoriLine.isEmpty() ? nullptr : &aHoriLine, SvxBoxInfoItemLine::HORI);
aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::HORI, aBorder.IsHorizontalLineValid);
aBoxInfo.SetLine(aVertLine.isEmpty() ? nullptr : &aVertLine, SvxBoxInfoItemLine::VERT);
aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::VERT, aBorder.IsVerticalLineValid);
aBox.SetAllDistances(static_cast<sal_uInt16>(convertMm100ToTwip(aBorder.Distance)));
aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::DISTANCE, aBorder.IsDistanceValid);
aSet.Put(aBox);
aSet.Put(aBoxInfo);
pDoc->SetTabBorders(rCursor, aSet);
}
break;
case FN_UNO_TABLE_BORDER_DISTANCES:
{
table::TableBorderDistances aTableBorderDistances;
if( !(aValue >>= aTableBorderDistances) ||
(!aTableBorderDistances.IsLeftDistanceValid &&
!aTableBorderDistances.IsRightDistanceValid &&
!aTableBorderDistances.IsTopDistanceValid &&
!aTableBorderDistances.IsBottomDistanceValid ))
break;
const sal_uInt16 nLeftDistance = convertMm100ToTwip(aTableBorderDistances.LeftDistance);
const sal_uInt16 nRightDistance = convertMm100ToTwip(aTableBorderDistances.RightDistance);
const sal_uInt16 nTopDistance = convertMm100ToTwip(aTableBorderDistances.TopDistance);
const sal_uInt16 nBottomDistance = convertMm100ToTwip(aTableBorderDistances.BottomDistance);
SwDoc* pDoc = pFormat->GetDoc();
SwTable* pTable = SwTable::FindTable( pFormat );
SwTableLines &rLines = pTable->GetTabLines();
pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::START, nullptr);
for(size_t i = 0; i < rLines.size(); ++i)
{
SwTableLine* pLine = rLines[i];
SwTableBoxes& rBoxes = pLine->GetTabBoxes();
for(size_t k = 0; k < rBoxes.size(); ++k)
{
SwTableBox* pBox = rBoxes[k];
const SwFrameFormat* pBoxFormat = pBox->GetFrameFormat();
const SvxBoxItem& rBox = pBoxFormat->GetBox();
if(
(aTableBorderDistances.IsLeftDistanceValid && nLeftDistance != rBox.GetDistance( SvxBoxItemLine::LEFT )) ||
(aTableBorderDistances.IsRightDistanceValid && nRightDistance != rBox.GetDistance( SvxBoxItemLine::RIGHT )) ||
(aTableBorderDistances.IsTopDistanceValid && nTopDistance != rBox.GetDistance( SvxBoxItemLine::TOP )) ||
(aTableBorderDistances.IsBottomDistanceValid && nBottomDistance != rBox.GetDistance( SvxBoxItemLine::BOTTOM )))
{
SvxBoxItem aSetBox( rBox );
SwFrameFormat* pSetBoxFormat = pBox->ClaimFrameFormat();
if( aTableBorderDistances.IsLeftDistanceValid )
aSetBox.SetDistance( nLeftDistance, SvxBoxItemLine::LEFT );
if( aTableBorderDistances.IsRightDistanceValid )
aSetBox.SetDistance( nRightDistance, SvxBoxItemLine::RIGHT );
if( aTableBorderDistances.IsTopDistanceValid )
aSetBox.SetDistance( nTopDistance, SvxBoxItemLine::TOP );
if( aTableBorderDistances.IsBottomDistanceValid )
aSetBox.SetDistance( nBottomDistance, SvxBoxItemLine::BOTTOM );
pDoc->SetAttr( aSetBox, *pSetBoxFormat );
}
}
}
pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::END, nullptr);
}
break;
case FN_UNO_TABLE_COLUMN_SEPARATORS:
{
UnoActionContext aContext(pFormat->GetDoc());
SwTable* pTable = SwTable::FindTable( pFormat );
lcl_SetTableSeparators(aValue, pTable, pTable->GetTabLines()[0]->GetTabBoxes()[0], false, pFormat->GetDoc());
}
break;
case FN_UNO_TABLE_COLUMN_RELATIVE_SUM:/*_readonly_*/ break;
case FN_UNO_TABLE_TEMPLATE_NAME:
{
SwTable* pTable = SwTable::FindTable(pFormat);
OUString sName;
if (!(aValue >>= sName))
break;
SwStyleNameMapper::FillUIName(sName, sName, SwGetPoolIdFromName::TabStyle);
pTable->SetTableStyleName(sName);
SwDoc* pDoc = pFormat->GetDoc();
pDoc->GetDocShell()->GetFEShell()->UpdateTableStyleFormatting(pTable->GetTableNode());
}
break;
default:
{
SwAttrSet aSet(pFormat->GetAttrSet());
m_pImpl->m_pPropSet->setPropertyValue(*pEntry, aValue, aSet);
pFormat->GetDoc()->SetAttr(aSet, *pFormat);
}
}
}
}
else if (m_pImpl->IsDescriptor())
{
m_pImpl->m_pTableProps->SetProperty(pEntry->nWID, pEntry->nMemberId, aValue);
}
else
throw uno::RuntimeException();
}
uno::Any SwXTextTable::getPropertyValue(const OUString& rPropertyName)
{
SolarMutexGuard aGuard;
uno::Any aRet;
SwFrameFormat* pFormat = GetFrameFormat();
const SfxItemPropertySimpleEntry* pEntry =
m_pImpl->m_pPropSet->getPropertyMap().getByName(rPropertyName);
if (!pEntry)
throw beans::UnknownPropertyException("Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
if(pFormat)
{
if(0xBF == pEntry->nMemberId)
{
aRet = lcl_GetSpecialProperty(pFormat, pEntry );
}
else
{
switch(pEntry->nWID)
{
case FN_UNO_TABLE_NAME:
{
aRet <<= getName();
}
break;
case FN_UNO_ANCHOR_TYPES:
case FN_UNO_TEXT_WRAP:
case FN_UNO_ANCHOR_TYPE:
::sw::GetDefaultTextContentValue(
aRet, OUString(), pEntry->nWID);
break;
case FN_UNO_RANGE_ROW_LABEL:
{
aRet <<= m_pImpl->m_bFirstRowAsLabel;
}
break;
case FN_UNO_RANGE_COL_LABEL:
aRet <<= m_pImpl->m_bFirstColumnAsLabel;
break;
case FN_UNO_TABLE_BORDER:
case FN_UNO_TABLE_BORDER2:
{
SwDoc* pDoc = pFormat->GetDoc();
// tables without layout (invisible header/footer?)
if(!lcl_FormatTable(pFormat))
break;
SwTable* pTable = SwTable::FindTable( pFormat );
SwTableLines &rLines = pTable->GetTabLines();
const SwTableBox* pTLBox = lcl_FindCornerTableBox(rLines, true);
const SwStartNode* pSttNd = pTLBox->GetSttNd();
SwPosition aPos(*pSttNd);
// set cursor to top left cell
auto pUnoCursor(pDoc->CreateUnoCursor(aPos, true));
pUnoCursor->Move( fnMoveForward, GoInNode );
pUnoCursor->SetRemainInSection( false );
const SwTableBox* pBRBox = lcl_FindCornerTableBox(rLines, false);
pUnoCursor->SetMark();
const SwStartNode* pLastNd = pBRBox->GetSttNd();
pUnoCursor->GetPoint()->nNode = *pLastNd;
pUnoCursor->Move( fnMoveForward, GoInNode );
SwUnoTableCursor& rCursor = dynamic_cast<SwUnoTableCursor&>(*pUnoCursor);
// HACK: remove pending actions for selecting old style tables
UnoActionRemoveContext aRemoveContext(rCursor);
rCursor.MakeBoxSels();
SfxItemSet aSet(pDoc->GetAttrPool(),
svl::Items<RES_BOX, RES_BOX,
SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER>{});
aSet.Put(SvxBoxInfoItem( SID_ATTR_BORDER_INNER ));
SwDoc::GetTabBorders(rCursor, aSet);
const SvxBoxInfoItem& rBoxInfoItem = aSet.Get(SID_ATTR_BORDER_INNER);
const SvxBoxItem& rBox = aSet.Get(RES_BOX);
if (FN_UNO_TABLE_BORDER == pEntry->nWID)
{
table::TableBorder aTableBorder;
aTableBorder.TopLine = SvxBoxItem::SvxLineToLine(rBox.GetTop(), true);
aTableBorder.IsTopLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::TOP);
aTableBorder.BottomLine = SvxBoxItem::SvxLineToLine(rBox.GetBottom(), true);
aTableBorder.IsBottomLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::BOTTOM);
aTableBorder.LeftLine = SvxBoxItem::SvxLineToLine(rBox.GetLeft(), true);
aTableBorder.IsLeftLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::LEFT);
aTableBorder.RightLine = SvxBoxItem::SvxLineToLine(rBox.GetRight(), true);
aTableBorder.IsRightLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::RIGHT );
aTableBorder.HorizontalLine = SvxBoxItem::SvxLineToLine(rBoxInfoItem.GetHori(), true);
aTableBorder.IsHorizontalLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::HORI);
aTableBorder.VerticalLine = SvxBoxItem::SvxLineToLine(rBoxInfoItem.GetVert(), true);
aTableBorder.IsVerticalLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::VERT);
aTableBorder.Distance = convertTwipToMm100(rBox.GetSmallestDistance());
aTableBorder.IsDistanceValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::DISTANCE);
aRet <<= aTableBorder;
}
else
{
table::TableBorder2 aTableBorder;
aTableBorder.TopLine = SvxBoxItem::SvxLineToLine(rBox.GetTop(), true);
aTableBorder.IsTopLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::TOP);
aTableBorder.BottomLine = SvxBoxItem::SvxLineToLine(rBox.GetBottom(), true);
aTableBorder.IsBottomLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::BOTTOM);
aTableBorder.LeftLine = SvxBoxItem::SvxLineToLine(rBox.GetLeft(), true);
aTableBorder.IsLeftLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::LEFT);
aTableBorder.RightLine = SvxBoxItem::SvxLineToLine(rBox.GetRight(), true);
aTableBorder.IsRightLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::RIGHT );
aTableBorder.HorizontalLine = SvxBoxItem::SvxLineToLine(rBoxInfoItem.GetHori(), true);
aTableBorder.IsHorizontalLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::HORI);
aTableBorder.VerticalLine = SvxBoxItem::SvxLineToLine(rBoxInfoItem.GetVert(), true);
aTableBorder.IsVerticalLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::VERT);
aTableBorder.Distance = convertTwipToMm100(rBox.GetSmallestDistance());
aTableBorder.IsDistanceValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::DISTANCE);
aRet <<= aTableBorder;
}
}
break;
case FN_UNO_TABLE_BORDER_DISTANCES :
{
table::TableBorderDistances aTableBorderDistances( 0, true, 0, true, 0, true, 0, true ) ;
SwTable* pTable = SwTable::FindTable( pFormat );
const SwTableLines &rLines = pTable->GetTabLines();
bool bFirst = true;
sal_uInt16 nLeftDistance = 0;
sal_uInt16 nRightDistance = 0;
sal_uInt16 nTopDistance = 0;
sal_uInt16 nBottomDistance = 0;
for(size_t i = 0; i < rLines.size(); ++i)
{
const SwTableLine* pLine = rLines[i];
const SwTableBoxes& rBoxes = pLine->GetTabBoxes();
for(size_t k = 0; k < rBoxes.size(); ++k)
{
const SwTableBox* pBox = rBoxes[k];
SwFrameFormat* pBoxFormat = pBox->GetFrameFormat();
const SvxBoxItem& rBox = pBoxFormat->GetBox();
if( bFirst )
{
nLeftDistance = convertTwipToMm100( rBox.GetDistance( SvxBoxItemLine::LEFT ));
nRightDistance = convertTwipToMm100( rBox.GetDistance( SvxBoxItemLine::RIGHT ));
nTopDistance = convertTwipToMm100( rBox.GetDistance( SvxBoxItemLine::TOP ));
nBottomDistance = convertTwipToMm100( rBox.GetDistance( SvxBoxItemLine::BOTTOM ));
bFirst = false;
}
else
{
if( aTableBorderDistances.IsLeftDistanceValid &&
nLeftDistance != convertTwipToMm100( rBox.GetDistance( SvxBoxItemLine::LEFT )))
aTableBorderDistances.IsLeftDistanceValid = false;
if( aTableBorderDistances.IsRightDistanceValid &&
nRightDistance != convertTwipToMm100( rBox.GetDistance( SvxBoxItemLine::RIGHT )))
aTableBorderDistances.IsRightDistanceValid = false;
if( aTableBorderDistances.IsTopDistanceValid &&
nTopDistance != convertTwipToMm100( rBox.GetDistance( SvxBoxItemLine::TOP )))
aTableBorderDistances.IsTopDistanceValid = false;
if( aTableBorderDistances.IsBottomDistanceValid &&
nBottomDistance != convertTwipToMm100( rBox.GetDistance( SvxBoxItemLine::BOTTOM )))
aTableBorderDistances.IsBottomDistanceValid = false;
}
}
if( !aTableBorderDistances.IsLeftDistanceValid &&
!aTableBorderDistances.IsRightDistanceValid &&
!aTableBorderDistances.IsTopDistanceValid &&
!aTableBorderDistances.IsBottomDistanceValid )
break;
}
if( aTableBorderDistances.IsLeftDistanceValid)
aTableBorderDistances.LeftDistance = nLeftDistance;
if( aTableBorderDistances.IsRightDistanceValid)
aTableBorderDistances.RightDistance = nRightDistance;
if( aTableBorderDistances.IsTopDistanceValid)
aTableBorderDistances.TopDistance = nTopDistance;
if( aTableBorderDistances.IsBottomDistanceValid)
aTableBorderDistances.BottomDistance = nBottomDistance;
aRet <<= aTableBorderDistances;
}
break;
case FN_UNO_TABLE_COLUMN_SEPARATORS:
{
SwTable* pTable = SwTable::FindTable( pFormat );
lcl_GetTableSeparators(aRet, pTable, pTable->GetTabLines()[0]->GetTabBoxes()[0], false);
}
break;
case FN_UNO_TABLE_COLUMN_RELATIVE_SUM:
aRet <<= sal_Int16(UNO_TABLE_COLUMN_SUM);
break;
case RES_ANCHOR:
// AnchorType is readonly and might be void (no return value)
break;
case FN_UNO_TEXT_SECTION:
{
SwTable* pTable = SwTable::FindTable( pFormat );
SwTableNode* pTableNode = pTable->GetTableNode();
SwSectionNode* pSectionNode = pTableNode->FindSectionNode();
if(pSectionNode)
{
SwSection& rSect = pSectionNode->GetSection();
uno::Reference< text::XTextSection > xSect =
SwXTextSections::GetObject( *rSect.GetFormat() );
aRet <<= xSect;
}
}
break;
case FN_UNO_TABLE_TEMPLATE_NAME:
{
SwTable* pTable = SwTable::FindTable(pFormat);
OUString sName;
SwStyleNameMapper::FillProgName(pTable->GetTableStyleName(), sName, SwGetPoolIdFromName::TabStyle);
aRet <<= sName;
}
break;
default:
{
const SwAttrSet& rSet = pFormat->GetAttrSet();
m_pImpl->m_pPropSet->getPropertyValue(*pEntry, rSet, aRet);
}
}
}
}
else if (m_pImpl->IsDescriptor())
{
const uno::Any* pAny = nullptr;
if (!m_pImpl->m_pTableProps->GetProperty(pEntry->nWID, pEntry->nMemberId, pAny))
throw lang::IllegalArgumentException();
else if(pAny)
aRet = *pAny;
}
else
throw uno::RuntimeException();
return aRet;
}
void SwXTextTable::addPropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/)
{ throw uno::RuntimeException("Not implemented", static_cast<cppu::OWeakObject*>(this)); }
void SwXTextTable::removePropertyChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*xListener*/)
{ throw uno::RuntimeException("Not implemented", static_cast<cppu::OWeakObject*>(this)); }
void SwXTextTable::addVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/)
{ throw uno::RuntimeException("Not implemented", static_cast<cppu::OWeakObject*>(this)); }
void SwXTextTable::removeVetoableChangeListener(const OUString& /*rPropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*xListener*/)
{ throw uno::RuntimeException("Not implemented", static_cast<cppu::OWeakObject*>(this)); }
OUString SwXTextTable::getName()
{
SolarMutexGuard aGuard;
SwFrameFormat* pFormat = GetFrameFormat();
if (!pFormat && !m_pImpl->IsDescriptor())
throw uno::RuntimeException();
if(pFormat)
{
return pFormat->GetName();
}
return m_pImpl->m_sTableName;
}
void SwXTextTable::setName(const OUString& rName)
{
SolarMutexGuard aGuard;
SwFrameFormat* pFormat = GetFrameFormat();
if ((!pFormat && !m_pImpl->IsDescriptor()) ||
rName.isEmpty() ||
rName.indexOf('.')>=0 ||
rName.indexOf(' ')>=0 )
throw uno::RuntimeException();
if(pFormat)
{
const OUString aOldName( pFormat->GetName() );
const SwFrameFormats* pFrameFormats = pFormat->GetDoc()->GetTableFrameFormats();
for (size_t i = pFrameFormats->size(); i;)
{
const SwFrameFormat* pTmpFormat = (*pFrameFormats)[--i];
if( !pTmpFormat->IsDefault() &&
pTmpFormat->GetName() == rName &&
pFormat->GetDoc()->IsUsed( *pTmpFormat ))
{
throw uno::RuntimeException();
}
}
pFormat->SetName( rName );
SwStartNode *pStNd;
SwNodeIndex aIdx( *pFormat->GetDoc()->GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
while ( nullptr != (pStNd = aIdx.GetNode().GetStartNode()) )
{
++aIdx;
SwNode *const pNd = & aIdx.GetNode();
if ( pNd->IsOLENode() &&
aOldName == static_cast<const SwOLENode*>(pNd)->GetChartTableName() )
{
static_cast<SwOLENode*>(pNd)->SetChartTableName( rName );
SwTable* pTable = SwTable::FindTable( pFormat );
//TL_CHART2: chart needs to be notfied about name changes
pFormat->GetDoc()->UpdateCharts( pTable->GetFrameFormat()->GetName() );
}
aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
}
pFormat->GetDoc()->getIDocumentState().SetModified();
}
else
m_pImpl->m_sTableName = rName;
}
sal_uInt16 SwXTextTable::Impl::GetRowCount()
{
sal_uInt16 nRet = 0;
SwFrameFormat* pFormat = GetFrameFormat();
if(pFormat)
{
SwTable* pTable = SwTable::FindTable( pFormat );
if(!pTable->IsTableComplex())
{
nRet = pTable->GetTabLines().size();
}
}
return nRet;
}
sal_uInt16 SwXTextTable::Impl::GetColumnCount()
{
SwFrameFormat* pFormat = GetFrameFormat();
sal_uInt16 nRet = 0;
if(pFormat)
{
SwTable* pTable = SwTable::FindTable( pFormat );
if(!pTable->IsTableComplex())
{
SwTableLines& rLines = pTable->GetTabLines();
SwTableLine* pLine = rLines.front();
nRet = pLine->GetTabBoxes().size();
}
}
return nRet;
}
void SwXTextTable::Impl::Notify(const SfxHint& rHint)
{
if(rHint.GetId() == SfxHintId::Dying)
{
m_pFrameFormat = nullptr;
EndListeningAll();
}
uno::Reference<uno::XInterface> const xThis(m_wThis);
if (xThis.is())
{ // fdo#72695: if UNO object is already dead, don't revive it with event
if(!m_pFrameFormat)
{
lang::EventObject const ev(xThis);
m_Listeners.disposeAndClear(ev);
}
else
{
lcl_SendChartEvent(xThis.get(), m_Listeners);
}
}
}
OUString SAL_CALL SwXTextTable::getImplementationName()
{ return "SwXTextTable"; }
sal_Bool SwXTextTable::supportsService(const OUString& rServiceName)
{ return cppu::supportsService(this, rServiceName); }
uno::Sequence<OUString> SwXTextTable::getSupportedServiceNames()
{
return {
"com.sun.star.document.LinkTarget",
"com.sun.star.text.TextTable",
"com.sun.star.text.TextContent",
"com.sun.star.text.TextSortable" };
}
class SwXCellRange::Impl
: public SvtListener
{
private:
::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper2
SwFrameFormat* m_pFrameFormat;
public:
uno::WeakReference<uno::XInterface> m_wThis;
::comphelper::OInterfaceContainerHelper2 m_ChartListeners;
sw::UnoCursorPointer m_pTableCursor;
SwRangeDescriptor m_RangeDescriptor;
const SfxItemPropertySet* m_pPropSet;
bool m_bFirstRowAsLabel;
bool m_bFirstColumnAsLabel;
Impl(sw::UnoCursorPointer const& pCursor, SwFrameFormat& rFrameFormat, SwRangeDescriptor const& rDesc)
: m_pFrameFormat(&rFrameFormat)
, m_ChartListeners(m_Mutex)
, m_pTableCursor(pCursor)
, m_RangeDescriptor(rDesc)
, m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TABLE_RANGE))
, m_bFirstRowAsLabel(false)
, m_bFirstColumnAsLabel(false)
{
StartListening(rFrameFormat.GetNotifier());
m_RangeDescriptor.Normalize();
}
SwFrameFormat* GetFrameFormat()
{
return m_pFrameFormat;
}
std::tuple<sal_uInt32, sal_uInt32, sal_uInt32, sal_uInt32> GetLabelCoordinates(bool bRow);
uno::Sequence<OUString> GetLabelDescriptions(SwXCellRange & rThis, bool bRow);
void SetLabelDescriptions(SwXCellRange & rThis,
const css::uno::Sequence<OUString>& rDesc, bool bRow);
sal_Int32 GetRowCount() const;
sal_Int32 GetColumnCount() const;
virtual void Notify(const SfxHint& ) override;
};
namespace
{
class theSwXCellRangeUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXCellRangeUnoTunnelId > {};
}
const uno::Sequence< sal_Int8 > & SwXCellRange::getUnoTunnelId()
{
return theSwXCellRangeUnoTunnelId::get().getSeq();
}
sal_Int64 SAL_CALL SwXCellRange::getSomething( const uno::Sequence< sal_Int8 >& rId )
{
if( isUnoTunnelId<SwXCellRange>(rId) )
{
return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
}
return 0;
}
OUString SwXCellRange::getImplementationName()
{ return "SwXCellRange"; }
sal_Bool SwXCellRange::supportsService(const OUString& rServiceName)
{ return cppu::supportsService(this, rServiceName); }
uno::Sequence<OUString> SwXCellRange::getSupportedServiceNames()
{
return {
"com.sun.star.text.CellRange",
"com.sun.star.style.CharacterProperties",
"com.sun.star.style.CharacterPropertiesAsian",
"com.sun.star.style.CharacterPropertiesComplex",
"com.sun.star.style.ParagraphProperties",
"com.sun.star.style.ParagraphPropertiesAsian",
"com.sun.star.style.ParagraphPropertiesComplex" };
}
SwXCellRange::SwXCellRange(sw::UnoCursorPointer const& pCursor,
SwFrameFormat& rFrameFormat, SwRangeDescriptor const & rDesc)
: m_pImpl(new Impl(pCursor, rFrameFormat, rDesc))
{
}
SwXCellRange::~SwXCellRange()
{
}
rtl::Reference<SwXCellRange> SwXCellRange::CreateXCellRange(
sw::UnoCursorPointer const& pCursor, SwFrameFormat& rFrameFormat,
SwRangeDescriptor const & rDesc)
{
SwXCellRange *const pCellRange(new SwXCellRange(pCursor, rFrameFormat, rDesc));
uno::Reference<table::XCellRange> xCellRange(pCellRange);
// need a permanent Reference to initialize m_wThis
pCellRange->m_pImpl->m_wThis = xCellRange;
return pCellRange;
}
void SwXCellRange::SetLabels(bool bFirstRowAsLabel, bool bFirstColumnAsLabel)
{
m_pImpl->m_bFirstRowAsLabel = bFirstRowAsLabel;
m_pImpl->m_bFirstColumnAsLabel = bFirstColumnAsLabel;
}
std::vector< uno::Reference< table::XCell > > SwXCellRange::GetCells()
{
SwFrameFormat *const pFormat = m_pImpl->GetFrameFormat();
const sal_Int32 nRowCount(m_pImpl->GetRowCount());
const sal_Int32 nColCount(m_pImpl->GetColumnCount());
std::vector< uno::Reference< table::XCell > > vResult;
vResult.reserve(static_cast<size_t>(nRowCount)*static_cast<size_t>(nColCount));
for(sal_Int32 nRow = 0; nRow < nRowCount; ++nRow)
for(sal_Int32 nCol = 0; nCol < nColCount; ++nCol)
vResult.emplace_back(lcl_CreateXCell(pFormat, m_pImpl->m_RangeDescriptor.nLeft + nCol, m_pImpl->m_RangeDescriptor.nTop + nRow));
return vResult;
}
uno::Reference<table::XCell> SAL_CALL
SwXCellRange::getCellByPosition(sal_Int32 nColumn, sal_Int32 nRow)
{
SolarMutexGuard aGuard;
uno::Reference< table::XCell > aRet;
SwFrameFormat *const pFormat = m_pImpl->GetFrameFormat();
if(pFormat)
{
if(nColumn >= 0 && nRow >= 0 &&
m_pImpl->GetColumnCount() > nColumn && m_pImpl->GetRowCount() > nRow )
{
SwXCell* pXCell = lcl_CreateXCell(pFormat,
m_pImpl->m_RangeDescriptor.nLeft + nColumn,
m_pImpl->m_RangeDescriptor.nTop + nRow);
if(pXCell)
aRet = pXCell;
}
}
if(!aRet.is())
throw lang::IndexOutOfBoundsException();
return aRet;
}
uno::Reference<table::XCellRange> SAL_CALL
SwXCellRange::getCellRangeByPosition(
sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom)
{
SolarMutexGuard aGuard;
uno::Reference< table::XCellRange > aRet;
SwFrameFormat *const pFormat = m_pImpl->GetFrameFormat();
if (pFormat && m_pImpl->GetColumnCount() > nRight
&& m_pImpl->GetRowCount() > nBottom &&
nLeft <= nRight && nTop <= nBottom
&& nLeft >= 0 && nRight >= 0 && nTop >= 0 && nBottom >= 0 )
{
SwTable* pTable = SwTable::FindTable( pFormat );
if(!pTable->IsTableComplex())
{
SwRangeDescriptor aNewDesc;
aNewDesc.nTop = nTop + m_pImpl->m_RangeDescriptor.nTop;
aNewDesc.nBottom = nBottom + m_pImpl->m_RangeDescriptor.nTop;
aNewDesc.nLeft = nLeft + m_pImpl->m_RangeDescriptor.nLeft;
aNewDesc.nRight = nRight + m_pImpl->m_RangeDescriptor.nLeft;
aNewDesc.Normalize();
const OUString sTLName = sw_GetCellName(aNewDesc.nLeft, aNewDesc.nTop);
const OUString sBRName = sw_GetCellName(aNewDesc.nRight, aNewDesc.nBottom);
const SwTableBox* pTLBox = pTable->GetTableBox( sTLName );
if(pTLBox)
{
const SwStartNode* pSttNd = pTLBox->GetSttNd();
SwPosition aPos(*pSttNd);
// set cursor in the upper-left cell of the range
auto pUnoCursor(pFormat->GetDoc()->CreateUnoCursor(aPos, true));
pUnoCursor->Move( fnMoveForward, GoInNode );
pUnoCursor->SetRemainInSection( false );
const SwTableBox* pBRBox = pTable->GetTableBox( sBRName );
if(pBRBox)
{
pUnoCursor->SetMark();
pUnoCursor->GetPoint()->nNode = *pBRBox->GetSttNd();
pUnoCursor->Move( fnMoveForward, GoInNode );
SwUnoTableCursor& rCursor = dynamic_cast<SwUnoTableCursor&>(*pUnoCursor);
// HACK: remove pending actions for selecting old style tables
UnoActionRemoveContext aRemoveContext(rCursor);
rCursor.MakeBoxSels();
// pUnoCursor will be provided and will not be deleted
aRet = SwXCellRange::CreateXCellRange(pUnoCursor, *pFormat, aNewDesc).get();
}
}
}
}
if(!aRet.is())
throw lang::IndexOutOfBoundsException();
return aRet;
}
uno::Reference<table::XCellRange> SAL_CALL
SwXCellRange::getCellRangeByName(const OUString& rRange)
{
SolarMutexGuard aGuard;
sal_Int32 nPos = 0;
const OUString sTLName(rRange.getToken(0, ':', nPos));
const OUString sBRName(rRange.getToken(0, ':', nPos));
if(sTLName.isEmpty() || sBRName.isEmpty())
throw uno::RuntimeException();
SwRangeDescriptor aDesc;
aDesc.nTop = aDesc.nLeft = aDesc.nBottom = aDesc.nRight = -1;
SwXTextTable::GetCellPosition( sTLName, aDesc.nLeft, aDesc.nTop );
SwXTextTable::GetCellPosition( sBRName, aDesc.nRight, aDesc.nBottom );
aDesc.Normalize();
return getCellRangeByPosition(
aDesc.nLeft - m_pImpl->m_RangeDescriptor.nLeft,
aDesc.nTop - m_pImpl->m_RangeDescriptor.nTop,
aDesc.nRight - m_pImpl->m_RangeDescriptor.nLeft,
aDesc.nBottom - m_pImpl->m_RangeDescriptor.nTop);
}
uno::Reference< beans::XPropertySetInfo > SwXCellRange::getPropertySetInfo()
{
static uno::Reference<beans::XPropertySetInfo> xRef = m_pImpl->m_pPropSet->getPropertySetInfo();
return xRef;
}
void SAL_CALL
SwXCellRange::setPropertyValue(const OUString& rPropertyName, const uno::Any& aValue)
{
SolarMutexGuard aGuard;
SwFrameFormat *const pFormat = m_pImpl->GetFrameFormat();
if(pFormat)
{
const SfxItemPropertySimpleEntry *const pEntry =
m_pImpl->m_pPropSet->getPropertyMap().getByName(rPropertyName);
if(!pEntry)
throw beans::UnknownPropertyException("Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
throw beans::PropertyVetoException("Property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
SwDoc *const pDoc = m_pImpl->m_pTableCursor->GetDoc();
SwUnoTableCursor& rCursor(dynamic_cast<SwUnoTableCursor&>(*m_pImpl->m_pTableCursor));
{
// HACK: remove pending actions for selecting old style tables
UnoActionRemoveContext aRemoveContext(rCursor);
}
rCursor.MakeBoxSels();
switch(pEntry->nWID )
{
case FN_UNO_TABLE_CELL_BACKGROUND:
{
std::unique_ptr<SfxPoolItem> aBrush(std::make_unique<SvxBrushItem>(RES_BACKGROUND));
SwDoc::GetBoxAttr(*m_pImpl->m_pTableCursor, aBrush);
aBrush->PutValue(aValue, pEntry->nMemberId);
pDoc->SetBoxAttr(*m_pImpl->m_pTableCursor, *aBrush);
}
break;
case RES_BOX :
{
SfxItemSet aSet(pDoc->GetAttrPool(),
svl::Items<RES_BOX, RES_BOX,
SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER>{});
SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::ALL, false);
SvxBoxInfoItemValidFlags nValid = SvxBoxInfoItemValidFlags::NONE;
switch(pEntry->nMemberId & ~CONVERT_TWIPS)
{
case LEFT_BORDER : nValid = SvxBoxInfoItemValidFlags::LEFT; break;
case RIGHT_BORDER: nValid = SvxBoxInfoItemValidFlags::RIGHT; break;
case TOP_BORDER : nValid = SvxBoxInfoItemValidFlags::TOP; break;
case BOTTOM_BORDER: nValid = SvxBoxInfoItemValidFlags::BOTTOM; break;
case LEFT_BORDER_DISTANCE :
case RIGHT_BORDER_DISTANCE:
case TOP_BORDER_DISTANCE :
case BOTTOM_BORDER_DISTANCE:
nValid = SvxBoxInfoItemValidFlags::DISTANCE;
break;
}
aBoxInfo.SetValid(nValid);
aSet.Put(aBoxInfo);
SwDoc::GetTabBorders(rCursor, aSet);
aSet.Put(aBoxInfo);
SvxBoxItem aBoxItem(aSet.Get(RES_BOX));
static_cast<SfxPoolItem&>(aBoxItem).PutValue(aValue, pEntry->nMemberId);
aSet.Put(aBoxItem);
pDoc->SetTabBorders(*m_pImpl->m_pTableCursor, aSet);
}
break;
case RES_BOXATR_FORMAT:
{
SfxUInt32Item aNumberFormat(RES_BOXATR_FORMAT);
static_cast<SfxPoolItem&>(aNumberFormat).PutValue(aValue, 0);
pDoc->SetBoxAttr(rCursor, aNumberFormat);
}
break;
case FN_UNO_RANGE_ROW_LABEL:
{
bool bTmp = *o3tl::doAccess<bool>(aValue);
if (m_pImpl->m_bFirstRowAsLabel != bTmp)
{
lcl_SendChartEvent(*this, m_pImpl->m_ChartListeners);
m_pImpl->m_bFirstRowAsLabel = bTmp;
}
}
break;
case FN_UNO_RANGE_COL_LABEL:
{
bool bTmp = *o3tl::doAccess<bool>(aValue);
if (m_pImpl->m_bFirstColumnAsLabel != bTmp)
{
lcl_SendChartEvent(*this, m_pImpl->m_ChartListeners);
m_pImpl->m_bFirstColumnAsLabel = bTmp;
}
}
break;
case RES_VERT_ORIENT:
{
sal_Int16 nAlign = -1;
aValue >>= nAlign;
if( nAlign >= text::VertOrientation::NONE && nAlign <= text::VertOrientation::BOTTOM)
pDoc->SetBoxAlign( rCursor, nAlign );
}
break;
default:
{
SfxItemSet aItemSet( pDoc->GetAttrPool(), {{pEntry->nWID, pEntry->nWID}} );
SwUnoCursorHelper::GetCursorAttr(rCursor.GetSelRing(),
aItemSet);
if (!SwUnoCursorHelper::SetCursorPropertyValue(
*pEntry, aValue, rCursor.GetSelRing(), aItemSet))
{
m_pImpl->m_pPropSet->setPropertyValue(*pEntry, aValue, aItemSet);
}
SwUnoCursorHelper::SetCursorAttr(rCursor.GetSelRing(),
aItemSet, SetAttrMode::DEFAULT, true);
}
}
}
}
uno::Any SAL_CALL SwXCellRange::getPropertyValue(const OUString& rPropertyName)
{
SolarMutexGuard aGuard;
uno::Any aRet;
SwFrameFormat *const pFormat = m_pImpl->GetFrameFormat();
if(pFormat)
{
const SfxItemPropertySimpleEntry *const pEntry =
m_pImpl->m_pPropSet->getPropertyMap().getByName(rPropertyName);
if(!pEntry)
throw beans::UnknownPropertyException("Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
switch(pEntry->nWID )
{
case FN_UNO_TABLE_CELL_BACKGROUND:
{
std::unique_ptr<SfxPoolItem> aBrush(std::make_unique<SvxBrushItem>(RES_BACKGROUND));
if (SwDoc::GetBoxAttr(*m_pImpl->m_pTableCursor, aBrush))
aBrush->QueryValue(aRet, pEntry->nMemberId);
}
break;
case RES_BOX :
{
SwDoc *const pDoc = m_pImpl->m_pTableCursor->GetDoc();
SfxItemSet aSet(pDoc->GetAttrPool(),
svl::Items<RES_BOX, RES_BOX,
SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER>{});
aSet.Put(SvxBoxInfoItem( SID_ATTR_BORDER_INNER ));
SwDoc::GetTabBorders(*m_pImpl->m_pTableCursor, aSet);
const SvxBoxItem& rBoxItem = aSet.Get(RES_BOX);
rBoxItem.QueryValue(aRet, pEntry->nMemberId);
}
break;
case RES_BOXATR_FORMAT:
OSL_FAIL("not implemented");
break;
case FN_UNO_PARA_STYLE:
{
SwFormatColl *const pTmpFormat =
SwUnoCursorHelper::GetCurTextFormatColl(*m_pImpl->m_pTableCursor, false);
OUString sRet;
if (pTmpFormat)
sRet = pTmpFormat->GetName();
aRet <<= sRet;
}
break;
case FN_UNO_RANGE_ROW_LABEL:
aRet <<= m_pImpl->m_bFirstRowAsLabel;
break;
case FN_UNO_RANGE_COL_LABEL:
aRet <<= m_pImpl->m_bFirstColumnAsLabel;
break;
case RES_VERT_ORIENT:
{
std::unique_ptr<SfxPoolItem> aVertOrient(
std::make_unique<SwFormatVertOrient>(RES_VERT_ORIENT));
if (SwDoc::GetBoxAttr(*m_pImpl->m_pTableCursor, aVertOrient))
{
aVertOrient->QueryValue( aRet, pEntry->nMemberId );
}
}
break;
default:
{
SfxItemSet aSet(
m_pImpl->m_pTableCursor->GetDoc()->GetAttrPool(),
svl::Items<
RES_CHRATR_BEGIN, RES_FRMATR_END - 1,
RES_UNKNOWNATR_CONTAINER,
RES_UNKNOWNATR_CONTAINER>{});
// first look at the attributes of the cursor
SwUnoTableCursor *const pCursor =
dynamic_cast<SwUnoTableCursor*>(&(*m_pImpl->m_pTableCursor));
SwUnoCursorHelper::GetCursorAttr(pCursor->GetSelRing(), aSet);
m_pImpl->m_pPropSet->getPropertyValue(*pEntry, aSet, aRet);
}
}
}
return aRet;
}
void SwXCellRange::addPropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/)
{ throw uno::RuntimeException("Not implemented", static_cast<cppu::OWeakObject*>(this)); }
void SwXCellRange::removePropertyChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/)
{ throw uno::RuntimeException("Not implemented", static_cast<cppu::OWeakObject*>(this)); }
void SwXCellRange::addVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/)
{ throw uno::RuntimeException("Not implemented", static_cast<cppu::OWeakObject*>(this)); }
void SwXCellRange::removeVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/)
{ throw uno::RuntimeException("Not implemented", static_cast<cppu::OWeakObject*>(this)); }
///@see SwXCellRange::getData
uno::Sequence<uno::Sequence<uno::Any>> SAL_CALL SwXCellRange::getDataArray()
{
SolarMutexGuard aGuard;
const sal_Int32 nRowCount = m_pImpl->GetRowCount();
const sal_Int32 nColCount = m_pImpl->GetColumnCount();
if(!nRowCount || !nColCount)
throw uno::RuntimeException("Table too complex", static_cast<cppu::OWeakObject*>(this));
lcl_EnsureCoreConnected(m_pImpl->GetFrameFormat(), static_cast<cppu::OWeakObject*>(this));
uno::Sequence< uno::Sequence< uno::Any > > aRowSeq(nRowCount);
auto vCells(GetCells());
auto pCurrentCell(vCells.begin());
for(auto& rRow : aRowSeq)
{
rRow = uno::Sequence< uno::Any >(nColCount);
for(auto& rCellAny : rRow)
{
auto pCell(static_cast<SwXCell*>(pCurrentCell->get()));
if(!pCell)
throw uno::RuntimeException("Table too complex", static_cast<cppu::OWeakObject*>(this));
rCellAny = pCell->GetAny();
++pCurrentCell;
}
}
return aRowSeq;
}
///@see SwXCellRange::setData
void SAL_CALL SwXCellRange::setDataArray(const uno::Sequence< uno::Sequence< uno::Any > >& rArray)
{
SolarMutexGuard aGuard;
const sal_Int32 nRowCount = m_pImpl->GetRowCount();
const sal_Int32 nColCount = m_pImpl->GetColumnCount();
if(!nRowCount || !nColCount)
throw uno::RuntimeException("Table too complex", static_cast<cppu::OWeakObject*>(this));
SwFrameFormat *const pFormat = m_pImpl->GetFrameFormat();
if(!pFormat)
return;
if(rArray.getLength() != nRowCount)
throw uno::RuntimeException("Row count mismatch. expected: " + OUString::number(nRowCount) + " got: " + OUString::number(rArray.getLength()), static_cast<cppu::OWeakObject*>(this));
auto vCells(GetCells());
auto pCurrentCell(vCells.begin());
for(const auto& rColSeq : rArray)
{
if(rColSeq.getLength() != nColCount)
throw uno::RuntimeException("Column count mismatch. expected: " + OUString::number(nColCount) + " got: " + OUString::number(rColSeq.getLength()), static_cast<cppu::OWeakObject*>(this));
for(const auto& aValue : rColSeq)
{
auto pCell(static_cast<SwXCell*>(pCurrentCell->get()));
if(!pCell || !pCell->GetTableBox())
throw uno::RuntimeException("Box for cell missing", static_cast<cppu::OWeakObject*>(this));
if(aValue.isExtractableTo(cppu::UnoType<OUString>::get()))
sw_setString(*pCell, aValue.get<OUString>());
else if(aValue.isExtractableTo(cppu::UnoType<double>::get()))
sw_setValue(*pCell, aValue.get<double>());
else
sw_setString(*pCell, OUString(), true);
++pCurrentCell;
}
}
}
uno::Sequence<uno::Sequence<double>> SAL_CALL
SwXCellRange::getData()
{
SolarMutexGuard aGuard;
const sal_Int32 nRowCount = m_pImpl->GetRowCount();
const sal_Int32 nColCount = m_pImpl->GetColumnCount();
if(!nRowCount || !nColCount)
throw uno::RuntimeException("Table too complex", static_cast<cppu::OWeakObject*>(this));
if (m_pImpl->m_bFirstColumnAsLabel || m_pImpl->m_bFirstRowAsLabel)
{
uno::Reference<chart::XChartDataArray> const xDataRange(
getCellRangeByPosition((m_pImpl->m_bFirstColumnAsLabel) ? 1 : 0,
(m_pImpl->m_bFirstRowAsLabel) ? 1 : 0,
nColCount-1, nRowCount-1), uno::UNO_QUERY_THROW);
return xDataRange->getData();
}
uno::Sequence< uno::Sequence< double > > vRows(nRowCount);
auto vCells(GetCells());
auto pCurrentCell(vCells.begin());
for(auto& rRow : vRows)
{
rRow = uno::Sequence<double>(nColCount);
for(auto& rValue : rRow)
{
if(!(*pCurrentCell))
throw uno::RuntimeException("Table too complex", static_cast<cppu::OWeakObject*>(this));
rValue = (*pCurrentCell)->getValue();
++pCurrentCell;
}
}
return vRows;
}
void SAL_CALL
SwXCellRange::setData(const uno::Sequence< uno::Sequence<double> >& rData)
{
SolarMutexGuard aGuard;
const sal_Int32 nRowCount = m_pImpl->GetRowCount();
const sal_Int32 nColCount = m_pImpl->GetColumnCount();
if(!nRowCount || !nColCount)
throw uno::RuntimeException("Table too complex", static_cast<cppu::OWeakObject*>(this));
if (m_pImpl->m_bFirstColumnAsLabel || m_pImpl->m_bFirstRowAsLabel)
{
uno::Reference<chart::XChartDataArray> const xDataRange(
getCellRangeByPosition((m_pImpl->m_bFirstColumnAsLabel) ? 1 : 0,
(m_pImpl->m_bFirstRowAsLabel) ? 1 : 0,
nColCount-1, nRowCount-1), uno::UNO_QUERY_THROW);
return xDataRange->setData(rData);
}
lcl_EnsureCoreConnected(m_pImpl->GetFrameFormat(), static_cast<cppu::OWeakObject*>(this));
if(rData.getLength() != nRowCount)
throw uno::RuntimeException("Row count mismatch. expected: " + OUString::number(nRowCount) + " got: " + OUString::number(rData.getLength()), static_cast<cppu::OWeakObject*>(this));
auto vCells(GetCells());
auto pCurrentCell(vCells.begin());
for(const auto& rRow : rData)
{
if(rRow.getLength() != nColCount)
throw uno::RuntimeException("Column count mismatch. expected: " + OUString::number(nColCount) + " got: " + OUString::number(rRow.getLength()), static_cast<cppu::OWeakObject*>(this));
for(const auto& rValue : rRow)
{
uno::Reference<table::XCell>(*pCurrentCell, uno::UNO_SET_THROW)->setValue(rValue);
++pCurrentCell;
}
}
}
std::tuple<sal_uInt32, sal_uInt32, sal_uInt32, sal_uInt32>
SwXCellRange::Impl::GetLabelCoordinates(bool bRow)
{
sal_uInt32 nLeft, nTop, nRight, nBottom;
nLeft = nTop = nRight = nBottom = 0;
if(bRow)
{
nTop = m_bFirstRowAsLabel ? 1 : 0;
nBottom = GetRowCount() - 1;
}
else
{
nLeft = m_bFirstColumnAsLabel ? 1 : 0;
nRight = GetColumnCount() - 1;
}
return std::make_tuple(nLeft, nTop, nRight, nBottom);
}
uno::Sequence<OUString>
SwXCellRange::Impl::GetLabelDescriptions(SwXCellRange & rThis, bool bRow)
{
SolarMutexGuard aGuard;
sal_uInt32 nLeft, nTop, nRight, nBottom;
std::tie(nLeft, nTop, nRight, nBottom) = GetLabelCoordinates(bRow);
if(!nRight && !nBottom)
throw uno::RuntimeException("Table too complex", static_cast<cppu::OWeakObject*>(&rThis));
lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(&rThis));
if (!(bRow ? m_bFirstColumnAsLabel : m_bFirstRowAsLabel))
return {}; // without labels we have no descriptions
auto xLabelRange(rThis.getCellRangeByPosition(nLeft, nTop, nRight, nBottom));
auto vCells(static_cast<SwXCellRange*>(xLabelRange.get())->GetCells());
uno::Sequence<OUString> vResult(vCells.size());
std::transform(vCells.begin(), vCells.end(), vResult.begin(),
[](uno::Reference<table::XCell> xCell) -> OUString { return uno::Reference<text::XText>(xCell, uno::UNO_QUERY_THROW)->getString(); });
return vResult;
}
uno::Sequence<OUString> SAL_CALL SwXCellRange::getRowDescriptions()
{
return m_pImpl->GetLabelDescriptions(*this, true);
}
uno::Sequence<OUString> SAL_CALL SwXCellRange::getColumnDescriptions()
{
return m_pImpl->GetLabelDescriptions(*this, false);
}
void SwXCellRange::Impl::SetLabelDescriptions(SwXCellRange & rThis,
const uno::Sequence<OUString>& rDesc, bool bRow)
{
SolarMutexGuard aGuard;
lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(&rThis));
if (!(bRow ? m_bFirstColumnAsLabel : m_bFirstRowAsLabel))
return; // if there are no labels we cannot set descriptions
sal_uInt32 nLeft, nTop, nRight, nBottom;
std::tie(nLeft, nTop, nRight, nBottom) = GetLabelCoordinates(bRow);
if(!nRight && !nBottom)
throw uno::RuntimeException("Table too complex", static_cast<cppu::OWeakObject*>(&rThis));
auto xLabelRange(rThis.getCellRangeByPosition(nLeft, nTop, nRight, nBottom));
if (!xLabelRange.is())
throw uno::RuntimeException("Missing Cell Range", static_cast<cppu::OWeakObject*>(&rThis));
auto vCells(static_cast<SwXCellRange*>(xLabelRange.get())->GetCells());
if (sal::static_int_cast<sal_uInt32>(rDesc.getLength()) != vCells.size())
throw uno::RuntimeException("Too few or too many descriptions", static_cast<cppu::OWeakObject*>(&rThis));
auto pDescIterator(rDesc.begin());
for(auto& xCell : vCells)
uno::Reference<text::XText>(xCell, uno::UNO_QUERY_THROW)->setString(*pDescIterator++);
}
void SAL_CALL SwXCellRange::setRowDescriptions(
const uno::Sequence<OUString>& rRowDesc)
{
m_pImpl->SetLabelDescriptions(*this, rRowDesc, true);
}
void SAL_CALL SwXCellRange::setColumnDescriptions(
const uno::Sequence<OUString>& rColumnDesc)
{
m_pImpl->SetLabelDescriptions(*this, rColumnDesc, false);
}
void SAL_CALL SwXCellRange::addChartDataChangeEventListener(
const uno::Reference<chart::XChartDataChangeEventListener> & xListener)
{
// no need to lock here as m_pImpl is const and container threadsafe
m_pImpl->m_ChartListeners.addInterface(xListener);
}
void SAL_CALL SwXCellRange::removeChartDataChangeEventListener(
const uno::Reference<chart::XChartDataChangeEventListener> & xListener)
{
// no need to lock here as m_pImpl is const and container threadsafe
m_pImpl->m_ChartListeners.removeInterface(xListener);
}
sal_Bool SwXCellRange::isNotANumber(double /*fNumber*/)
{ throw uno::RuntimeException("Not implemented", static_cast<cppu::OWeakObject*>(this)); }
double SwXCellRange::getNotANumber()
{ throw uno::RuntimeException("Not implemented", static_cast<cppu::OWeakObject*>(this)); }
uno::Sequence< beans::PropertyValue > SwXCellRange::createSortDescriptor()
{
SolarMutexGuard aGuard;
return SwUnoCursorHelper::CreateSortDescriptor(true);
}
void SAL_CALL SwXCellRange::sort(const uno::Sequence< beans::PropertyValue >& rDescriptor)
{
SolarMutexGuard aGuard;
SwSortOptions aSortOpt;
SwFrameFormat *const pFormat = m_pImpl->GetFrameFormat();
if(pFormat && SwUnoCursorHelper::ConvertSortProperties(rDescriptor, aSortOpt))
{
SwUnoTableCursor& rTableCursor = dynamic_cast<SwUnoTableCursor&>(*m_pImpl->m_pTableCursor);
rTableCursor.MakeBoxSels();
UnoActionContext aContext(pFormat->GetDoc());
pFormat->GetDoc()->SortTable(rTableCursor.GetSelectedBoxes(), aSortOpt);
}
}
sal_Int32 SwXCellRange::Impl::GetColumnCount() const
{
return m_RangeDescriptor.nRight - m_RangeDescriptor.nLeft + 1;
}
sal_Int32 SwXCellRange::Impl::GetRowCount() const
{
return m_RangeDescriptor.nBottom - m_RangeDescriptor.nTop + 1;
}
const SwUnoCursor* SwXCellRange::GetTableCursor() const
{
SwFrameFormat *const pFormat = m_pImpl->GetFrameFormat();
return pFormat ? &(*m_pImpl->m_pTableCursor) : nullptr;
}
void SwXCellRange::Impl::Notify( const SfxHint& rHint )
{
uno::Reference<uno::XInterface> const xThis(m_wThis);
if(rHint.GetId() == SfxHintId::Dying)
{
m_pFrameFormat = nullptr;
m_pTableCursor.reset(nullptr);
}
if (xThis.is())
{ // fdo#72695: if UNO object is already dead, don't revive it with event
if(m_pFrameFormat)
lcl_SendChartEvent(xThis.get(), m_ChartListeners);
else
m_ChartListeners.disposeAndClear(lang::EventObject(xThis));
}
}
class SwXTableRows::Impl : public SvtListener
{
private:
SwFrameFormat* m_pFrameFormat;
public:
explicit Impl(SwFrameFormat& rFrameFormat) : m_pFrameFormat(&rFrameFormat)
{
StartListening(rFrameFormat.GetNotifier());
}
SwFrameFormat* GetFrameFormat() { return m_pFrameFormat; }
virtual void Notify(const SfxHint&) override;
};
// SwXTableRows
OUString SwXTableRows::getImplementationName()
{ return "SwXTableRows"; }
sal_Bool SwXTableRows::supportsService(const OUString& rServiceName)
{ return cppu::supportsService(this, rServiceName); }
uno::Sequence< OUString > SwXTableRows::getSupportedServiceNames()
{ return { "com.sun.star.text.TableRows" }; }
SwXTableRows::SwXTableRows(SwFrameFormat& rFrameFormat) :
m_pImpl(new SwXTableRows::Impl(rFrameFormat))
{ }
SwXTableRows::~SwXTableRows()
{ }
SwFrameFormat* SwXTableRows::GetFrameFormat()
{
return m_pImpl->GetFrameFormat();
}
sal_Int32 SwXTableRows::getCount()
{
SolarMutexGuard aGuard;
SwFrameFormat* pFrameFormat = GetFrameFormat();
if(!pFrameFormat)
throw uno::RuntimeException();
SwTable* pTable = SwTable::FindTable(pFrameFormat);
return pTable->GetTabLines().size();
}
///@see SwXCell::CreateXCell (TODO: seems to be copy and paste programming here)
uno::Any SwXTableRows::getByIndex(sal_Int32 nIndex)
{
SolarMutexGuard aGuard;
SwFrameFormat* pFrameFormat(lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this)));
if(nIndex < 0)
throw lang::IndexOutOfBoundsException();
SwTable* pTable = SwTable::FindTable( pFrameFormat );
if(o3tl::make_unsigned(nIndex) >= pTable->GetTabLines().size())
throw lang::IndexOutOfBoundsException();
SwTableLine* pLine = pTable->GetTabLines()[nIndex];
FindUnoInstanceHint<SwTableLine,SwXTextTableRow> aHint{pLine};
pFrameFormat->GetNotifier().Broadcast(aHint);
if(!aHint.m_pResult)
aHint.m_pResult = new SwXTextTableRow(pFrameFormat, pLine);
uno::Reference<beans::XPropertySet> xRet = static_cast<beans::XPropertySet*>(aHint.m_pResult);
return uno::makeAny(xRet);
}
uno::Type SAL_CALL SwXTableRows::getElementType()
{
return cppu::UnoType<beans::XPropertySet>::get();
}
sal_Bool SwXTableRows::hasElements()
{
SolarMutexGuard aGuard;
SwFrameFormat* pFrameFormat = GetFrameFormat();
if(!pFrameFormat)
throw uno::RuntimeException();
// a table always has rows
return true;
}
void SwXTableRows::insertByIndex(sal_Int32 nIndex, sal_Int32 nCount)
{
SolarMutexGuard aGuard;
if (nCount == 0)
return;
SwFrameFormat* pFrameFormat(lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this)));
SwTable* pTable = lcl_EnsureTableNotComplex(SwTable::FindTable(pFrameFormat), static_cast<cppu::OWeakObject*>(this));
const size_t nRowCount = pTable->GetTabLines().size();
if (nCount <= 0 || 0 > nIndex || o3tl::make_unsigned(nIndex) > nRowCount)
throw uno::RuntimeException("Illegal arguments", static_cast<cppu::OWeakObject*>(this));
const OUString sTLName = sw_GetCellName(0, nIndex);
const SwTableBox* pTLBox = pTable->GetTableBox(sTLName);
bool bAppend = false;
if(!pTLBox)
{
bAppend = true;
// to append at the end the cursor must be in the last line
SwTableLines& rLines = pTable->GetTabLines();
SwTableLine* pLine = rLines.back();
SwTableBoxes& rBoxes = pLine->GetTabBoxes();
pTLBox = rBoxes.front();
}
if(!pTLBox)
throw uno::RuntimeException("Illegal arguments", static_cast<cppu::OWeakObject*>(this));
const SwStartNode* pSttNd = pTLBox->GetSttNd();
SwPosition aPos(*pSttNd);
// set cursor to the upper-left cell of the range
UnoActionContext aAction(pFrameFormat->GetDoc());
std::shared_ptr<SwUnoTableCursor> const pUnoCursor(
std::dynamic_pointer_cast<SwUnoTableCursor>(
pFrameFormat->GetDoc()->CreateUnoCursor(aPos, true)));
pUnoCursor->Move( fnMoveForward, GoInNode );
{
// remove actions - TODO: why?
UnoActionRemoveContext aRemoveContext(pUnoCursor->GetDoc());
}
pFrameFormat->GetDoc()->InsertRow(*pUnoCursor, static_cast<sal_uInt16>(nCount), bAppend);
}
void SwXTableRows::removeByIndex(sal_Int32 nIndex, sal_Int32 nCount)
{
SolarMutexGuard aGuard;
if (nCount == 0)
return;
SwFrameFormat* pFrameFormat(lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this)));
if(nIndex < 0 || nCount <=0 )
throw uno::RuntimeException();
SwTable* pTable = lcl_EnsureTableNotComplex(SwTable::FindTable(pFrameFormat), static_cast<cppu::OWeakObject*>(this));
OUString sTLName = sw_GetCellName(0, nIndex);
const SwTableBox* pTLBox = pTable->GetTableBox(sTLName);
if(!pTLBox)
throw uno::RuntimeException("Illegal arguments", static_cast<cppu::OWeakObject*>(this));
const SwStartNode* pSttNd = pTLBox->GetSttNd();
SwPosition aPos(*pSttNd);
// set cursor to the upper-left cell of the range
auto pUnoCursor(pFrameFormat->GetDoc()->CreateUnoCursor(aPos, true));
pUnoCursor->Move(fnMoveForward, GoInNode);
pUnoCursor->SetRemainInSection( false );
const OUString sBLName = sw_GetCellName(0, nIndex + nCount - 1);
const SwTableBox* pBLBox = pTable->GetTableBox( sBLName );
if(!pBLBox)
throw uno::RuntimeException("Illegal arguments", static_cast<cppu::OWeakObject*>(this));
pUnoCursor->SetMark();
pUnoCursor->GetPoint()->nNode = *pBLBox->GetSttNd();
pUnoCursor->Move(fnMoveForward, GoInNode);
SwUnoTableCursor& rCursor = dynamic_cast<SwUnoTableCursor&>(*pUnoCursor);
{
// HACK: remove pending actions for selecting old style tables
UnoActionRemoveContext aRemoveContext(rCursor);
}
rCursor.MakeBoxSels();
{ // these braces are important
UnoActionContext aAction(pFrameFormat->GetDoc());
pFrameFormat->GetDoc()->DeleteRow(*pUnoCursor);
pUnoCursor.reset();
}
{
// invalidate all actions - TODO: why?
UnoActionRemoveContext aRemoveContext(pFrameFormat->GetDoc());
}
}
void SwXTableRows::Impl::Notify( const SfxHint& rHint)
{
if(rHint.GetId() == SfxHintId::Dying)
m_pFrameFormat = nullptr;
}
// SwXTableColumns
class SwXTableColumns::Impl : public SvtListener
{
SwFrameFormat* m_pFrameFormat;
public:
explicit Impl(SwFrameFormat& rFrameFormat) : m_pFrameFormat(&rFrameFormat)
{
StartListening(rFrameFormat.GetNotifier());
}
SwFrameFormat* GetFrameFormat() { return m_pFrameFormat; }
virtual void Notify(const SfxHint&) override;
};
OUString SwXTableColumns::getImplementationName()
{ return "SwXTableColumns"; }
sal_Bool SwXTableColumns::supportsService(const OUString& rServiceName)
{ return cppu::supportsService(this, rServiceName); }
uno::Sequence< OUString > SwXTableColumns::getSupportedServiceNames()
{ return { "com.sun.star.text.TableColumns"}; }
SwXTableColumns::SwXTableColumns(SwFrameFormat& rFrameFormat) :
m_pImpl(new SwXTableColumns::Impl(rFrameFormat))
{ }
SwXTableColumns::~SwXTableColumns()
{ }
SwFrameFormat* SwXTableColumns::GetFrameFormat() const
{
return m_pImpl->GetFrameFormat();
}
sal_Int32 SwXTableColumns::getCount()
{
SolarMutexGuard aGuard;
SwFrameFormat* pFrameFormat(lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this)));
SwTable* pTable = SwTable::FindTable( pFrameFormat );
// if(!pTable->IsTableComplex())
// throw uno::RuntimeException("Table too complex", static_cast<cppu::OWeakObject*>(this));
SwTableLines& rLines = pTable->GetTabLines();
SwTableLine* pLine = rLines.front();
return pLine->GetTabBoxes().size();
}
uno::Any SwXTableColumns::getByIndex(sal_Int32 nIndex)
{
SolarMutexGuard aGuard;
if(nIndex < 0 || getCount() <= nIndex)
throw lang::IndexOutOfBoundsException();
return uno::makeAny(uno::Reference<uno::XInterface>()); // i#21699 not supported
}
uno::Type SAL_CALL SwXTableColumns::getElementType()
{
return cppu::UnoType<uno::XInterface>::get();
}
sal_Bool SwXTableColumns::hasElements()
{
SolarMutexGuard aGuard;
lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this));
return true;
}
///@see SwXTableRows::insertByIndex (TODO: seems to be copy and paste programming here)
void SwXTableColumns::insertByIndex(sal_Int32 nIndex, sal_Int32 nCount)
{
SolarMutexGuard aGuard;
if (nCount == 0)
return;
SwFrameFormat* pFrameFormat(lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this)));
SwTable* pTable = lcl_EnsureTableNotComplex(SwTable::FindTable(pFrameFormat), static_cast<cppu::OWeakObject*>(this));
SwTableLines& rLines = pTable->GetTabLines();
SwTableLine* pLine = rLines.front();
const size_t nColCount = pLine->GetTabBoxes().size();
if (nCount <= 0 || 0 > nIndex || o3tl::make_unsigned(nIndex) > nColCount)
throw uno::RuntimeException("Illegal arguments", static_cast<cppu::OWeakObject*>(this));
const OUString sTLName = sw_GetCellName(nIndex, 0);
const SwTableBox* pTLBox = pTable->GetTableBox( sTLName );
bool bAppend = false;
if(!pTLBox)
{
bAppend = true;
// to append at the end the cursor must be in the last line
SwTableBoxes& rBoxes = pLine->GetTabBoxes();
pTLBox = rBoxes.back();
}
if(!pTLBox)
throw uno::RuntimeException("Illegal arguments", static_cast<cppu::OWeakObject*>(this));
const SwStartNode* pSttNd = pTLBox->GetSttNd();
SwPosition aPos(*pSttNd);
UnoActionContext aAction(pFrameFormat->GetDoc());
auto pUnoCursor(pFrameFormat->GetDoc()->CreateUnoCursor(aPos, true));
pUnoCursor->Move(fnMoveForward, GoInNode);
{
// remove actions - TODO: why?
UnoActionRemoveContext aRemoveContext(pUnoCursor->GetDoc());
}
pFrameFormat->GetDoc()->InsertCol(*pUnoCursor, static_cast<sal_uInt16>(nCount), bAppend);
}
///@see SwXTableRows::removeByIndex (TODO: seems to be copy and paste programming here)
void SwXTableColumns::removeByIndex(sal_Int32 nIndex, sal_Int32 nCount)
{
SolarMutexGuard aGuard;
if (nCount == 0)
return;
SwFrameFormat* pFrameFormat(lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this)));
if(nIndex < 0 || nCount <=0 )
throw uno::RuntimeException();
SwTable* pTable = lcl_EnsureTableNotComplex(SwTable::FindTable(pFrameFormat), static_cast<cppu::OWeakObject*>(this));
const OUString sTLName = sw_GetCellName(nIndex, 0);
const SwTableBox* pTLBox = pTable->GetTableBox( sTLName );
if(!pTLBox)
throw uno::RuntimeException("Cell not found", static_cast<cppu::OWeakObject*>(this));
const SwStartNode* pSttNd = pTLBox->GetSttNd();
SwPosition aPos(*pSttNd);
// set cursor to the upper-left cell of the range
auto pUnoCursor(pFrameFormat->GetDoc()->CreateUnoCursor(aPos, true));
pUnoCursor->Move(fnMoveForward, GoInNode);
pUnoCursor->SetRemainInSection(false);
const OUString sTRName = sw_GetCellName(nIndex + nCount - 1, 0);
const SwTableBox* pTRBox = pTable->GetTableBox(sTRName);
if(!pTRBox)
throw uno::RuntimeException("Cell not found", static_cast<cppu::OWeakObject*>(this));
pUnoCursor->SetMark();
pUnoCursor->GetPoint()->nNode = *pTRBox->GetSttNd();
pUnoCursor->Move(fnMoveForward, GoInNode);
SwUnoTableCursor& rCursor = dynamic_cast<SwUnoTableCursor&>(*pUnoCursor);
{
// HACK: remove pending actions for selecting old style tables
UnoActionRemoveContext aRemoveContext(rCursor);
}
rCursor.MakeBoxSels();
{ // these braces are important
UnoActionContext aAction(pFrameFormat->GetDoc());
pFrameFormat->GetDoc()->DeleteCol(*pUnoCursor);
pUnoCursor.reset();
}
{
// invalidate all actions - TODO: why?
UnoActionRemoveContext aRemoveContext(pFrameFormat->GetDoc());
}
}
void SwXTableColumns::Impl::Notify(const SfxHint& rHint)
{
if(rHint.GetId() == SfxHintId::Dying)
m_pFrameFormat = nullptr;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|