1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413 | /* -*- 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 <xiescher.hxx>
#include <com/sun/star/beans/NamedValue.hpp>
#include <com/sun/star/container/XIndexContainer.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <com/sun/star/embed/Aspects.hpp>
#include <com/sun/star/embed/XEmbeddedObject.hpp>
#include <com/sun/star/embed/XEmbedPersist.hpp>
#include <com/sun/star/awt/PushButtonType.hpp>
#include <com/sun/star/awt/ScrollBarOrientation.hpp>
#include <com/sun/star/awt/VisualEffect.hpp>
#include <com/sun/star/style/VerticalAlignment.hpp>
#include <com/sun/star/drawing/XControlShape.hpp>
#include <com/sun/star/form/XForm.hpp>
#include <com/sun/star/form/XFormsSupplier.hpp>
#include <com/sun/star/form/binding/XBindableValue.hpp>
#include <com/sun/star/form/binding/XValueBinding.hpp>
#include <com/sun/star/form/binding/XListEntrySink.hpp>
#include <com/sun/star/form/binding/XListEntrySource.hpp>
#include <com/sun/star/script/ScriptEventDescriptor.hpp>
#include <com/sun/star/script/XEventAttacherManager.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <sfx2/objsh.hxx>
#include <unotools/moduleoptions.hxx>
#include <unotools/fltrcfg.hxx>
#include <vcl/dibtools.hxx>
#include <vcl/gdimtf.hxx>
#include <vcl/window.hxx>
#include <vcl/wmf.hxx>
#include <comphelper/classids.hxx>
#include <comphelper/documentinfo.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <basegfx/point/b2dpoint.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <sal/log.hxx>
#include <svx/svdopath.hxx>
#include <svx/svdocirc.hxx>
#include <svx/svdoedge.hxx>
#include <svx/svdogrp.hxx>
#include <svx/svdoashp.hxx>
#include <svx/svdograf.hxx>
#include <svx/svdoole2.hxx>
#include <svx/svdouno.hxx>
#include <svx/svdpage.hxx>
#include <editeng/editobj.hxx>
#include <editeng/outliner.hxx>
#include <editeng/outlobj.hxx>
#include <svx/svditer.hxx>
#include <editeng/writingmodeitem.hxx>
#include <svx/xlnclit.hxx>
#include <svx/xlndsit.hxx>
#include <svx/xlnedcit.hxx>
#include <svx/xlnedit.hxx>
#include <svx/xlnedwit.hxx>
#include <svx/xlnstcit.hxx>
#include <svx/xlnstit.hxx>
#include <svx/xlnstwit.hxx>
#include <svx/xlnwtit.hxx>
#include <svx/sdasitm.hxx>
#include <svx/sdshcitm.hxx>
#include <svx/sdshitm.hxx>
#include <svx/sdsxyitm.hxx>
#include <svx/sdtagitm.hxx>
#include <svx/sdtditm.hxx>
#include <editeng/eeitem.hxx>
#include <svx/xflclit.hxx>
#include <sal/macros.h>
#include <editeng/adjustitem.hxx>
#include <svx/xfillit0.hxx>
#include <svx/xlineit0.hxx>
#include <svx/xlinjoit.hxx>
#include <svx/xlntrit.hxx>
#include <svx/xbtmpit.hxx>
#include <svx/xbitmap.hxx>
#include <svtools/embedhlp.hxx>
#include <sot/storage.hxx>
#include <document.hxx>
#include <drwlayer.hxx>
#include <userdat.hxx>
#include <unonames.hxx>
#include <convuno.hxx>
#include <postit.hxx>
#include <globstr.hrc>
#include <scresid.hxx>
#include <fprogressbar.hxx>
#include <xltracer.hxx>
#include <xistream.hxx>
#include <xihelper.hxx>
#include <xiformula.hxx>
#include <xilink.hxx>
#include <xistyle.hxx>
#include <xipage.hxx>
#include <xichart.hxx>
#include <xicontent.hxx>
#include <scextopt.hxx>
#include <namebuff.hxx>
#include <sfx2/docfile.hxx>
#include <memory>
#include <numeric>
#include <utility>
using namespace com::sun::star;
using ::com::sun::star::uno::makeAny;
using ::com::sun::star::uno::Any;
using ::com::sun::star::beans::XPropertySet;
using ::com::sun::star::uno::makeAny;
using ::com::sun::star::uno::Exception;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::Sequence;
using ::com::sun::star::uno::UNO_QUERY;
using ::com::sun::star::uno::UNO_QUERY_THROW;
using ::com::sun::star::uno::UNO_SET_THROW;
using ::com::sun::star::beans::NamedValue;
using ::com::sun::star::lang::XMultiServiceFactory;
using ::com::sun::star::container::XIndexContainer;
using ::com::sun::star::container::XNameContainer;
using ::com::sun::star::frame::XModel;
using ::com::sun::star::awt::XControlModel;
using ::com::sun::star::embed::XEmbeddedObject;
using ::com::sun::star::embed::XEmbedPersist;
using ::com::sun::star::drawing::XControlShape;
using ::com::sun::star::drawing::XShape;
using ::com::sun::star::form::XFormComponent;
using ::com::sun::star::form::XFormsSupplier;
using ::com::sun::star::form::binding::XBindableValue;
using ::com::sun::star::form::binding::XValueBinding;
using ::com::sun::star::form::binding::XListEntrySink;
using ::com::sun::star::form::binding::XListEntrySource;
using ::com::sun::star::script::ScriptEventDescriptor;
using ::com::sun::star::script::XEventAttacherManager;
using ::com::sun::star::table::CellAddress;
using ::com::sun::star::table::CellRangeAddress;
// Drawing objects ============================================================
XclImpDrawObjBase::XclImpDrawObjBase( const XclImpRoot& rRoot ) :
XclImpRoot( rRoot ),
mnObjId( EXC_OBJ_INVALID_ID ),
mnTab( 0 ),
mnObjType( EXC_OBJTYPE_UNKNOWN ),
mnDffShapeId( 0 ),
mnDffFlags( ShapeFlag::NONE ),
mbHasAnchor( false ),
mbHidden( false ),
mbVisible( true ),
mbPrintable( true ),
mbAreaObj( false ),
mbAutoMargin( true ),
mbSimpleMacro( true ),
mbProcessSdr( true ),
mbInsertSdr( true ),
mbCustomDff( false ),
mbNotifyMacroEventRead( false )
{
}
XclImpDrawObjBase::~XclImpDrawObjBase()
{
}
XclImpDrawObjRef XclImpDrawObjBase::ReadObj3( const XclImpRoot& rRoot, XclImpStream& rStrm )
{
XclImpDrawObjRef xDrawObj;
if( rStrm.GetRecLeft() >= 30 )
{
sal_uInt16 nObjType;
rStrm.Ignore( 4 );
nObjType = rStrm.ReaduInt16();
switch( nObjType )
{
case EXC_OBJTYPE_GROUP: xDrawObj= std::make_shared<XclImpGroupObj>( rRoot ); break;
case EXC_OBJTYPE_LINE: xDrawObj= std::make_shared<XclImpLineObj>( rRoot ); break;
case EXC_OBJTYPE_RECTANGLE: xDrawObj= std::make_shared<XclImpRectObj>( rRoot ); break;
case EXC_OBJTYPE_OVAL: xDrawObj= std::make_shared<XclImpOvalObj>( rRoot ); break;
case EXC_OBJTYPE_ARC: xDrawObj= std::make_shared<XclImpArcObj>( rRoot ); break;
case EXC_OBJTYPE_CHART: xDrawObj= std::make_shared<XclImpChartObj>( rRoot ); break;
case EXC_OBJTYPE_TEXT: xDrawObj= std::make_shared<XclImpTextObj>( rRoot ); break;
case EXC_OBJTYPE_BUTTON: xDrawObj= std::make_shared<XclImpButtonObj>( rRoot ); break;
case EXC_OBJTYPE_PICTURE: xDrawObj= std::make_shared<XclImpPictureObj>( rRoot ); break;
default:
SAL_WARN("sc.filter", "XclImpDrawObjBase::ReadObj3 - unknown object type 0x" << std::hex << nObjType );
rRoot.GetTracer().TraceUnsupportedObjects();
}
}
if (!xDrawObj)
{
xDrawObj = std::make_shared<XclImpPhObj>(rRoot);
}
xDrawObj->mnTab = rRoot.GetCurrScTab();
xDrawObj->ImplReadObj3( rStrm );
return xDrawObj;
}
XclImpDrawObjRef XclImpDrawObjBase::ReadObj4( const XclImpRoot& rRoot, XclImpStream& rStrm )
{
XclImpDrawObjRef xDrawObj;
if( rStrm.GetRecLeft() >= 30 )
{
sal_uInt16 nObjType;
rStrm.Ignore( 4 );
nObjType = rStrm.ReaduInt16();
switch( nObjType )
{
case EXC_OBJTYPE_GROUP: xDrawObj = std::make_shared<XclImpGroupObj>( rRoot ); break;
case EXC_OBJTYPE_LINE: xDrawObj = std::make_shared<XclImpLineObj>( rRoot ); break;
case EXC_OBJTYPE_RECTANGLE: xDrawObj = std::make_shared<XclImpRectObj>( rRoot ); break;
case EXC_OBJTYPE_OVAL: xDrawObj = std::make_shared<XclImpOvalObj>( rRoot ); break;
case EXC_OBJTYPE_ARC: xDrawObj = std::make_shared<XclImpArcObj>( rRoot ); break;
case EXC_OBJTYPE_CHART: xDrawObj = std::make_shared<XclImpChartObj>( rRoot ); break;
case EXC_OBJTYPE_TEXT: xDrawObj = std::make_shared<XclImpTextObj>( rRoot ); break;
case EXC_OBJTYPE_BUTTON: xDrawObj = std::make_shared<XclImpButtonObj>( rRoot ); break;
case EXC_OBJTYPE_PICTURE: xDrawObj = std::make_shared<XclImpPictureObj>( rRoot ); break;
case EXC_OBJTYPE_POLYGON: xDrawObj = std::make_shared<XclImpPolygonObj>( rRoot ); break;
default:
SAL_WARN("sc.filter", "XclImpDrawObjBase::ReadObj4 - unknown object type 0x" << std::hex << nObjType );
rRoot.GetTracer().TraceUnsupportedObjects();
}
}
if (!xDrawObj)
{
xDrawObj = std::make_shared<XclImpPhObj>(rRoot);
}
xDrawObj->mnTab = rRoot.GetCurrScTab();
xDrawObj->ImplReadObj4( rStrm );
return xDrawObj;
}
XclImpDrawObjRef XclImpDrawObjBase::ReadObj5( const XclImpRoot& rRoot, XclImpStream& rStrm )
{
XclImpDrawObjRef xDrawObj;
if( rStrm.GetRecLeft() >= 34 )
{
sal_uInt16 nObjType(EXC_OBJTYPE_UNKNOWN);
rStrm.Ignore( 4 );
nObjType = rStrm.ReaduInt16();
switch( nObjType )
{
case EXC_OBJTYPE_GROUP: xDrawObj = std::make_shared<XclImpGroupObj>( rRoot ); break;
case EXC_OBJTYPE_LINE: xDrawObj = std::make_shared<XclImpLineObj>( rRoot ); break;
case EXC_OBJTYPE_RECTANGLE: xDrawObj = std::make_shared<XclImpRectObj>( rRoot ); break;
case EXC_OBJTYPE_OVAL: xDrawObj = std::make_shared<XclImpOvalObj>( rRoot ); break;
case EXC_OBJTYPE_ARC: xDrawObj = std::make_shared<XclImpArcObj>( rRoot ); break;
case EXC_OBJTYPE_CHART: xDrawObj = std::make_shared<XclImpChartObj>( rRoot ); break;
case EXC_OBJTYPE_TEXT: xDrawObj = std::make_shared<XclImpTextObj>( rRoot ); break;
case EXC_OBJTYPE_BUTTON: xDrawObj = std::make_shared<XclImpButtonObj>( rRoot ); break;
case EXC_OBJTYPE_PICTURE: xDrawObj = std::make_shared<XclImpPictureObj>( rRoot ); break;
case EXC_OBJTYPE_POLYGON: xDrawObj = std::make_shared<XclImpPolygonObj>( rRoot ); break;
case EXC_OBJTYPE_CHECKBOX: xDrawObj = std::make_shared<XclImpCheckBoxObj>( rRoot ); break;
case EXC_OBJTYPE_OPTIONBUTTON: xDrawObj = std::make_shared<XclImpOptionButtonObj>( rRoot ); break;
case EXC_OBJTYPE_EDIT: xDrawObj = std::make_shared<XclImpEditObj>( rRoot ); break;
case EXC_OBJTYPE_LABEL: xDrawObj = std::make_shared<XclImpLabelObj>( rRoot ); break;
case EXC_OBJTYPE_DIALOG: xDrawObj = std::make_shared<XclImpDialogObj>( rRoot ); break;
case EXC_OBJTYPE_SPIN: xDrawObj = std::make_shared<XclImpSpinButtonObj>( rRoot ); break;
case EXC_OBJTYPE_SCROLLBAR: xDrawObj = std::make_shared<XclImpScrollBarObj>( rRoot ); break;
case EXC_OBJTYPE_LISTBOX: xDrawObj = std::make_shared<XclImpListBoxObj>( rRoot ); break;
case EXC_OBJTYPE_GROUPBOX: xDrawObj = std::make_shared<XclImpGroupBoxObj>( rRoot ); break;
case EXC_OBJTYPE_DROPDOWN: xDrawObj = std::make_shared<XclImpDropDownObj>( rRoot ); break;
default:
SAL_WARN("sc.filter", "XclImpDrawObjBase::ReadObj5 - unknown object type 0x" << std::hex << nObjType );
rRoot.GetTracer().TraceUnsupportedObjects();
xDrawObj = std::make_shared<XclImpPhObj>( rRoot );
}
}
OSL_ENSURE(xDrawObj, "object import failed");
if (xDrawObj)
{
xDrawObj->mnTab = rRoot.GetCurrScTab();
xDrawObj->ImplReadObj5( rStrm );
}
return xDrawObj;
}
XclImpDrawObjRef XclImpDrawObjBase::ReadObj8( const XclImpRoot& rRoot, XclImpStream& rStrm )
{
XclImpDrawObjRef xDrawObj;
if( rStrm.GetRecLeft() >= 10 )
{
sal_uInt16 nSubRecId(0), nSubRecSize(0), nObjType(0);
nSubRecId = rStrm.ReaduInt16();
nSubRecSize = rStrm.ReaduInt16();
nObjType = rStrm.ReaduInt16();
OSL_ENSURE( nSubRecId == EXC_ID_OBJCMO, "XclImpDrawObjBase::ReadObj8 - OBJCMO subrecord expected" );
if( (nSubRecId == EXC_ID_OBJCMO) && (nSubRecSize >= 6) )
{
switch( nObjType )
{
// in BIFF8, all simple objects support text
case EXC_OBJTYPE_LINE:
case EXC_OBJTYPE_ARC:
xDrawObj = std::make_shared<XclImpTextObj>( rRoot );
// lines and arcs may be 2-dimensional
xDrawObj->SetAreaObj( false );
break;
// in BIFF8, all simple objects support text
case EXC_OBJTYPE_RECTANGLE:
case EXC_OBJTYPE_OVAL:
case EXC_OBJTYPE_POLYGON:
case EXC_OBJTYPE_DRAWING:
case EXC_OBJTYPE_TEXT:
xDrawObj = std::make_shared<XclImpTextObj>( rRoot );
break;
case EXC_OBJTYPE_GROUP: xDrawObj = std::make_shared<XclImpGroupObj>( rRoot ); break;
case EXC_OBJTYPE_CHART: xDrawObj = std::make_shared<XclImpChartObj>( rRoot ); break;
case EXC_OBJTYPE_BUTTON: xDrawObj = std::make_shared<XclImpButtonObj>( rRoot ); break;
case EXC_OBJTYPE_PICTURE: xDrawObj = std::make_shared<XclImpPictureObj>( rRoot ); break;
case EXC_OBJTYPE_CHECKBOX: xDrawObj = std::make_shared<XclImpCheckBoxObj>( rRoot ); break;
case EXC_OBJTYPE_OPTIONBUTTON: xDrawObj = std::make_shared<XclImpOptionButtonObj>( rRoot ); break;
case EXC_OBJTYPE_EDIT: xDrawObj = std::make_shared<XclImpEditObj>( rRoot ); break;
case EXC_OBJTYPE_LABEL: xDrawObj = std::make_shared<XclImpLabelObj>( rRoot ); break;
case EXC_OBJTYPE_DIALOG: xDrawObj = std::make_shared<XclImpDialogObj>( rRoot ); break;
case EXC_OBJTYPE_SPIN: xDrawObj = std::make_shared<XclImpSpinButtonObj>( rRoot ); break;
case EXC_OBJTYPE_SCROLLBAR: xDrawObj = std::make_shared<XclImpScrollBarObj>( rRoot ); break;
case EXC_OBJTYPE_LISTBOX: xDrawObj = std::make_shared<XclImpListBoxObj>( rRoot ); break;
case EXC_OBJTYPE_GROUPBOX: xDrawObj = std::make_shared<XclImpGroupBoxObj>( rRoot ); break;
case EXC_OBJTYPE_DROPDOWN: xDrawObj = std::make_shared<XclImpDropDownObj>( rRoot ); break;
case EXC_OBJTYPE_NOTE: xDrawObj = std::make_shared<XclImpNoteObj>( rRoot ); break;
default:
SAL_WARN("sc.filter", "XclImpDrawObjBase::ReadObj8 - unknown object type 0x" << std::hex << nObjType );
rRoot.GetTracer().TraceUnsupportedObjects();
}
}
}
if (!xDrawObj) //ensure placeholder for unknown or broken records
{
SAL_WARN( "sc.filter", "XclImpDrawObjBase::ReadObj8 import failed, substituting placeholder");
xDrawObj = std::make_shared<XclImpPhObj>( rRoot );
}
xDrawObj->mnTab = rRoot.GetCurrScTab();
xDrawObj->ImplReadObj8( rStrm );
return xDrawObj;
}
void XclImpDrawObjBase::SetAnchor( const XclObjAnchor& rAnchor )
{
maAnchor = rAnchor;
mbHasAnchor = true;
}
void XclImpDrawObjBase::SetDffData(
const DffObjData& rDffObjData, const OUString& rObjName, const OUString& rHyperlink,
bool bVisible, bool bAutoMargin )
{
mnDffShapeId = rDffObjData.nShapeId;
mnDffFlags = rDffObjData.nSpFlags;
maObjName = rObjName;
maHyperlink = rHyperlink;
mbVisible = bVisible;
mbAutoMargin = bAutoMargin;
}
OUString XclImpDrawObjBase::GetObjName() const
{
/* #i51348# Always return a non-empty name. Create English
default names depending on the object type. This is not implemented as
virtual functions in derived classes, as class type and object type may
not match. */
return maObjName.isEmpty() ? GetObjectManager().GetDefaultObjName(*this) : maObjName;
}
const XclObjAnchor* XclImpDrawObjBase::GetAnchor() const
{
return mbHasAnchor ? &maAnchor : nullptr;
}
bool XclImpDrawObjBase::IsValidSize( const tools::Rectangle& rAnchorRect ) const
{
// XclObjAnchor rounds up the width, width of 3 is the result of an Excel width of 0
return mbAreaObj ?
((rAnchorRect.GetWidth() > 3) && (rAnchorRect.GetHeight() > 1)) :
((rAnchorRect.GetWidth() > 3) || (rAnchorRect.GetHeight() > 1));
}
ScRange XclImpDrawObjBase::GetUsedArea( SCTAB nScTab ) const
{
ScRange aScUsedArea( ScAddress::INITIALIZE_INVALID );
// #i44077# object inserted -> update used area for OLE object import
if( mbHasAnchor && GetAddressConverter().ConvertRange( aScUsedArea, maAnchor, nScTab, nScTab, false ) )
{
// reduce range, if object ends directly on borders between two columns or rows
if( (maAnchor.mnRX == 0) && (aScUsedArea.aStart.Col() < aScUsedArea.aEnd.Col()) )
aScUsedArea.aEnd.IncCol( -1 );
if( (maAnchor.mnBY == 0) && (aScUsedArea.aStart.Row() < aScUsedArea.aEnd.Row()) )
aScUsedArea.aEnd.IncRow( -1 );
}
return aScUsedArea;
}
std::size_t XclImpDrawObjBase::GetProgressSize() const
{
return DoGetProgressSize();
}
SdrObjectUniquePtr XclImpDrawObjBase::CreateSdrObject( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect, bool bIsDff ) const
{
SdrObjectUniquePtr xSdrObj;
if( bIsDff && !mbCustomDff )
{
rDffConv.Progress( GetProgressSize() );
}
else
{
xSdrObj = DoCreateSdrObj( rDffConv, rAnchorRect );
//added for exporting OCX control
/* mnObjType value set should be as below table:
0x0000 Group 0x0001 Line
0x0002 Rectangle 0x0003 Oval
0x0004 Arc 0x0005 Chart
0x0006 Text 0x0009 Polygon
+-----------------------------------------------------+
OCX ==>| 0x0008 Picture |
+-----------------------------------------------------+
| 0x0007 Button |
| 0x000B Checkbox 0x000C Radio button |
| 0x000D Edit box 0x000E Label |
TBX ==> | 0x000F Dialog box 0x0010 Spin control |
| 0x0011 Scrollbar 0x0012 List |
| 0x0013 Group box 0x0014 Dropdown list |
+-----------------------------------------------------+
0x0019 Note 0x001E OfficeArt object
*/
if( xSdrObj && xSdrObj->IsUnoObj() &&
( (mnObjType < 25 && mnObjType > 10) || mnObjType == 7 || mnObjType == 8 ) )
{
SdrUnoObj* pSdrUnoObj = dynamic_cast< SdrUnoObj* >( xSdrObj.get() );
if( pSdrUnoObj != nullptr )
{
const Reference< XControlModel >& xCtrlModel = pSdrUnoObj->GetUnoControlModel();
Reference< XPropertySet > xPropSet(xCtrlModel,UNO_QUERY);
const static OUString sPropertyName("ControlTypeinMSO");
enum { eCreateFromOffice = 0, eCreateFromMSTBXControl, eCreateFromMSOCXControl };
if( mnObjType == 7 || (mnObjType < 25 && mnObjType > 10) )//TBX
{
//Need summary type for export. Detail type(checkbox, button ...) has been contained by mnObjType
const sal_Int16 nTBXControlType = eCreateFromMSTBXControl ;
try
{
xPropSet->setPropertyValue(sPropertyName, Any(nTBXControlType));
}
catch(const Exception&)
{
SAL_WARN("sc.filter", "XclImpDrawObjBase::CreateSdrObject, this control can't be set the property ControlTypeinMSO!");
}
}
if( mnObjType == 8 )//OCX
{
//Need summary type for export
const static OUString sObjIdPropertyName("ObjIDinMSO");
const XclImpPictureObj* const pObj = dynamic_cast< const XclImpPictureObj* const >(this);
if( pObj != nullptr && pObj->IsOcxControl() )
{
const sal_Int16 nOCXControlType = eCreateFromMSOCXControl;
try
{
xPropSet->setPropertyValue(sPropertyName, Any(nOCXControlType));
//Detail type(checkbox, button ...)
xPropSet->setPropertyValue(sObjIdPropertyName, makeAny<sal_uInt16>(mnObjId));
}
catch(const Exception&)
{
SAL_WARN("sc.filter", "XclImpDrawObjBase::CreateSdrObject, this control can't be set the property ObjIDinMSO!");
}
}
}
}
}
}
return xSdrObj;
}
void XclImpDrawObjBase::NotifyMacroEventRead()
{
if (mbNotifyMacroEventRead)
return;
SfxObjectShell* pDocShell = GetDocShell();
if (!pDocShell)
return;
comphelper::DocumentInfo::notifyMacroEventRead(pDocShell->GetModel());
mbNotifyMacroEventRead = true;
}
void XclImpDrawObjBase::PreProcessSdrObject( XclImpDffConverter& rDffConv, SdrObject& rSdrObj )
{
// default: front layer, derived classes may have to set other layer in DoPreProcessSdrObj()
rSdrObj.NbcSetLayer( SC_LAYER_FRONT );
// set object name (GetObjName() will always return a non-empty name)
rSdrObj.SetName( GetObjName() );
// #i39167# full width for all objects regardless of horizontal alignment
rSdrObj.SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
// automatic text margin
if( mbAutoMargin )
{
sal_Int32 nMargin = rDffConv.GetDefaultTextMargin();
rSdrObj.SetMergedItem( makeSdrTextLeftDistItem( nMargin ) );
rSdrObj.SetMergedItem( makeSdrTextRightDistItem( nMargin ) );
rSdrObj.SetMergedItem( makeSdrTextUpperDistItem( nMargin ) );
rSdrObj.SetMergedItem( makeSdrTextLowerDistItem( nMargin ) );
}
// macro and hyperlink
// removed oracle/sun check for mbSimpleMacro ( no idea what its for )
if (!maMacroName.isEmpty() || !maHyperlink.isEmpty())
{
if( ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( &rSdrObj, true ) )
{
OUString sMacro = XclTools::GetSbMacroUrl(maMacroName, GetDocShell());
if (!sMacro.isEmpty())
NotifyMacroEventRead();
pInfo->SetMacro(sMacro);
pInfo->SetHlink( maHyperlink );
}
}
// call virtual function for object type specific processing
DoPreProcessSdrObj( rDffConv, rSdrObj );
}
void XclImpDrawObjBase::PostProcessSdrObject( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const
{
// call virtual function for object type specific processing
DoPostProcessSdrObj( rDffConv, rSdrObj );
}
// protected ------------------------------------------------------------------
void XclImpDrawObjBase::ReadName5( XclImpStream& rStrm, sal_uInt16 nNameLen )
{
maObjName.clear();
if( nNameLen > 0 )
{
// name length field is repeated before the name
maObjName = rStrm.ReadByteString( false );
// skip padding byte for word boundaries
if( rStrm.GetRecPos() & 1 ) rStrm.Ignore( 1 );
}
}
void XclImpDrawObjBase::ReadMacro3( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
maMacroName.clear();
rStrm.Ignore( nMacroSize );
// skip padding byte for word boundaries, not contained in nMacroSize
if( rStrm.GetRecPos() & 1 ) rStrm.Ignore( 1 );
}
void XclImpDrawObjBase::ReadMacro4( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
maMacroName.clear();
rStrm.Ignore( nMacroSize );
}
void XclImpDrawObjBase::ReadMacro5( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
maMacroName.clear();
rStrm.Ignore( nMacroSize );
}
void XclImpDrawObjBase::ReadMacro8( XclImpStream& rStrm )
{
maMacroName.clear();
if( rStrm.GetRecLeft() > 6 )
{
// macro is stored in a tNameXR token containing a link to a defined name
sal_uInt16 nFmlaSize;
nFmlaSize = rStrm.ReaduInt16();
rStrm.Ignore( 4 );
OSL_ENSURE( nFmlaSize == 7, "XclImpDrawObjBase::ReadMacro - unexpected formula size" );
if( nFmlaSize == 7 )
{
sal_uInt8 nTokenId;
sal_uInt16 nExtSheet, nExtName;
nTokenId = rStrm.ReaduInt8();
nExtSheet = rStrm.ReaduInt16();
nExtName = rStrm.ReaduInt16();
OSL_ENSURE( nTokenId == XclTokenArrayHelper::GetTokenId( EXC_TOKID_NAMEX, EXC_TOKCLASS_REF ),
"XclImpDrawObjBase::ReadMacro - tNameXR token expected" );
if( nTokenId == XclTokenArrayHelper::GetTokenId( EXC_TOKID_NAMEX, EXC_TOKCLASS_REF ) )
maMacroName = GetLinkManager().GetMacroName( nExtSheet, nExtName );
}
}
}
void XclImpDrawObjBase::ConvertLineStyle( SdrObject& rSdrObj, const XclObjLineData& rLineData ) const
{
if( rLineData.IsAuto() )
{
XclObjLineData aAutoData;
aAutoData.mnAuto = 0;
ConvertLineStyle( rSdrObj, aAutoData );
}
else
{
long nLineWidth = 35 * ::std::min( rLineData.mnWidth, EXC_OBJ_LINE_THICK );
rSdrObj.SetMergedItem( XLineWidthItem( nLineWidth ) );
rSdrObj.SetMergedItem( XLineColorItem( EMPTY_OUSTRING, GetPalette().GetColor( rLineData.mnColorIdx ) ) );
rSdrObj.SetMergedItem( XLineJointItem( css::drawing::LineJoint_MITER ) );
sal_uLong nDotLen = ::std::max< sal_uLong >( 70 * rLineData.mnWidth, 35 );
sal_uLong nDashLen = 3 * nDotLen;
sal_uLong nDist = 2 * nDotLen;
switch( rLineData.mnStyle )
{
default:
case EXC_OBJ_LINE_SOLID:
rSdrObj.SetMergedItem( XLineStyleItem( drawing::LineStyle_SOLID ) );
break;
case EXC_OBJ_LINE_DASH:
rSdrObj.SetMergedItem( XLineStyleItem( drawing::LineStyle_DASH ) );
rSdrObj.SetMergedItem( XLineDashItem( EMPTY_OUSTRING, XDash( css::drawing::DashStyle_RECT, 0, nDotLen, 1, nDashLen, nDist ) ) );
break;
case EXC_OBJ_LINE_DOT:
rSdrObj.SetMergedItem( XLineStyleItem( drawing::LineStyle_DASH ) );
rSdrObj.SetMergedItem( XLineDashItem( EMPTY_OUSTRING, XDash( css::drawing::DashStyle_RECT, 1, nDotLen, 0, nDashLen, nDist ) ) );
break;
case EXC_OBJ_LINE_DASHDOT:
rSdrObj.SetMergedItem( XLineStyleItem( drawing::LineStyle_DASH ) );
rSdrObj.SetMergedItem( XLineDashItem( EMPTY_OUSTRING, XDash( css::drawing::DashStyle_RECT, 1, nDotLen, 1, nDashLen, nDist ) ) );
break;
case EXC_OBJ_LINE_DASHDOTDOT:
rSdrObj.SetMergedItem( XLineStyleItem( drawing::LineStyle_DASH ) );
rSdrObj.SetMergedItem( XLineDashItem( EMPTY_OUSTRING, XDash( css::drawing::DashStyle_RECT, 2, nDotLen, 1, nDashLen, nDist ) ) );
break;
case EXC_OBJ_LINE_MEDTRANS:
rSdrObj.SetMergedItem( XLineStyleItem( drawing::LineStyle_SOLID ) );
rSdrObj.SetMergedItem( XLineTransparenceItem( 50 ) );
break;
case EXC_OBJ_LINE_DARKTRANS:
rSdrObj.SetMergedItem( XLineStyleItem( drawing::LineStyle_SOLID ) );
rSdrObj.SetMergedItem( XLineTransparenceItem( 25 ) );
break;
case EXC_OBJ_LINE_LIGHTTRANS:
rSdrObj.SetMergedItem( XLineStyleItem( drawing::LineStyle_SOLID ) );
rSdrObj.SetMergedItem( XLineTransparenceItem( 75 ) );
break;
case EXC_OBJ_LINE_NONE:
rSdrObj.SetMergedItem( XLineStyleItem( drawing::LineStyle_NONE ) );
break;
}
}
}
void XclImpDrawObjBase::ConvertFillStyle( SdrObject& rSdrObj, const XclObjFillData& rFillData ) const
{
if( rFillData.IsAuto() )
{
XclObjFillData aAutoData;
aAutoData.mnAuto = 0;
ConvertFillStyle( rSdrObj, aAutoData );
}
else if( rFillData.mnPattern == EXC_PATT_NONE )
{
rSdrObj.SetMergedItem( XFillStyleItem( drawing::FillStyle_NONE ) );
}
else
{
Color aPattColor = GetPalette().GetColor( rFillData.mnPattColorIdx );
Color aBackColor = GetPalette().GetColor( rFillData.mnBackColorIdx );
if( (rFillData.mnPattern == EXC_PATT_SOLID) || (aPattColor == aBackColor) )
{
rSdrObj.SetMergedItem( XFillStyleItem( drawing::FillStyle_SOLID ) );
rSdrObj.SetMergedItem( XFillColorItem( EMPTY_OUSTRING, aPattColor ) );
}
else
{
static const sal_uInt8 sppnPatterns[][ 8 ] =
{
{ 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55 },
{ 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD, 0x77, 0xDD },
{ 0x88, 0x22, 0x88, 0x22, 0x88, 0x22, 0x88, 0x22 },
{ 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00 },
{ 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC },
{ 0x33, 0x66, 0xCC, 0x99, 0x33, 0x66, 0xCC, 0x99 },
{ 0xCC, 0x66, 0x33, 0x99, 0xCC, 0x66, 0x33, 0x99 },
{ 0xCC, 0xCC, 0x33, 0x33, 0xCC, 0xCC, 0x33, 0x33 },
{ 0xCC, 0xFF, 0x33, 0xFF, 0xCC, 0xFF, 0x33, 0xFF },
{ 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00 },
{ 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88 },
{ 0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88 },
{ 0x88, 0x44, 0x22, 0x11, 0x88, 0x44, 0x22, 0x11 },
{ 0xFF, 0x11, 0x11, 0x11, 0xFF, 0x11, 0x11, 0x11 },
{ 0xAA, 0x44, 0xAA, 0x11, 0xAA, 0x44, 0xAA, 0x11 },
{ 0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00 },
{ 0x80, 0x00, 0x08, 0x00, 0x80, 0x00, 0x08, 0x00 }
};
const sal_uInt8* const pnPattern = sppnPatterns[std::min<size_t>(rFillData.mnPattern - 2, SAL_N_ELEMENTS(sppnPatterns) - 1)];
// create 2-colored 8x8 DIB
SvMemoryStream aMemStrm;
aMemStrm.WriteUInt32( 12 ).WriteInt16( 8 ).WriteInt16( 8 ).WriteUInt16( 1 ).WriteUInt16( 1 );
aMemStrm.WriteUChar( 0xFF ).WriteUChar( 0xFF ).WriteUChar( 0xFF );
aMemStrm.WriteUChar( 0x00 ).WriteUChar( 0x00 ).WriteUChar( 0x00 );
for( size_t nIdx = 0; nIdx < 8; ++nIdx )
aMemStrm.WriteUInt32( pnPattern[ nIdx ] ); // 32-bit little-endian
aMemStrm.Seek( STREAM_SEEK_TO_BEGIN );
Bitmap aBitmap;
ReadDIB(aBitmap, aMemStrm, false);
XOBitmap aXOBitmap(( BitmapEx(aBitmap) ));
aXOBitmap.Bitmap2Array();
if( aXOBitmap.GetBackgroundColor() == COL_BLACK )
::std::swap( aPattColor, aBackColor );
aXOBitmap.SetPixelColor( aPattColor );
aXOBitmap.SetBackgroundColor( aBackColor );
aXOBitmap.Array2Bitmap();
aBitmap = aXOBitmap.GetBitmap().GetBitmap();
rSdrObj.SetMergedItem(XFillStyleItem(drawing::FillStyle_BITMAP));
rSdrObj.SetMergedItem(XFillBitmapItem(EMPTY_OUSTRING, Graphic(aBitmap)));
}
}
}
void XclImpDrawObjBase::ConvertFrameStyle( SdrObject& rSdrObj, sal_uInt16 nFrameFlags ) const
{
if( ::get_flag( nFrameFlags, EXC_OBJ_FRAME_SHADOW ) )
{
rSdrObj.SetMergedItem( makeSdrShadowItem( true ) );
rSdrObj.SetMergedItem( makeSdrShadowXDistItem( 35 ) );
rSdrObj.SetMergedItem( makeSdrShadowYDistItem( 35 ) );
rSdrObj.SetMergedItem( makeSdrShadowColorItem( GetPalette().GetColor( EXC_COLOR_WINDOWTEXT ) ) );
}
}
Color XclImpDrawObjBase::GetSolidLineColor( const XclObjLineData& rLineData ) const
{
Color aColor( COL_TRANSPARENT );
if( rLineData.IsAuto() )
{
XclObjLineData aAutoData;
aAutoData.mnAuto = 0;
aColor = GetSolidLineColor( aAutoData );
}
else if( rLineData.mnStyle != EXC_OBJ_LINE_NONE )
{
aColor = GetPalette().GetColor( rLineData.mnColorIdx );
}
return aColor;
}
Color XclImpDrawObjBase::GetSolidFillColor( const XclObjFillData& rFillData ) const
{
Color aColor( COL_TRANSPARENT );
if( rFillData.IsAuto() )
{
XclObjFillData aAutoData;
aAutoData.mnAuto = 0;
aColor = GetSolidFillColor( aAutoData );
}
else if( rFillData.mnPattern != EXC_PATT_NONE )
{
Color aPattColor = GetPalette().GetColor( rFillData.mnPattColorIdx );
Color aBackColor = GetPalette().GetColor( rFillData.mnBackColorIdx );
aColor = XclTools::GetPatternColor( aPattColor, aBackColor, rFillData.mnPattern );
}
return aColor;
}
void XclImpDrawObjBase::DoReadObj3( XclImpStream&, sal_uInt16 )
{
}
void XclImpDrawObjBase::DoReadObj4( XclImpStream&, sal_uInt16 )
{
}
void XclImpDrawObjBase::DoReadObj5( XclImpStream&, sal_uInt16, sal_uInt16 )
{
}
void XclImpDrawObjBase::DoReadObj8SubRec( XclImpStream&, sal_uInt16, sal_uInt16 )
{
}
std::size_t XclImpDrawObjBase::DoGetProgressSize() const
{
return 1;
}
SdrObjectUniquePtr XclImpDrawObjBase::DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& ) const
{
rDffConv.Progress( GetProgressSize() );
return nullptr;
}
void XclImpDrawObjBase::DoPreProcessSdrObj( XclImpDffConverter&, SdrObject& ) const
{
// trace if object is not printable
if( !IsPrintable() )
GetTracer().TraceObjectNotPrintable();
}
void XclImpDrawObjBase::DoPostProcessSdrObj( XclImpDffConverter&, SdrObject& ) const
{
}
void XclImpDrawObjBase::ImplReadObj3( XclImpStream& rStrm )
{
// back to offset 4 (ignore object count field)
rStrm.Seek( 4 );
sal_uInt16 nObjFlags, nMacroSize;
mnObjType = rStrm.ReaduInt16();
mnObjId = rStrm.ReaduInt16();
nObjFlags = rStrm.ReaduInt16();
rStrm >> maAnchor;
nMacroSize = rStrm.ReaduInt16();
rStrm.Ignore( 2 );
mbHasAnchor = true;
mbHidden = ::get_flag( nObjFlags, EXC_OBJ_HIDDEN );
mbVisible = ::get_flag( nObjFlags, EXC_OBJ_VISIBLE );
DoReadObj3( rStrm, nMacroSize );
}
void XclImpDrawObjBase::ImplReadObj4( XclImpStream& rStrm )
{
// back to offset 4 (ignore object count field)
rStrm.Seek( 4 );
sal_uInt16 nObjFlags, nMacroSize;
mnObjType = rStrm.ReaduInt16();
mnObjId = rStrm.ReaduInt16();
nObjFlags = rStrm.ReaduInt16();
rStrm >> maAnchor;
nMacroSize = rStrm.ReaduInt16();
rStrm.Ignore( 2 );
mbHasAnchor = true;
mbHidden = ::get_flag( nObjFlags, EXC_OBJ_HIDDEN );
mbVisible = ::get_flag( nObjFlags, EXC_OBJ_VISIBLE );
mbPrintable = ::get_flag( nObjFlags, EXC_OBJ_PRINTABLE );
DoReadObj4( rStrm, nMacroSize );
}
void XclImpDrawObjBase::ImplReadObj5( XclImpStream& rStrm )
{
// back to offset 4 (ignore object count field)
rStrm.Seek( 4 );
sal_uInt16 nObjFlags, nMacroSize, nNameLen;
mnObjType = rStrm.ReaduInt16();
mnObjId = rStrm.ReaduInt16();
nObjFlags = rStrm.ReaduInt16();
rStrm >> maAnchor;
nMacroSize = rStrm.ReaduInt16();
rStrm.Ignore( 2 );
nNameLen = rStrm.ReaduInt16();
rStrm.Ignore( 2 );
mbHasAnchor = true;
mbHidden = ::get_flag( nObjFlags, EXC_OBJ_HIDDEN );
mbVisible = ::get_flag( nObjFlags, EXC_OBJ_VISIBLE );
mbPrintable = ::get_flag( nObjFlags, EXC_OBJ_PRINTABLE );
DoReadObj5( rStrm, nNameLen, nMacroSize );
}
void XclImpDrawObjBase::ImplReadObj8( XclImpStream& rStrm )
{
// back to beginning
rStrm.Seek( EXC_REC_SEEK_TO_BEGIN );
bool bLoop = true;
while( bLoop && (rStrm.GetRecLeft() >= 4) )
{
sal_uInt16 nSubRecId, nSubRecSize;
nSubRecId = rStrm.ReaduInt16();
nSubRecSize = rStrm.ReaduInt16();
rStrm.PushPosition();
// sometimes the last subrecord has an invalid length (OBJLBSDATA) -> min()
nSubRecSize = static_cast< sal_uInt16 >( ::std::min< std::size_t >( nSubRecSize, rStrm.GetRecLeft() ) );
switch( nSubRecId )
{
case EXC_ID_OBJCMO:
OSL_ENSURE( rStrm.GetRecPos() == 4, "XclImpDrawObjBase::ImplReadObj8 - unexpected OBJCMO subrecord" );
if( (rStrm.GetRecPos() == 4) && (nSubRecSize >= 6) )
{
sal_uInt16 nObjFlags;
mnObjType = rStrm.ReaduInt16();
mnObjId = rStrm.ReaduInt16( );
nObjFlags = rStrm.ReaduInt16( );
mbPrintable = ::get_flag( nObjFlags, EXC_OBJCMO_PRINTABLE );
}
break;
case EXC_ID_OBJMACRO:
ReadMacro8( rStrm );
break;
case EXC_ID_OBJEND:
bLoop = false;
break;
default:
DoReadObj8SubRec( rStrm, nSubRecId, nSubRecSize );
}
rStrm.PopPosition();
rStrm.Ignore( nSubRecSize );
}
/* Call DoReadObj8SubRec() with EXC_ID_OBJEND for further stream
processing (e.g. charts), even if the OBJEND subrecord is missing. */
DoReadObj8SubRec( rStrm, EXC_ID_OBJEND, 0 );
/* Pictures that Excel reads from BIFF5 and writes to BIFF8 still have the
IMGDATA record following the OBJ record (but they use the image data
stored in DFF). The IMGDATA record may be continued by several CONTINUE
records. But the last CONTINUE record may be in fact an MSODRAWING
record that contains the DFF data of the next drawing object! So we
have to skip just enough CONTINUE records to look at the next
MSODRAWING/CONTINUE record. */
if( (rStrm.GetNextRecId() == EXC_ID3_IMGDATA) && rStrm.StartNextRecord() )
{
sal_uInt32 nDataSize;
rStrm.Ignore( 4 );
nDataSize = rStrm.ReaduInt32();
nDataSize -= rStrm.GetRecLeft();
// skip following CONTINUE records until IMGDATA ends
while( (nDataSize > 0) && (rStrm.GetNextRecId() == EXC_ID_CONT) && rStrm.StartNextRecord() )
{
OSL_ENSURE( nDataSize >= rStrm.GetRecLeft(), "XclImpDrawObjBase::ImplReadObj8 - CONTINUE too long" );
nDataSize -= ::std::min< sal_uInt32 >( rStrm.GetRecLeft(), nDataSize );
}
OSL_ENSURE( nDataSize == 0, "XclImpDrawObjBase::ImplReadObj8 - missing CONTINUE records" );
// next record may be MSODRAWING or CONTINUE or anything else
}
}
void XclImpDrawObjVector::InsertGrouped( XclImpDrawObjRef const & xDrawObj )
{
if( !mObjs.empty() )
if( XclImpGroupObj* pGroupObj = dynamic_cast< XclImpGroupObj* >( mObjs.back().get() ) )
if( pGroupObj->TryInsert( xDrawObj ) )
return;
mObjs.push_back( xDrawObj );
}
std::size_t XclImpDrawObjVector::GetProgressSize() const
{
return std::accumulate(mObjs.begin(), mObjs.end(), std::size_t(0),
[](const std::size_t& rSum, const XclImpDrawObjRef& rxObj) { return rSum + rxObj->GetProgressSize(); });
}
XclImpPhObj::XclImpPhObj( const XclImpRoot& rRoot ) :
XclImpDrawObjBase( rRoot )
{
SetProcessSdrObj( false );
}
XclImpGroupObj::XclImpGroupObj( const XclImpRoot& rRoot ) :
XclImpDrawObjBase( rRoot ),
mnFirstUngrouped( 0 )
{
}
bool XclImpGroupObj::TryInsert( XclImpDrawObjRef const & xDrawObj )
{
if( xDrawObj->GetObjId() == mnFirstUngrouped )
return false;
// insert into own list or into nested group
maChildren.InsertGrouped( xDrawObj );
return true;
}
void XclImpGroupObj::DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
rStrm.Ignore( 4 );
mnFirstUngrouped = rStrm.ReaduInt16();
rStrm.Ignore( 16 );
ReadMacro3( rStrm, nMacroSize );
}
void XclImpGroupObj::DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
rStrm.Ignore( 4 );
mnFirstUngrouped = rStrm.ReaduInt16();
rStrm.Ignore( 16 );
ReadMacro4( rStrm, nMacroSize );
}
void XclImpGroupObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize )
{
rStrm.Ignore( 4 );
mnFirstUngrouped = rStrm.ReaduInt16();
rStrm.Ignore( 16 );
ReadName5( rStrm, nNameLen );
ReadMacro5( rStrm, nMacroSize );
}
std::size_t XclImpGroupObj::DoGetProgressSize() const
{
return XclImpDrawObjBase::DoGetProgressSize() + maChildren.GetProgressSize();
}
SdrObjectUniquePtr XclImpGroupObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& /*rAnchorRect*/ ) const
{
std::unique_ptr<SdrObjGroup, SdrObjectFreeOp> xSdrObj(
new SdrObjGroup(
*GetDoc().GetDrawLayer()));
// child objects in BIFF2-BIFF5 have absolute size, not needed to pass own anchor rectangle
SdrObjList& rObjList = *xSdrObj->GetSubList(); // SdrObjGroup always returns existing sublist
for( const auto& rxChild : maChildren )
rDffConv.ProcessObject( rObjList, *rxChild );
rDffConv.Progress();
return xSdrObj;
}
XclImpLineObj::XclImpLineObj( const XclImpRoot& rRoot ) :
XclImpDrawObjBase( rRoot ),
mnArrows( 0 ),
mnStartPoint( EXC_OBJ_LINE_TL )
{
SetAreaObj( false );
}
void XclImpLineObj::DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
rStrm >> maLineData;
mnArrows = rStrm.ReaduInt16();
mnStartPoint = rStrm.ReaduInt8();
rStrm.Ignore( 1 );
ReadMacro3( rStrm, nMacroSize );
}
void XclImpLineObj::DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
rStrm >> maLineData;
mnArrows = rStrm.ReaduInt16();
mnStartPoint = rStrm.ReaduInt8();
rStrm.Ignore( 1 );
ReadMacro4( rStrm, nMacroSize );
}
void XclImpLineObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize )
{
rStrm >> maLineData;
mnArrows = rStrm.ReaduInt16();
mnStartPoint = rStrm.ReaduInt8();
rStrm.Ignore( 1 );
ReadName5( rStrm, nNameLen );
ReadMacro5( rStrm, nMacroSize );
}
SdrObjectUniquePtr XclImpLineObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const
{
::basegfx::B2DPolygon aB2DPolygon;
switch( mnStartPoint )
{
default:
case EXC_OBJ_LINE_TL:
aB2DPolygon.append( ::basegfx::B2DPoint( rAnchorRect.Left(), rAnchorRect.Top() ) );
aB2DPolygon.append( ::basegfx::B2DPoint( rAnchorRect.Right(), rAnchorRect.Bottom() ) );
break;
case EXC_OBJ_LINE_TR:
aB2DPolygon.append( ::basegfx::B2DPoint( rAnchorRect.Right(), rAnchorRect.Top() ) );
aB2DPolygon.append( ::basegfx::B2DPoint( rAnchorRect.Left(), rAnchorRect.Bottom() ) );
break;
case EXC_OBJ_LINE_BR:
aB2DPolygon.append( ::basegfx::B2DPoint( rAnchorRect.Right(), rAnchorRect.Bottom() ) );
aB2DPolygon.append( ::basegfx::B2DPoint( rAnchorRect.Left(), rAnchorRect.Top() ) );
break;
case EXC_OBJ_LINE_BL:
aB2DPolygon.append( ::basegfx::B2DPoint( rAnchorRect.Left(), rAnchorRect.Bottom() ) );
aB2DPolygon.append( ::basegfx::B2DPoint( rAnchorRect.Right(), rAnchorRect.Top() ) );
break;
}
SdrObjectUniquePtr xSdrObj(
new SdrPathObj(
*GetDoc().GetDrawLayer(),
OBJ_LINE,
::basegfx::B2DPolyPolygon(aB2DPolygon)));
ConvertLineStyle( *xSdrObj, maLineData );
// line ends
sal_uInt8 nArrowType = ::extract_value< sal_uInt8 >( mnArrows, 0, 4 );
bool bLineStart = false;
bool bLineEnd = false;
bool bFilled = false;
switch( nArrowType )
{
case EXC_OBJ_ARROW_OPEN: bLineStart = false; bLineEnd = true; bFilled = false; break;
case EXC_OBJ_ARROW_OPENBOTH: bLineStart = true; bLineEnd = true; bFilled = false; break;
case EXC_OBJ_ARROW_FILLED: bLineStart = false; bLineEnd = true; bFilled = true; break;
case EXC_OBJ_ARROW_FILLEDBOTH: bLineStart = true; bLineEnd = true; bFilled = true; break;
}
if( bLineStart || bLineEnd )
{
sal_uInt8 nArrowWidth = ::extract_value< sal_uInt8 >( mnArrows, 4, 4 );
double fArrowWidth = 3.0;
switch( nArrowWidth )
{
case EXC_OBJ_ARROW_NARROW: fArrowWidth = 2.0; break;
case EXC_OBJ_ARROW_MEDIUM: fArrowWidth = 3.0; break;
case EXC_OBJ_ARROW_WIDE: fArrowWidth = 5.0; break;
}
sal_uInt8 nArrowLength = ::extract_value< sal_uInt8 >( mnArrows, 8, 4 );
double fArrowLength = 3.0;
switch( nArrowLength )
{
case EXC_OBJ_ARROW_NARROW: fArrowLength = 2.5; break;
case EXC_OBJ_ARROW_MEDIUM: fArrowLength = 3.5; break;
case EXC_OBJ_ARROW_WIDE: fArrowLength = 6.0; break;
}
::basegfx::B2DPolygon aArrowPoly;
#define EXC_ARROW_POINT( x, y ) ::basegfx::B2DPoint( fArrowWidth * (x), fArrowLength * (y) )
if( bFilled )
{
aArrowPoly.append( EXC_ARROW_POINT( 0, 100 ) );
aArrowPoly.append( EXC_ARROW_POINT( 50, 0 ) );
aArrowPoly.append( EXC_ARROW_POINT( 100, 100 ) );
}
else
{
sal_uInt8 nLineWidth = ::limit_cast< sal_uInt8 >( maLineData.mnWidth, EXC_OBJ_LINE_THIN, EXC_OBJ_LINE_THICK );
aArrowPoly.append( EXC_ARROW_POINT( 50, 0 ) );
aArrowPoly.append( EXC_ARROW_POINT( 100, 100 - 3 * nLineWidth ) );
aArrowPoly.append( EXC_ARROW_POINT( 100 - 5 * nLineWidth, 100 ) );
aArrowPoly.append( EXC_ARROW_POINT( 50, 12 * nLineWidth ) );
aArrowPoly.append( EXC_ARROW_POINT( 5 * nLineWidth, 100 ) );
aArrowPoly.append( EXC_ARROW_POINT( 0, 100 - 3 * nLineWidth ) );
}
#undef EXC_ARROW_POINT
::basegfx::B2DPolyPolygon aArrowPolyPoly( aArrowPoly );
long nWidth = static_cast< long >( 125 * fArrowWidth );
if( bLineStart )
{
xSdrObj->SetMergedItem( XLineStartItem( EMPTY_OUSTRING, aArrowPolyPoly ) );
xSdrObj->SetMergedItem( XLineStartWidthItem( nWidth ) );
xSdrObj->SetMergedItem( XLineStartCenterItem( false ) );
}
if( bLineEnd )
{
xSdrObj->SetMergedItem( XLineEndItem( EMPTY_OUSTRING, aArrowPolyPoly ) );
xSdrObj->SetMergedItem( XLineEndWidthItem( nWidth ) );
xSdrObj->SetMergedItem( XLineEndCenterItem( false ) );
}
}
rDffConv.Progress();
return xSdrObj;
}
XclImpRectObj::XclImpRectObj( const XclImpRoot& rRoot ) :
XclImpDrawObjBase( rRoot ),
mnFrameFlags( 0 )
{
SetAreaObj( true );
}
void XclImpRectObj::ReadFrameData( XclImpStream& rStrm )
{
rStrm >> maFillData >> maLineData;
mnFrameFlags = rStrm.ReaduInt16();
}
void XclImpRectObj::ConvertRectStyle( SdrObject& rSdrObj ) const
{
ConvertLineStyle( rSdrObj, maLineData );
ConvertFillStyle( rSdrObj, maFillData );
ConvertFrameStyle( rSdrObj, mnFrameFlags );
}
void XclImpRectObj::DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
ReadFrameData( rStrm );
ReadMacro3( rStrm, nMacroSize );
}
void XclImpRectObj::DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
ReadFrameData( rStrm );
ReadMacro4( rStrm, nMacroSize );
}
void XclImpRectObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize )
{
ReadFrameData( rStrm );
ReadName5( rStrm, nNameLen );
ReadMacro5( rStrm, nMacroSize );
}
SdrObjectUniquePtr XclImpRectObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const
{
SdrObjectUniquePtr xSdrObj(
new SdrRectObj(
*GetDoc().GetDrawLayer(),
rAnchorRect));
ConvertRectStyle( *xSdrObj );
rDffConv.Progress();
return xSdrObj;
}
XclImpOvalObj::XclImpOvalObj( const XclImpRoot& rRoot ) :
XclImpRectObj( rRoot )
{
}
SdrObjectUniquePtr XclImpOvalObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const
{
SdrObjectUniquePtr xSdrObj(
new SdrCircObj(
*GetDoc().GetDrawLayer(),
SdrCircKind::Full,
rAnchorRect));
ConvertRectStyle( *xSdrObj );
rDffConv.Progress();
return xSdrObj;
}
XclImpArcObj::XclImpArcObj( const XclImpRoot& rRoot ) :
XclImpDrawObjBase( rRoot ),
mnQuadrant( EXC_OBJ_ARC_TR )
{
SetAreaObj( false ); // arc may be 2-dimensional
}
void XclImpArcObj::DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
rStrm >> maFillData >> maLineData;
mnQuadrant = rStrm.ReaduInt8();
rStrm.Ignore( 1 );
ReadMacro3( rStrm, nMacroSize );
}
void XclImpArcObj::DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
rStrm >> maFillData >> maLineData;
mnQuadrant = rStrm.ReaduInt8();
rStrm.Ignore( 1 );
ReadMacro4( rStrm, nMacroSize );
}
void XclImpArcObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize )
{
rStrm >> maFillData >> maLineData;
mnQuadrant = rStrm.ReaduInt8();
rStrm.Ignore( 1 );
ReadName5( rStrm, nNameLen );
ReadMacro5( rStrm, nMacroSize );
}
SdrObjectUniquePtr XclImpArcObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const
{
tools::Rectangle aNewRect = rAnchorRect;
long nStartAngle = 0;
long nEndAngle = 0;
switch( mnQuadrant )
{
default:
case EXC_OBJ_ARC_TR:
nStartAngle = 0;
nEndAngle = 9000;
aNewRect.AdjustLeft( -(rAnchorRect.GetWidth()) );
aNewRect.AdjustBottom(rAnchorRect.GetHeight() );
break;
case EXC_OBJ_ARC_TL:
nStartAngle = 9000;
nEndAngle = 18000;
aNewRect.AdjustRight(rAnchorRect.GetWidth() );
aNewRect.AdjustBottom(rAnchorRect.GetHeight() );
break;
case EXC_OBJ_ARC_BL:
nStartAngle = 18000;
nEndAngle = 27000;
aNewRect.AdjustRight(rAnchorRect.GetWidth() );
aNewRect.AdjustTop( -(rAnchorRect.GetHeight()) );
break;
case EXC_OBJ_ARC_BR:
nStartAngle = 27000;
nEndAngle = 0;
aNewRect.AdjustLeft( -(rAnchorRect.GetWidth()) );
aNewRect.AdjustTop( -(rAnchorRect.GetHeight()) );
break;
}
SdrCircKind eObjKind = maFillData.IsFilled() ? SdrCircKind::Section : SdrCircKind::Arc;
SdrObjectUniquePtr xSdrObj(
new SdrCircObj(
*GetDoc().GetDrawLayer(),
eObjKind,
aNewRect,
nStartAngle,
nEndAngle));
ConvertFillStyle( *xSdrObj, maFillData );
ConvertLineStyle( *xSdrObj, maLineData );
rDffConv.Progress();
return xSdrObj;
}
XclImpPolygonObj::XclImpPolygonObj( const XclImpRoot& rRoot ) :
XclImpRectObj( rRoot ),
mnPolyFlags( 0 ),
mnPointCount( 0 )
{
SetAreaObj( false ); // polygon may be 2-dimensional
}
void XclImpPolygonObj::ReadCoordList( XclImpStream& rStrm )
{
if( (rStrm.GetNextRecId() == EXC_ID_COORDLIST) && rStrm.StartNextRecord() )
{
OSL_ENSURE( rStrm.GetRecLeft() / 4 == mnPointCount, "XclImpPolygonObj::ReadCoordList - wrong polygon point count" );
while( rStrm.GetRecLeft() >= 4 )
{
sal_uInt16 nX, nY;
nX = rStrm.ReaduInt16();
nY = rStrm.ReaduInt16();
maCoords.emplace_back( nX, nY );
}
}
}
void XclImpPolygonObj::DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
ReadFrameData( rStrm );
mnPolyFlags = rStrm.ReaduInt16();
rStrm.Ignore( 10 );
mnPointCount = rStrm.ReaduInt16();
rStrm.Ignore( 8 );
ReadMacro4( rStrm, nMacroSize );
ReadCoordList( rStrm );
}
void XclImpPolygonObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize )
{
ReadFrameData( rStrm );
mnPolyFlags = rStrm.ReaduInt16();
rStrm.Ignore( 10 );
mnPointCount = rStrm.ReaduInt16();
rStrm.Ignore( 8 );
ReadName5( rStrm, nNameLen );
ReadMacro5( rStrm, nMacroSize );
ReadCoordList( rStrm );
}
namespace {
::basegfx::B2DPoint lclGetPolyPoint( const tools::Rectangle& rAnchorRect, const Point& rPoint )
{
return ::basegfx::B2DPoint(
rAnchorRect.Left() + static_cast< sal_Int32 >( ::std::min< double >( rPoint.X(), 16384.0 ) / 16384.0 * rAnchorRect.GetWidth() + 0.5 ),
rAnchorRect.Top() + static_cast< sal_Int32 >( ::std::min< double >( rPoint.Y(), 16384.0 ) / 16384.0 * rAnchorRect.GetHeight() + 0.5 ) );
}
} // namespace
SdrObjectUniquePtr XclImpPolygonObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const
{
SdrObjectUniquePtr xSdrObj;
if( maCoords.size() >= 2 )
{
// create the polygon
::basegfx::B2DPolygon aB2DPolygon;
for( const auto& rCoord : maCoords )
aB2DPolygon.append( lclGetPolyPoint( rAnchorRect, rCoord ) );
// close polygon if specified
if( ::get_flag( mnPolyFlags, EXC_OBJ_POLY_CLOSED ) && (maCoords.front() != maCoords.back()) )
aB2DPolygon.append( lclGetPolyPoint( rAnchorRect, maCoords.front() ) );
// create the SdrObject
SdrObjKind eObjKind = maFillData.IsFilled() ? OBJ_PATHPOLY : OBJ_PATHPLIN;
xSdrObj.reset(
new SdrPathObj(
*GetDoc().GetDrawLayer(),
eObjKind,
::basegfx::B2DPolyPolygon(aB2DPolygon)));
ConvertRectStyle( *xSdrObj );
}
rDffConv.Progress();
return xSdrObj;
}
void XclImpObjTextData::ReadByteString( XclImpStream& rStrm )
{
mxString.reset();
if( maData.mnTextLen > 0 )
{
mxString = std::make_shared<XclImpString>( rStrm.ReadRawByteString( maData.mnTextLen ) );
// skip padding byte for word boundaries
if( rStrm.GetRecPos() & 1 ) rStrm.Ignore( 1 );
}
}
void XclImpObjTextData::ReadFormats( XclImpStream& rStrm )
{
if( mxString )
mxString->ReadObjFormats( rStrm, maData.mnFormatSize );
else
rStrm.Ignore( maData.mnFormatSize );
}
XclImpTextObj::XclImpTextObj( const XclImpRoot& rRoot ) :
XclImpRectObj( rRoot )
{
}
void XclImpTextObj::DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
ReadFrameData( rStrm );
maTextData.maData.ReadObj3( rStrm );
ReadMacro3( rStrm, nMacroSize );
maTextData.ReadByteString( rStrm );
maTextData.ReadFormats( rStrm );
}
void XclImpTextObj::DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
ReadFrameData( rStrm );
maTextData.maData.ReadObj3( rStrm );
ReadMacro4( rStrm, nMacroSize );
maTextData.ReadByteString( rStrm );
maTextData.ReadFormats( rStrm );
}
void XclImpTextObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize )
{
ReadFrameData( rStrm );
maTextData.maData.ReadObj5( rStrm );
ReadName5( rStrm, nNameLen );
ReadMacro5( rStrm, nMacroSize );
maTextData.ReadByteString( rStrm );
rStrm.Ignore( maTextData.maData.mnLinkSize ); // ignore text link formula
maTextData.ReadFormats( rStrm );
}
SdrObjectUniquePtr XclImpTextObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const
{
std::unique_ptr<SdrObjCustomShape, SdrObjectFreeOp> xSdrObj(
new SdrObjCustomShape(
*GetDoc().GetDrawLayer()));
xSdrObj->NbcSetSnapRect( rAnchorRect );
OUString aRectType = "rectangle";
xSdrObj->MergeDefaultAttributes( &aRectType );
ConvertRectStyle( *xSdrObj );
bool bAutoSize = ::get_flag( maTextData.maData.mnFlags, EXC_OBJ_TEXT_AUTOSIZE );
xSdrObj->SetMergedItem( makeSdrTextAutoGrowWidthItem( bAutoSize ) );
xSdrObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( bAutoSize ) );
xSdrObj->SetMergedItem( makeSdrTextWordWrapItem( true ) );
rDffConv.Progress();
return xSdrObj;
}
void XclImpTextObj::DoPreProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const
{
// set text data
if( SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( &rSdrObj ) )
{
if( maTextData.mxString )
{
if( maTextData.mxString->IsRich() )
{
// rich text
std::unique_ptr< EditTextObject > xEditObj(
XclImpStringHelper::CreateTextObject( GetRoot(), *maTextData.mxString ) );
std::unique_ptr<OutlinerParaObject> pOutlineObj(new OutlinerParaObject( *xEditObj ));
pOutlineObj->SetOutlinerMode( OutlinerMode::TextObject );
pTextObj->NbcSetOutlinerParaObject( std::move(pOutlineObj) );
}
else
{
// plain text
pTextObj->NbcSetText( maTextData.mxString->GetText() );
}
/* #i96858# Do not apply any formatting if there is no text.
SdrObjCustomShape::SetVerticalWriting (initiated from
SetMergedItem) calls SdrTextObj::ForceOutlinerParaObject which
ensures that we can erroneously write a ClientTextbox record
(with no content) while exporting to XLS, which can cause a
corrupted exported document. */
SvxAdjust eHorAlign = SvxAdjust::Left;
SdrTextVertAdjust eVerAlign = SDRTEXTVERTADJUST_TOP;
// orientation (this is only a fake, drawing does not support real text orientation)
namespace csst = ::com::sun::star::text;
csst::WritingMode eWriteMode = csst::WritingMode_LR_TB;
switch( maTextData.maData.mnOrient )
{
default:
case EXC_OBJ_ORIENT_NONE:
{
eWriteMode = csst::WritingMode_LR_TB;
switch( maTextData.maData.GetHorAlign() )
{
case EXC_OBJ_HOR_LEFT: eHorAlign = SvxAdjust::Left; break;
case EXC_OBJ_HOR_CENTER: eHorAlign = SvxAdjust::Center; break;
case EXC_OBJ_HOR_RIGHT: eHorAlign = SvxAdjust::Right; break;
case EXC_OBJ_HOR_JUSTIFY: eHorAlign = SvxAdjust::Block; break;
}
switch( maTextData.maData.GetVerAlign() )
{
case EXC_OBJ_VER_TOP: eVerAlign = SDRTEXTVERTADJUST_TOP; break;
case EXC_OBJ_VER_CENTER: eVerAlign = SDRTEXTVERTADJUST_CENTER; break;
case EXC_OBJ_VER_BOTTOM: eVerAlign = SDRTEXTVERTADJUST_BOTTOM; break;
case EXC_OBJ_VER_JUSTIFY: eVerAlign = SDRTEXTVERTADJUST_BLOCK; break;
}
}
break;
case EXC_OBJ_ORIENT_90CCW:
{
if( SdrObjCustomShape* pObjCustomShape = dynamic_cast< SdrObjCustomShape* >( &rSdrObj ) )
{
css::beans::PropertyValue aTextRotateAngle;
aTextRotateAngle.Name = "TextRotateAngle";
aTextRotateAngle.Value <<= 180.0;
SdrCustomShapeGeometryItem aGeometryItem(pObjCustomShape->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ));
aGeometryItem.SetPropertyValue( aTextRotateAngle );
pObjCustomShape->SetMergedItem( aGeometryItem );
}
eWriteMode = csst::WritingMode_TB_RL;
switch( maTextData.maData.GetHorAlign() )
{
case EXC_OBJ_HOR_LEFT: eVerAlign = SDRTEXTVERTADJUST_TOP; break;
case EXC_OBJ_HOR_CENTER: eVerAlign = SDRTEXTVERTADJUST_CENTER; break;
case EXC_OBJ_HOR_RIGHT: eVerAlign = SDRTEXTVERTADJUST_BOTTOM; break;
case EXC_OBJ_HOR_JUSTIFY: eVerAlign = SDRTEXTVERTADJUST_BLOCK; break;
}
MSO_Anchor eTextAnchor = static_cast<MSO_Anchor>(rDffConv.GetPropertyValue( DFF_Prop_anchorText, mso_anchorTop ));
switch( eTextAnchor )
{
case mso_anchorTopCentered :
case mso_anchorMiddleCentered :
case mso_anchorBottomCentered :
{
eHorAlign = SvxAdjust::Center;
}
break;
default:
{
switch( maTextData.maData.GetVerAlign() )
{
case EXC_OBJ_VER_TOP: eHorAlign = SvxAdjust::Right; break;
case EXC_OBJ_VER_CENTER: eHorAlign = SvxAdjust::Center; break;
case EXC_OBJ_VER_BOTTOM: eHorAlign = SvxAdjust::Left; break;
case EXC_OBJ_VER_JUSTIFY: eHorAlign = SvxAdjust::Block; break;
}
}
}
}
break;
case EXC_OBJ_ORIENT_STACKED:
{
// sj: STACKED is not supported, maybe it can be optimized here a bit
[[fallthrough]];
}
case EXC_OBJ_ORIENT_90CW:
{
eWriteMode = csst::WritingMode_TB_RL;
switch( maTextData.maData.GetHorAlign() )
{
case EXC_OBJ_HOR_LEFT: eVerAlign = SDRTEXTVERTADJUST_BOTTOM; break;
case EXC_OBJ_HOR_CENTER: eVerAlign = SDRTEXTVERTADJUST_CENTER; break;
case EXC_OBJ_HOR_RIGHT: eVerAlign = SDRTEXTVERTADJUST_TOP; break;
case EXC_OBJ_HOR_JUSTIFY: eVerAlign = SDRTEXTVERTADJUST_BLOCK; break;
}
MSO_Anchor eTextAnchor = static_cast<MSO_Anchor>(rDffConv.GetPropertyValue( DFF_Prop_anchorText, mso_anchorTop ));
switch ( eTextAnchor )
{
case mso_anchorTopCentered :
case mso_anchorMiddleCentered :
case mso_anchorBottomCentered :
{
eHorAlign = SvxAdjust::Center;
}
break;
default:
{
switch( maTextData.maData.GetVerAlign() )
{
case EXC_OBJ_VER_TOP: eHorAlign = SvxAdjust::Left; break;
case EXC_OBJ_VER_CENTER: eHorAlign = SvxAdjust::Center; break;
case EXC_OBJ_VER_BOTTOM: eHorAlign = SvxAdjust::Right; break;
case EXC_OBJ_VER_JUSTIFY: eHorAlign = SvxAdjust::Block; break;
}
}
}
}
break;
}
rSdrObj.SetMergedItem( SvxAdjustItem( eHorAlign, EE_PARA_JUST ) );
rSdrObj.SetMergedItem( SdrTextVertAdjustItem( eVerAlign ) );
rSdrObj.SetMergedItem( SvxWritingModeItem( eWriteMode, SDRATTR_TEXTDIRECTION ) );
}
}
// base class processing
XclImpRectObj::DoPreProcessSdrObj( rDffConv, rSdrObj );
}
XclImpChartObj::XclImpChartObj( const XclImpRoot& rRoot, bool bOwnTab ) :
XclImpRectObj( rRoot ),
mbOwnTab( bOwnTab )
{
SetSimpleMacro( false );
SetCustomDffObj( true );
}
void XclImpChartObj::ReadChartSubStream( XclImpStream& rStrm )
{
/* If chart is read from a chartsheet (mbOwnTab == true), the BOF record
has already been read. If chart is embedded as object, the next record
has to be the BOF record. */
if( mbOwnTab )
{
/* #i109800# The input stream may point somewhere inside the chart
substream and not exactly to the leading BOF record. To read this
record correctly in the following, the stream has to rewind it, so
that the next call to StartNextRecord() will find it correctly. */
if( rStrm.GetRecId() != EXC_ID5_BOF )
rStrm.RewindRecord();
}
else
{
if( (rStrm.GetNextRecId() == EXC_ID5_BOF) && rStrm.StartNextRecord() )
{
sal_uInt16 nBofType;
rStrm.Seek( 2 );
nBofType = rStrm.ReaduInt16();
SAL_WARN_IF( nBofType != EXC_BOF_CHART, "sc.filter", "XclImpChartObj::ReadChartSubStream - no chart BOF record" );
}
else
{
SAL_INFO("sc.filter", "XclImpChartObj::ReadChartSubStream - missing chart substream");
return;
}
}
// read chart, even if BOF record contains wrong substream identifier
mxChart = std::make_shared<XclImpChart>( GetRoot(), mbOwnTab );
mxChart->ReadChartSubStream( rStrm );
if( mbOwnTab )
FinalizeTabChart();
}
void XclImpChartObj::DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
// read OBJ record and the following chart substream
ReadFrameData( rStrm );
rStrm.Ignore( 18 );
ReadMacro3( rStrm, nMacroSize );
// set frame format from OBJ record, it is used if chart itself is transparent
if( mxChart )
mxChart->UpdateObjFrame( maLineData, maFillData );
}
void XclImpChartObj::DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
// read OBJ record and the following chart substream
ReadFrameData( rStrm );
rStrm.Ignore( 18 );
ReadMacro4( rStrm, nMacroSize );
// set frame format from OBJ record, it is used if chart itself is transparent
if( mxChart )
mxChart->UpdateObjFrame( maLineData, maFillData );
}
void XclImpChartObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize )
{
// read OBJ record and the following chart substream
ReadFrameData( rStrm );
rStrm.Ignore( 18 );
ReadName5( rStrm, nNameLen );
ReadMacro5( rStrm, nMacroSize );
ReadChartSubStream( rStrm );
// set frame format from OBJ record, it is used if chart itself is transparent
if( mxChart )
mxChart->UpdateObjFrame( maLineData, maFillData );
}
void XclImpChartObj::DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 /*nSubRecSize*/ )
{
// read the following chart substream
if( nSubRecId == EXC_ID_OBJEND )
{
// enable CONTINUE handling for the entire chart substream
rStrm.ResetRecord( true );
ReadChartSubStream( rStrm );
/* disable CONTINUE handling again to be able to read
following CONTINUE records as MSODRAWING records. */
rStrm.ResetRecord( false );
}
}
std::size_t XclImpChartObj::DoGetProgressSize() const
{
return mxChart ? mxChart->GetProgressSize() : 1;
}
SdrObjectUniquePtr XclImpChartObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const
{
SdrObjectUniquePtr xSdrObj;
SfxObjectShell* pDocShell = GetDocShell();
if( rDffConv.SupportsOleObjects() && SvtModuleOptions().IsChart() && pDocShell && mxChart && !mxChart->IsPivotChart() )
{
// create embedded chart object
OUString aEmbObjName;
OUString sBaseURL(GetRoot().GetMedium().GetBaseURL());
Reference< XEmbeddedObject > xEmbObj = pDocShell->GetEmbeddedObjectContainer().
CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID ).GetByteSequence(), aEmbObjName, &sBaseURL );
/* Set the size to the embedded object, this prevents that font sizes
of text objects are changed in the chart when the object is
inserted into the draw page. */
sal_Int64 nAspect = css::embed::Aspects::MSOLE_CONTENT;
MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xEmbObj->getMapUnit( nAspect ) );
Size aSize( vcl::Window::LogicToLogic( rAnchorRect.GetSize(), MapMode( MapUnit::Map100thMM ), MapMode( aUnit ) ) );
css::awt::Size aAwtSize( aSize.Width(), aSize.Height() );
xEmbObj->setVisualAreaSize( nAspect, aAwtSize );
// #i121334# This call will change the chart's default background fill from white to transparent.
// Add here again if this is wanted (see task description for details)
// ChartHelper::AdaptDefaultsForChart( xEmbObj );
// create the container OLE object
xSdrObj.reset(
new SdrOle2Obj(
*GetDoc().GetDrawLayer(),
svt::EmbeddedObjectRef(xEmbObj, nAspect),
aEmbObjName,
rAnchorRect));
}
return xSdrObj;
}
void XclImpChartObj::DoPostProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const
{
const SdrOle2Obj* pSdrOleObj = dynamic_cast< const SdrOle2Obj* >( &rSdrObj );
if( mxChart && pSdrOleObj )
{
const Reference< XEmbeddedObject >& xEmbObj = pSdrOleObj->GetObjRef();
if( xEmbObj.is() && ::svt::EmbeddedObjectRef::TryRunningState( xEmbObj ) ) try
{
Reference< XEmbedPersist > xPersist( xEmbObj, UNO_QUERY_THROW );
Reference< XModel > xModel( xEmbObj->getComponent(), UNO_QUERY_THROW );
mxChart->Convert( xModel, rDffConv, xPersist->getEntryName(), rSdrObj.GetLogicRect() );
}
catch( const Exception& )
{
}
}
}
void XclImpChartObj::FinalizeTabChart()
{
/* #i44077# Calculate and store DFF anchor for sheet charts.
Needed to get used area if this chart is inserted as OLE object. */
OSL_ENSURE( mbOwnTab, "XclImpChartObj::FinalizeTabChart - not allowed for embedded chart objects" );
// set uninitialized page to landscape
if( !GetPageSettings().GetPageData().mbValid )
GetPageSettings().SetPaperSize( EXC_PAPERSIZE_DEFAULT, false );
// calculate size of the chart object
const XclPageData& rPageData = GetPageSettings().GetPageData();
Size aPaperSize = rPageData.GetScPaperSize();
long nWidth = XclTools::GetHmmFromTwips( aPaperSize.Width() );
long nHeight = XclTools::GetHmmFromTwips( aPaperSize.Height() );
// subtract page margins, give some more extra space
nWidth -= (XclTools::GetHmmFromInch( rPageData.mfLeftMargin + rPageData.mfRightMargin ) + 2000);
nHeight -= (XclTools::GetHmmFromInch( rPageData.mfTopMargin + rPageData.mfBottomMargin ) + 1000);
// print column/row headers?
if( rPageData.mbPrintHeadings )
{
nWidth -= 2000;
nHeight -= 1000;
}
// create the object anchor
XclObjAnchor aAnchor;
aAnchor.SetRect( GetRoot(), GetCurrScTab(), tools::Rectangle( 1000, 500, nWidth, nHeight ), MapUnit::Map100thMM );
SetAnchor( aAnchor );
}
XclImpNoteObj::XclImpNoteObj( const XclImpRoot& rRoot ) :
XclImpTextObj( rRoot ),
maScPos( ScAddress::INITIALIZE_INVALID ),
mnNoteFlags( 0 )
{
SetSimpleMacro( false );
// caption object will be created manually
SetInsertSdrObj( false );
}
void XclImpNoteObj::SetNoteData( const ScAddress& rScPos, sal_uInt16 nNoteFlags )
{
maScPos = rScPos;
mnNoteFlags = nNoteFlags;
}
void XclImpNoteObj::DoPreProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const
{
// create formatted text
XclImpTextObj::DoPreProcessSdrObj( rDffConv, rSdrObj );
OutlinerParaObject* pOutlinerObj = rSdrObj.GetOutlinerParaObject();
if( maScPos.IsValid() && pOutlinerObj )
{
// create cell note with all data from drawing object
ScNoteUtil::CreateNoteFromObjectData(
GetDoc(), maScPos,
rSdrObj.GetMergedItemSet().Clone(), // new object on heap expected
new OutlinerParaObject( *pOutlinerObj ), // new object on heap expected
rSdrObj.GetLogicRect(),
::get_flag( mnNoteFlags, EXC_NOTE_VISIBLE ) );
}
}
XclImpControlHelper::XclImpControlHelper( const XclImpRoot& rRoot, XclCtrlBindMode eBindMode ) :
mrRoot( rRoot ),
meBindMode( eBindMode )
{
}
XclImpControlHelper::~XclImpControlHelper()
{
}
SdrObjectUniquePtr XclImpControlHelper::CreateSdrObjectFromShape(
const Reference< XShape >& rxShape, const tools::Rectangle& rAnchorRect ) const
{
mxShape = rxShape;
SdrObjectUniquePtr xSdrObj( SdrObject::getSdrObjectFromXShape( rxShape ) );
if( xSdrObj )
{
xSdrObj->NbcSetSnapRect( rAnchorRect );
// #i30543# insert into control layer
xSdrObj->NbcSetLayer( SC_LAYER_CONTROLS );
}
return xSdrObj;
}
void XclImpControlHelper::ApplySheetLinkProps() const
{
Reference< XControlModel > xCtrlModel = XclControlHelper::GetControlModel( mxShape );
if( !xCtrlModel.is() )
return;
// sheet links
if( SfxObjectShell* pDocShell = mrRoot.GetDocShell() )
{
Reference< XMultiServiceFactory > xFactory( pDocShell->GetModel(), UNO_QUERY );
if( xFactory.is() )
{
// cell link
if( mxCellLink ) try
{
Reference< XBindableValue > xBindable( xCtrlModel, UNO_QUERY_THROW );
// create argument sequence for createInstanceWithArguments()
CellAddress aApiAddress;
ScUnoConversion::FillApiAddress( aApiAddress, *mxCellLink );
NamedValue aValue;
aValue.Name = SC_UNONAME_BOUNDCELL;
aValue.Value <<= aApiAddress;
Sequence< Any > aArgs( 1 );
aArgs[ 0 ] <<= aValue;
// create the CellValueBinding instance and set at the control model
OUString aServiceName;
switch( meBindMode )
{
case EXC_CTRL_BINDCONTENT: aServiceName = SC_SERVICENAME_VALBIND; break;
case EXC_CTRL_BINDPOSITION: aServiceName = SC_SERVICENAME_LISTCELLBIND; break;
}
Reference< XValueBinding > xBinding(
xFactory->createInstanceWithArguments( aServiceName, aArgs ), UNO_QUERY_THROW );
xBindable->setValueBinding( xBinding );
}
catch( const Exception& )
{
}
// source range
if( mxSrcRange ) try
{
Reference< XListEntrySink > xEntrySink( xCtrlModel, UNO_QUERY_THROW );
// create argument sequence for createInstanceWithArguments()
CellRangeAddress aApiRange;
ScUnoConversion::FillApiRange( aApiRange, *mxSrcRange );
NamedValue aValue;
aValue.Name = SC_UNONAME_CELLRANGE;
aValue.Value <<= aApiRange;
Sequence< Any > aArgs( 1 );
aArgs[ 0 ] <<= aValue;
// create the EntrySource instance and set at the control model
Reference< XListEntrySource > xEntrySource( xFactory->createInstanceWithArguments(
SC_SERVICENAME_LISTSOURCE, aArgs ), UNO_QUERY_THROW );
xEntrySink->setListEntrySource( xEntrySource );
}
catch( const Exception& )
{
}
}
}
}
void XclImpControlHelper::ProcessControl( const XclImpDrawObjBase& rDrawObj ) const
{
Reference< XControlModel > xCtrlModel = XclControlHelper::GetControlModel( mxShape );
if( !xCtrlModel.is() )
return;
ApplySheetLinkProps();
ScfPropertySet aPropSet( xCtrlModel );
// #i51348# set object name at control model
aPropSet.SetStringProperty( "Name", rDrawObj.GetObjName() );
// control visible and printable?
aPropSet.SetBoolProperty( "EnableVisible", rDrawObj.IsVisible() );
aPropSet.SetBoolProperty( "Printable", rDrawObj.IsPrintable() );
// virtual call for type specific processing
DoProcessControl( aPropSet );
}
void XclImpControlHelper::ReadCellLinkFormula( XclImpStream& rStrm, bool bWithBoundSize )
{
ScRangeList aScRanges;
ReadRangeList( aScRanges, rStrm, bWithBoundSize );
// Use first cell of first range
if ( !aScRanges.empty() )
{
const ScRange & rScRange = aScRanges.front();
mxCellLink = std::make_shared<ScAddress>( rScRange.aStart );
}
}
void XclImpControlHelper::ReadSourceRangeFormula( XclImpStream& rStrm, bool bWithBoundSize )
{
ScRangeList aScRanges;
ReadRangeList( aScRanges, rStrm, bWithBoundSize );
// Use first range
if ( !aScRanges.empty() )
{
const ScRange & rScRange = aScRanges.front();
mxSrcRange = std::make_shared<ScRange>( rScRange );
}
}
void XclImpControlHelper::DoProcessControl( ScfPropertySet& ) const
{
}
void XclImpControlHelper::ReadRangeList( ScRangeList& rScRanges, XclImpStream& rStrm )
{
XclTokenArray aXclTokArr;
aXclTokArr.ReadSize( rStrm );
rStrm.Ignore( 4 );
aXclTokArr.ReadArray( rStrm );
mrRoot.GetFormulaCompiler().CreateRangeList( rScRanges, EXC_FMLATYPE_CONTROL, aXclTokArr, rStrm );
}
void XclImpControlHelper::ReadRangeList( ScRangeList& rScRanges, XclImpStream& rStrm, bool bWithBoundSize )
{
if( bWithBoundSize )
{
sal_uInt16 nSize;
nSize = rStrm.ReaduInt16();
if( nSize > 0 )
{
rStrm.PushPosition();
ReadRangeList( rScRanges, rStrm );
rStrm.PopPosition();
rStrm.Ignore( nSize );
}
}
else
{
ReadRangeList( rScRanges, rStrm );
}
}
XclImpTbxObjBase::XclImpTbxObjBase( const XclImpRoot& rRoot ) :
XclImpTextObj( rRoot ),
XclImpControlHelper( rRoot, EXC_CTRL_BINDPOSITION )
{
SetSimpleMacro( false );
SetCustomDffObj( true );
}
namespace {
void lclExtractColor( sal_uInt8& rnColorIdx, const DffPropSet& rDffPropSet, sal_uInt32 nPropId )
{
if( rDffPropSet.IsProperty( nPropId ) )
{
sal_uInt32 nColor = rDffPropSet.GetPropertyValue( nPropId, 0 );
if( (nColor & 0xFF000000) == 0x08000000 )
rnColorIdx = ::extract_value< sal_uInt8 >( nColor, 0, 8 );
}
}
} // namespace
void XclImpTbxObjBase::SetDffProperties( const DffPropSet& rDffPropSet )
{
maFillData.mnPattern = rDffPropSet.GetPropertyBool( DFF_Prop_fFilled ) ? EXC_PATT_SOLID : EXC_PATT_NONE;
lclExtractColor( maFillData.mnBackColorIdx, rDffPropSet, DFF_Prop_fillBackColor );
lclExtractColor( maFillData.mnPattColorIdx, rDffPropSet, DFF_Prop_fillColor );
::set_flag( maFillData.mnAuto, EXC_OBJ_LINE_AUTO, false );
maLineData.mnStyle = rDffPropSet.GetPropertyBool( DFF_Prop_fLine ) ? EXC_OBJ_LINE_SOLID : EXC_OBJ_LINE_NONE;
lclExtractColor( maLineData.mnColorIdx, rDffPropSet, DFF_Prop_lineColor );
::set_flag( maLineData.mnAuto, EXC_OBJ_FILL_AUTO, false );
}
bool XclImpTbxObjBase::FillMacroDescriptor( ScriptEventDescriptor& rDescriptor ) const
{
return XclControlHelper::FillMacroDescriptor( rDescriptor, DoGetEventType(), GetMacroName(), GetDocShell() );
}
void XclImpTbxObjBase::ConvertFont( ScfPropertySet& rPropSet ) const
{
if( maTextData.mxString )
{
const XclFormatRunVec& rFormatRuns = maTextData.mxString->GetFormats();
if( rFormatRuns.empty() )
GetFontBuffer().WriteDefaultCtrlFontProperties( rPropSet );
else
GetFontBuffer().WriteFontProperties( rPropSet, EXC_FONTPROPSET_CONTROL, rFormatRuns.front().mnFontIdx );
}
}
void XclImpTbxObjBase::ConvertLabel( ScfPropertySet& rPropSet ) const
{
if( maTextData.mxString )
{
OUString aLabel = maTextData.mxString->GetText();
if( maTextData.maData.mnShortcut > 0 )
{
sal_Int32 nPos = aLabel.indexOf( static_cast< sal_Unicode >( maTextData.maData.mnShortcut ) );
if( nPos != -1 )
aLabel = aLabel.replaceAt( nPos, 0, "~" );
}
rPropSet.SetStringProperty( "Label", aLabel );
//Excel Alt text <==> Aoo description
//For TBX control, if user does not operate alt text, alt text will be set label text as default value in Excel.
//In this case, DFF_Prop_wzDescription will not be set in excel file.
//So In the end of SvxMSDffManager::ImportShape, description will not be set. But actually in excel,
//the alt text is the label value. So here set description as label text first which is called before ImportShape.
Reference< css::beans::XPropertySet > xPropset( mxShape, UNO_QUERY );
try{
if(xPropset.is())
xPropset->setPropertyValue( "Description", makeAny(aLabel) );
}catch( ... )
{
SAL_WARN("sc.filter", "Can't set a default text for TBX Control ");
}
}
ConvertFont( rPropSet );
}
SdrObjectUniquePtr XclImpTbxObjBase::DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const
{
SdrObjectUniquePtr xSdrObj( rDffConv.CreateSdrObject( *this, rAnchorRect ) );
rDffConv.Progress();
return xSdrObj;
}
void XclImpTbxObjBase::DoPreProcessSdrObj( XclImpDffConverter& /*rDffConv*/, SdrObject& /*rSdrObj*/ ) const
{
// do not call DoPreProcessSdrObj() from base class (to skip text processing)
ProcessControl( *this );
}
XclImpButtonObj::XclImpButtonObj( const XclImpRoot& rRoot ) :
XclImpTbxObjBase( rRoot )
{
}
void XclImpButtonObj::DoProcessControl( ScfPropertySet& rPropSet ) const
{
// label and text formatting
ConvertLabel( rPropSet );
/* Horizontal text alignment. For unknown reason, the property type is a
simple sal_Int16 and not a com.sun.star.style.HorizontalAlignment. */
sal_Int16 nHorAlign = 1;
switch( maTextData.maData.GetHorAlign() )
{
case EXC_OBJ_HOR_LEFT: nHorAlign = 0; break;
case EXC_OBJ_HOR_CENTER: nHorAlign = 1; break;
case EXC_OBJ_HOR_RIGHT: nHorAlign = 2; break;
}
rPropSet.SetProperty( "Align", nHorAlign );
// vertical text alignment
namespace csss = ::com::sun::star::style;
csss::VerticalAlignment eVerAlign = csss::VerticalAlignment_MIDDLE;
switch( maTextData.maData.GetVerAlign() )
{
case EXC_OBJ_VER_TOP: eVerAlign = csss::VerticalAlignment_TOP; break;
case EXC_OBJ_VER_CENTER: eVerAlign = csss::VerticalAlignment_MIDDLE; break;
case EXC_OBJ_VER_BOTTOM: eVerAlign = csss::VerticalAlignment_BOTTOM; break;
}
rPropSet.SetProperty( "VerticalAlign", eVerAlign );
// always wrap text automatically
rPropSet.SetBoolProperty( "MultiLine", true );
// default button
bool bDefButton = ::get_flag( maTextData.maData.mnButtonFlags, EXC_OBJ_BUTTON_DEFAULT );
rPropSet.SetBoolProperty( "DefaultButton", bDefButton );
// button type (flags cannot be combined in OOo)
namespace cssa = ::com::sun::star::awt;
cssa::PushButtonType eButtonType = cssa::PushButtonType_STANDARD;
if( ::get_flag( maTextData.maData.mnButtonFlags, EXC_OBJ_BUTTON_CLOSE ) )
eButtonType = cssa::PushButtonType_OK;
else if( ::get_flag( maTextData.maData.mnButtonFlags, EXC_OBJ_BUTTON_CANCEL ) )
eButtonType = cssa::PushButtonType_CANCEL;
else if( ::get_flag( maTextData.maData.mnButtonFlags, EXC_OBJ_BUTTON_HELP ) )
eButtonType = cssa::PushButtonType_HELP;
// property type is short, not enum
rPropSet.SetProperty( "PushButtonType", sal_Int16( eButtonType ) );
}
OUString XclImpButtonObj::DoGetServiceName() const
{
return "com.sun.star.form.component.CommandButton";
}
XclTbxEventType XclImpButtonObj::DoGetEventType() const
{
return EXC_TBX_EVENT_ACTION;
}
XclImpCheckBoxObj::XclImpCheckBoxObj( const XclImpRoot& rRoot ) :
XclImpTbxObjBase( rRoot ),
mnState( EXC_OBJ_CHECKBOX_UNCHECKED ),
mnCheckBoxFlags( 0 )
{
}
void XclImpCheckBoxObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 /*nMacroSize*/ )
{
ReadFrameData( rStrm );
rStrm.Ignore( 10 );
maTextData.maData.mnFlags = rStrm.ReaduInt16();
rStrm.Ignore( 20 );
ReadName5( rStrm, nNameLen );
ReadMacro5( rStrm, rStrm.ReaduInt16() ); // first macro size invalid and unused
ReadCellLinkFormula( rStrm, true );
maTextData.maData.mnTextLen = rStrm.ReaduInt16();
maTextData.ReadByteString( rStrm );
mnState = rStrm.ReaduInt16();
maTextData.maData.mnShortcut = rStrm.ReaduInt16();
maTextData.maData.mnShortcutEA = rStrm.ReaduInt16();
mnCheckBoxFlags = rStrm.ReaduInt16();
}
void XclImpCheckBoxObj::DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize )
{
switch( nSubRecId )
{
case EXC_ID_OBJCBLS:
// do not read EXC_ID_OBJCBLSDATA, not written by OOo Excel export
mnState = rStrm.ReaduInt16();
rStrm.Ignore( 4 );
maTextData.maData.mnShortcut = rStrm.ReaduInt16();
maTextData.maData.mnShortcutEA = rStrm.ReaduInt16();
mnCheckBoxFlags = rStrm.ReaduInt16();
break;
case EXC_ID_OBJCBLSFMLA:
ReadCellLinkFormula( rStrm, false );
break;
default:
XclImpTbxObjBase::DoReadObj8SubRec( rStrm, nSubRecId, nSubRecSize );
}
}
void XclImpCheckBoxObj::DoProcessControl( ScfPropertySet& rPropSet ) const
{
// label and text formatting
ConvertLabel( rPropSet );
// state
bool bSupportsTristate = GetObjType() == EXC_OBJTYPE_CHECKBOX;
sal_Int16 nApiState = 0;
switch( mnState )
{
case EXC_OBJ_CHECKBOX_UNCHECKED: nApiState = 0; break;
case EXC_OBJ_CHECKBOX_CHECKED: nApiState = 1; break;
case EXC_OBJ_CHECKBOX_TRISTATE: nApiState = bSupportsTristate ? 2 : 1; break;
}
if( bSupportsTristate )
rPropSet.SetBoolProperty( "TriState", nApiState == 2 );
rPropSet.SetProperty( "DefaultState", nApiState );
// box style
namespace AwtVisualEffect = ::com::sun::star::awt::VisualEffect;
sal_Int16 nEffect = ::get_flagvalue( mnCheckBoxFlags, EXC_OBJ_CHECKBOX_FLAT, AwtVisualEffect::FLAT, AwtVisualEffect::LOOK3D );
rPropSet.SetProperty( "VisualEffect", nEffect );
// do not wrap text automatically
rPropSet.SetBoolProperty( "MultiLine", false );
// #i40279# always centered vertically
namespace csss = ::com::sun::star::style;
rPropSet.SetProperty( "VerticalAlign", csss::VerticalAlignment_MIDDLE );
// background color
if( maFillData.IsFilled() )
{
sal_Int32 nColor = static_cast< sal_Int32 >( GetSolidFillColor( maFillData ) );
rPropSet.SetProperty( "BackgroundColor", nColor );
}
}
OUString XclImpCheckBoxObj::DoGetServiceName() const
{
return "com.sun.star.form.component.CheckBox";
}
XclTbxEventType XclImpCheckBoxObj::DoGetEventType() const
{
return EXC_TBX_EVENT_ACTION;
}
XclImpOptionButtonObj::XclImpOptionButtonObj( const XclImpRoot& rRoot ) :
XclImpCheckBoxObj( rRoot ),
mnNextInGroup( 0 ),
mnFirstInGroup( 1 )
{
}
void XclImpOptionButtonObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 /*nMacroSize*/ )
{
ReadFrameData( rStrm );
rStrm.Ignore( 10 );
maTextData.maData.mnFlags = rStrm.ReaduInt16();
rStrm.Ignore( 32 );
ReadName5( rStrm, nNameLen );
ReadMacro5( rStrm, rStrm.ReaduInt16() ); // first macro size invalid and unused
ReadCellLinkFormula( rStrm, true );
maTextData.maData.mnTextLen = rStrm.ReaduInt16();
maTextData.ReadByteString( rStrm );
mnState = rStrm.ReaduInt16();
maTextData.maData.mnShortcut = rStrm.ReaduInt16();
maTextData.maData.mnShortcutEA = rStrm.ReaduInt16();
mnCheckBoxFlags = rStrm.ReaduInt16();
mnNextInGroup = rStrm.ReaduInt16();
mnFirstInGroup = rStrm.ReaduInt16();
}
void XclImpOptionButtonObj::DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize )
{
switch( nSubRecId )
{
case EXC_ID_OBJRBODATA:
mnNextInGroup = rStrm.ReaduInt16();
mnFirstInGroup = rStrm.ReaduInt16();
break;
default:
XclImpCheckBoxObj::DoReadObj8SubRec( rStrm, nSubRecId, nSubRecSize );
}
}
void XclImpOptionButtonObj::DoProcessControl( ScfPropertySet& rPropSet ) const
{
XclImpCheckBoxObj::DoProcessControl( rPropSet );
// TODO: grouping
XclImpOptionButtonObj* pTbxObj = dynamic_cast< XclImpOptionButtonObj* >( GetObjectManager().GetSheetDrawing( GetTab() ).FindDrawObj( mnNextInGroup ).get() );
if ( pTbxObj && pTbxObj->mnFirstInGroup )
{
// Group has terminated
// traverse each RadioButton in group and
// a) apply the groupname
// b) propagate the linked cell from the lead radiobutton
// c) apply the correct Ref value
XclImpOptionButtonObj* pLeader = pTbxObj;
sal_Int32 nRefVal = 1;
do
{
Reference< XControlModel > xCtrlModel = XclControlHelper::GetControlModel( pTbxObj->mxShape );
if ( xCtrlModel.is() )
{
ScfPropertySet aProps( xCtrlModel );
OUString sGroupName = OUString::number( pLeader->GetDffShapeId() );
aProps.SetStringProperty( "GroupName", sGroupName );
aProps.SetStringProperty( "RefValue", OUString::number( nRefVal++ ) );
if ( pLeader->HasCellLink() && !pTbxObj->HasCellLink() )
{
// propagate cell link info
pTbxObj->mxCellLink = std::make_shared<ScAddress>( *pLeader->mxCellLink );
pTbxObj->ApplySheetLinkProps();
}
pTbxObj = dynamic_cast< XclImpOptionButtonObj* >( GetObjectManager().GetSheetDrawing( GetTab() ).FindDrawObj( pTbxObj->mnNextInGroup ).get() );
}
else
pTbxObj = nullptr;
} while ( pTbxObj && ( pTbxObj->mnFirstInGroup != 1 ) );
}
else
{
// not the leader? try and find it
}
}
OUString XclImpOptionButtonObj::DoGetServiceName() const
{
return "com.sun.star.form.component.RadioButton";
}
XclTbxEventType XclImpOptionButtonObj::DoGetEventType() const
{
return EXC_TBX_EVENT_ACTION;
}
XclImpLabelObj::XclImpLabelObj( const XclImpRoot& rRoot ) :
XclImpTbxObjBase( rRoot )
{
}
void XclImpLabelObj::DoProcessControl( ScfPropertySet& rPropSet ) const
{
// label and text formatting
ConvertLabel( rPropSet );
// text alignment (always top/left aligned)
rPropSet.SetProperty( "Align", sal_Int16( 0 ) );
namespace csss = ::com::sun::star::style;
rPropSet.SetProperty( "VerticalAlign", csss::VerticalAlignment_TOP );
// always wrap text automatically
rPropSet.SetBoolProperty( "MultiLine", true );
}
OUString XclImpLabelObj::DoGetServiceName() const
{
return "com.sun.star.form.component.FixedText";
}
XclTbxEventType XclImpLabelObj::DoGetEventType() const
{
return EXC_TBX_EVENT_MOUSE;
}
XclImpGroupBoxObj::XclImpGroupBoxObj( const XclImpRoot& rRoot ) :
XclImpTbxObjBase( rRoot ),
mnGroupBoxFlags( 0 )
{
}
void XclImpGroupBoxObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 /*nMacroSize*/ )
{
ReadFrameData( rStrm );
rStrm.Ignore( 10 );
maTextData.maData.mnFlags = rStrm.ReaduInt16();
rStrm.Ignore( 26 );
ReadName5( rStrm, nNameLen );
ReadMacro5( rStrm, rStrm.ReaduInt16() ); // first macro size invalid and unused
maTextData.maData.mnTextLen = rStrm.ReaduInt16();
maTextData.ReadByteString( rStrm );
maTextData.maData.mnShortcut = rStrm.ReaduInt16();
maTextData.maData.mnShortcutEA = rStrm.ReaduInt16( );
mnGroupBoxFlags = rStrm.ReaduInt16();
}
void XclImpGroupBoxObj::DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize )
{
switch( nSubRecId )
{
case EXC_ID_OBJGBODATA:
maTextData.maData.mnShortcut = rStrm.ReaduInt16();
maTextData.maData.mnShortcutEA = rStrm.ReaduInt16();
mnGroupBoxFlags = rStrm.ReaduInt16();
break;
default:
XclImpTbxObjBase::DoReadObj8SubRec( rStrm, nSubRecId, nSubRecSize );
}
}
void XclImpGroupBoxObj::DoProcessControl( ScfPropertySet& rPropSet ) const
{
// label and text formatting
ConvertLabel( rPropSet );
}
OUString XclImpGroupBoxObj::DoGetServiceName() const
{
return "com.sun.star.form.component.GroupBox";
}
XclTbxEventType XclImpGroupBoxObj::DoGetEventType() const
{
return EXC_TBX_EVENT_MOUSE;
}
XclImpDialogObj::XclImpDialogObj( const XclImpRoot& rRoot ) :
XclImpTbxObjBase( rRoot )
{
}
void XclImpDialogObj::DoProcessControl( ScfPropertySet& rPropSet ) const
{
// label and text formatting
ConvertLabel( rPropSet );
}
OUString XclImpDialogObj::DoGetServiceName() const
{
// dialog frame faked by a groupbox
return "com.sun.star.form.component.GroupBox";
}
XclTbxEventType XclImpDialogObj::DoGetEventType() const
{
return EXC_TBX_EVENT_MOUSE;
}
XclImpEditObj::XclImpEditObj( const XclImpRoot& rRoot ) :
XclImpTbxObjBase( rRoot ),
mnContentType( EXC_OBJ_EDIT_TEXT ),
mnMultiLine( 0 ),
mnScrollBar( 0 ),
mnListBoxObjId( 0 )
{
}
bool XclImpEditObj::IsNumeric() const
{
return (mnContentType == EXC_OBJ_EDIT_INTEGER) || (mnContentType == EXC_OBJ_EDIT_DOUBLE);
}
void XclImpEditObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 /*nMacroSize*/ )
{
ReadFrameData( rStrm );
rStrm.Ignore( 10 );
maTextData.maData.mnFlags = rStrm.ReaduInt16();
rStrm.Ignore( 14 );
ReadName5( rStrm, nNameLen );
ReadMacro5( rStrm, rStrm.ReaduInt16() ); // first macro size invalid and unused
maTextData.maData.mnTextLen = rStrm.ReaduInt16();
maTextData.ReadByteString( rStrm );
mnContentType = rStrm.ReaduInt16();
mnMultiLine = rStrm.ReaduInt16();
mnScrollBar = rStrm.ReaduInt16();
mnListBoxObjId = rStrm.ReaduInt16();
}
void XclImpEditObj::DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize )
{
switch( nSubRecId )
{
case EXC_ID_OBJEDODATA:
mnContentType = rStrm.ReaduInt16();
mnMultiLine = rStrm.ReaduInt16();
mnScrollBar = rStrm.ReaduInt16();
mnListBoxObjId = rStrm.ReaduInt16();
break;
default:
XclImpTbxObjBase::DoReadObj8SubRec( rStrm, nSubRecId, nSubRecSize );
}
}
void XclImpEditObj::DoProcessControl( ScfPropertySet& rPropSet ) const
{
if( maTextData.mxString )
{
OUString aText = maTextData.mxString->GetText();
if( IsNumeric() )
{
// TODO: OUString::toDouble() does not handle local decimal separator
rPropSet.SetProperty( "DefaultValue", aText.toDouble() );
rPropSet.SetBoolProperty( "Spin", mnScrollBar != 0 );
}
else
{
rPropSet.SetProperty( "DefaultText", aText );
rPropSet.SetBoolProperty( "MultiLine", mnMultiLine != 0 );
rPropSet.SetBoolProperty( "VScroll", mnScrollBar != 0 );
}
}
ConvertFont( rPropSet );
}
OUString XclImpEditObj::DoGetServiceName() const
{
return IsNumeric() ?
OUString( "com.sun.star.form.component.NumericField" ) :
OUString( "com.sun.star.form.component.TextField" );
}
XclTbxEventType XclImpEditObj::DoGetEventType() const
{
return EXC_TBX_EVENT_TEXT;
}
XclImpTbxObjScrollableBase::XclImpTbxObjScrollableBase( const XclImpRoot& rRoot ) :
XclImpTbxObjBase( rRoot ),
mnValue( 0 ),
mnMin( 0 ),
mnMax( 100 ),
mnStep( 1 ),
mnPageStep( 10 ),
mnOrient( 0 ),
mnThumbWidth( 1 ),
mnScrollFlags( 0 )
{
}
void XclImpTbxObjScrollableBase::ReadSbs( XclImpStream& rStrm )
{
rStrm.Ignore( 4 );
mnValue = rStrm.ReaduInt16();
mnMin = rStrm.ReaduInt16();
mnMax = rStrm.ReaduInt16();
mnStep = rStrm.ReaduInt16();
mnPageStep = rStrm.ReaduInt16();
mnOrient = rStrm.ReaduInt16();
mnThumbWidth = rStrm.ReaduInt16();
mnScrollFlags = rStrm.ReaduInt16();
}
void XclImpTbxObjScrollableBase::DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize )
{
switch( nSubRecId )
{
case EXC_ID_OBJSBS:
ReadSbs( rStrm );
break;
case EXC_ID_OBJSBSFMLA:
ReadCellLinkFormula( rStrm, false );
break;
default:
XclImpTbxObjBase::DoReadObj8SubRec( rStrm, nSubRecId, nSubRecSize );
}
}
XclImpSpinButtonObj::XclImpSpinButtonObj( const XclImpRoot& rRoot ) :
XclImpTbxObjScrollableBase( rRoot )
{
}
void XclImpSpinButtonObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 /*nMacroSize*/ )
{
ReadFrameData( rStrm );
ReadSbs( rStrm );
ReadName5( rStrm, nNameLen );
ReadMacro5( rStrm, rStrm.ReaduInt16() ); // first macro size invalid and unused
ReadCellLinkFormula( rStrm, true );
}
void XclImpSpinButtonObj::DoProcessControl( ScfPropertySet& rPropSet ) const
{
// Calc's "Border" property is not the 3D/flat style effect in Excel (#i34712#)
rPropSet.SetProperty( "Border", css::awt::VisualEffect::NONE );
rPropSet.SetProperty< sal_Int32 >( "DefaultSpinValue", mnValue );
rPropSet.SetProperty< sal_Int32 >( "SpinValueMin", mnMin );
rPropSet.SetProperty< sal_Int32 >( "SpinValueMax", mnMax );
rPropSet.SetProperty< sal_Int32 >( "SpinIncrement", mnStep );
// Excel spin buttons always vertical
rPropSet.SetProperty( "Orientation", css::awt::ScrollBarOrientation::VERTICAL );
}
OUString XclImpSpinButtonObj::DoGetServiceName() const
{
return "com.sun.star.form.component.SpinButton";
}
XclTbxEventType XclImpSpinButtonObj::DoGetEventType() const
{
return EXC_TBX_EVENT_VALUE;
}
XclImpScrollBarObj::XclImpScrollBarObj( const XclImpRoot& rRoot ) :
XclImpTbxObjScrollableBase( rRoot )
{
}
void XclImpScrollBarObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 /*nMacroSize*/ )
{
ReadFrameData( rStrm );
ReadSbs( rStrm );
ReadName5( rStrm, nNameLen );
ReadMacro5( rStrm, rStrm.ReaduInt16() ); // first macro size invalid and unused
ReadCellLinkFormula( rStrm, true );
}
void XclImpScrollBarObj::DoProcessControl( ScfPropertySet& rPropSet ) const
{
// Calc's "Border" property is not the 3D/flat style effect in Excel (#i34712#)
rPropSet.SetProperty( "Border", css::awt::VisualEffect::NONE );
rPropSet.SetProperty< sal_Int32 >( "DefaultScrollValue", mnValue );
rPropSet.SetProperty< sal_Int32 >( "ScrollValueMin", mnMin );
rPropSet.SetProperty< sal_Int32 >( "ScrollValueMax", mnMax );
rPropSet.SetProperty< sal_Int32 >( "LineIncrement", mnStep );
rPropSet.SetProperty< sal_Int32 >( "BlockIncrement", mnPageStep );
rPropSet.SetProperty( "VisibleSize", ::std::min< sal_Int32 >( mnPageStep, 1 ) );
namespace AwtScrollOrient = ::com::sun::star::awt::ScrollBarOrientation;
sal_Int32 nApiOrient = ::get_flagvalue( mnOrient, EXC_OBJ_SCROLLBAR_HOR, AwtScrollOrient::HORIZONTAL, AwtScrollOrient::VERTICAL );
rPropSet.SetProperty( "Orientation", nApiOrient );
}
OUString XclImpScrollBarObj::DoGetServiceName() const
{
return "com.sun.star.form.component.ScrollBar";
}
XclTbxEventType XclImpScrollBarObj::DoGetEventType() const
{
return EXC_TBX_EVENT_VALUE;
}
XclImpTbxObjListBase::XclImpTbxObjListBase( const XclImpRoot& rRoot ) :
XclImpTbxObjScrollableBase( rRoot ),
mnEntryCount( 0 ),
mnSelEntry( 0 ),
mnListFlags( 0 ),
mnEditObjId( 0 ),
mbHasDefFontIdx( false )
{
}
void XclImpTbxObjListBase::ReadLbsData( XclImpStream& rStrm )
{
ReadSourceRangeFormula( rStrm, true );
mnEntryCount = rStrm.ReaduInt16();
mnSelEntry = rStrm.ReaduInt16();
mnListFlags = rStrm.ReaduInt16();
mnEditObjId = rStrm.ReaduInt16();
}
void XclImpTbxObjListBase::SetBoxFormatting( ScfPropertySet& rPropSet ) const
{
// border style
namespace AwtVisualEffect = ::com::sun::star::awt::VisualEffect;
sal_Int16 nApiBorder = ::get_flagvalue( mnListFlags, EXC_OBJ_LISTBOX_FLAT, AwtVisualEffect::FLAT, AwtVisualEffect::LOOK3D );
rPropSet.SetProperty( "Border", nApiBorder );
// font formatting
if( mbHasDefFontIdx )
GetFontBuffer().WriteFontProperties( rPropSet, EXC_FONTPROPSET_CONTROL, maTextData.maData.mnDefFontIdx );
else
GetFontBuffer().WriteDefaultCtrlFontProperties( rPropSet );
}
XclImpListBoxObj::XclImpListBoxObj( const XclImpRoot& rRoot ) :
XclImpTbxObjListBase( rRoot )
{
}
void XclImpListBoxObj::ReadFullLbsData( XclImpStream& rStrm, std::size_t nRecLeft )
{
std::size_t nRecEnd = rStrm.GetRecPos() + nRecLeft;
ReadLbsData( rStrm );
OSL_ENSURE( (rStrm.GetRecPos() == nRecEnd) || (rStrm.GetRecPos() + mnEntryCount == nRecEnd),
"XclImpListBoxObj::ReadFullLbsData - invalid size of OBJLBSDATA record" );
while( rStrm.IsValid() && (rStrm.GetRecPos() < nRecEnd) )
maSelection.push_back( rStrm.ReaduInt8() );
}
void XclImpListBoxObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 /*nMacroSize*/ )
{
ReadFrameData( rStrm );
ReadSbs( rStrm );
rStrm.Ignore( 18 );
maTextData.maData.mnDefFontIdx = rStrm.ReaduInt16();
rStrm.Ignore( 4 );
ReadName5( rStrm, nNameLen );
ReadMacro5( rStrm, rStrm.ReaduInt16() ); // first macro size invalid and unused
ReadCellLinkFormula( rStrm, true );
ReadFullLbsData( rStrm, rStrm.GetRecLeft() );
mbHasDefFontIdx = true;
}
void XclImpListBoxObj::DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize )
{
switch( nSubRecId )
{
case EXC_ID_OBJLBSDATA:
ReadFullLbsData( rStrm, nSubRecSize );
break;
default:
XclImpTbxObjListBase::DoReadObj8SubRec( rStrm, nSubRecId, nSubRecSize );
}
}
void XclImpListBoxObj::DoProcessControl( ScfPropertySet& rPropSet ) const
{
// listbox formatting
SetBoxFormatting( rPropSet );
// selection type
sal_uInt8 nSelType = ::extract_value< sal_uInt8 >( mnListFlags, 4, 2 );
bool bMultiSel = nSelType != EXC_OBJ_LISTBOX_SINGLE;
rPropSet.SetBoolProperty( "MultiSelection", bMultiSel );
// selection (do not set, if listbox is linked to a cell)
if( !HasCellLink() )
{
ScfInt16Vec aSelVec;
// multi selection: API expects sequence of list entry indexes
if( bMultiSel )
{
sal_Int16 nIndex = 0;
for( const auto& rItem : maSelection )
{
if( rItem != 0 )
aSelVec.push_back( nIndex );
++nIndex;
}
}
// single selection: mnSelEntry is one-based, API expects zero-based
else if( mnSelEntry > 0 )
aSelVec.push_back( static_cast< sal_Int16 >( mnSelEntry - 1 ) );
if( !aSelVec.empty() )
{
Sequence<sal_Int16> aSelSeq(aSelVec.data(), static_cast<sal_Int32>(aSelVec.size()));
rPropSet.SetProperty( "DefaultSelection", aSelSeq );
}
}
}
OUString XclImpListBoxObj::DoGetServiceName() const
{
return "com.sun.star.form.component.ListBox";
}
XclTbxEventType XclImpListBoxObj::DoGetEventType() const
{
return EXC_TBX_EVENT_CHANGE;
}
XclImpDropDownObj::XclImpDropDownObj( const XclImpRoot& rRoot ) :
XclImpTbxObjListBase( rRoot ),
mnLeft( 0 ),
mnTop( 0 ),
mnRight( 0 ),
mnBottom( 0 ),
mnDropDownFlags( 0 ),
mnLineCount( 0 ),
mnMinWidth( 0 )
{
}
sal_uInt16 XclImpDropDownObj::GetDropDownType() const
{
return ::extract_value< sal_uInt8 >( mnDropDownFlags, 0, 2 );
}
void XclImpDropDownObj::ReadFullLbsData( XclImpStream& rStrm )
{
ReadLbsData( rStrm );
mnDropDownFlags = rStrm.ReaduInt16();
mnLineCount = rStrm.ReaduInt16();
mnMinWidth = rStrm.ReaduInt16();
maTextData.maData.mnTextLen = rStrm.ReaduInt16();
maTextData.ReadByteString( rStrm );
// dropdowns of auto-filters have 'simple' style, they don't have a text area
if( GetDropDownType() == EXC_OBJ_DROPDOWN_SIMPLE )
SetProcessSdrObj( false );
}
void XclImpDropDownObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 /*nMacroSize*/ )
{
ReadFrameData( rStrm );
ReadSbs( rStrm );
rStrm.Ignore( 18 );
maTextData.maData.mnDefFontIdx = rStrm.ReaduInt16();
rStrm.Ignore( 14 );
mnLeft = rStrm.ReaduInt16();
mnTop = rStrm.ReaduInt16();
mnRight = rStrm.ReaduInt16();
mnBottom = rStrm.ReaduInt16();
rStrm.Ignore( 4 );
ReadName5( rStrm, nNameLen );
ReadMacro5( rStrm, rStrm.ReaduInt16() ); // first macro size invalid and unused
ReadCellLinkFormula( rStrm, true );
ReadFullLbsData( rStrm );
mbHasDefFontIdx = true;
}
void XclImpDropDownObj::DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize )
{
switch( nSubRecId )
{
case EXC_ID_OBJLBSDATA:
ReadFullLbsData( rStrm );
break;
default:
XclImpTbxObjListBase::DoReadObj8SubRec( rStrm, nSubRecId, nSubRecSize );
}
}
void XclImpDropDownObj::DoProcessControl( ScfPropertySet& rPropSet ) const
{
// dropdown listbox formatting
SetBoxFormatting( rPropSet );
// enable dropdown button
rPropSet.SetBoolProperty( "Dropdown", true );
// dropdown line count
rPropSet.SetProperty( "LineCount", mnLineCount );
if( GetDropDownType() == EXC_OBJ_DROPDOWN_COMBOBOX )
{
// text of editable combobox
if( maTextData.mxString )
rPropSet.SetStringProperty( "DefaultText", maTextData.mxString->GetText() );
}
else
{
// selection (do not set, if dropdown is linked to a cell)
if( !HasCellLink() && (mnSelEntry > 0) )
{
Sequence< sal_Int16 > aSelSeq( 1 );
aSelSeq[ 0 ] = mnSelEntry - 1;
rPropSet.SetProperty( "DefaultSelection", aSelSeq );
}
}
}
OUString XclImpDropDownObj::DoGetServiceName() const
{
return (GetDropDownType() == EXC_OBJ_DROPDOWN_COMBOBOX) ?
OUString( "com.sun.star.form.component.ComboBox" ) :
OUString( "com.sun.star.form.component.ListBox" );
}
XclTbxEventType XclImpDropDownObj::DoGetEventType() const
{
return (GetDropDownType() == EXC_OBJ_DROPDOWN_COMBOBOX) ? EXC_TBX_EVENT_TEXT : EXC_TBX_EVENT_CHANGE;
}
XclImpPictureObj::XclImpPictureObj( const XclImpRoot& rRoot ) :
XclImpRectObj( rRoot ),
XclImpControlHelper( rRoot, EXC_CTRL_BINDCONTENT ),
mnStorageId( 0 ),
mnCtlsStrmPos( 0 ),
mnCtlsStrmSize( 0 ),
mbEmbedded( false ),
mbLinked( false ),
mbSymbol( false ),
mbControl( false ),
mbUseCtlsStrm( false )
{
SetAreaObj( true );
SetSimpleMacro( true );
SetCustomDffObj( true );
}
OUString XclImpPictureObj::GetOleStorageName() const
{
OUStringBuffer aStrgName;
if( (mbEmbedded || mbLinked) && !mbControl && (mnStorageId > 0) )
{
aStrgName = mbEmbedded ? OUStringLiteral(EXC_STORAGE_OLE_EMBEDDED) : OUStringLiteral(EXC_STORAGE_OLE_LINKED);
static const char spcHexChars[] = "0123456789ABCDEF";
for( sal_uInt8 nIndex = 32; nIndex > 0; nIndex -= 4 )
aStrgName.append(OUStringChar( spcHexChars[ ::extract_value< sal_uInt8 >( mnStorageId, nIndex - 4, 4 ) ] ));
}
return aStrgName.makeStringAndClear();
}
void XclImpPictureObj::DoReadObj3( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
sal_uInt16 nLinkSize;
ReadFrameData( rStrm );
rStrm.Ignore( 6 );
nLinkSize = rStrm.ReaduInt16();
rStrm.Ignore( 2 );
ReadFlags3( rStrm );
ReadMacro3( rStrm, nMacroSize );
ReadPictFmla( rStrm, nLinkSize );
if( (rStrm.GetNextRecId() == EXC_ID3_IMGDATA) && rStrm.StartNextRecord() )
maGraphic = XclImpDrawing::ReadImgData( GetRoot(), rStrm );
}
void XclImpPictureObj::DoReadObj4( XclImpStream& rStrm, sal_uInt16 nMacroSize )
{
sal_uInt16 nLinkSize;
ReadFrameData( rStrm );
rStrm.Ignore( 6 );
nLinkSize = rStrm.ReaduInt16();
rStrm.Ignore( 2 );
ReadFlags3( rStrm );
ReadMacro4( rStrm, nMacroSize );
ReadPictFmla( rStrm, nLinkSize );
if( (rStrm.GetNextRecId() == EXC_ID3_IMGDATA) && rStrm.StartNextRecord() )
maGraphic = XclImpDrawing::ReadImgData( GetRoot(), rStrm );
}
void XclImpPictureObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uInt16 nMacroSize )
{
sal_uInt16 nLinkSize;
ReadFrameData( rStrm );
rStrm.Ignore( 6 );
nLinkSize = rStrm.ReaduInt16();
rStrm.Ignore( 2 );
ReadFlags3( rStrm );
rStrm.Ignore( 4 );
ReadName5( rStrm, nNameLen );
ReadMacro5( rStrm, nMacroSize );
ReadPictFmla( rStrm, nLinkSize );
if( (rStrm.GetNextRecId() == EXC_ID3_IMGDATA) && rStrm.StartNextRecord() )
{
// page background is stored as hidden picture with name "__BkgndObj"
if ( IsHidden() && (GetObjName() == "__BkgndObj") )
GetPageSettings().ReadImgData( rStrm );
else
maGraphic = XclImpDrawing::ReadImgData( GetRoot(), rStrm );
}
}
void XclImpPictureObj::DoReadObj8SubRec( XclImpStream& rStrm, sal_uInt16 nSubRecId, sal_uInt16 nSubRecSize )
{
switch( nSubRecId )
{
case EXC_ID_OBJFLAGS:
ReadFlags8( rStrm );
break;
case EXC_ID_OBJPICTFMLA:
ReadPictFmla( rStrm, rStrm.ReaduInt16() );
break;
default:
XclImpDrawObjBase::DoReadObj8SubRec( rStrm, nSubRecId, nSubRecSize );
}
}
SdrObjectUniquePtr XclImpPictureObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const
{
// try to create an OLE object or form control
SdrObjectUniquePtr xSdrObj( rDffConv.CreateSdrObject( *this, rAnchorRect ) );
// insert a graphic replacement for unsupported ole object ( if none already
// exists ) Hmm ok, it's possibly that there has been some imported
// graphic at a base level but unlikely, normally controls have a valid
// preview in the IMGDATA record ( see below )
// It might be possible to push such an imported graphic up to this
// XclImpPictureObj instance but there are so many layers of indirection I
// don't see an easy way. This way at least ensures that we can
// avoid a 'blank' shape that can result from a failed control import
if ( !xSdrObj && IsOcxControl() && maGraphic.GetType() == GraphicType::NONE )
{
const_cast< XclImpPictureObj* >( this )->maGraphic =
SdrOle2Obj::GetEmptyOLEReplacementGraphic();
}
// no OLE - create a plain picture from IMGDATA record data
if( !xSdrObj && (maGraphic.GetType() != GraphicType::NONE) )
{
xSdrObj.reset(
new SdrGrafObj(
*GetDoc().GetDrawLayer(),
maGraphic,
rAnchorRect));
ConvertRectStyle( *xSdrObj );
}
rDffConv.Progress();
return xSdrObj;
}
OUString XclImpPictureObj::GetObjName() const
{
if( IsOcxControl() )
{
OUString sName( GetObjectManager().GetOleNameOverride( GetTab(), GetObjId() ) );
if (!sName.isEmpty())
return sName;
}
return XclImpDrawObjBase::GetObjName();
}
void XclImpPictureObj::DoPreProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& rSdrObj ) const
{
if( IsOcxControl() )
{
// do not call XclImpRectObj::DoPreProcessSdrObj(), it would trace missing "printable" feature
ProcessControl( *this );
}
else if( mbEmbedded || mbLinked )
{
// trace missing "printable" feature
XclImpRectObj::DoPreProcessSdrObj( rDffConv, rSdrObj );
SfxObjectShell* pDocShell = GetDocShell();
SdrOle2Obj* pOleSdrObj = dynamic_cast< SdrOle2Obj* >( &rSdrObj );
if( pOleSdrObj && pDocShell )
{
comphelper::EmbeddedObjectContainer& rEmbObjCont = pDocShell->GetEmbeddedObjectContainer();
Reference< XEmbeddedObject > xEmbObj = pOleSdrObj->GetObjRef();
OUString aOldName( pOleSdrObj->GetPersistName() );
/* The object persistence should be already in the storage, but
the object still might not be inserted into the container. */
if( rEmbObjCont.HasEmbeddedObject( aOldName ) )
{
if( !rEmbObjCont.HasEmbeddedObject( xEmbObj ) )
// filter code is allowed to call the following method
rEmbObjCont.AddEmbeddedObject( xEmbObj, aOldName );
}
else
{
/* If the object is still not in container it must be inserted
there, the name must be generated in this case. */
OUString aNewName;
rEmbObjCont.InsertEmbeddedObject( xEmbObj, aNewName );
if( aOldName != aNewName )
// SetPersistName, not SetName
pOleSdrObj->SetPersistName( aNewName );
}
}
}
}
void XclImpPictureObj::ReadFlags3( XclImpStream& rStrm )
{
sal_uInt16 nFlags;
nFlags = rStrm.ReaduInt16();
mbSymbol = ::get_flag( nFlags, EXC_OBJ_PIC_SYMBOL );
}
void XclImpPictureObj::ReadFlags8( XclImpStream& rStrm )
{
sal_uInt16 nFlags;
nFlags = rStrm.ReaduInt16();
mbSymbol = ::get_flag( nFlags, EXC_OBJ_PIC_SYMBOL );
mbControl = ::get_flag( nFlags, EXC_OBJ_PIC_CONTROL );
mbUseCtlsStrm = ::get_flag( nFlags, EXC_OBJ_PIC_CTLSSTREAM );
OSL_ENSURE( mbControl || !mbUseCtlsStrm, "XclImpPictureObj::ReadFlags8 - CTLS stream for controls only" );
SetProcessSdrObj( mbControl || !mbUseCtlsStrm );
}
void XclImpPictureObj::ReadPictFmla( XclImpStream& rStrm, sal_uInt16 nLinkSize )
{
std::size_t nLinkEnd = rStrm.GetRecPos() + nLinkSize;
if( nLinkSize >= 6 )
{
sal_uInt16 nFmlaSize;
nFmlaSize = rStrm.ReaduInt16();
OSL_ENSURE( nFmlaSize > 0, "XclImpPictureObj::ReadPictFmla - missing link formula" );
// BIFF3/BIFF4 do not support storages, nothing to do here
if( (nFmlaSize > 0) && (GetBiff() >= EXC_BIFF5) )
{
rStrm.Ignore( 4 );
sal_uInt8 nToken;
nToken = rStrm.ReaduInt8();
// different processing for linked vs. embedded OLE objects
if( nToken == XclTokenArrayHelper::GetTokenId( EXC_TOKID_NAMEX, EXC_TOKCLASS_REF ) )
{
mbLinked = true;
switch( GetBiff() )
{
case EXC_BIFF5:
{
sal_Int16 nRefIdx;
sal_uInt16 nNameIdx;
nRefIdx = rStrm.ReadInt16();
rStrm.Ignore( 8 );
nNameIdx = rStrm.ReaduInt16();
rStrm.Ignore( 12 );
const ExtName* pExtName = GetOldRoot().pExtNameBuff->GetNameByIndex( nRefIdx, nNameIdx );
if( pExtName && pExtName->IsOLE() )
mnStorageId = pExtName->nStorageId;
}
break;
case EXC_BIFF8:
{
sal_uInt16 nXti, nExtName;
nXti = rStrm.ReaduInt16();
nExtName = rStrm.ReaduInt16();
const XclImpExtName* pExtName = GetLinkManager().GetExternName( nXti, nExtName );
if( pExtName && (pExtName->GetType() == xlExtOLE) )
mnStorageId = pExtName->GetStorageId();
}
break;
default:
DBG_ERROR_BIFF();
}
}
else if( nToken == XclTokenArrayHelper::GetTokenId( EXC_TOKID_TBL, EXC_TOKCLASS_NONE ) )
{
mbEmbedded = true;
OSL_ENSURE( nFmlaSize == 5, "XclImpPictureObj::ReadPictFmla - unexpected formula size" );
rStrm.Ignore( nFmlaSize - 1 ); // token ID already read
if( nFmlaSize & 1 )
rStrm.Ignore( 1 ); // padding byte
// a class name may follow inside the picture link
if( rStrm.GetRecPos() + 2 <= nLinkEnd )
{
sal_uInt16 nLen = rStrm.ReaduInt16();
if( nLen > 0 )
maClassName = (GetBiff() == EXC_BIFF8) ? rStrm.ReadUniString( nLen ) : rStrm.ReadRawByteString( nLen );
}
}
// else: ignore other formulas, e.g. pictures linked to cell ranges
}
}
// seek behind picture link data
rStrm.Seek( nLinkEnd );
// read additional data for embedded OLE objects following the picture link
if( IsOcxControl() )
{
// #i26521# form controls to be ignored
if( maClassName == "Forms.HTML:Hidden.1" )
{
SetProcessSdrObj( false );
return;
}
if( rStrm.GetRecLeft() <= 8 ) return;
// position and size of control data in 'Ctls' stream
mnCtlsStrmPos = static_cast< std::size_t >( rStrm.ReaduInt32() );
mnCtlsStrmSize = static_cast< std::size_t >( rStrm.ReaduInt32() );
if( rStrm.GetRecLeft() <= 8 ) return;
// additional string (16-bit characters), e.g. for progress bar control
sal_uInt32 nAddStrSize;
nAddStrSize = rStrm.ReaduInt32();
OSL_ENSURE( rStrm.GetRecLeft() >= nAddStrSize + 4, "XclImpPictureObj::ReadPictFmla - missing data" );
if( rStrm.GetRecLeft() >= nAddStrSize + 4 )
{
rStrm.Ignore( nAddStrSize );
// cell link and source range
ReadCellLinkFormula( rStrm, true );
ReadSourceRangeFormula( rStrm, true );
}
}
else if( mbEmbedded && (rStrm.GetRecLeft() >= 4) )
{
mnStorageId = rStrm.ReaduInt32();
}
}
// DFF stream conversion ======================================================
void XclImpSolverContainer::InsertSdrObjectInfo( SdrObject& rSdrObj, sal_uInt32 nDffShapeId, ShapeFlag nDffFlags )
{
if( nDffShapeId > 0 )
{
maSdrInfoMap[ nDffShapeId ].Set( &rSdrObj, nDffFlags );
maSdrObjMap[ &rSdrObj ] = nDffShapeId;
}
}
void XclImpSolverContainer::RemoveSdrObjectInfo( SdrObject& rSdrObj )
{
// remove info of passed object from the maps
XclImpSdrObjMap::iterator aIt = maSdrObjMap.find( &rSdrObj );
if( aIt != maSdrObjMap.end() )
{
maSdrInfoMap.erase( aIt->second );
maSdrObjMap.erase( aIt );
}
// remove info of all child objects of a group object
if( SdrObjGroup* pGroupObj = dynamic_cast< SdrObjGroup* >( &rSdrObj ) )
{
if( SdrObjList* pSubList = pGroupObj->GetSubList() )
{
// iterate flat over the list because this function already works recursively
SdrObjListIter aObjIt( pSubList, SdrIterMode::Flat );
for( SdrObject* pChildObj = aObjIt.Next(); pChildObj; pChildObj = aObjIt.Next() )
RemoveSdrObjectInfo( *pChildObj );
}
}
}
void XclImpSolverContainer::UpdateConnectorRules()
{
for (auto const & pRule : aCList)
{
UpdateConnection( pRule->nShapeA, pRule->pAObj, &pRule->nSpFlagsA );
UpdateConnection( pRule->nShapeB, pRule->pBObj, &pRule->nSpFlagsB );
UpdateConnection( pRule->nShapeC, pRule->pCObj );
}
}
void XclImpSolverContainer::RemoveConnectorRules()
{
aCList.clear();
maSdrInfoMap.clear();
maSdrObjMap.clear();
}
void XclImpSolverContainer::UpdateConnection( sal_uInt32 nDffShapeId, SdrObject*& rpSdrObj, ShapeFlag* pnDffFlags )
{
XclImpSdrInfoMap::const_iterator aIt = maSdrInfoMap.find( nDffShapeId );
if( aIt != maSdrInfoMap.end() )
{
rpSdrObj = aIt->second.mpSdrObj;
if( pnDffFlags )
*pnDffFlags = aIt->second.mnDffFlags;
}
}
XclImpSimpleDffConverter::XclImpSimpleDffConverter( const XclImpRoot& rRoot, SvStream& rDffStrm ) :
SvxMSDffManager( rDffStrm, rRoot.GetBasePath(), 0, nullptr, rRoot.GetDoc().GetDrawLayer(), 1440, COL_DEFAULT, nullptr ),
XclImpRoot( rRoot )
{
SetSvxMSDffSettings( SVXMSDFF_SETTINGS_CROP_BITMAPS | SVXMSDFF_SETTINGS_IMPORT_EXCEL );
}
XclImpSimpleDffConverter::~XclImpSimpleDffConverter()
{
}
bool XclImpSimpleDffConverter::GetColorFromPalette( sal_uInt16 nIndex, Color& rColor ) const
{
Color nColor = GetPalette().GetColor( nIndex );
if( nColor == COL_AUTO )
return false;
rColor = nColor;
return true;
}
XclImpDffConverter::XclImpDffConvData::XclImpDffConvData(
XclImpDrawing& rDrawing, SdrModel& rSdrModel, SdrPage& rSdrPage ) :
mrDrawing( rDrawing ),
mrSdrModel( rSdrModel ),
mrSdrPage( rSdrPage ),
mnLastCtrlIndex( -1 ),
mbHasCtrlForm( false )
{
}
static const OUStringLiteral gaStdFormName( "Standard" ); /// Standard name of control forms.
XclImpDffConverter::XclImpDffConverter( const XclImpRoot& rRoot, SvStream& rDffStrm ) :
XclImpSimpleDffConverter( rRoot, rDffStrm ),
oox::ole::MSConvertOCXControls( rRoot.GetDocShell()->GetModel() ),
mnOleImpFlags( 0 ),
mbNotifyMacroEventRead(false)
{
const SvtFilterOptions& rFilterOpt = SvtFilterOptions::Get();
if( rFilterOpt.IsMathType2Math() )
mnOleImpFlags |= OLE_MATHTYPE_2_STARMATH;
if( rFilterOpt.IsWinWord2Writer() )
mnOleImpFlags |= OLE_WINWORD_2_STARWRITER;
if( rFilterOpt.IsPowerPoint2Impress() )
mnOleImpFlags |= OLE_POWERPOINT_2_STARIMPRESS;
// try to open the 'Ctls' storage stream containing OCX control properties
mxCtlsStrm = OpenStream( EXC_STREAM_CTLS );
// default text margin (convert EMU to drawing layer units)
mnDefTextMargin = EXC_OBJ_TEXT_MARGIN;
ScaleEmu( mnDefTextMargin );
}
XclImpDffConverter::~XclImpDffConverter()
{
}
OUString XclImpObjectManager::GetOleNameOverride( SCTAB nTab, sal_uInt16 nObjId )
{
OUString sOleName;
OUString sCodeName = GetExtDocOptions().GetCodeName( nTab );
if (mxOleCtrlNameOverride.is() && mxOleCtrlNameOverride->hasByName(sCodeName))
{
Reference< XIndexContainer > xIdToOleName;
mxOleCtrlNameOverride->getByName( sCodeName ) >>= xIdToOleName;
xIdToOleName->getByIndex( nObjId ) >>= sOleName;
}
return sOleName;
}
void XclImpDffConverter::StartProgressBar( std::size_t nProgressSize )
{
mxProgress = std::make_shared<ScfProgressBar>( GetDocShell(), STR_PROGRESS_CALCULATING );
mxProgress->AddSegment( nProgressSize );
mxProgress->Activate();
}
void XclImpDffConverter::Progress( std::size_t nDelta )
{
OSL_ENSURE( mxProgress, "XclImpDffConverter::Progress - invalid call, no progress bar" );
mxProgress->Progress( nDelta );
}
void XclImpDffConverter::InitializeDrawing( XclImpDrawing& rDrawing, SdrModel& rSdrModel, SdrPage& rSdrPage )
{
XclImpDffConvDataRef xConvData = std::make_shared<XclImpDffConvData>( rDrawing, rSdrModel, rSdrPage );
maDataStack.push_back( xConvData );
SetModel( &xConvData->mrSdrModel, 1440 );
}
void XclImpDffConverter::ProcessObject( SdrObjList& rObjList, XclImpDrawObjBase& rDrawObj )
{
if( rDrawObj.IsProcessSdrObj() )
{
if( const XclObjAnchor* pAnchor = rDrawObj.GetAnchor() )
{
tools::Rectangle aAnchorRect = GetConvData().mrDrawing.CalcAnchorRect( *pAnchor, false );
if( rDrawObj.IsValidSize( aAnchorRect ) )
{
// CreateSdrObject() recursively creates embedded child objects
SdrObjectUniquePtr xSdrObj( rDrawObj.CreateSdrObject( *this, aAnchorRect, false ) );
if( xSdrObj )
rDrawObj.PreProcessSdrObject( *this, *xSdrObj );
// call InsertSdrObject() also, if SdrObject is missing
InsertSdrObject( rObjList, rDrawObj, xSdrObj.release() );
}
}
}
}
void XclImpDffConverter::ProcessDrawing( const XclImpDrawObjVector& rDrawObjs )
{
SdrPage& rSdrPage = GetConvData().mrSdrPage;
for( const auto& rxDrawObj : rDrawObjs )
ProcessObject( rSdrPage, *rxDrawObj );
}
void XclImpDffConverter::ProcessDrawing( SvStream& rDffStrm )
{
if( rDffStrm.TellEnd() > 0 )
{
rDffStrm.Seek( STREAM_SEEK_TO_BEGIN );
DffRecordHeader aHeader;
ReadDffRecordHeader( rDffStrm, aHeader );
OSL_ENSURE( aHeader.nRecType == DFF_msofbtDgContainer, "XclImpDffConverter::ProcessDrawing - unexpected record" );
if( aHeader.nRecType == DFF_msofbtDgContainer )
ProcessDgContainer( rDffStrm, aHeader );
}
}
void XclImpDffConverter::FinalizeDrawing()
{
OSL_ENSURE( !maDataStack.empty(), "XclImpDffConverter::FinalizeDrawing - no drawing manager on stack" );
maDataStack.pop_back();
// restore previous model at core DFF converter
if( !maDataStack.empty() )
SetModel( &maDataStack.back()->mrSdrModel, 1440 );
}
void XclImpDffConverter::NotifyMacroEventRead()
{
if (mbNotifyMacroEventRead)
return;
comphelper::DocumentInfo::notifyMacroEventRead(mxModel);
mbNotifyMacroEventRead = true;
}
SdrObjectUniquePtr XclImpDffConverter::CreateSdrObject( const XclImpTbxObjBase& rTbxObj, const tools::Rectangle& rAnchorRect )
{
SdrObjectUniquePtr xSdrObj;
OUString aServiceName = rTbxObj.GetServiceName();
if( SupportsOleObjects() && !aServiceName.isEmpty() ) try
{
// create the form control from scratch
Reference< XFormComponent > xFormComp( ScfApiHelper::CreateInstance( GetDocShell(), aServiceName ), UNO_QUERY_THROW );
// set controls form, needed in virtual function InsertControl()
InitControlForm();
// try to insert the control into the form
css::awt::Size aDummySize;
Reference< XShape > xShape;
XclImpDffConvData& rConvData = GetConvData();
if( rConvData.mxCtrlForm.is() && InsertControl( xFormComp, aDummySize, &xShape, true ) )
{
xSdrObj = rTbxObj.CreateSdrObjectFromShape( xShape, rAnchorRect );
// try to attach a macro to the control
ScriptEventDescriptor aDescriptor;
if( (rConvData.mnLastCtrlIndex >= 0) && rTbxObj.FillMacroDescriptor( aDescriptor ) )
{
NotifyMacroEventRead();
Reference< XEventAttacherManager > xEventMgr( rConvData.mxCtrlForm, UNO_QUERY_THROW );
xEventMgr->registerScriptEvent( rConvData.mnLastCtrlIndex, aDescriptor );
}
}
}
catch( const Exception& )
{
}
return xSdrObj;
}
SdrObjectUniquePtr XclImpDffConverter::CreateSdrObject( const XclImpPictureObj& rPicObj, const tools::Rectangle& rAnchorRect )
{
SdrObjectUniquePtr xSdrObj;
if( SupportsOleObjects() )
{
if( rPicObj.IsOcxControl() )
{
if( mxCtlsStrm.is() ) try
{
/* set controls form, needed in virtual function InsertControl()
called from ReadOCXExcelKludgeStream() */
InitControlForm();
// read from mxCtlsStrm into xShape, insert the control model into the form
Reference< XShape > xShape;
if( GetConvData().mxCtrlForm.is() )
{
Reference< XFormComponent > xFComp;
css::awt::Size aSz; // not used in import
ReadOCXCtlsStream( mxCtlsStrm, xFComp, rPicObj.GetCtlsStreamPos(), rPicObj.GetCtlsStreamSize() );
// recreate the method formerly known as ReadOCXExcelKludgeStream()
if ( xFComp.is() )
{
ScfPropertySet aPropSet( xFComp );
aPropSet.SetStringProperty( "Name", rPicObj.GetObjName() );
InsertControl( xFComp, aSz,&xShape,true);
xSdrObj = rPicObj.CreateSdrObjectFromShape( xShape, rAnchorRect );
}
}
}
catch( const Exception& )
{
}
}
else
{
SfxObjectShell* pDocShell = GetDocShell();
tools::SvRef<SotStorage> xSrcStrg = GetRootStorage();
OUString aStrgName = rPicObj.GetOleStorageName();
if( pDocShell && xSrcStrg.is() && (!aStrgName.isEmpty()) )
{
// first try to resolve graphic from DFF storage
Graphic aGraphic;
tools::Rectangle aVisArea;
if( !GetBLIP( GetPropertyValue( DFF_Prop_pib, 0 ), aGraphic, &aVisArea ) )
{
// if not found, use graphic from object (imported from IMGDATA record)
aGraphic = rPicObj.GetGraphic();
}
if( aGraphic.GetType() != GraphicType::NONE )
{
ErrCode nError = ERRCODE_NONE;
namespace cssea = ::com::sun::star::embed::Aspects;
sal_Int64 nAspects = rPicObj.IsSymbol() ? cssea::MSOLE_ICON : cssea::MSOLE_CONTENT;
xSdrObj.reset(
CreateSdrOLEFromStorage(
GetConvData().mrSdrModel,
aStrgName,
xSrcStrg,
pDocShell->GetStorage(),
aGraphic,
rAnchorRect,
aVisArea,
nullptr,
nError,
mnOleImpFlags,
nAspects,
GetRoot().GetMedium().GetBaseURL()));
}
}
}
}
return xSdrObj;
}
bool XclImpDffConverter::SupportsOleObjects() const
{
return GetConvData().mrDrawing.SupportsOleObjects();
}
// virtual functions ----------------------------------------------------------
void XclImpDffConverter::ProcessClientAnchor2( SvStream& rDffStrm,
DffRecordHeader& rHeader, DffObjData& rObjData )
{
// find the OBJ record data related to the processed shape
XclImpDffConvData& rConvData = GetConvData();
if( XclImpDrawObjBase* pDrawObj = rConvData.mrDrawing.FindDrawObj( rObjData.rSpHd ).get() )
{
OSL_ENSURE( rHeader.nRecType == DFF_msofbtClientAnchor, "XclImpDffConverter::ProcessClientAnchor2 - no client anchor record" );
XclObjAnchor aAnchor;
rHeader.SeekToContent( rDffStrm );
sal_uInt8 nFlags(0);
rDffStrm.ReadUChar( nFlags );
rDffStrm.SeekRel( 1 ); // flags
rDffStrm >> aAnchor; // anchor format equal to BIFF5 OBJ records
pDrawObj->SetAnchor( aAnchor );
rObjData.aChildAnchor = rConvData.mrDrawing.CalcAnchorRect( aAnchor, true );
rObjData.bChildAnchor = true;
// page anchoring is the best approximation we have if mbMove
// is set
rObjData.bPageAnchor = ( nFlags & 0x1 );
}
}
namespace {
struct XclImpDrawObjClientData : public SvxMSDffClientData
{
const XclImpDrawObjBase* m_pTopLevelObj;
XclImpDrawObjClientData()
: m_pTopLevelObj(nullptr)
{
}
virtual void NotifyFreeObj(SdrObject*) override {}
};
}
SdrObject* XclImpDffConverter::ProcessObj( SvStream& rDffStrm, DffObjData& rDffObjData,
SvxMSDffClientData& rClientData, tools::Rectangle& /*rTextRect*/, SdrObject* pOldSdrObj )
{
XclImpDffConvData& rConvData = GetConvData();
/* pOldSdrObj passes a generated SdrObject. This function owns this object
and can modify it. The function has either to return it back to caller
or to delete it by itself. */
SdrObjectUniquePtr xSdrObj( pOldSdrObj );
// find the OBJ record data related to the processed shape
XclImpDrawObjRef xDrawObj = rConvData.mrDrawing.FindDrawObj( rDffObjData.rSpHd );
const tools::Rectangle& rAnchorRect = rDffObjData.aChildAnchor;
// Do not process the global page group shape
bool bGlobalPageGroup( rDffObjData.nSpFlags & ShapeFlag::Patriarch );
if( !xDrawObj || !xDrawObj->IsProcessSdrObj() || bGlobalPageGroup )
return nullptr; // simply return, xSdrObj will be destroyed
/* Pass pointer to top-level object back to caller. If the processed
object is embedded in a group, the pointer is already set to the
top-level parent object. */
XclImpDrawObjClientData& rDrawObjClientData = static_cast<XclImpDrawObjClientData&>(rClientData);
const bool bIsTopLevel = !rDrawObjClientData.m_pTopLevelObj;
if (bIsTopLevel )
rDrawObjClientData.m_pTopLevelObj = xDrawObj.get();
// connectors don't have to be area objects
if( dynamic_cast< SdrEdgeObj* >( xSdrObj.get() ) )
xDrawObj->SetAreaObj( false );
/* Check for valid size for all objects. Needed to ignore lots of invisible
phantom objects from deleted rows or columns (for performance reasons).
#i30816# Include objects embedded in groups.
#i58780# Ignore group shapes, size is not initialized. */
bool bEmbeddedGroup = !bIsTopLevel && dynamic_cast< SdrObjGroup* >( xSdrObj.get() );
if( !bEmbeddedGroup && !xDrawObj->IsValidSize( rAnchorRect ) )
return nullptr; // simply return, xSdrObj will be destroyed
// set shape information from DFF stream
OUString aObjName = GetPropertyString( DFF_Prop_wzName, rDffStrm );
OUString aHyperlink = ReadHlinkProperty( rDffStrm );
bool bVisible = !GetPropertyBool( DFF_Prop_fHidden );
bool bAutoMargin = GetPropertyBool( DFF_Prop_AutoTextMargin );
xDrawObj->SetDffData( rDffObjData, aObjName, aHyperlink, bVisible, bAutoMargin );
/* Connect textbox data (string, alignment, text orientation) to object.
don't ask for a text-ID, DFF export doesn't set one. */
if( XclImpTextObj* pTextObj = dynamic_cast< XclImpTextObj* >( xDrawObj.get() ) )
if( const XclImpObjTextData* pTextData = rConvData.mrDrawing.FindTextData( rDffObjData.rSpHd ) )
pTextObj->SetTextData( *pTextData );
// copy line and fill formatting of TBX form controls from DFF properties
if( XclImpTbxObjBase* pTbxObj = dynamic_cast< XclImpTbxObjBase* >( xDrawObj.get() ) )
pTbxObj->SetDffProperties( *this );
// try to create a custom SdrObject that overwrites the passed object
SdrObjectUniquePtr xNewSdrObj( xDrawObj->CreateSdrObject( *this, rAnchorRect, true ) );
if( xNewSdrObj )
xSdrObj = std::move( xNewSdrObj );
// process the SdrObject
if( xSdrObj )
{
// filled without color -> set system window color
if( GetPropertyBool( DFF_Prop_fFilled ) && !IsProperty( DFF_Prop_fillColor ) )
xSdrObj->SetMergedItem( XFillColorItem( EMPTY_OUSTRING, GetPalette().GetColor( EXC_COLOR_WINDOWBACK ) ) );
// additional processing on the SdrObject
xDrawObj->PreProcessSdrObject( *this, *xSdrObj );
/* If the SdrObject will not be inserted into the draw page, delete it
here. Happens e.g. for notes: The PreProcessSdrObject() call above
has inserted the note into the document, and the SdrObject is not
needed anymore. */
if( !xDrawObj->IsInsertSdrObj() )
xSdrObj.reset();
}
if( xSdrObj )
{
/* Store the relation between shape ID and SdrObject for connectors.
Must be done here (and not in InsertSdrObject() function),
otherwise all SdrObjects embedded in groups would be lost. */
rConvData.maSolverCont.InsertSdrObjectInfo( *xSdrObj, xDrawObj->GetDffShapeId(), xDrawObj->GetDffFlags() );
/* If the drawing object is embedded in a group object, call
PostProcessSdrObject() here. For top-level objects this will be
done automatically in InsertSdrObject() but grouped shapes are
inserted into their groups somewhere in the SvxMSDffManager base
class without chance of notification. Unfortunately, now this is
called before the object is really inserted into its group object,
but that should not have any effect for grouped objects. */
if( !bIsTopLevel )
xDrawObj->PostProcessSdrObject( *this, *xSdrObj );
}
return xSdrObj.release();
}
SdrObject* XclImpDffConverter::FinalizeObj(DffObjData& rDffObjData, SdrObject* pOldSdrObj )
{
XclImpDffConvData& rConvData = GetConvData();
/* pOldSdrObj passes a generated SdrObject. This function owns this object
and can modify it. The function has either to return it back to caller
or to delete it by itself. */
SdrObjectUniquePtr xSdrObj( pOldSdrObj );
// find the OBJ record data related to the processed shape
XclImpDrawObjRef xDrawObj = rConvData.mrDrawing.FindDrawObj( rDffObjData.rSpHd );
if( xSdrObj && xDrawObj )
{
// cell anchoring
if ( !rDffObjData.bPageAnchor )
ScDrawLayer::SetCellAnchoredFromPosition( *xSdrObj, GetDoc(), xDrawObj->GetTab(), false );
}
return xSdrObj.release();
}
bool XclImpDffConverter::InsertControl( const Reference< XFormComponent >& rxFormComp,
const css::awt::Size& /*rSize*/, Reference< XShape >* pxShape,
bool /*bFloatingCtrl*/ )
{
if( GetDocShell() ) try
{
XclImpDffConvData& rConvData = GetConvData();
Reference< XIndexContainer > xFormIC( rConvData.mxCtrlForm, UNO_QUERY_THROW );
Reference< XControlModel > xCtrlModel( rxFormComp, UNO_QUERY_THROW );
// create the control shape
Reference< XShape > xShape( ScfApiHelper::CreateInstance( GetDocShell(), "com.sun.star.drawing.ControlShape" ), UNO_QUERY_THROW );
Reference< XControlShape > xCtrlShape( xShape, UNO_QUERY_THROW );
// insert the new control into the form
sal_Int32 nNewIndex = xFormIC->getCount();
xFormIC->insertByIndex( nNewIndex, Any( rxFormComp ) );
// on success: store new index of the control for later use (macro events)
rConvData.mnLastCtrlIndex = nNewIndex;
// set control model at control shape and pass back shape to caller
xCtrlShape->setControl( xCtrlModel );
if( pxShape ) *pxShape = xShape;
return true;
}
catch( const Exception& )
{
OSL_FAIL( "XclImpDffConverter::InsertControl - cannot create form control" );
}
return false;
}
// private --------------------------------------------------------------------
XclImpDffConverter::XclImpDffConvData& XclImpDffConverter::GetConvData()
{
OSL_ENSURE( !maDataStack.empty(), "XclImpDffConverter::GetConvData - no drawing manager on stack" );
return *maDataStack.back();
}
const XclImpDffConverter::XclImpDffConvData& XclImpDffConverter::GetConvData() const
{
OSL_ENSURE( !maDataStack.empty(), "XclImpDffConverter::GetConvData - no drawing manager on stack" );
return *maDataStack.back();
}
OUString XclImpDffConverter::ReadHlinkProperty( SvStream& rDffStrm ) const
{
/* Reads hyperlink data from a complex DFF property. Contents of this
property are equal to the HLINK record, import of this record is
implemented in class XclImpHyperlink. This function has to create an
instance of the XclImpStream class to be able to reuse the
functionality of XclImpHyperlink. */
OUString aString;
sal_uInt32 nBufferSize = GetPropertyValue( DFF_Prop_pihlShape, 0 );
if( (0 < nBufferSize) && (nBufferSize <= 0xFFFF) && SeekToContent( DFF_Prop_pihlShape, rDffStrm ) )
{
// create a faked BIFF record that can be read by XclImpStream class
SvMemoryStream aMemStream;
aMemStream.WriteUInt16( 0 ).WriteUInt16( nBufferSize );
// copy from DFF stream to memory stream
::std::vector< sal_uInt8 > aBuffer( nBufferSize );
sal_uInt8* pnData = aBuffer.data();
if (rDffStrm.ReadBytes(pnData, nBufferSize) == nBufferSize)
{
aMemStream.WriteBytes(pnData, nBufferSize);
// create BIFF import stream to be able to use XclImpHyperlink class
XclImpStream aXclStrm( aMemStream, GetRoot() );
if( aXclStrm.StartNextRecord() )
aString = XclImpHyperlink::ReadEmbeddedData( aXclStrm );
}
}
return aString;
}
bool XclImpDffConverter::ProcessDgContainer( SvStream& rDffStrm, const DffRecordHeader& rDgHeader )
{
std::size_t nEndPos = rDgHeader.GetRecEndFilePos();
bool isBreak(false);
while (!isBreak && rDffStrm.good() && rDffStrm.Tell() < nEndPos)
{
DffRecordHeader aHeader;
ReadDffRecordHeader( rDffStrm, aHeader );
switch( aHeader.nRecType )
{
case DFF_msofbtSolverContainer:
isBreak = !ProcessSolverContainer( rDffStrm, aHeader );
break;
case DFF_msofbtSpgrContainer:
isBreak = !ProcessShGrContainer( rDffStrm, aHeader );
break;
default:
isBreak = !aHeader.SeekToEndOfRecord( rDffStrm );
}
}
// seek to end of drawing page container
isBreak = !rDgHeader.SeekToEndOfRecord( rDffStrm );
// #i12638# #i37900# connector rules
XclImpSolverContainer& rSolverCont = GetConvData().maSolverCont;
rSolverCont.UpdateConnectorRules();
SolveSolver( rSolverCont );
rSolverCont.RemoveConnectorRules();
return !isBreak;
}
bool XclImpDffConverter::ProcessShGrContainer( SvStream& rDffStrm, const DffRecordHeader& rShGrHeader )
{
std::size_t nEndPos = rShGrHeader.GetRecEndFilePos();
bool isBreak(false);
while (!isBreak && rDffStrm.good() && rDffStrm.Tell() < nEndPos)
{
DffRecordHeader aHeader;
ReadDffRecordHeader( rDffStrm, aHeader );
switch( aHeader.nRecType )
{
case DFF_msofbtSpgrContainer:
case DFF_msofbtSpContainer:
isBreak = !ProcessShContainer( rDffStrm, aHeader );
break;
default:
isBreak = !aHeader.SeekToEndOfRecord( rDffStrm );
}
}
// seek to end of shape group container
return rShGrHeader.SeekToEndOfRecord( rDffStrm ) && !isBreak;
}
bool XclImpDffConverter::ProcessSolverContainer( SvStream& rDffStrm, const DffRecordHeader& rSolverHeader )
{
// solver container wants to read the solver container header again
rSolverHeader.SeekToBegOfRecord( rDffStrm );
// read the entire solver container
ReadSvxMSDffSolverContainer( rDffStrm, GetConvData().maSolverCont );
// seek to end of solver container
return rSolverHeader.SeekToEndOfRecord( rDffStrm );
}
bool XclImpDffConverter::ProcessShContainer( SvStream& rDffStrm, const DffRecordHeader& rShHeader )
{
rShHeader.SeekToBegOfRecord( rDffStrm );
tools::Rectangle aDummy;
XclImpDrawObjClientData aDrawObjClientData;
/* The call to ImportObj() creates and returns a new SdrObject for the
processed shape. We take ownership of the returned object here. If the
shape is a group object, all embedded objects are created recursively,
and the returned group object contains them all. ImportObj() calls the
virtual functions ProcessClientAnchor2() and ProcessObj() and writes
the pointer to the related draw object data (OBJ record) into aDrawObjClientData. */
SdrObjectUniquePtr xSdrObj( ImportObj( rDffStrm, aDrawObjClientData, aDummy, aDummy, /*nCalledByGroup*/0, /*pShapeId*/nullptr ) );
if (aDrawObjClientData.m_pTopLevelObj && xSdrObj )
InsertSdrObject( GetConvData().mrSdrPage, *aDrawObjClientData.m_pTopLevelObj, xSdrObj.release() );
return rShHeader.SeekToEndOfRecord( rDffStrm );
}
void XclImpDffConverter::InsertSdrObject( SdrObjList& rObjList, const XclImpDrawObjBase& rDrawObj, SdrObject* pSdrObj )
{
XclImpDffConvData& rConvData = GetConvData();
/* Take ownership of the passed object. If insertion fails (e.g. rDrawObj
states to skip insertion), the object is automatically deleted. */
SdrObjectUniquePtr xSdrObj( pSdrObj );
if( xSdrObj && rDrawObj.IsInsertSdrObj() )
{
rObjList.NbcInsertObject( xSdrObj.release() );
// callback to drawing manager for e.g. tracking of used sheet area
rConvData.mrDrawing.OnObjectInserted( rDrawObj );
// callback to drawing object for post processing (use pSdrObj, xSdrObj already released)
rDrawObj.PostProcessSdrObject( *this, *pSdrObj );
}
/* SdrObject still here? Insertion failed, remove data from shape ID map.
The SdrObject will be destructed then. */
if( xSdrObj )
rConvData.maSolverCont.RemoveSdrObjectInfo( *xSdrObj );
}
void XclImpDffConverter::InitControlForm()
{
XclImpDffConvData& rConvData = GetConvData();
if( rConvData.mbHasCtrlForm )
return;
rConvData.mbHasCtrlForm = true;
if( SupportsOleObjects() ) try
{
Reference< XFormsSupplier > xFormsSupplier( rConvData.mrSdrPage.getUnoPage(), UNO_QUERY_THROW );
Reference< XNameContainer > xFormsNC( xFormsSupplier->getForms(), UNO_SET_THROW );
// find or create the Standard form used to insert the imported controls
if( xFormsNC->hasByName( gaStdFormName ) )
{
xFormsNC->getByName( gaStdFormName ) >>= rConvData.mxCtrlForm;
}
else if( SfxObjectShell* pDocShell = GetDocShell() )
{
rConvData.mxCtrlForm.set( ScfApiHelper::CreateInstance( pDocShell, "com.sun.star.form.component.Form" ), UNO_QUERY_THROW );
xFormsNC->insertByName( gaStdFormName, Any( rConvData.mxCtrlForm ) );
}
}
catch( const Exception& )
{
}
}
// Drawing manager ============================================================
XclImpDrawing::XclImpDrawing( const XclImpRoot& rRoot, bool bOleObjects ) :
XclImpRoot( rRoot ),
mbOleObjs( bOleObjects )
{
}
XclImpDrawing::~XclImpDrawing()
{
}
Graphic XclImpDrawing::ReadImgData( const XclImpRoot& rRoot, XclImpStream& rStrm )
{
Graphic aGraphic;
sal_uInt16 nFormat = rStrm.ReaduInt16();
rStrm.Ignore( 2 );//nEnv
sal_uInt32 nDataSize = rStrm.ReaduInt32();
if( nDataSize <= rStrm.GetRecLeft() )
{
switch( nFormat )
{
case EXC_IMGDATA_WMF: ReadWmf( aGraphic, rStrm ); break;
case EXC_IMGDATA_BMP: ReadBmp( aGraphic, rRoot, rStrm ); break;
default: OSL_FAIL( "XclImpDrawing::ReadImgData - unknown image format" );
}
}
return aGraphic;
}
void XclImpDrawing::ReadObj( XclImpStream& rStrm )
{
XclImpDrawObjRef xDrawObj;
/* #i61786# In BIFF8 streams, OBJ records may occur without MSODRAWING
records. In this case, the OBJ records are in BIFF5 format. Do a sanity
check here that there is no DFF data loaded before. */
OSL_ENSURE( maDffStrm.Tell() == 0, "XclImpDrawing::ReadObj - unexpected DFF stream data, OBJ will be ignored" );
if( maDffStrm.Tell() == 0 ) switch( GetBiff() )
{
case EXC_BIFF3:
xDrawObj = XclImpDrawObjBase::ReadObj3( GetRoot(), rStrm );
break;
case EXC_BIFF4:
xDrawObj = XclImpDrawObjBase::ReadObj4( GetRoot(), rStrm );
break;
case EXC_BIFF5:
case EXC_BIFF8:
xDrawObj = XclImpDrawObjBase::ReadObj5( GetRoot(), rStrm );
break;
default:
DBG_ERROR_BIFF();
}
if( xDrawObj )
{
// insert into maRawObjs or into the last open group object
maRawObjs.InsertGrouped( xDrawObj );
// to be able to find objects by ID
maObjMapId[ xDrawObj->GetObjId() ] = xDrawObj;
}
}
void XclImpDrawing::ReadMsoDrawing( XclImpStream& rStrm )
{
OSL_ENSURE_BIFF( GetBiff() == EXC_BIFF8 );
// disable internal CONTINUE handling
rStrm.ResetRecord( false );
// read leading MSODRAWING record
ReadDffRecord( rStrm );
// read following drawing records, but do not start following unrelated record
bool bLoop = true;
while( bLoop ) switch( rStrm.GetNextRecId() )
{
case EXC_ID_MSODRAWING:
case EXC_ID_MSODRAWINGSEL:
case EXC_ID_CONT:
rStrm.StartNextRecord();
ReadDffRecord( rStrm );
break;
case EXC_ID_OBJ:
rStrm.StartNextRecord();
ReadObj8( rStrm );
break;
case EXC_ID_TXO:
rStrm.StartNextRecord();
ReadTxo( rStrm );
break;
default:
bLoop = false;
}
// re-enable internal CONTINUE handling
rStrm.ResetRecord( true );
}
XclImpDrawObjRef XclImpDrawing::FindDrawObj( const DffRecordHeader& rHeader ) const
{
/* maObjMap stores objects by position of the client data (OBJ record) in
the DFF stream, which is always behind shape start position of the
passed header. The function upper_bound() finds the first element in
the map whose key is greater than the start position of the header. Its
end position is used to test whether the found object is really related
to the shape. */
XclImpDrawObjRef xDrawObj;
XclImpObjMap::const_iterator aIt = maObjMap.upper_bound( rHeader.GetRecBegFilePos() );
if( (aIt != maObjMap.end()) && (aIt->first <= rHeader.GetRecEndFilePos()) )
xDrawObj = aIt->second;
return xDrawObj;
}
XclImpDrawObjRef XclImpDrawing::FindDrawObj( sal_uInt16 nObjId ) const
{
XclImpDrawObjRef xDrawObj;
XclImpObjMapById::const_iterator aIt = maObjMapId.find( nObjId );
if( aIt != maObjMapId.end() )
xDrawObj = aIt->second;
return xDrawObj;
}
const XclImpObjTextData* XclImpDrawing::FindTextData( const DffRecordHeader& rHeader ) const
{
/* maTextMap stores textbox data by position of the client data (TXO
record) in the DFF stream, which is always behind shape start position
of the passed header. The function upper_bound() finds the first
element in the map whose key is greater than the start position of the
header. Its end position is used to test whether the found object is
really related to the shape. */
XclImpObjTextMap::const_iterator aIt = maTextMap.upper_bound( rHeader.GetRecBegFilePos() );
if( (aIt != maTextMap.end()) && (aIt->first <= rHeader.GetRecEndFilePos()) )
return aIt->second.get();
return nullptr;
}
void XclImpDrawing::SetSkipObj( sal_uInt16 nObjId )
{
maSkipObjs.push_back( nObjId );
}
std::size_t XclImpDrawing::GetProgressSize() const
{
return std::accumulate(maObjMap.begin(), maObjMap.end(), maRawObjs.GetProgressSize(),
[](const std::size_t& rSum, const XclImpObjMap::value_type& rEntry) { return rSum + rEntry.second->GetProgressSize(); });
}
void XclImpDrawing::ImplConvertObjects( XclImpDffConverter& rDffConv, SdrModel& rSdrModel, SdrPage& rSdrPage )
{
//rhbz#636521, disable undo during conversion. faster, smaller and stops
//temp objects being inserted into the undo list
bool bOrigUndoStatus = rSdrModel.IsUndoEnabled();
rSdrModel.EnableUndo(false);
// register this drawing manager at the passed (global) DFF manager
rDffConv.InitializeDrawing( *this, rSdrModel, rSdrPage );
// process list of objects to be skipped
for( const auto& rSkipObj : maSkipObjs )
if( XclImpDrawObjBase* pDrawObj = FindDrawObj( rSkipObj ).get() )
pDrawObj->SetProcessSdrObj( false );
// process drawing objects without DFF data
rDffConv.ProcessDrawing( maRawObjs );
// process all objects in the DFF stream
rDffConv.ProcessDrawing( maDffStrm );
// unregister this drawing manager at the passed (global) DFF manager
rDffConv.FinalizeDrawing();
rSdrModel.EnableUndo(bOrigUndoStatus);
}
// protected ------------------------------------------------------------------
void XclImpDrawing::AppendRawObject( const XclImpDrawObjRef& rxDrawObj )
{
OSL_ENSURE( rxDrawObj, "XclImpDrawing::AppendRawObject - unexpected empty reference" );
maRawObjs.push_back( rxDrawObj );
}
// private --------------------------------------------------------------------
void XclImpDrawing::ReadWmf( Graphic& rGraphic, XclImpStream& rStrm ) // static helper
{
// extract graphic data from IMGDATA and following CONTINUE records
rStrm.Ignore( 8 );
SvMemoryStream aMemStrm;
rStrm.CopyToStream( aMemStrm, rStrm.GetRecLeft() );
aMemStrm.Seek( STREAM_SEEK_TO_BEGIN );
// import the graphic from memory stream
GDIMetaFile aGDIMetaFile;
if( ::ReadWindowMetafile( aMemStrm, aGDIMetaFile ) )
rGraphic = aGDIMetaFile;
}
void XclImpDrawing::ReadBmp( Graphic& rGraphic, const XclImpRoot& rRoot, XclImpStream& rStrm ) // static helper
{
// extract graphic data from IMGDATA and following CONTINUE records
SvMemoryStream aMemStrm;
/* Excel 3 and 4 seem to write broken BMP data. Usually they write a
DIBCOREHEADER (12 bytes) containing width, height, planes = 1, and
pixel depth = 32 bit. After that, 3 unused bytes are added before the
actual pixel data. This does even confuse Excel 5 and later, which
cannot read the image data correctly. */
if( rRoot.GetBiff() <= EXC_BIFF4 )
{
rStrm.PushPosition();
sal_uInt32 nHdrSize;
sal_uInt16 nWidth, nHeight, nPlanes, nDepth;
nHdrSize = rStrm.ReaduInt32();
nWidth = rStrm.ReaduInt16();
nHeight = rStrm.ReaduInt16();
nPlanes = rStrm.ReaduInt16();
nDepth = rStrm.ReaduInt16();
if( (nHdrSize == 12) && (nPlanes == 1) && (nDepth == 32) )
{
rStrm.Ignore( 3 );
aMemStrm.SetEndian( SvStreamEndian::LITTLE );
aMemStrm.WriteUInt32( nHdrSize ).WriteUInt16( nWidth ).WriteUInt16( nHeight ).WriteUInt16( nPlanes ).WriteUInt16( nDepth );
rStrm.CopyToStream( aMemStrm, rStrm.GetRecLeft() );
}
rStrm.PopPosition();
}
// no special handling above -> just copy the remaining record data
if( aMemStrm.Tell() == 0 )
rStrm.CopyToStream( aMemStrm, rStrm.GetRecLeft() );
// import the graphic from memory stream
aMemStrm.Seek( STREAM_SEEK_TO_BEGIN );
Bitmap aBitmap;
if( ReadDIB(aBitmap, aMemStrm, false) ) // read DIB without file header
rGraphic = aBitmap;
}
void XclImpDrawing::ReadDffRecord( XclImpStream& rStrm )
{
maDffStrm.Seek( STREAM_SEEK_TO_END );
rStrm.CopyRecordToStream( maDffStrm );
}
void XclImpDrawing::ReadObj8( XclImpStream& rStrm )
{
XclImpDrawObjRef xDrawObj = XclImpDrawObjBase::ReadObj8( GetRoot(), rStrm );
// store the new object in the internal containers
maObjMap[ maDffStrm.Tell() ] = xDrawObj;
maObjMapId[ xDrawObj->GetObjId() ] = xDrawObj;
}
void XclImpDrawing::ReadTxo( XclImpStream& rStrm )
{
XclImpObjTextRef xTextData = std::make_shared<XclImpObjTextData>();
maTextMap[ maDffStrm.Tell() ] = xTextData;
// 1) read the TXO record
xTextData->maData.ReadTxo8( rStrm );
// 2) first CONTINUE with string
xTextData->mxString.reset();
bool bValid = true;<--- Variable 'bValid' is assigned a value that is never used.
if( xTextData->maData.mnTextLen > 0 )
{
bValid = (rStrm.GetNextRecId() == EXC_ID_CONT) && rStrm.StartNextRecord();
OSL_ENSURE( bValid, "XclImpDrawing::ReadTxo - missing CONTINUE record" );
if( bValid )
xTextData->mxString = std::make_shared<XclImpString>( rStrm.ReadUniString( xTextData->maData.mnTextLen ) );
}
// 3) second CONTINUE with formatting runs
if( xTextData->maData.mnFormatSize > 0 )
{
bValid = (rStrm.GetNextRecId() == EXC_ID_CONT) && rStrm.StartNextRecord();
OSL_ENSURE( bValid, "XclImpDrawing::ReadTxo - missing CONTINUE record" );
if( bValid )
xTextData->ReadFormats( rStrm );
}
}
XclImpSheetDrawing::XclImpSheetDrawing( const XclImpRoot& rRoot, SCTAB nScTab ) :
XclImpDrawing( rRoot, true ),
maScUsedArea( ScAddress::INITIALIZE_INVALID )
{
maScUsedArea.aStart.SetTab( nScTab );
maScUsedArea.aEnd.SetTab( nScTab );
}
void XclImpSheetDrawing::ReadNote( XclImpStream& rStrm )
{
switch( GetBiff() )
{
case EXC_BIFF2:
case EXC_BIFF3:
case EXC_BIFF4:
case EXC_BIFF5:
ReadNote3( rStrm );
break;
case EXC_BIFF8:
ReadNote8( rStrm );
break;
default:
DBG_ERROR_BIFF();
}
}
void XclImpSheetDrawing::ReadTabChart( XclImpStream& rStrm )
{
OSL_ENSURE_BIFF( GetBiff() >= EXC_BIFF5 );
auto xChartObj = std::make_shared<XclImpChartObj>( GetRoot(), true );
xChartObj->ReadChartSubStream( rStrm );
// insert the chart as raw object without connected DFF data
AppendRawObject( xChartObj );
}
void XclImpSheetDrawing::ConvertObjects( XclImpDffConverter& rDffConv )
{
if( SdrModel* pSdrModel = GetDoc().GetDrawLayer() )
if( SdrPage* pSdrPage = GetSdrPage( maScUsedArea.aStart.Tab() ) )
ImplConvertObjects( rDffConv, *pSdrModel, *pSdrPage );
}
tools::Rectangle XclImpSheetDrawing::CalcAnchorRect( const XclObjAnchor& rAnchor, bool /*bDffAnchor*/ ) const
{
return rAnchor.GetRect( GetRoot(), maScUsedArea.aStart.Tab(), MapUnit::Map100thMM );
}
void XclImpSheetDrawing::OnObjectInserted( const XclImpDrawObjBase& rDrawObj )
{
ScRange aScObjArea = rDrawObj.GetUsedArea( maScUsedArea.aStart.Tab() );
if( aScObjArea.IsValid() )
maScUsedArea.ExtendTo( aScObjArea );
}
// private --------------------------------------------------------------------
void XclImpSheetDrawing::ReadNote3( XclImpStream& rStrm )
{
XclAddress aXclPos;
sal_uInt16 nTotalLen;
rStrm >> aXclPos;
nTotalLen = rStrm.ReaduInt16();
ScAddress aScNotePos( ScAddress::UNINITIALIZED );
if( GetAddressConverter().ConvertAddress( aScNotePos, aXclPos, maScUsedArea.aStart.Tab(), true ) )
{
sal_uInt16 nPartLen = ::std::min( nTotalLen, static_cast< sal_uInt16 >( rStrm.GetRecLeft() ) );
OUStringBuffer aNoteText = rStrm.ReadRawByteString( nPartLen );
nTotalLen = nTotalLen - nPartLen;
while( (nTotalLen > 0) && (rStrm.GetNextRecId() == EXC_ID_NOTE) && rStrm.StartNextRecord() )
{
rStrm >> aXclPos;
nPartLen = rStrm.ReaduInt16();
OSL_ENSURE( aXclPos.mnRow == 0xFFFF, "XclImpObjectManager::ReadNote3 - missing continuation NOTE record" );
if( aXclPos.mnRow == 0xFFFF )
{
OSL_ENSURE( nPartLen <= nTotalLen, "XclImpObjectManager::ReadNote3 - string too long" );
aNoteText.append(rStrm.ReadRawByteString( nPartLen ));
nTotalLen = nTotalLen - ::std::min( nTotalLen, nPartLen );
}
else
{
// seems to be a new note, record already started -> load the note
rStrm.Seek( EXC_REC_SEEK_TO_BEGIN );
ReadNote( rStrm );
nTotalLen = 0;
}
}
ScNoteUtil::CreateNoteFromString( GetDoc(), aScNotePos, aNoteText.makeStringAndClear(), false, false );
}
}
void XclImpSheetDrawing::ReadNote8( XclImpStream& rStrm )
{
XclAddress aXclPos;
sal_uInt16 nFlags, nObjId;
rStrm >> aXclPos;
nFlags = rStrm.ReaduInt16();
nObjId = rStrm.ReaduInt16();
ScAddress aScNotePos( ScAddress::UNINITIALIZED );
if( GetAddressConverter().ConvertAddress( aScNotePos, aXclPos, maScUsedArea.aStart.Tab(), true ) )
if( nObjId != EXC_OBJ_INVALID_ID )
if( XclImpNoteObj* pNoteObj = dynamic_cast< XclImpNoteObj* >( FindDrawObj( nObjId ).get() ) )
pNoteObj->SetNoteData( aScNotePos, nFlags );
}
// The object manager =========================================================
XclImpObjectManager::XclImpObjectManager( const XclImpRoot& rRoot ) :
XclImpRoot( rRoot )
{
maDefObjNames[ EXC_OBJTYPE_GROUP ] = "Group";
maDefObjNames[ EXC_OBJTYPE_LINE ] = ScResId( STR_SHAPE_LINE );
maDefObjNames[ EXC_OBJTYPE_RECTANGLE ] = ScResId( STR_SHAPE_RECTANGLE );
maDefObjNames[ EXC_OBJTYPE_OVAL ] = ScResId( STR_SHAPE_OVAL );
maDefObjNames[ EXC_OBJTYPE_ARC ] = "Arc";
maDefObjNames[ EXC_OBJTYPE_CHART ] = "Chart";
maDefObjNames[ EXC_OBJTYPE_TEXT ] = "Text";
maDefObjNames[ EXC_OBJTYPE_BUTTON ] = ScResId( STR_FORM_BUTTON );
maDefObjNames[ EXC_OBJTYPE_PICTURE ] = "Picture";
maDefObjNames[ EXC_OBJTYPE_POLYGON ] = "Freeform";
maDefObjNames[ EXC_OBJTYPE_CHECKBOX ] = ScResId( STR_FORM_CHECKBOX );
maDefObjNames[ EXC_OBJTYPE_OPTIONBUTTON ] = ScResId( STR_FORM_OPTIONBUTTON );
maDefObjNames[ EXC_OBJTYPE_EDIT ] = "Edit Box";
maDefObjNames[ EXC_OBJTYPE_LABEL ] = ScResId( STR_FORM_LABEL );
maDefObjNames[ EXC_OBJTYPE_DIALOG ] = "Dialog Frame";
maDefObjNames[ EXC_OBJTYPE_SPIN ] = ScResId( STR_FORM_SPINNER );
maDefObjNames[ EXC_OBJTYPE_SCROLLBAR ] = ScResId( STR_FORM_SCROLLBAR );
maDefObjNames[ EXC_OBJTYPE_LISTBOX ] = ScResId( STR_FORM_LISTBOX );
maDefObjNames[ EXC_OBJTYPE_GROUPBOX ] = ScResId( STR_FORM_GROUPBOX );
maDefObjNames[ EXC_OBJTYPE_DROPDOWN ] = ScResId( STR_FORM_DROPDOWN );
maDefObjNames[ EXC_OBJTYPE_NOTE ] = "Comment";
maDefObjNames[ EXC_OBJTYPE_DRAWING ] = ScResId( STR_SHAPE_AUTOSHAPE );
}
XclImpObjectManager::~XclImpObjectManager()
{
}
void XclImpObjectManager::ReadMsoDrawingGroup( XclImpStream& rStrm )
{
OSL_ENSURE_BIFF( GetBiff() == EXC_BIFF8 );
// Excel continues this record with MSODRAWINGGROUP and CONTINUE records, hmm.
rStrm.ResetRecord( true, EXC_ID_MSODRAWINGGROUP );
maDggStrm.Seek( STREAM_SEEK_TO_END );
rStrm.CopyRecordToStream( maDggStrm );
}
XclImpSheetDrawing& XclImpObjectManager::GetSheetDrawing( SCTAB nScTab )
{
XclImpSheetDrawingRef& rxDrawing = maSheetDrawings[ nScTab ];
if( !rxDrawing )
rxDrawing = std::make_shared<XclImpSheetDrawing>( GetRoot(), nScTab );
return *rxDrawing;
}
void XclImpObjectManager::ConvertObjects()
{
// do nothing if the document does not contain a drawing layer
if( !GetDoc().GetDrawLayer() )
return;
// get total progress bar size for all sheet drawing managers
std::size_t nProgressSize = std::accumulate(maSheetDrawings.begin(), maSheetDrawings.end(), std::size_t(0),
[](const std::size_t& rSum, const XclImpSheetDrawingMap::value_type& rEntry) { return rSum + rEntry.second->GetProgressSize(); });
// nothing to do if progress bar is zero (no objects present)
if( nProgressSize == 0 )
return;
XclImpDffConverter aDffConv( GetRoot(), maDggStrm );
aDffConv.StartProgressBar( nProgressSize );
for( auto& rEntry : maSheetDrawings )
rEntry.second->ConvertObjects( aDffConv );
// #i112436# don't call ScChartListenerCollection::SetDirty here,
// instead use InterpretDirtyCells in ScDocument::CalcAfterLoad.
}
OUString XclImpObjectManager::GetDefaultObjName( const XclImpDrawObjBase& rDrawObj ) const
{
OUStringBuffer aDefName;
DefObjNameMap::const_iterator aIt = maDefObjNames.find( rDrawObj.GetObjType() );
if( aIt != maDefObjNames.end() )
aDefName.append(aIt->second);
return aDefName.append(' ').append(static_cast<sal_Int32>(rDrawObj.GetObjId())).makeStringAndClear();
}
ScRange XclImpObjectManager::GetUsedArea( SCTAB nScTab ) const
{
XclImpSheetDrawingMap::const_iterator aIt = maSheetDrawings.find( nScTab );
if( aIt != maSheetDrawings.end() )
return aIt->second->GetUsedArea();
return ScRange( ScAddress::INITIALIZE_INVALID );
}
// DFF property set helper ====================================================
XclImpDffPropSet::XclImpDffPropSet( const XclImpRoot& rRoot ) :
XclImpRoot( rRoot ),
maDffConv( rRoot, maDummyStrm )
{
}
void XclImpDffPropSet::Read( XclImpStream& rStrm )
{
sal_uInt32 nPropSetSize;
rStrm.PushPosition();
rStrm.Ignore( 4 );
nPropSetSize = rStrm.ReaduInt32();
rStrm.PopPosition();
mxMemStrm.reset( new SvMemoryStream );
rStrm.CopyToStream( *mxMemStrm, 8 + nPropSetSize );
mxMemStrm->Seek( STREAM_SEEK_TO_BEGIN );
maDffConv.ReadPropSet( *mxMemStrm, nullptr );
}
sal_uInt32 XclImpDffPropSet::GetPropertyValue( sal_uInt16 nPropId ) const
{
return maDffConv.GetPropertyValue( nPropId, 0 );
}
void XclImpDffPropSet::FillToItemSet( SfxItemSet& rItemSet ) const
{
if( mxMemStrm )
maDffConv.ApplyAttributes( *mxMemStrm, rItemSet );
}
XclImpStream& operator>>( XclImpStream& rStrm, XclImpDffPropSet& rPropSet )
{
rPropSet.Read( rStrm );
return rStrm;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|