1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
|
/* -*- 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 <utility>
#include <comphelper/configurationlistener.hxx>
#include <comphelper/propertysequence.hxx>
#include <comphelper/propertyvalue.hxx>
#include <tools/color.hxx>
#include <svl/numformat.hxx>
#include <svl/poolitem.hxx>
#include <svl/itemset.hxx>
#include <svl/itempool.hxx>
#include <vcl/commandinfoprovider.hxx>
#include <vcl/event.hxx>
#include <vcl/toolbox.hxx>
#include <vcl/customweld.hxx>
#include <vcl/vclptr.hxx>
#include <vcl/weldutils.hxx>
#include <svtools/valueset.hxx>
#include <svtools/ctrlbox.hxx>
#include <svl/style.hxx>
#include <svtools/ctrltool.hxx>
#include <svtools/borderhelper.hxx>
#include <vcl/InterimItemWindow.hxx>
#include <sfx2/tbxctrl.hxx>
#include <sfx2/tplpitem.hxx>
#include <sfx2/sfxstatuslistener.hxx>
#include <sfx2/viewsh.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <sfx2/viewfrm.hxx>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <vcl/virdev.hxx>
#include <com/sun/star/awt/FontDescriptor.hpp>
#include <com/sun/star/table/BorderLine2.hpp>
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
#include <com/sun/star/frame/XDispatchProvider.hpp>
#include <com/sun/star/frame/XFrame.hpp>
#include <svx/strings.hrc>
#include <svx/svxids.hrc>
#include <helpids.h>
#include <sfx2/sidebar/Sidebar.hxx>
#include <svx/xtable.hxx>
#include <editeng/editids.hrc>
#include <editeng/fontitem.hxx>
#include <editeng/fhgtitem.hxx>
#include <editeng/boxitem.hxx>
#include <editeng/charreliefitem.hxx>
#include <editeng/contouritem.hxx>
#include <editeng/colritem.hxx>
#include <editeng/crossedoutitem.hxx>
#include <editeng/emphasismarkitem.hxx>
#include <editeng/flstitem.hxx>
#include <editeng/lineitem.hxx>
#include <editeng/postitem.hxx>
#include <editeng/shdditem.hxx>
#include <editeng/udlnitem.hxx>
#include <editeng/wghtitem.hxx>
#include <editeng/svxfont.hxx>
#include <editeng/cmapitem.hxx>
#include <svx/colorwindow.hxx>
#include <svx/colorbox.hxx>
#include <svx/tbcontrl.hxx>
#include <svx/dialmgr.hxx>
#include <svx/PaletteManager.hxx>
#include <memory>
#include <tbxcolorupdate.hxx>
#include <editeng/eerdll.hxx>
#include <editeng/editrids.hrc>
#include <svx/xdef.hxx>
#include <svx/xfillit0.hxx>
#include <svx/xflclit.hxx>
#include <svl/currencytable.hxx>
#include <svtools/langtab.hxx>
#include <cppu/unotype.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <officecfg/Office/Common.hxx>
#include <o3tl/safeint.hxx>
#include <o3tl/string_view.hxx>
#include <o3tl/typed_flags_set.hxx>
#include <bitmaps.hlst>
#include <sal/log.hxx>
#include <unotools/collatorwrapper.hxx>
#include <comphelper/lok.hxx>
#include <tools/json_writer.hxx>
#include <editeng/editeng.hxx>
#define MAX_MRU_FONTNAME_ENTRIES 5
#define COMBO_WIDTH_IN_CHARS 18
#define MAX_MRU_CURRENCIES 5
#define INVALID_CURRENCY sal_uInt16(-2)
// namespaces
using namespace ::editeng;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::lang;
namespace
{
struct ScriptInfo
{
tools::Long textWidth;
SvtScriptType scriptType;
sal_Int32 changePos;
ScriptInfo(SvtScriptType scrptType, sal_Int32 position)
: textWidth(0)
, scriptType(scrptType)
, changePos(position)
{
}
};
class SvxStyleBox_Base
{
public:
SvxStyleBox_Base(std::unique_ptr<weld::ComboBox> xWidget, OUString rCommand, SfxStyleFamily eFamily,
const Reference<XFrame>& _xFrame, OUString aClearFormatKey,
OUString aMoreKey, bool bInSpecialMode, SvxStyleToolBoxControl& rCtrl);
virtual ~SvxStyleBox_Base()
{
}
void SetFamily( SfxStyleFamily eNewFamily );
void SetDefaultStyle( const OUString& rDefault ) { sDefaultStyle = rDefault; }
int get_count() const { return m_xWidget->get_count(); }
OUString get_text(int nIndex) const { return m_xWidget->get_text(nIndex); }
OUString get_active_text() const { return m_xWidget->get_active_text(); }
void append_text(const OUString& rStr)
{
OUString sId(OUString::number(m_xWidget->get_count()));
m_xWidget->append(sId, rStr);
}
void insert_separator(int pos, const OUString& rId)
{
m_xWidget->insert_separator(pos, rId);
}
void set_active_or_entry_text(const OUString& rText)
{
const int nFound = m_xWidget->find_text(rText);
if (nFound != -1)
m_xWidget->set_active(nFound);
else
m_xWidget->set_entry_text(rText);
}
void set_active(int nActive)
{
m_xWidget->set_active(nActive);
}
void freeze()
{
m_xWidget->freeze();
}
void save_value()
{
m_xWidget->save_value();
}
void clear()
{
m_xWidget->clear();
m_nMaxUserDrawFontWidth = 0;
}
void thaw()
{
m_xWidget->thaw();
}
virtual bool DoKeyInput(const KeyEvent& rKEvt);
private:
std::optional<SvxFont> m_oFont;
std::optional<SvxFont> m_oCJKFont;
std::optional<SvxFont> m_oCTLFont;
DECL_LINK(SelectHdl, weld::ComboBox&, void);
DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
DECL_LINK(ActivateHdl, weld::ComboBox&, bool);
DECL_LINK(FocusOutHdl, weld::Widget&, void);
DECL_LINK(DumpAsPropertyTreeHdl, tools::JsonWriter&, void);
DECL_LINK(CustomRenderHdl, weld::ComboBox::render_args, void);
DECL_LINK(CustomGetSizeHdl, OutputDevice&, Size);
/// Calculate the optimal width of the dropdown. Very expensive operation, triggers lots of font measurement.
void CalcOptimalExtraUserWidth(vcl::RenderContext& rRenderContext);
void Select(bool bNonTravelSelect);
tools::Rectangle CalcBoundRect(vcl::RenderContext& rRenderContext, const OUString &rStyleName, std::vector<ScriptInfo>& rScriptChanges, double fRatio = 1);
protected:
SvxStyleToolBoxControl& m_rCtrl;
std::unique_ptr<weld::Builder> m_xMenuBuilder;
std::unique_ptr<weld::Menu> m_xMenu;
std::unique_ptr<weld::ComboBox> m_xWidget;
SfxStyleFamily eStyleFamily;
int m_nMaxUserDrawFontWidth;
int m_nLastItemWithMenu;
bool bRelease;
Reference< XFrame > m_xFrame;
OUString m_aCommand;
OUString aClearFormatKey;
OUString aMoreKey;
OUString sDefaultStyle;
bool bInSpecialMode;
void ReleaseFocus();
static Color TestColorsVisible(const Color &FontCol, const Color &BackCol);
void UserDrawEntry(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect, const tools::Rectangle& rTextRect, const OUString &rStyleName, const std::vector<ScriptInfo>& rScriptChanges);
void SetupEntry(vcl::RenderContext& rRenderContext, sal_Int32 nItem, const tools::Rectangle& rRect, std::u16string_view rStyleName, bool bIsNotSelected);
DECL_LINK(MenuSelectHdl, const OUString&, void);
DECL_STATIC_LINK(SvxStyleBox_Base, ShowMoreHdl, void*, void);
};
class SvxStyleBox_Impl final : public InterimItemWindow
, public SvxStyleBox_Base
{
public:
SvxStyleBox_Impl(vcl::Window* pParent, const OUString& rCommand, SfxStyleFamily eFamily,
const Reference< XFrame >& _xFrame,const OUString& rClearFormatKey, const OUString& rMoreKey, bool bInSpecialMode, SvxStyleToolBoxControl& rCtrl);
virtual ~SvxStyleBox_Impl() override
{
disposeOnce();
}
virtual void dispose() override
{
m_xWidget.reset();
m_xMenu.reset();
m_xMenuBuilder.reset();
InterimItemWindow::dispose();
}
virtual bool DoKeyInput(const KeyEvent& rKEvt) override;
private:
virtual void DataChanged(const DataChangedEvent& rDCEvt) override;
void SetOptimalSize();
};
class SvxFontNameBox_Impl;
class SvxFontNameBox_Base;
class SvxFontNameToolBoxControl final : public cppu::ImplInheritanceHelper<svt::ToolboxController,
css::lang::XServiceInfo>
{
public:
SvxFontNameToolBoxControl();
// XStatusListener
virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
// XToolbarController
virtual css::uno::Reference<css::awt::XWindow> SAL_CALL createItemWindow(const css::uno::Reference<css::awt::XWindow>& rParent) override;
// XComponent
virtual void SAL_CALL dispose() override;
// XServiceInfo
virtual OUString SAL_CALL getImplementationName() override;
virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) override;
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
private:
VclPtr<SvxFontNameBox_Impl> m_xVclBox;
std::unique_ptr<SvxFontNameBox_Base> m_xWeldBox;
SvxFontNameBox_Base* m_pBox;
};
class FontOptionsListener final : public comphelper::ConfigurationListenerProperty<bool>
{
private:
SvxFontNameBox_Base& m_rBox;
virtual void setProperty(const css::uno::Any &rProperty) override;
public:
FontOptionsListener(const rtl::Reference<comphelper::ConfigurationListener>& rListener, const OUString& rProp, SvxFontNameBox_Base& rBox)
: comphelper::ConfigurationListenerProperty<bool>(rListener, rProp)
, m_rBox(rBox)
{
}
};
class SvxFontNameBox_Base
{
private:
rtl::Reference<comphelper::ConfigurationListener> m_xListener;
FontOptionsListener m_aWYSIWYG;
FontOptionsListener m_aHistory;
protected:
SvxFontNameToolBoxControl& m_rCtrl;
std::unique_ptr<FontNameBox> m_xWidget;
const FontList* pFontList;
::std::unique_ptr<FontList> m_aOwnFontList;
vcl::Font aCurFont;
sal_uInt16 nFtCount;
bool bRelease;
Reference< XFrame > m_xFrame;
bool mbCheckingUnknownFont;
void ReleaseFocus_Impl();
void Select(bool bNonTravelSelect);
void EndPreview()
{
Sequence< PropertyValue > aArgs;
const Reference<XDispatchProvider> xProvider(m_xFrame, UNO_QUERY);
SfxToolBoxControl::Dispatch(xProvider, ".uno:CharEndPreviewFontName", aArgs);
}
bool CheckFontIsAvailable(std::u16string_view fontname);
void CheckAndMarkUnknownFont();
public:
SvxFontNameBox_Base(std::unique_ptr<weld::ComboBox> xWidget, const Reference<XFrame>& rFrame,
SvxFontNameToolBoxControl& rCtrl);
virtual ~SvxFontNameBox_Base()
{
m_xListener->dispose();
}
void FillList();
void Update( const css::awt::FontDescriptor* pFontDesc );
sal_uInt16 GetListCount() const { return nFtCount; }
void Clear() { m_xWidget->clear(); nFtCount = 0; }
void Fill( const FontList* pList )
{
m_xWidget->Fill(pList);
nFtCount = pList->GetFontNameCount();
}
void SetOwnFontList(::std::unique_ptr<FontList> && _aOwnFontList) { m_aOwnFontList = std::move(_aOwnFontList); }
virtual void set_sensitive(bool bSensitive)
{
m_xWidget->set_sensitive(bSensitive);
}
void set_active_or_entry_text(const OUString& rText);
void statusChanged_Impl(const css::frame::FeatureStateEvent& rEvent);
virtual bool DoKeyInput(const KeyEvent& rKEvt);
void EnableControls();
DECL_LINK(SelectHdl, weld::ComboBox&, void);
DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
DECL_LINK(ActivateHdl, weld::ComboBox&, bool);
DECL_LINK(FocusInHdl, weld::Widget&, void);
DECL_LINK(FocusOutHdl, weld::Widget&, void);
DECL_LINK(DumpAsPropertyTreeHdl, tools::JsonWriter&, void);
};
void FontOptionsListener::setProperty(const css::uno::Any &rProperty)
{
comphelper::ConfigurationListenerProperty<bool>::setProperty(rProperty);
m_rBox.EnableControls();
}
class SvxFontNameBox_Impl final : public InterimItemWindow
, public SvxFontNameBox_Base
{
private:
virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
virtual void GetFocus() override
{
if (m_xWidget)
m_xWidget->grab_focus();
InterimItemWindow::GetFocus();
}
void SetOptimalSize();
virtual bool DoKeyInput(const KeyEvent& rKEvt) override;
public:
SvxFontNameBox_Impl(vcl::Window* pParent,
const Reference<XFrame>& rFrame, SvxFontNameToolBoxControl& rCtrl);
virtual void dispose() override
{
m_xWidget.reset();
InterimItemWindow::dispose();
}
virtual ~SvxFontNameBox_Impl() override
{
disposeOnce();
}
virtual Reference< css::accessibility::XAccessible > CreateAccessible() override;
virtual void set_sensitive(bool bSensitive) override
{
m_xWidget->set_sensitive(bSensitive);
if (bSensitive)
InterimItemWindow::Enable();
else
InterimItemWindow::Disable();
}
};
// SelectHdl needs the Modifiers, get them in MouseButtonUp
class SvxFrmValueSet_Impl final : public ValueSet
{
private:
sal_uInt16 nModifier;
virtual bool MouseButtonUp(const MouseEvent& rMEvt) override
{
nModifier = rMEvt.GetModifier();
return ValueSet::MouseButtonUp(rMEvt);
}
public:
SvxFrmValueSet_Impl()
: ValueSet(nullptr)
, nModifier(0)
{
}
sal_uInt16 GetModifier() const {return nModifier;}
};
}
namespace {
class SvxFrameToolBoxControl;
class SvxFrameWindow_Impl final : public WeldToolbarPopup
{
private:
rtl::Reference<SvxFrameToolBoxControl> mxControl;
std::unique_ptr<SvxFrmValueSet_Impl> mxFrameSet;
std::unique_ptr<weld::CustomWeld> mxFrameSetWin;
std::vector<std::pair<BitmapEx, OUString>> aImgVec;
bool bParagraphMode;
bool m_bIsWriter;
void InitImageList();
void CalcSizeValueSet();
DECL_LINK( SelectHdl, ValueSet*, void );
void SetDiagonalDownBorder(const SvxLineItem& dDownLineItem);
void SetDiagonalUpBorder(const SvxLineItem& dUpLineItem);
public:
SvxFrameWindow_Impl(SvxFrameToolBoxControl* pControl, weld::Widget* pParent);
virtual void GrabFocus() override
{
mxFrameSet->GrabFocus();
}
virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
};
class SvxFrameToolBoxControl : public svt::PopupWindowController
{
public:
explicit SvxFrameToolBoxControl( const css::uno::Reference< css::uno::XComponentContext >& rContext );
// XInitialization
virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& rArguments ) override;
// XServiceInfo
virtual OUString SAL_CALL getImplementationName() override;
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
virtual void SAL_CALL execute(sal_Int16 nKeyModifier) override;
private:
virtual std::unique_ptr<WeldToolbarPopup> weldPopupWindow() override;
virtual VclPtr<vcl::Window> createVclPopupWindow( vcl::Window* pParent ) override;
};
class LineListBox final : public ValueSet
{
public:
typedef Color (*ColorFunc)(Color);
typedef Color (*ColorDistFunc)(Color, Color);
LineListBox();
/** Set the width in Twips */
Size SetWidth( tools::Long nWidth )
{
tools::Long nOldWidth = m_nWidth;
m_nWidth = nWidth;
return UpdateEntries( nOldWidth );
}
void SetNone( const OUString& sNone )
{
m_sNone = sNone;
}
/** Insert a listbox entry with all widths in Twips. */
void InsertEntry(const BorderWidthImpl& rWidthImpl,
SvxBorderLineStyle nStyle, tools::Long nMinWidth = 0,
ColorFunc pColor1Fn = &sameColor,
ColorFunc pColor2Fn = &sameColor,
ColorDistFunc pColorDistFn = &sameDistColor);
SvxBorderLineStyle GetEntryStyle( sal_Int32 nPos ) const;
SvxBorderLineStyle GetSelectEntryStyle() const;
void SetSourceUnit( FieldUnit eNewUnit ) { eSourceUnit = eNewUnit; }
const Color& GetColor() const { return aColor; }
virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
private:
void ImpGetLine(tools::Long nLine1, tools::Long nLine2, tools::Long nDistance,
Color nColor1, Color nColor2, Color nColorDist,
SvxBorderLineStyle nStyle, BitmapEx& rBmp);
void UpdatePaintLineColor(); // returns sal_True if maPaintCol has changed
Size UpdateEntries( tools::Long nOldWidth );
sal_Int32 GetStylePos( sal_Int32 nListPos, tools::Long nWidth );
const Color& GetPaintColor() const
{
return maPaintCol;
}
Color GetColorLine1( sal_Int32 nPos );
Color GetColorLine2( sal_Int32 nPos );
Color GetColorDist( sal_Int32 nPos );
LineListBox( const LineListBox& ) = delete;
LineListBox& operator =( const LineListBox& ) = delete;
std::vector<std::unique_ptr<ImpLineListData>> m_vLineList;
tools::Long m_nWidth;
OUString m_sNone;
ScopedVclPtr<VirtualDevice> aVirDev;
Size aTxtSize;
Color const aColor;
Color maPaintCol;
FieldUnit eSourceUnit;
};
SvxBorderLineStyle LineListBox::GetSelectEntryStyle() const
{
SvxBorderLineStyle nStyle = SvxBorderLineStyle::SOLID;
size_t nPos = GetSelectItemPos();
if (nPos != VALUESET_ITEM_NOTFOUND)
{
if (!m_sNone.isEmpty())
--nPos;
nStyle = GetEntryStyle( nPos );
}
return nStyle;
}
void LineListBox::ImpGetLine( tools::Long nLine1, tools::Long nLine2, tools::Long nDistance,
Color aColor1, Color aColor2, Color aColorDist,
SvxBorderLineStyle nStyle, BitmapEx& rBmp )
{
auto nMinWidth = GetDrawingArea()->get_ref_device().approximate_digit_width() * COMBO_WIDTH_IN_CHARS;
Size aSize(nMinWidth, aTxtSize.Height());
aSize.AdjustWidth( -(aTxtSize.Width()) );
aSize.AdjustWidth( -6 );
// SourceUnit to Twips
if ( eSourceUnit == FieldUnit::POINT )
{
nLine1 /= 5;
nLine2 /= 5;
nDistance /= 5;
}
// Paint the lines
aSize = aVirDev->PixelToLogic( aSize );
tools::Long nPix = aVirDev->PixelToLogic( Size( 0, 1 ) ).Height();
sal_uInt32 n1 = nLine1;
sal_uInt32 n2 = nLine2;
tools::Long nDist = nDistance;
n1 += nPix-1;
n1 -= n1%nPix;
if ( n2 )
{
nDist += nPix-1;
nDist -= nDist%nPix;
n2 += nPix-1;
n2 -= n2%nPix;
}
tools::Long nVirHeight = n1+nDist+n2;
if ( nVirHeight > aSize.Height() )
aSize.setHeight( nVirHeight );
// negative width should not be drawn
if ( aSize.Width() <= 0 )
return;
Size aVirSize = aVirDev->LogicToPixel( aSize );
if ( aVirDev->GetOutputSizePixel() != aVirSize )
aVirDev->SetOutputSizePixel( aVirSize );
aVirDev->SetFillColor( aColorDist );
aVirDev->DrawRect( tools::Rectangle( Point(), aSize ) );
aVirDev->SetFillColor( aColor1 );
double y1 = double( n1 ) / 2;
svtools::DrawLine( *aVirDev, basegfx::B2DPoint( 0, y1 ), basegfx::B2DPoint( aSize.Width( ), y1 ), n1, nStyle );
if ( n2 )
{
double y2 = n1 + nDist + double( n2 ) / 2;
aVirDev->SetFillColor( aColor2 );
svtools::DrawLine( *aVirDev, basegfx::B2DPoint( 0, y2 ), basegfx::B2DPoint( aSize.Width(), y2 ), n2, SvxBorderLineStyle::SOLID );
}
rBmp = aVirDev->GetBitmapEx( Point(), Size( aSize.Width(), n1+nDist+n2 ) );
}
LineListBox::LineListBox()
: ValueSet(nullptr)
, m_nWidth( 5 )
, aVirDev(VclPtr<VirtualDevice>::Create())
, aColor(Application::GetSettings().GetStyleSettings().GetWindowTextColor())
, maPaintCol(COL_BLACK)
, eSourceUnit(FieldUnit::POINT)
{
aVirDev->SetLineColor();
aVirDev->SetMapMode( MapMode( MapUnit::MapTwip ) );
}
void LineListBox::SetDrawingArea(weld::DrawingArea* pDrawingArea)
{
ValueSet::SetDrawingArea(pDrawingArea);
OutputDevice& rDevice = pDrawingArea->get_ref_device();
aTxtSize.setWidth( rDevice.approximate_digit_width() );
aTxtSize.setHeight( rDevice.GetTextHeight() );
UpdatePaintLineColor();
}
sal_Int32 LineListBox::GetStylePos( sal_Int32 nListPos, tools::Long nWidth )
{
sal_Int32 nPos = -1;
if (!m_sNone.isEmpty())
nListPos--;
sal_Int32 n = 0;
size_t i = 0;
size_t nCount = m_vLineList.size();
while ( nPos == -1 && i < nCount )
{
auto& pData = m_vLineList[ i ];
if ( pData->GetMinWidth() <= nWidth )
{
if ( nListPos == n )
nPos = static_cast<sal_Int32>(i);
n++;
}
i++;
}
return nPos;
}
void LineListBox::InsertEntry(
const BorderWidthImpl& rWidthImpl, SvxBorderLineStyle nStyle, tools::Long nMinWidth,
ColorFunc pColor1Fn, ColorFunc pColor2Fn, ColorDistFunc pColorDistFn )
{
m_vLineList.emplace_back(new ImpLineListData(
rWidthImpl, nStyle, nMinWidth, pColor1Fn, pColor2Fn, pColorDistFn));
}
SvxBorderLineStyle LineListBox::GetEntryStyle( sal_Int32 nPos ) const
{
ImpLineListData* pData = (0 <= nPos && o3tl::make_unsigned(nPos) < m_vLineList.size()) ? m_vLineList[ nPos ].get() : nullptr;
return pData ? pData->GetStyle() : SvxBorderLineStyle::NONE;
}
void LineListBox::UpdatePaintLineColor()
{
const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
Color aNewCol( rSettings.GetWindowColor().IsDark()? rSettings.GetLabelTextColor() : aColor );
bool bRet = aNewCol != maPaintCol;
if( bRet )
maPaintCol = aNewCol;
}
Size LineListBox::UpdateEntries( tools::Long nOldWidth )
{
Size aSize;
UpdatePaintLineColor( );
sal_Int32 nSelEntry = GetSelectItemPos();
sal_Int32 nTypePos = GetStylePos( nSelEntry, nOldWidth );
// Remove the old entries
Clear();
sal_uInt16 nId(1);
// Add the new entries based on the defined width
if (!m_sNone.isEmpty())
InsertItem(nId++, Image(), m_sNone);
sal_uInt16 n = 0;
sal_uInt16 nCount = m_vLineList.size( );
while ( n < nCount )
{
auto& pData = m_vLineList[ n ];
if ( pData->GetMinWidth() <= m_nWidth )
{
BitmapEx aBmp;
ImpGetLine( pData->GetLine1ForWidth( m_nWidth ),
pData->GetLine2ForWidth( m_nWidth ),
pData->GetDistForWidth( m_nWidth ),
GetColorLine1( GetItemCount( ) ),
GetColorLine2( GetItemCount( ) ),
GetColorDist( GetItemCount( ) ),
pData->GetStyle(), aBmp );
InsertItem(nId, Image(aBmp), SvtLineListBox::GetLineStyleName(pData->GetStyle()));
Size aBmpSize = aBmp.GetSizePixel();
if (aBmpSize.Width() > aSize.Width())
aSize.setWidth(aBmpSize.getWidth());
if (aBmpSize.Height() > aSize.Height())
aSize.setHeight(aBmpSize.getHeight());
if ( n == nTypePos )
SelectItem(nId);
}
else if ( n == nTypePos )
SetNoSelection();
n++;
++nId;
}
Invalidate();
return aSize;
}
Color LineListBox::GetColorLine1( sal_Int32 nPos )
{
sal_Int32 nStyle = GetStylePos( nPos, m_nWidth );
if (nStyle == -1)
return GetPaintColor( );
auto& pData = m_vLineList[ nStyle ];
return pData->GetColorLine1( GetColor( ) );
}
Color LineListBox::GetColorLine2( sal_Int32 nPos )
{
sal_Int32 nStyle = GetStylePos( nPos, m_nWidth );
if (nStyle == -1)
return GetPaintColor( );
auto& pData = m_vLineList[ nStyle ];
return pData->GetColorLine2( GetColor( ) );
}
Color LineListBox::GetColorDist( sal_Int32 nPos )
{
Color rResult = Application::GetSettings().GetStyleSettings().GetFieldColor();
sal_Int32 nStyle = GetStylePos( nPos, m_nWidth );
if (nStyle == -1)
return rResult;
auto& pData = m_vLineList[ nStyle ];
return pData->GetColorDist( GetColor( ), rResult );
}
}
namespace {
class SvxLineWindow_Impl final : public WeldToolbarPopup
{
private:
rtl::Reference<SvxFrameToolBoxControl> m_xControl;
std::unique_ptr<LineListBox> m_xLineStyleLb;
std::unique_ptr<weld::CustomWeld> m_xLineStyleLbWin;
bool m_bIsWriter;
DECL_LINK( SelectHdl, ValueSet*, void );
public:
SvxLineWindow_Impl(SvxFrameToolBoxControl* pControl, weld::Widget* pParent);
virtual void GrabFocus() override
{
m_xLineStyleLb->GrabFocus();
}
};
}
class SvxStyleToolBoxControl;
class SfxStyleControllerItem_Impl : public SfxStatusListener
{
public:
SfxStyleControllerItem_Impl( const Reference< XDispatchProvider >& rDispatchProvider,
sal_uInt16 nSlotId,
const OUString& rCommand,
SvxStyleToolBoxControl& rTbxCtl );
protected:
virtual void StateChangedAtStatusListener( SfxItemState eState, const SfxPoolItem* pState ) override;
private:
SvxStyleToolBoxControl& rControl;
};
#define BUTTON_PADDING 10
#define ITEM_HEIGHT 30
SvxStyleBox_Base::SvxStyleBox_Base(std::unique_ptr<weld::ComboBox> xWidget,
OUString aCommand,
SfxStyleFamily eFamily,
const Reference< XFrame >& _xFrame,
OUString _aClearFormatKey,
OUString _aMoreKey,
bool bInSpec, SvxStyleToolBoxControl& rCtrl)
: m_rCtrl(rCtrl)
, m_xMenuBuilder(Application::CreateBuilder(nullptr, "svx/ui/stylemenu.ui"))
, m_xMenu(m_xMenuBuilder->weld_menu("menu"))
, m_xWidget(std::move(xWidget))
, eStyleFamily( eFamily )
, m_nMaxUserDrawFontWidth(0)
, m_nLastItemWithMenu(-1)
, bRelease( true )
, m_xFrame(_xFrame)
, m_aCommand(std::move( aCommand ))
, aClearFormatKey(std::move( _aClearFormatKey ))
, aMoreKey(std::move( _aMoreKey ))
, bInSpecialMode( bInSpec )
{
m_xWidget->connect_changed(LINK(this, SvxStyleBox_Base, SelectHdl));
m_xWidget->connect_key_press(LINK(this, SvxStyleBox_Base, KeyInputHdl));
m_xWidget->connect_entry_activate(LINK(this, SvxStyleBox_Base, ActivateHdl));
m_xWidget->connect_focus_out(LINK(this, SvxStyleBox_Base, FocusOutHdl));
m_xWidget->connect_get_property_tree(LINK(this, SvxStyleBox_Base, DumpAsPropertyTreeHdl));
m_xWidget->set_help_id(HID_STYLE_LISTBOX);
m_xWidget->set_entry_completion(true);
m_xMenu->connect_activate(LINK(this, SvxStyleBox_Base, MenuSelectHdl));
m_xWidget->connect_custom_get_size(LINK(this, SvxStyleBox_Base, CustomGetSizeHdl));
m_xWidget->connect_custom_render(LINK(this, SvxStyleBox_Base, CustomRenderHdl));
m_xWidget->set_custom_renderer(true);
m_xWidget->set_entry_width_chars(COMBO_WIDTH_IN_CHARS + 3);
}
IMPL_LINK(SvxStyleBox_Base, CustomGetSizeHdl, OutputDevice&, rArg, Size)
{
CalcOptimalExtraUserWidth(rArg);
if (comphelper::LibreOfficeKit::isActive())
return Size(m_nMaxUserDrawFontWidth * rArg.GetDPIX() / 96, ITEM_HEIGHT * rArg.GetDPIY() / 96);
return Size(m_nMaxUserDrawFontWidth, ITEM_HEIGHT);
}
SvxStyleBox_Impl::SvxStyleBox_Impl(vcl::Window* pParent,
const OUString& rCommand,
SfxStyleFamily eFamily,
const Reference< XFrame >& _xFrame,
const OUString& rClearFormatKey,
const OUString& rMoreKey,
bool bInSpec, SvxStyleToolBoxControl& rCtrl)
: InterimItemWindow(pParent, "svx/ui/applystylebox.ui", "ApplyStyleBox")
, SvxStyleBox_Base(m_xBuilder->weld_combo_box("applystyle"), rCommand, eFamily, _xFrame,
rClearFormatKey, rMoreKey, bInSpec, rCtrl)
{
InitControlBase(m_xWidget.get());
set_id("applystyle");
SetOptimalSize();
}
void SvxStyleBox_Base::ReleaseFocus()
{
if ( !bRelease )
{
bRelease = true;
return;
}
if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
m_xFrame->getContainerWindow()->setFocus();
}
IMPL_LINK(SvxStyleBox_Base, MenuSelectHdl, const OUString&, rMenuIdent, void)
{
if (m_nLastItemWithMenu < 0 || m_nLastItemWithMenu >= m_xWidget->get_count())
return;
OUString sEntry = m_xWidget->get_text(m_nLastItemWithMenu);
ReleaseFocus(); // It must be after getting entry pos!
Sequence<PropertyValue> aArgs{ comphelper::makePropertyValue("Param", sEntry),
comphelper::makePropertyValue("Family",
sal_Int16( eStyleFamily )) };
const Reference<XDispatchProvider> xProvider(m_xFrame, UNO_QUERY);
if (rMenuIdent == "update")
{
SfxToolBoxControl::Dispatch(xProvider, ".uno:StyleUpdateByExample", aArgs);
}
else if (rMenuIdent == "edit")
{
SfxToolBoxControl::Dispatch(xProvider, ".uno:EditStyle", aArgs);
}
}
IMPL_STATIC_LINK_NOARG(SvxStyleBox_Base, ShowMoreHdl, void*, void)
{
SfxViewFrame* pViewFrm = SfxViewFrame::Current();
DBG_ASSERT( pViewFrm, "SvxStyleBox_Base::Select(): no viewframe" );
if (!pViewFrm)
return;
pViewFrm->ShowChildWindow(SID_SIDEBAR);
::sfx2::sidebar::Sidebar::ShowPanel(u"StyleListPanel", pViewFrm->GetFrame().GetFrameInterface(), true);
}
IMPL_LINK(SvxStyleBox_Base, SelectHdl, weld::ComboBox&, rCombo, void)
{
Select(rCombo.changed_by_direct_pick()); // only when picked from the list
}
IMPL_LINK_NOARG(SvxStyleBox_Base, ActivateHdl, weld::ComboBox&, bool)
{
Select(true);
return true;
}
void SvxStyleBox_Base::Select(bool bNonTravelSelect)
{
if (!bNonTravelSelect)
return;
OUString aSearchEntry(m_xWidget->get_active_text());
bool bDoIt = true, bClear = false;
if( bInSpecialMode )
{
if( aSearchEntry == aClearFormatKey && m_xWidget->get_active() == 0 )
{
aSearchEntry = sDefaultStyle;
bClear = true;
//not only apply default style but also call 'ClearFormatting'
Sequence< PropertyValue > aEmptyVals;
const Reference<XDispatchProvider> xProvider(m_xFrame, UNO_QUERY);
SfxToolBoxControl::Dispatch(xProvider, ".uno:ResetAttributes", aEmptyVals);
}
else if (aSearchEntry == aMoreKey && m_xWidget->get_active() == (m_xWidget->get_count() - 1))
{
Application::PostUserEvent(LINK(nullptr, SvxStyleBox_Base, ShowMoreHdl));
//tdf#113214 change text back to previous entry
set_active_or_entry_text(m_xWidget->get_saved_value());
bDoIt = false;
}
}
//Do we need to create a new style?
SfxObjectShell *pShell = SfxObjectShell::Current();
if (!pShell)
return;
SfxStyleSheetBasePool* pPool = pShell->GetStyleSheetPool();
SfxStyleSheetBase* pStyle = nullptr;
bool bCreateNew = false;
if ( pPool )
{
pStyle = pPool->First(eStyleFamily);
while ( pStyle && pStyle->GetName() != aSearchEntry )
pStyle = pPool->Next();
}
if ( !pStyle )
{
// cannot find the style for whatever reason
// therefore create a new style
bCreateNew = true;
}
/* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
This instance may be deleted in the meantime (i.e. when a dialog is opened
while in Dispatch()), accessing members will crash in this case. */
ReleaseFocus();
if( !bDoIt )
return;
if ( bClear )
set_active_or_entry_text(aSearchEntry);
m_xWidget->save_value();
Sequence< PropertyValue > aArgs( 2 );
auto pArgs = aArgs.getArray();
pArgs[0].Value <<= aSearchEntry;
pArgs[1].Name = "Family";
pArgs[1].Value <<= sal_Int16( eStyleFamily );
const Reference<XDispatchProvider> xProvider(m_xFrame, UNO_QUERY);
if( bCreateNew )
{
pArgs[0].Name = "Param";
SfxToolBoxControl::Dispatch(xProvider, ".uno:StyleNewByExample", aArgs);
}
else
{
pArgs[0].Name = "Template";
SfxToolBoxControl::Dispatch(xProvider, m_aCommand, aArgs);
}
}
void SvxStyleBox_Base::SetFamily( SfxStyleFamily eNewFamily )
{
eStyleFamily = eNewFamily;
}
IMPL_LINK_NOARG(SvxStyleBox_Base, FocusOutHdl, weld::Widget&, void)
{
if (!m_xWidget->has_focus()) // a combobox can be comprised of different subwidget so double-check if none of those has focus
set_active_or_entry_text(m_xWidget->get_saved_value());
}
IMPL_LINK(SvxStyleBox_Base, KeyInputHdl, const KeyEvent&, rKEvt, bool)
{
return DoKeyInput(rKEvt);
}
bool SvxStyleBox_Base::DoKeyInput(const KeyEvent& rKEvt)
{
bool bHandled = false;
sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
switch (nCode)
{
case KEY_TAB:
bRelease = false;
Select(true);
break;
case KEY_ESCAPE:
set_active_or_entry_text(m_xWidget->get_saved_value());
if (!m_rCtrl.IsInSidebar())
{
ReleaseFocus();
bHandled = true;
}
break;
}
return bHandled;
}
bool SvxStyleBox_Impl::DoKeyInput(const KeyEvent& rKEvt)
{
return SvxStyleBox_Base::DoKeyInput(rKEvt) || ChildKeyInput(rKEvt);
}
void SvxStyleBox_Impl::DataChanged( const DataChangedEvent& rDCEvt )
{
if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
(rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
{
SetOptimalSize();
}
InterimItemWindow::DataChanged( rDCEvt );
}
void SvxStyleBox_Impl::SetOptimalSize()
{
// set width in chars low so the size request will not be overridden
m_xWidget->set_entry_width_chars(1);
// tdf#132338 purely using this calculation to keep things their traditional width
Size aSize(LogicToPixel(Size((COMBO_WIDTH_IN_CHARS + 3) * 4, 0), MapMode(MapUnit::MapAppFont)));
m_xWidget->set_size_request(aSize.Width(), -1);
SetSizePixel(get_preferred_size());
}
namespace
{
std::vector<ScriptInfo> CheckScript(const OUString &rStyleName)
{
assert(!rStyleName.isEmpty()); // must have a preview text here!
std::vector<ScriptInfo> aScriptChanges;
auto aEditEngine = EditEngine(nullptr);
aEditEngine.SetText(rStyleName);
auto aScript = aEditEngine.GetScriptType({ 0, 0, 0, 0 });
for (sal_Int32 i = 1; i <= rStyleName.getLength(); i++)
{
auto aNextScript = aEditEngine.GetScriptType({ 0, i, 0, i });
if (aNextScript != aScript || i == rStyleName.getLength())
aScriptChanges.emplace_back(aScript, i);
aScript = aNextScript;
}
return aScriptChanges;
}
}
tools::Rectangle SvxStyleBox_Base::CalcBoundRect(vcl::RenderContext& rRenderContext, const OUString &rStyleName, std::vector<ScriptInfo>& rScriptChanges, double fRatio)
{
tools::Rectangle aTextRect;
SvtScriptType aScript;
sal_uInt16 nIdx = 0;
sal_Int32 nStart = 0;
sal_Int32 nEnd;
size_t nCnt = rScriptChanges.size();
if (nCnt)
{
nEnd = rScriptChanges[nIdx].changePos;
aScript = rScriptChanges[nIdx].scriptType;
}
else
{
nEnd = rStyleName.getLength();
aScript = SvtScriptType::LATIN;
}
do
{
auto oFont = (aScript == SvtScriptType::ASIAN) ?
m_oCJKFont :
((aScript == SvtScriptType::COMPLEX) ?
m_oCTLFont :
m_oFont);
rRenderContext.Push(vcl::PushFlags::FONT);
if (oFont)
rRenderContext.SetFont(*oFont);
if (fRatio != 1)
{
vcl::Font aFont(rRenderContext.GetFont());
Size aPixelSize(aFont.GetFontSize());
aPixelSize.setWidth(aPixelSize.Width() * fRatio);
aPixelSize.setHeight(aPixelSize.Height() * fRatio);
aFont.SetFontSize(aPixelSize);
rRenderContext.SetFont(aFont);
}
tools::Rectangle aRect;
rRenderContext.GetTextBoundRect(aRect, rStyleName, nStart, nStart, nEnd - nStart);
aTextRect = aTextRect.Union(aRect);
tools::Long nWidth = rRenderContext.GetTextWidth(rStyleName, nStart, nEnd - nStart);
rRenderContext.Pop();
if (nIdx >= rScriptChanges.size())
break;
rScriptChanges[nIdx++].textWidth = nWidth;
if (nEnd < rStyleName.getLength() && nIdx < nCnt)
{
nStart = nEnd;
nEnd = rScriptChanges[nIdx].changePos;
aScript = rScriptChanges[nIdx].scriptType;
}
else
break;
}
while(true);
return aTextRect;
}
void SvxStyleBox_Base::UserDrawEntry(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect, const tools::Rectangle& rTextRect, const OUString &rStyleName, const std::vector<ScriptInfo>& rScriptChanges)
{
// IMG_TXT_DISTANCE in ilstbox.hxx is 6, then 1 is added as
// nBorder, and we are adding 1 in order to look better when
// italics is present
const int nLeftDistance = 8;
Point aPos(rRect.TopLeft());
aPos.AdjustX(nLeftDistance );
double fRatio = 1;
if (rTextRect.Bottom() > rRect.GetHeight())
fRatio = static_cast<double>(rRect.GetHeight()) / rTextRect.Bottom();
else
aPos.AdjustY((rRect.GetHeight() - rTextRect.Bottom()) / 2);
SvtScriptType aScript;
sal_uInt16 nIdx = 0;
sal_Int32 nStart = 0;
sal_Int32 nEnd;
size_t nCnt = rScriptChanges.size();
if (nCnt)
{
nEnd = rScriptChanges[nIdx].changePos;
aScript = rScriptChanges[nIdx].scriptType;
}
else
{
nEnd = rStyleName.getLength();
aScript = SvtScriptType::LATIN;
}
do
{
auto oFont = (aScript == SvtScriptType::ASIAN) ?
m_oCJKFont :
((aScript == SvtScriptType::COMPLEX) ?
m_oCTLFont :
m_oFont);
rRenderContext.Push(vcl::PushFlags::FONT);
if (oFont)
rRenderContext.SetFont(*oFont);
if (fRatio != 1)
{
vcl::Font aFont(rRenderContext.GetFont());
Size aPixelSize(aFont.GetFontSize());
aPixelSize.setWidth(aPixelSize.Width() * fRatio);
aPixelSize.setHeight(aPixelSize.Height() * fRatio);
aFont.SetFontSize(aPixelSize);
rRenderContext.SetFont(aFont);
}
rRenderContext.DrawText(aPos, rStyleName, nStart, nEnd - nStart);
rRenderContext.Pop();
aPos.AdjustX(rScriptChanges[nIdx++].textWidth * fRatio);
if (nEnd < rStyleName.getLength() && nIdx < nCnt)
{
nStart = nEnd;
nEnd = rScriptChanges[nIdx].changePos;
aScript = rScriptChanges[nIdx].scriptType;
}
else
break;
}
while(true);
}
static bool GetWhich(const SfxItemSet& rSet, sal_uInt16 nSlot, sal_uInt16& rWhich)
{
rWhich = rSet.GetPool()->GetWhich(nSlot);
return rSet.GetItemState(rWhich) >= SfxItemState::DEFAULT;
}
static bool SetFont(const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont)
{
sal_uInt16 nWhich;
if (GetWhich(rSet, nSlot, nWhich))
{
const auto& rFontItem = static_cast<const SvxFontItem&>(rSet.Get(nWhich));
rFont.SetFamilyName(rFontItem.GetFamilyName());
rFont.SetStyleName(rFontItem.GetStyleName());
return true;
}
return false;
}
static bool SetFontSize(vcl::RenderContext& rRenderContext, const SfxItemSet& rSet, sal_uInt16 nSlot, SvxFont& rFont)
{
sal_uInt16 nWhich;
if (GetWhich(rSet, nSlot, nWhich))
{
const auto& rFontHeightItem = static_cast<const SvxFontHeightItem&>(rSet.Get(nWhich));
if (SfxObjectShell *pShell = SfxObjectShell::Current())
{
Size aFontSize(0, rFontHeightItem.GetHeight());
Size aPixelSize(rRenderContext.LogicToPixel(aFontSize, MapMode(pShell->GetMapUnit())));
rFont.SetFontSize(aPixelSize);
return true;
}
}
return false;
}
static void SetFontStyle(const SfxItemSet& rSet, sal_uInt16 nPosture, sal_uInt16 nWeight, SvxFont& rFont)
{
sal_uInt16 nWhich;
if (GetWhich(rSet, nPosture, nWhich))
{
const auto& rItem = static_cast<const SvxPostureItem&>(rSet.Get(nWhich));
rFont.SetItalic(rItem.GetPosture());
}
if (GetWhich(rSet, nWeight, nWhich))
{
const auto& rItem = static_cast<const SvxWeightItem&>(rSet.Get(nWhich));
rFont.SetWeight(rItem.GetWeight());
}
}
void SvxStyleBox_Base::SetupEntry(vcl::RenderContext& rRenderContext, sal_Int32 nItem, const tools::Rectangle& rRect, std::u16string_view rStyleName, bool bIsNotSelected)
{
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
if (!bIsNotSelected)
rRenderContext.SetTextColor(rStyleSettings.GetHighlightTextColor());
else
rRenderContext.SetTextColor(rStyleSettings.GetDialogTextColor());
// handle the push-button
if (!bIsNotSelected)
{
if (nItem == 0 || nItem == m_xWidget->get_count() - 1)
m_xWidget->set_item_menu(OUString::number(nItem), nullptr);
else
{
m_nLastItemWithMenu = nItem;
m_xWidget->set_item_menu(OUString::number(nItem), m_xMenu.get());
}
}
if (nItem <= 0 || nItem >= m_xWidget->get_count() - 1)
return;
SfxObjectShell *pShell = SfxObjectShell::Current();
if (!pShell)
return;
SfxStyleSheetBasePool* pPool = pShell->GetStyleSheetPool();
if (!pPool)
return;
SfxStyleSheetBase* pStyle = pPool->First(eStyleFamily);
while (pStyle && pStyle->GetName() != rStyleName)
pStyle = pPool->Next();
if (!pStyle )
return;
std::optional<SfxItemSet> const pItemSet(pStyle->GetItemSetForPreview());
if (!pItemSet) return;
SvxFont aFont;
SvxFont aCJKFont;
SvxFont aCTLFont;
SetFontStyle(*pItemSet, SID_ATTR_CHAR_POSTURE, SID_ATTR_CHAR_WEIGHT, aFont);
SetFontStyle(*pItemSet, SID_ATTR_CHAR_CJK_POSTURE, SID_ATTR_CHAR_CJK_WEIGHT, aCJKFont);
SetFontStyle(*pItemSet, SID_ATTR_CHAR_CTL_POSTURE, SID_ATTR_CHAR_CTL_WEIGHT, aCTLFont);
const SfxPoolItem *pItem = pItemSet->GetItem( SID_ATTR_CHAR_CONTOUR );
if ( pItem )
{
auto aVal = static_cast< const SvxContourItem* >( pItem )->GetValue();
aFont.SetOutline(aVal);
aCJKFont.SetOutline(aVal);
aCTLFont.SetOutline(aVal);
}
pItem = pItemSet->GetItem( SID_ATTR_CHAR_SHADOWED );
if ( pItem )
{
auto aVal = static_cast< const SvxShadowedItem* >( pItem )->GetValue();
aFont.SetShadow(aVal);
aCJKFont.SetShadow(aVal);
aCTLFont.SetShadow(aVal);
}
pItem = pItemSet->GetItem( SID_ATTR_CHAR_RELIEF );
if ( pItem )
{
auto aVal = static_cast< const SvxCharReliefItem* >( pItem )->GetValue();
aFont.SetRelief(aVal);
aCJKFont.SetRelief(aVal);
aCTLFont.SetRelief(aVal);
}
pItem = pItemSet->GetItem( SID_ATTR_CHAR_UNDERLINE );
if ( pItem )
{
auto aVal = static_cast<const SvxUnderlineItem*>(pItem)->GetLineStyle();
aFont.SetUnderline(aVal);
aCJKFont.SetUnderline(aVal);
aCTLFont.SetUnderline(aVal);
}
pItem = pItemSet->GetItem( SID_ATTR_CHAR_OVERLINE );
if ( pItem )
{
auto aVal = static_cast< const SvxOverlineItem* >( pItem )->GetValue();
aFont.SetOverline(aVal);
aCJKFont.SetOverline(aVal);
aCTLFont.SetOverline(aVal);
}
pItem = pItemSet->GetItem( SID_ATTR_CHAR_STRIKEOUT );
if ( pItem )
{
auto aVal = static_cast< const SvxCrossedOutItem* >( pItem )->GetStrikeout();
aFont.SetStrikeout(aVal);
aCJKFont.SetStrikeout(aVal);
aCTLFont.SetStrikeout(aVal);
}
pItem = pItemSet->GetItem( SID_ATTR_CHAR_CASEMAP );
if ( pItem )
{
auto aVal = static_cast<const SvxCaseMapItem*>(pItem)->GetCaseMap();
aFont.SetCaseMap(aVal);
aCJKFont.SetCaseMap(aVal);
aCTLFont.SetCaseMap(aVal);
}
pItem = pItemSet->GetItem( SID_ATTR_CHAR_EMPHASISMARK );
if ( pItem )
{
auto aVal = static_cast< const SvxEmphasisMarkItem* >( pItem )->GetEmphasisMark();
aFont.SetEmphasisMark(aVal);
aCJKFont.SetEmphasisMark(aVal);
aCTLFont.SetEmphasisMark(aVal);
}
// setup the device & draw
Color aFontCol = COL_AUTO, aBackCol = COL_AUTO;
pItem = pItemSet->GetItem( SID_ATTR_CHAR_COLOR );
// text color, when nothing is selected
if ( (nullptr != pItem) && bIsNotSelected)
aFontCol = static_cast< const SvxColorItem* >( pItem )->GetValue();
drawing::FillStyle style = drawing::FillStyle_NONE;
// which kind of Fill style is selected
pItem = pItemSet->GetItem( XATTR_FILLSTYLE );
// only when ok and not selected
if ( (nullptr != pItem) && bIsNotSelected)
style = static_cast< const XFillStyleItem* >( pItem )->GetValue();
switch(style)
{
case drawing::FillStyle_SOLID:
{
// set background color
pItem = pItemSet->GetItem( XATTR_FILLCOLOR );
if ( nullptr != pItem )
aBackCol = static_cast< const XFillColorItem* >( pItem )->GetColorValue();
if ( aBackCol != COL_AUTO )
{
rRenderContext.SetFillColor(aBackCol);
rRenderContext.DrawRect(rRect);
}
}
break;
default: break;
//TODO Draw the other background styles: gradient, hatching and bitmap
}
// when the font and background color are too similar, adjust the Font-Color
if( (aFontCol != COL_AUTO) || (aBackCol != COL_AUTO) )
aFontCol = TestColorsVisible(aFontCol, (aBackCol != COL_AUTO) ? aBackCol : rRenderContext.GetBackground().GetColor());
// set text color
if ( aFontCol != COL_AUTO )
rRenderContext.SetTextColor(aFontCol);
if (SetFont(*pItemSet, SID_ATTR_CHAR_FONT, aFont) &&
SetFontSize(rRenderContext, *pItemSet, SID_ATTR_CHAR_FONTHEIGHT, aFont))
m_oFont = aFont;
if (SetFont(*pItemSet, SID_ATTR_CHAR_CJK_FONT, aCJKFont) &&
SetFontSize(rRenderContext, *pItemSet, SID_ATTR_CHAR_CJK_FONTHEIGHT, aCJKFont))
m_oCJKFont = aCJKFont;
if (SetFont(*pItemSet, SID_ATTR_CHAR_CTL_FONT, aCTLFont) &&
SetFontSize(rRenderContext, *pItemSet, SID_ATTR_CHAR_CTL_FONTHEIGHT, aCTLFont))
m_oCTLFont = aCTLFont;
}
IMPL_LINK(SvxStyleBox_Base, CustomRenderHdl, weld::ComboBox::render_args, aPayload, void)
{
vcl::RenderContext& rRenderContext = std::get<0>(aPayload);
const ::tools::Rectangle& rRect = std::get<1>(aPayload);
bool bSelected = std::get<2>(aPayload);
const OUString& rId = std::get<3>(aPayload);
sal_uInt32 nIndex = rId.toUInt32();
OUString aStyleName(m_xWidget->get_text(nIndex));
rRenderContext.Push(vcl::PushFlags::FILLCOLOR | vcl::PushFlags::FONT | vcl::PushFlags::TEXTCOLOR);
SetupEntry(rRenderContext, nIndex, rRect, aStyleName, !bSelected);
auto aScriptChanges = CheckScript(aStyleName);
auto aTextRect = CalcBoundRect(rRenderContext, aStyleName, aScriptChanges);
UserDrawEntry(rRenderContext, rRect, aTextRect, aStyleName, aScriptChanges);
rRenderContext.Pop();
}
void SvxStyleBox_Base::CalcOptimalExtraUserWidth(vcl::RenderContext& rRenderContext)
{
if (m_nMaxUserDrawFontWidth)
return;
tools::Long nMaxNormalFontWidth = 0;
sal_Int32 nEntryCount = m_xWidget->get_count();
for (sal_Int32 i = 0; i < nEntryCount; ++i)
{
OUString sStyleName(get_text(i));
tools::Rectangle aTextRectForDefaultFont;
rRenderContext.GetTextBoundRect(aTextRectForDefaultFont, sStyleName);
const tools::Long nWidth = aTextRectForDefaultFont.GetWidth();
nMaxNormalFontWidth = std::max(nWidth, nMaxNormalFontWidth);
}
m_nMaxUserDrawFontWidth = nMaxNormalFontWidth;
for (sal_Int32 i = 1; i < nEntryCount-1; ++i)
{
OUString sStyleName(get_text(i));
if (sStyleName.isEmpty())
continue;
rRenderContext.Push(vcl::PushFlags::FILLCOLOR | vcl::PushFlags::FONT | vcl::PushFlags::TEXTCOLOR);
SetupEntry(rRenderContext, i, tools::Rectangle(0, 0, RECT_MAX, ITEM_HEIGHT), sStyleName, true);
auto aScriptChanges = CheckScript(sStyleName);
tools::Rectangle aTextRectForActualFont = CalcBoundRect(rRenderContext, sStyleName, aScriptChanges);
if (aTextRectForActualFont.Bottom() > ITEM_HEIGHT)
{
//Font didn't fit, re-calculate with adjustment ratio.
double fRatio = static_cast<double>(ITEM_HEIGHT) / aTextRectForActualFont.Bottom();
aTextRectForActualFont = CalcBoundRect(rRenderContext, sStyleName, aScriptChanges, fRatio);
}
rRenderContext.Pop();
const int nWidth = aTextRectForActualFont.GetWidth() + m_xWidget->get_menu_button_width() + BUTTON_PADDING;
m_nMaxUserDrawFontWidth = std::max(nWidth, m_nMaxUserDrawFontWidth);
}
}
// test is the color between Font- and background-color to be identify
// return is always the Font-Color
// when both light or dark, change the Contrast
// in other case do not change the origin color
// when the color is R=G=B=128 the DecreaseContrast make 128 the need an exception
Color SvxStyleBox_Base::TestColorsVisible(const Color &FontCol, const Color &BackCol)
{
constexpr sal_uInt8 ChgVal = 60; // increase/decrease the Contrast
Color retCol = FontCol;
if ((FontCol.IsDark() == BackCol.IsDark()) && (FontCol.IsBright() == BackCol.IsBright()))
{
sal_uInt8 lumi = retCol.GetLuminance();
if((lumi > 120) && (lumi < 140))
retCol.DecreaseLuminance(ChgVal / 2);
else
retCol.DecreaseContrast(ChgVal);
}
return retCol;
}
IMPL_LINK(SvxStyleBox_Base, DumpAsPropertyTreeHdl, tools::JsonWriter&, rJsonWriter, void)
{
if (!m_xWidget)
return;
{
auto entriesNode = rJsonWriter.startNode("entries");
for (int i = 0, nEntryCount = m_xWidget->get_count(); i < nEntryCount; ++i)
{
auto entryNode = rJsonWriter.startNode("");
rJsonWriter.put("", m_xWidget->get_text(i));
}
}
int nActive = m_xWidget->get_active();
rJsonWriter.put("selectedCount", static_cast<sal_Int32>(nActive == -1 ? 0 : 1));
{
auto selectedNode = rJsonWriter.startNode("selectedEntries");
if (nActive != -1)
{
auto node = rJsonWriter.startNode("");
rJsonWriter.put("", static_cast<sal_Int32>(nActive));
}
}
rJsonWriter.put("command", ".uno:StyleApply");
}
static bool lcl_GetDocFontList(const FontList** ppFontList, SvxFontNameBox_Base* pBox)
{
bool bChanged = false;
const SfxObjectShell* pDocSh = SfxObjectShell::Current();
const SvxFontListItem* pFontListItem = nullptr;
if ( pDocSh )
pFontListItem =
static_cast<const SvxFontListItem*>(pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST ));
else
{
::std::unique_ptr<FontList> aFontList(new FontList(Application::GetDefaultDevice()));
*ppFontList = aFontList.get();
pBox->SetOwnFontList(std::move(aFontList));
bChanged = true;
}
if ( pFontListItem )
{
const FontList* pNewFontList = pFontListItem->GetFontList();
DBG_ASSERT( pNewFontList, "Doc-FontList not available!" );
// No old list, but a new list
if ( !*ppFontList && pNewFontList )
{
// => take over
*ppFontList = pNewFontList;
bChanged = true;
}
else
{
// Comparing the font lists is not perfect.
// When you change the font list in the Doc, you can track
// changes here only on the Listbox, because ppFontList
// has already been updated.
bChanged =
( ( *ppFontList != pNewFontList ) ||
pBox->GetListCount() != pNewFontList->GetFontNameCount() );
// HACK: Comparing is incomplete
if ( bChanged )
*ppFontList = pNewFontList;
}
if ( pBox )
pBox->set_sensitive(true);
}
else if ( pBox && ( pDocSh || !ppFontList ))
{
// Disable box only when we have a SfxObjectShell and didn't get a font list OR
// we don't have a SfxObjectShell and no current font list.
// It's possible that we currently have no SfxObjectShell, but a current font list.
// See #i58471: When a user set the focus into the font name combo box and opens
// the help window with F1. After closing the help window, we disable the font name
// combo box. The SfxObjectShell::Current() method returns in that case zero. But the
// font list hasn't changed and therefore the combo box shouldn't be disabled!
pBox->set_sensitive(false);
}
// Fill the FontBox, also the new list if necessary
if ( pBox && bChanged )
{
if ( *ppFontList )
pBox->Fill( *ppFontList );
else
pBox->Clear();
}
return bChanged;
}
SvxFontNameBox_Base::SvxFontNameBox_Base(std::unique_ptr<weld::ComboBox> xWidget,
const Reference<XFrame>& rFrame,
SvxFontNameToolBoxControl& rCtrl)
: m_xListener(new comphelper::ConfigurationListener("/org.openoffice.Office.Common/Font/View"))
, m_aWYSIWYG(m_xListener, "ShowFontBoxWYSIWYG", *this)
, m_aHistory(m_xListener, "History", *this)
, m_rCtrl(rCtrl)
, m_xWidget(new FontNameBox(std::move(xWidget)))
, pFontList(nullptr)
, nFtCount(0)
, bRelease(true)
, m_xFrame(rFrame)
, mbCheckingUnknownFont(false)
{
EnableControls();
m_xWidget->connect_changed(LINK(this, SvxFontNameBox_Base, SelectHdl));
m_xWidget->connect_key_press(LINK(this, SvxFontNameBox_Base, KeyInputHdl));
m_xWidget->connect_entry_activate(LINK(this, SvxFontNameBox_Base, ActivateHdl));
m_xWidget->connect_focus_in(LINK(this, SvxFontNameBox_Base, FocusInHdl));
m_xWidget->connect_focus_out(LINK(this, SvxFontNameBox_Base, FocusOutHdl));
m_xWidget->connect_get_property_tree(LINK(this, SvxFontNameBox_Base, DumpAsPropertyTreeHdl));
m_xWidget->set_entry_width_chars(COMBO_WIDTH_IN_CHARS + 5);
}
SvxFontNameBox_Impl::SvxFontNameBox_Impl(vcl::Window* pParent, const Reference<XFrame>& rFrame,
SvxFontNameToolBoxControl& rCtrl)
: InterimItemWindow(pParent, "svx/ui/fontnamebox.ui", "FontNameBox", true, reinterpret_cast<sal_uInt64>(SfxViewShell::Current()))
, SvxFontNameBox_Base(m_xBuilder->weld_combo_box("fontnamecombobox"), rFrame, rCtrl)
{
set_id("fontnamecombobox");
SetOptimalSize();
}
void SvxFontNameBox_Base::FillList()
{
if (!m_xWidget) // e.g. disposed
return;
// Save old Selection, set back in the end
int nStartPos, nEndPos;
m_xWidget->get_entry_selection_bounds(nStartPos, nEndPos);
// Did Doc-Fontlist change?
lcl_GetDocFontList(&pFontList, this);
m_xWidget->select_entry_region(nStartPos, nEndPos);
}
bool SvxFontNameBox_Base::CheckFontIsAvailable(std::u16string_view fontname)
{
lcl_GetDocFontList(&pFontList, this);
return pFontList && pFontList->IsAvailable(fontname);
}
void SvxFontNameBox_Base::CheckAndMarkUnknownFont()
{
if (mbCheckingUnknownFont) //tdf#117537 block rentry
return;
mbCheckingUnknownFont = true;
OUString fontname = m_xWidget->get_active_text();
// tdf#154680 If a font is set and that font is unknown, show it in italic.
vcl::Font font = m_xWidget->get_entry_font();
if (fontname.isEmpty() || CheckFontIsAvailable(fontname))
{
if( font.GetItalic() != ITALIC_NONE )
{
font.SetItalic( ITALIC_NONE );
m_xWidget->set_entry_font(font);
m_xWidget->set_tooltip_text(SvxResId(RID_SVXSTR_CHARFONTNAME));
}
}
else
{
if( font.GetItalic() != ITALIC_NORMAL )
{
font.SetItalic( ITALIC_NORMAL );
m_xWidget->set_entry_font(font);
m_xWidget->set_tooltip_text(SvxResId(RID_SVXSTR_CHARFONTNAME_NOTAVAILABLE));
}
}
mbCheckingUnknownFont = false;
}
void SvxFontNameBox_Base::Update( const css::awt::FontDescriptor* pFontDesc )
{
if ( pFontDesc )
{
aCurFont.SetFamilyName ( pFontDesc->Name );
aCurFont.SetFamily ( FontFamily( pFontDesc->Family ) );
aCurFont.SetStyleName ( pFontDesc->StyleName );
aCurFont.SetPitch ( FontPitch( pFontDesc->Pitch ) );
aCurFont.SetCharSet ( rtl_TextEncoding( pFontDesc->CharSet ) );
}
OUString aCurName = aCurFont.GetFamilyName();
OUString aText = m_xWidget->get_active_text();
if (aText != aCurName)
set_active_or_entry_text(aCurName);
}
void SvxFontNameBox_Base::set_active_or_entry_text(const OUString& rText)
{
m_xWidget->set_active_or_entry_text(rText);
CheckAndMarkUnknownFont();
}
IMPL_LINK_NOARG(SvxFontNameBox_Base, FocusInHdl, weld::Widget&, void)
{
FillList();
}
IMPL_LINK(SvxFontNameBox_Base, KeyInputHdl, const KeyEvent&, rKEvt, bool)
{
return DoKeyInput(rKEvt);
}
bool SvxFontNameBox_Base::DoKeyInput(const KeyEvent& rKEvt)
{
bool bHandled = false;
sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
switch (nCode)
{
case KEY_TAB:
bRelease = false;
Select(true);
break;
case KEY_ESCAPE:
set_active_or_entry_text(m_xWidget->get_saved_value());
if (!m_rCtrl.IsInSidebar())
{
ReleaseFocus_Impl();
bHandled = true;
}
EndPreview();
break;
}
return bHandled;
}
bool SvxFontNameBox_Impl::DoKeyInput(const KeyEvent& rKEvt)
{
return SvxFontNameBox_Base::DoKeyInput(rKEvt) || ChildKeyInput(rKEvt);
}
IMPL_LINK_NOARG(SvxFontNameBox_Base, FocusOutHdl, weld::Widget&, void)
{
if (!m_xWidget->has_focus()) // a combobox can be comprised of different subwidget so double-check if none of those has focus
{
set_active_or_entry_text(m_xWidget->get_saved_value());
// send EndPreview
EndPreview();
}
}
void SvxFontNameBox_Impl::SetOptimalSize()
{
// set width in chars low so the size request will not be overridden
m_xWidget->set_entry_width_chars(1);
// tdf#132338 purely using this calculation to keep things their traditional width
Size aSize(LogicToPixel(Size((COMBO_WIDTH_IN_CHARS +5) * 4, 0), MapMode(MapUnit::MapAppFont)));
m_xWidget->set_size_request(aSize.Width(), -1);
SetSizePixel(get_preferred_size());
}
void SvxFontNameBox_Impl::DataChanged( const DataChangedEvent& rDCEvt )
{
if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
(rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
{
SetOptimalSize();
}
else if ( ( rDCEvt.GetType() == DataChangedEventType::FONTS ) ||
( rDCEvt.GetType() == DataChangedEventType::DISPLAY ) )
{
// The old font list in shell has likely been destroyed at this point, so we need to get
// the new one before doing anything further.
lcl_GetDocFontList( &pFontList, this );
}
}
void SvxFontNameBox_Base::ReleaseFocus_Impl()
{
if ( !bRelease )
{
bRelease = true;
return;
}
if ( m_xFrame.is() && m_xFrame->getContainerWindow().is() )
m_xFrame->getContainerWindow()->setFocus();
}
void SvxFontNameBox_Base::EnableControls()
{
bool bEnableMRU = m_aHistory.get();
sal_uInt16 nEntries = bEnableMRU ? MAX_MRU_FONTNAME_ENTRIES : 0;
bool bNewWYSIWYG = m_aWYSIWYG.get();
bool bOldWYSIWYG = m_xWidget->IsWYSIWYGEnabled();
if (m_xWidget->get_max_mru_count() != nEntries || bNewWYSIWYG != bOldWYSIWYG)
{
// refill in the next GetFocus-Handler
pFontList = nullptr;
Clear();
m_xWidget->set_max_mru_count(nEntries);
}
if (bNewWYSIWYG != bOldWYSIWYG)
m_xWidget->EnableWYSIWYG(bNewWYSIWYG);
}
IMPL_LINK(SvxFontNameBox_Base, SelectHdl, weld::ComboBox&, rCombo, void)
{
Select(rCombo.changed_by_direct_pick()); // only when picked from the list
}
IMPL_LINK_NOARG(SvxFontNameBox_Base, ActivateHdl, weld::ComboBox&, bool)
{
Select(true);
return true;
}
void SvxFontNameBox_Base::Select(bool bNonTravelSelect)
{
Sequence< PropertyValue > aArgs( 1 );
auto pArgs = aArgs.getArray();
std::unique_ptr<SvxFontItem> pFontItem;
if ( pFontList )
{
FontMetric aFontMetric( pFontList->Get(m_xWidget->get_active_text(),
aCurFont.GetWeight(),
aCurFont.GetItalic() ) );
aCurFont = aFontMetric;
pFontItem.reset( new SvxFontItem( aFontMetric.GetFamilyType(),
aFontMetric.GetFamilyName(),
aFontMetric.GetStyleName(),
aFontMetric.GetPitch(),
aFontMetric.GetCharSet(),
SID_ATTR_CHAR_FONT ) );
Any a;
pFontItem->QueryValue( a );
pArgs[0].Value = a;
}
const Reference<XDispatchProvider> xProvider(m_xFrame, UNO_QUERY);
if (bNonTravelSelect)
{
CheckAndMarkUnknownFont();
// #i33380# DR 2004-09-03 Moved the following line above the Dispatch() call.
// This instance may be deleted in the meantime (i.e. when a dialog is opened
// while in Dispatch()), accessing members will crash in this case.
ReleaseFocus_Impl();
EndPreview();
if (pFontItem)
{
pArgs[0].Name = "CharFontName";
SfxToolBoxControl::Dispatch(xProvider, ".uno:CharFontName", aArgs);
}
}
else
{
if (pFontItem)
{
pArgs[0].Name = "CharPreviewFontName";
SfxToolBoxControl::Dispatch(xProvider, ".uno:CharPreviewFontName", aArgs);
}
}
}
IMPL_LINK(SvxFontNameBox_Base, DumpAsPropertyTreeHdl, tools::JsonWriter&, rJsonWriter, void)
{
{
auto entriesNode = rJsonWriter.startNode("entries");
for (int i = 0, nEntryCount = m_xWidget->get_count(); i < nEntryCount; ++i)
{
auto entryNode = rJsonWriter.startNode("");
rJsonWriter.put("", m_xWidget->get_text(i));
}
}
int nSelectedEntry = m_xWidget->get_active();
rJsonWriter.put("selectedCount", static_cast<sal_Int32>(nSelectedEntry == -1 ? 0 : 1));
{
auto selectedNode = rJsonWriter.startNode("selectedEntries");
if (nSelectedEntry != -1)
{
auto entryNode = rJsonWriter.startNode("");
rJsonWriter.put("", m_xWidget->get_text(nSelectedEntry));
}
}
rJsonWriter.put("command", ".uno:CharFontName");
}
ColorWindow::ColorWindow(OUString rCommand,
std::shared_ptr<PaletteManager> xPaletteManager,
ColorStatus& rColorStatus,
sal_uInt16 nSlotId,
const Reference< XFrame >& rFrame,
const MenuOrToolMenuButton& rMenuButton,
TopLevelParentFunction aTopLevelParentFunction,
ColorSelectFunction aColorSelectFunction)
: WeldToolbarPopup(rFrame, rMenuButton.get_widget(), "svx/ui/colorwindow.ui", "palette_popup_window")
, theSlotId(nSlotId)
, maCommand(std::move(rCommand))
, maMenuButton(rMenuButton)
, mxPaletteManager(std::move(xPaletteManager))
, mrColorStatus(rColorStatus)
, maTopLevelParentFunction(std::move(aTopLevelParentFunction))
, maColorSelectFunction(std::move(aColorSelectFunction))
, mxColorSet(new SvxColorValueSet(m_xBuilder->weld_scrolled_window("colorsetwin", true)))
, mxRecentColorSet(new SvxColorValueSet(nullptr))
, mxPaletteListBox(m_xBuilder->weld_combo_box("palette_listbox"))
, mxButtonAutoColor(m_xBuilder->weld_button("auto_color_button"))
, mxButtonNoneColor(m_xBuilder->weld_button("none_color_button"))
, mxButtonPicker(m_xBuilder->weld_button("color_picker_button"))
, mxAutomaticSeparator(m_xBuilder->weld_widget("separator4"))
, mxColorSetWin(new weld::CustomWeld(*m_xBuilder, "colorset", *mxColorSet))
, mxRecentColorSetWin(new weld::CustomWeld(*m_xBuilder, "recent_colorset", *mxRecentColorSet))
, mpDefaultButton(nullptr)
{
mxColorSet->SetStyle( WinBits(WB_FLATVALUESET | WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT | WB_TABSTOP) );
mxRecentColorSet->SetStyle( WinBits(WB_FLATVALUESET | WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT | WB_TABSTOP) );
switch ( theSlotId )
{
case SID_ATTR_CHAR_COLOR_BACKGROUND:
case SID_BACKGROUND_COLOR:
case SID_ATTR_CHAR_BACK_COLOR:
case SID_TABLE_CELL_BACKGROUND_COLOR:
{
mxButtonAutoColor->set_label( SvxResId( RID_SVXSTR_NOFILL ) );
break;
}
case SID_AUTHOR_COLOR:
{
mxButtonAutoColor->set_label( SvxResId( RID_SVXSTR_BY_AUTHOR ) );
break;
}
case SID_BMPMASK_COLOR:
{
mxButtonAutoColor->set_label( SvxResId( RID_SVXSTR_TRANSPARENT ) );
break;
}
case SID_ATTR_CHAR_COLOR:
case SID_ATTR_CHAR_COLOR2:
case SID_EXTRUSION_3D_COLOR:
{
mxButtonAutoColor->set_label(EditResId(RID_SVXSTR_AUTOMATIC));
break;
}
case SID_FM_CTL_PROPERTIES:
{
mxButtonAutoColor->set_label( SvxResId( RID_SVXSTR_DEFAULT ) );
break;
}
default:
{
mxButtonAutoColor->hide();
mxAutomaticSeparator->hide();
break;
}
}
mxPaletteListBox->connect_changed(LINK(this, ColorWindow, SelectPaletteHdl));
std::vector<OUString> aPaletteList = mxPaletteManager->GetPaletteList();
mxPaletteListBox->freeze();
for (const auto& rPalette : aPaletteList)
mxPaletteListBox->append_text(rPalette);
mxPaletteListBox->thaw();
OUString aPaletteName( officecfg::Office::Common::UserColors::PaletteName::get() );
mxPaletteListBox->set_active_text(aPaletteName);
const int nSelectedEntry(mxPaletteListBox->get_active());
if (nSelectedEntry != -1)
mxPaletteManager->SetPalette(nSelectedEntry);
mxButtonAutoColor->connect_clicked(LINK(this, ColorWindow, AutoColorClickHdl));
mxButtonNoneColor->connect_clicked(LINK(this, ColorWindow, AutoColorClickHdl));
mxButtonPicker->connect_clicked(LINK(this, ColorWindow, OpenPickerClickHdl));
mxColorSet->SetSelectHdl(LINK( this, ColorWindow, SelectHdl));
mxRecentColorSet->SetSelectHdl(LINK( this, ColorWindow, SelectHdl));
m_xTopLevel->set_help_id(HID_POPUP_COLOR);
mxColorSet->SetHelpId(HID_POPUP_COLOR_CTRL);
mxPaletteManager->ReloadColorSet(*mxColorSet);
const sal_uInt32 nMaxItems(SvxColorValueSet::getMaxRowCount() * SvxColorValueSet::getColumnCount());
Size aSize = mxColorSet->layoutAllVisible(nMaxItems);
mxColorSet->set_size_request(aSize.Width(), aSize.Height());
mxPaletteManager->ReloadRecentColorSet(*mxRecentColorSet);
aSize = mxRecentColorSet->layoutAllVisible(mxPaletteManager->GetRecentColorCount());
mxRecentColorSet->set_size_request(aSize.Width(), aSize.Height());
AddStatusListener( ".uno:ColorTableState" );
AddStatusListener( maCommand );
if ( maCommand == ".uno:FrameLineColor" )
{
AddStatusListener( ".uno:BorderTLBR" );
AddStatusListener( ".uno:BorderBLTR" );
}
}
void ColorWindow::GrabFocus()
{
if (mxColorSet->IsNoSelection() && mpDefaultButton)
mpDefaultButton->grab_focus();
else
mxColorSet->GrabFocus();
}
void ColorWindow::ShowNoneButton()
{
mxButtonNoneColor->show();
}
ColorWindow::~ColorWindow()
{
}
NamedColor ColorWindow::GetSelectEntryColor(ValueSet const * pColorSet)
{
Color aColor = pColorSet->GetItemColor(pColorSet->GetSelectedItemId());
OUString sColorName = pColorSet->GetItemText(pColorSet->GetSelectedItemId());
return { aColor, sColorName };
}
namespace
{
NamedColor GetAutoColor(sal_uInt16 nSlotId)
{
Color aColor;
OUString sColorName;
switch (nSlotId)
{
case SID_ATTR_CHAR_COLOR_BACKGROUND:
case SID_BACKGROUND_COLOR:
case SID_ATTR_CHAR_BACK_COLOR:
case SID_TABLE_CELL_BACKGROUND_COLOR:
aColor = COL_TRANSPARENT;
sColorName = SvxResId(RID_SVXSTR_NOFILL);
break;
case SID_AUTHOR_COLOR:
aColor = COL_TRANSPARENT;
sColorName = SvxResId(RID_SVXSTR_BY_AUTHOR);
break;
case SID_BMPMASK_COLOR:
aColor = COL_TRANSPARENT;
sColorName = SvxResId(RID_SVXSTR_TRANSPARENT);
break;
case SID_FM_CTL_PROPERTIES:
aColor = COL_TRANSPARENT;
sColorName = SvxResId(RID_SVXSTR_DEFAULT);
break;
case SID_ATTR_CHAR_COLOR:
case SID_ATTR_CHAR_COLOR2:
case SID_EXTRUSION_3D_COLOR:
default:
aColor = COL_AUTO;
sColorName = EditResId(RID_SVXSTR_AUTOMATIC);
break;
}
return {aColor, sColorName};
}
NamedColor GetNoneColor()
{
OUString aName = comphelper::LibreOfficeKit::isActive()
? SvxResId(RID_SVXSTR_INVISIBLE)
: SvxResId(RID_SVXSTR_NONE);
return { COL_NONE_COLOR, aName };
}
}
NamedColor ColorWindow::GetSelectEntryColor() const
{
if (!mxColorSet->IsNoSelection())
return GetSelectEntryColor(mxColorSet.get());
if (!mxRecentColorSet->IsNoSelection())
return GetSelectEntryColor(mxRecentColorSet.get());
if (mxButtonNoneColor.get() == mpDefaultButton)
return GetNoneColor();
return GetAutoColor();
}
IMPL_LINK(ColorWindow, SelectHdl, ValueSet*, pColorSet, void)
{
NamedColor aNamedColor = GetSelectEntryColor(pColorSet);
if (pColorSet != mxRecentColorSet.get())
{
mxPaletteManager->AddRecentColor(aNamedColor.m_aColor, aNamedColor.m_aName);
if (!maMenuButton.get_active())
mxPaletteManager->ReloadRecentColorSet(*mxRecentColorSet);
}
mxPaletteManager->SetSplitButtonColor(aNamedColor);
// deliberate take a copy here in case maMenuButton.set_inactive
// triggers a callback that destroys ourself
ColorSelectFunction aColorSelectFunction(maColorSelectFunction);
OUString sCommand(maCommand);
// Same for querying IsTheme early.
bool bThemePaletteSelected = mxPaletteManager->IsThemePaletteSelected();
sal_uInt16 nSelectedItemId = pColorSet->GetSelectedItemId();
if (bThemePaletteSelected)
{
sal_uInt16 nThemeIndex;
sal_uInt16 nEffectIndex;
if (PaletteManager::GetThemeAndEffectIndex(nSelectedItemId, nThemeIndex, nEffectIndex))
{
aNamedColor.m_nThemeIndex = nThemeIndex;
mxPaletteManager->GetLumModOff(nThemeIndex, nEffectIndex, aNamedColor.m_nLumMod, aNamedColor.m_nLumOff);
}
}
maMenuButton.set_inactive();
aColorSelectFunction(sCommand, aNamedColor);
}
IMPL_LINK_NOARG(ColorWindow, SelectPaletteHdl, weld::ComboBox&, void)
{
int nPos = mxPaletteListBox->get_active();
mxPaletteManager->SetPalette( nPos );
mxPaletteManager->ReloadColorSet(*mxColorSet);
mxColorSet->layoutToGivenHeight(mxColorSet->GetOutputSizePixel().Height(), mxPaletteManager->GetColorCount());
}
NamedColor ColorWindow::GetAutoColor() const
{
return ::GetAutoColor(theSlotId);
}
IMPL_LINK(ColorWindow, AutoColorClickHdl, weld::Button&, rButton, void)
{
NamedColor aNamedColor = &rButton == mxButtonAutoColor.get() ? GetAutoColor() : GetNoneColor();
mxColorSet->SetNoSelection();
mxRecentColorSet->SetNoSelection();
mpDefaultButton = &rButton;
mxPaletteManager->SetSplitButtonColor(aNamedColor);
// deliberate take a copy here in case maMenuButton.set_inactive
// triggers a callback that destroys ourself
ColorSelectFunction aColorSelectFunction(maColorSelectFunction);
OUString sCommand(maCommand);
maMenuButton.set_inactive();
aColorSelectFunction(sCommand, aNamedColor);
}
IMPL_LINK_NOARG(ColorWindow, OpenPickerClickHdl, weld::Button&, void)
{
// copy before set_inactive
auto nColor = GetSelectEntryColor().m_aColor;
auto pParentWindow = maTopLevelParentFunction();
OUString sCommand = maCommand;
std::shared_ptr<PaletteManager> xPaletteManager(mxPaletteManager);
maMenuButton.set_inactive();
xPaletteManager->PopupColorPicker(pParentWindow, sCommand, nColor);
}
void ColorWindow::SetNoSelection()
{
mxColorSet->SetNoSelection();
mxRecentColorSet->SetNoSelection();
mpDefaultButton = nullptr;
}
bool ColorWindow::IsNoSelection() const
{
if (!mxColorSet->IsNoSelection())
return false;
if (!mxRecentColorSet->IsNoSelection())
return false;
return !mxButtonAutoColor->get_visible() && !mxButtonNoneColor->get_visible();
}
void ColorWindow::statusChanged( const css::frame::FeatureStateEvent& rEvent )
{
if (rEvent.FeatureURL.Complete == ".uno:ColorTableState")
{
if (rEvent.IsEnabled && mxPaletteManager->GetPalette() == 0)
{
mxPaletteManager->ReloadColorSet(*mxColorSet);
mxColorSet->layoutToGivenHeight(mxColorSet->GetOutputSizePixel().Height(), mxPaletteManager->GetColorCount());
}
}
else
{
mrColorStatus.statusChanged(rEvent);
SelectEntry(mrColorStatus.GetColor());
}
}
bool ColorWindow::SelectValueSetEntry(SvxColorValueSet* pColorSet, const Color& rColor)
{
for (size_t i = 1; i <= pColorSet->GetItemCount(); ++i)
{
if (rColor == pColorSet->GetItemColor(i))
{
pColorSet->SelectItem(i);
return true;
}
}
return false;
}
void ColorWindow::SelectEntry(const NamedColor& rNamedColor)
{
SetNoSelection();
const Color &rColor = rNamedColor.m_aColor;
if (mxButtonAutoColor->get_visible() && rColor.IsFullyTransparent())
{
mpDefaultButton = mxButtonAutoColor.get();
return;
}
if (mxButtonNoneColor->get_visible() && rColor == COL_NONE_COLOR)
{
mpDefaultButton = mxButtonNoneColor.get();
return;
}
// try current palette
bool bFoundColor = SelectValueSetEntry(mxColorSet.get(), rColor);
// try recently used
if (!bFoundColor)
bFoundColor = SelectValueSetEntry(mxRecentColorSet.get(), rColor);
// if it's not there, add it there now to the end of the recently used
// so its available somewhere handy, but not without trashing the
// whole recently used
if (!bFoundColor)
{
const OUString& rColorName = rNamedColor.m_aName;
mxPaletteManager->AddRecentColor(rColor, rColorName, false);
mxPaletteManager->ReloadRecentColorSet(*mxRecentColorSet);
SelectValueSetEntry(mxRecentColorSet.get(), rColor);
}
}
void ColorWindow::SelectEntry(const Color& rColor)
{
OUString sColorName = "#" + rColor.AsRGBHexString().toAsciiUpperCase();
ColorWindow::SelectEntry({rColor, sColorName});
}
ColorStatus::ColorStatus() :
maColor( COL_TRANSPARENT ),
maTLBRColor( COL_TRANSPARENT ),
maBLTRColor( COL_TRANSPARENT )
{
}
void ColorStatus::statusChanged( const css::frame::FeatureStateEvent& rEvent )
{
Color aColor( COL_TRANSPARENT );
css::table::BorderLine2 aTable;
if ( rEvent.State >>= aTable )
{
SvxBorderLine aLine;
SvxBoxItem::LineToSvxLine( aTable, aLine, false );
if ( !aLine.isEmpty() )
aColor = aLine.GetColor();
}
else
rEvent.State >>= aColor;
if ( rEvent.FeatureURL.Path == "BorderTLBR" )
maTLBRColor = aColor;
else if ( rEvent.FeatureURL.Path == "BorderBLTR" )
maBLTRColor = aColor;
else
maColor = aColor;
}
Color ColorStatus::GetColor()
{
Color aColor( maColor );
if ( maTLBRColor != COL_TRANSPARENT )
{
if ( aColor != maTLBRColor && aColor != COL_TRANSPARENT )
return COL_TRANSPARENT;
aColor = maTLBRColor;
}
if ( maBLTRColor != COL_TRANSPARENT )
{
if ( aColor != maBLTRColor && aColor != COL_TRANSPARENT )
return COL_TRANSPARENT;
return maBLTRColor;
}
return aColor;
}
SvxFrameWindow_Impl::SvxFrameWindow_Impl(SvxFrameToolBoxControl* pControl, weld::Widget* pParent)
: WeldToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/floatingframeborder.ui", "FloatingFrameBorder")
, mxControl(pControl)
, mxFrameSet(new SvxFrmValueSet_Impl)
, mxFrameSetWin(new weld::CustomWeld(*m_xBuilder, "valueset", *mxFrameSet))
, bParagraphMode(false)
, m_bIsWriter(false)
{
// check whether the document is Writer or not
if (Reference<lang::XServiceInfo> xSI{ m_xFrame->getController()->getModel(), UNO_QUERY })
m_bIsWriter = xSI->supportsService("com.sun.star.text.TextDocument");
mxFrameSet->SetStyle(WB_ITEMBORDER | WB_DOUBLEBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT);
AddStatusListener(".uno:BorderReducedMode");
InitImageList();
/*
* 1 2 3 4 5
* ------------------------------------------------------
* NONE LEFT RIGHT LEFTRIGHT DIAGONALDOWN
* TOP BOTTOM TOPBOTTOM OUTER DIAGONALUP
* ------------------------------------------------------
* HOR HORINNER VERINNER ALL CRISSCROSS <- can be switched of via bParagraphMode
*/
sal_uInt16 i = 0;
// diagonal borders available only for Calc.
// Therefore, Calc uses 10 border types while
// Writer uses 8 of them - for a single cell.
for ( i=1; i < (m_bIsWriter ? 9 : 11); i++ )
mxFrameSet->InsertItem(i, Image(aImgVec[i-1].first), aImgVec[i-1].second);
//bParagraphMode should have been set in StateChanged
if ( !bParagraphMode )
// when multiple cell selected:
// Writer has 12 border types and Calc has 15 of them.
for ( i = (m_bIsWriter ? 9 : 11); i < (m_bIsWriter ? 13 : 16); i++ )
mxFrameSet->InsertItem(i, Image(aImgVec[i-1].first), aImgVec[i-1].second);
// adjust frame column for Writer
sal_uInt16 colCount = m_bIsWriter ? 4 : 5;
mxFrameSet->SetColCount( colCount );
mxFrameSet->SetSelectHdl( LINK( this, SvxFrameWindow_Impl, SelectHdl ) );
CalcSizeValueSet();
mxFrameSet->SetHelpId( HID_POPUP_FRAME );
mxFrameSet->SetAccessibleName( SvxResId(RID_SVXSTR_FRAME) );
}
namespace {
enum class FrmValidFlags {
NONE = 0x00,
Left = 0x01,
Right = 0x02,
Top = 0x04,
Bottom = 0x08,
HInner = 0x10,
VInner = 0x20,
AllMask = 0x3f,
};
}
namespace o3tl {
template<> struct typed_flags<FrmValidFlags> : is_typed_flags<FrmValidFlags, 0x3f> {};
}
// By default unset lines remain unchanged.
// Via Shift unset lines are reset
IMPL_LINK_NOARG(SvxFrameWindow_Impl, SelectHdl, ValueSet*, void)
{
SvxBoxItem aBorderOuter( SID_ATTR_BORDER_OUTER );
SvxBoxInfoItem aBorderInner( SID_ATTR_BORDER_INNER );
SvxBorderLine theDefLine;
// diagonal down border
SvxBorderLine dDownBorderLine(nullptr, SvxBorderLineWidth::Hairline);
SvxLineItem dDownLineItem(SID_ATTR_BORDER_DIAG_TLBR);
// diagonal up border
SvxBorderLine dUpBorderLine(nullptr, SvxBorderLineWidth::Hairline);
SvxLineItem dUpLineItem(SID_ATTR_BORDER_DIAG_BLTR);
bool bIsDiagonalBorder = false;
SvxBorderLine *pLeft = nullptr,
*pRight = nullptr,
*pTop = nullptr,
*pBottom = nullptr;
sal_uInt16 nSel = mxFrameSet->GetSelectedItemId();
sal_uInt16 nModifier = mxFrameSet->GetModifier();
FrmValidFlags nValidFlags = FrmValidFlags::NONE;
// tdf#48622, tdf#145828 use correct default to create intended 0.75pt
// cell border using the border formatting tool in the standard toolbar
theDefLine.GuessLinesWidths(theDefLine.GetBorderLineStyle(), SvxBorderLineWidth::Thin);
// nSel has 15 cases which means 15 border
// types for Calc. But Writer uses only 12
// of them - when diagonal borders excluded.
if (m_bIsWriter)
{
// add appropriate increments
// to match the correct borders.
if (nSel > 8) { nSel += 2; }
else if (nSel > 4) { nSel++; }
}
switch ( nSel )
{
case 1: nValidFlags |= FrmValidFlags::AllMask;
// set nullptr to remove diagonal lines
dDownLineItem.SetLine(nullptr);
dUpLineItem.SetLine(nullptr);
SetDiagonalDownBorder(dDownLineItem);
SetDiagonalUpBorder(dUpLineItem);
break; // NONE
case 2: pLeft = &theDefLine;
nValidFlags |= FrmValidFlags::Left;
break; // LEFT
case 3: pRight = &theDefLine;
nValidFlags |= FrmValidFlags::Right;
break; // RIGHT
case 4: pLeft = pRight = &theDefLine;
nValidFlags |= FrmValidFlags::Right|FrmValidFlags::Left;
break; // LEFTRIGHT
case 5: dDownLineItem.SetLine(&dDownBorderLine);
SetDiagonalDownBorder(dDownLineItem);
bIsDiagonalBorder = true;
break; // DIAGONAL DOWN
case 6: pTop = &theDefLine;
nValidFlags |= FrmValidFlags::Top;
break; // TOP
case 7: pBottom = &theDefLine;
nValidFlags |= FrmValidFlags::Bottom;
break; // BOTTOM
case 8: pTop = pBottom = &theDefLine;
nValidFlags |= FrmValidFlags::Bottom|FrmValidFlags::Top;
break; // TOPBOTTOM
case 9: pLeft = pRight = pTop = pBottom = &theDefLine;
nValidFlags |= FrmValidFlags::Left | FrmValidFlags::Right | FrmValidFlags::Top | FrmValidFlags::Bottom;
break; // OUTER
case 10:
dUpLineItem.SetLine(&dUpBorderLine);
SetDiagonalUpBorder(dUpLineItem);
bIsDiagonalBorder = true;
break; // DIAGONAL UP
// Inner Table:
case 11: // HOR
pTop = pBottom = &theDefLine;
aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::HORI );
aBorderInner.SetLine( nullptr, SvxBoxInfoItemLine::VERT );
nValidFlags |= FrmValidFlags::HInner|FrmValidFlags::Top|FrmValidFlags::Bottom;
break;
case 12: // HORINNER
pLeft = pRight = pTop = pBottom = &theDefLine;
aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::HORI );
aBorderInner.SetLine( nullptr, SvxBoxInfoItemLine::VERT );
nValidFlags |= FrmValidFlags::Right|FrmValidFlags::Left|FrmValidFlags::HInner|FrmValidFlags::Top|FrmValidFlags::Bottom;
break;
case 13: // VERINNER
pLeft = pRight = pTop = pBottom = &theDefLine;
aBorderInner.SetLine( nullptr, SvxBoxInfoItemLine::HORI );
aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::VERT );
nValidFlags |= FrmValidFlags::Right|FrmValidFlags::Left|FrmValidFlags::VInner|FrmValidFlags::Top|FrmValidFlags::Bottom;
break;
case 14: // ALL
pLeft = pRight = pTop = pBottom = &theDefLine;
aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::HORI );
aBorderInner.SetLine( &theDefLine, SvxBoxInfoItemLine::VERT );
nValidFlags |= FrmValidFlags::AllMask;
break;
case 15:
// set both diagonal lines to draw criss-cross line
dDownLineItem.SetLine(&dDownBorderLine);
dUpLineItem.SetLine(&dUpBorderLine);
SetDiagonalDownBorder(dDownLineItem);
SetDiagonalUpBorder(dUpLineItem);
bIsDiagonalBorder = true;
break; // CRISS-CROSS
default:
break;
}
// if diagonal borders selected,
// no need to execute this block
if (!bIsDiagonalBorder)
{
aBorderOuter.SetLine( pLeft, SvxBoxItemLine::LEFT );
aBorderOuter.SetLine( pRight, SvxBoxItemLine::RIGHT );
aBorderOuter.SetLine( pTop, SvxBoxItemLine::TOP );
aBorderOuter.SetLine( pBottom, SvxBoxItemLine::BOTTOM );
if(nModifier == KEY_SHIFT)
nValidFlags |= FrmValidFlags::AllMask;
aBorderInner.SetValid( SvxBoxInfoItemValidFlags::TOP, bool(nValidFlags&FrmValidFlags::Top ));
aBorderInner.SetValid( SvxBoxInfoItemValidFlags::BOTTOM, bool(nValidFlags&FrmValidFlags::Bottom ));
aBorderInner.SetValid( SvxBoxInfoItemValidFlags::LEFT, bool(nValidFlags&FrmValidFlags::Left));
aBorderInner.SetValid( SvxBoxInfoItemValidFlags::RIGHT, bool(nValidFlags&FrmValidFlags::Right ));
aBorderInner.SetValid( SvxBoxInfoItemValidFlags::HORI, bool(nValidFlags&FrmValidFlags::HInner ));
aBorderInner.SetValid( SvxBoxInfoItemValidFlags::VERT, bool(nValidFlags&FrmValidFlags::VInner));
aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISTANCE );
aBorderInner.SetValid( SvxBoxInfoItemValidFlags::DISABLE, false );
Any a1, a2;
aBorderOuter.QueryValue( a1 );
aBorderInner.QueryValue( a2 );
Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue("OuterBorder", a1),
comphelper::makePropertyValue("InnerBorder", a2) };
mxControl->dispatchCommand( ".uno:SetBorderStyle", aArgs );
}
// coverity[ check_after_deref : FALSE]
if (mxFrameSet)
{
/* #i33380# Moved the following line above the Dispatch() call.
This instance may be deleted in the meantime (i.e. when a dialog is opened
while in Dispatch()), accessing members will crash in this case. */
mxFrameSet->SetNoSelection();
}
mxControl->EndPopupMode();
}
void SvxFrameWindow_Impl::SetDiagonalDownBorder(const SvxLineItem& dDownLineItem)
{
// apply diagonal down border
Any a;
dDownLineItem.QueryValue(a);
Sequence<PropertyValue> aArgs{ comphelper::makePropertyValue("BorderTLBR", a) };
mxControl->dispatchCommand(".uno:BorderTLBR", aArgs);
}
void SvxFrameWindow_Impl::SetDiagonalUpBorder(const SvxLineItem& dUpLineItem)
{
// apply diagonal up border
Any a;
dUpLineItem.QueryValue(a);
Sequence<PropertyValue> aArgs{ comphelper::makePropertyValue("BorderBLTR", a) };
mxControl->dispatchCommand(".uno:BorderBLTR", aArgs);
}
void SvxFrameWindow_Impl::statusChanged( const css::frame::FeatureStateEvent& rEvent )
{
if ( rEvent.FeatureURL.Complete != ".uno:BorderReducedMode" )
return;
bool bValue;
if ( !(rEvent.State >>= bValue) )
return;
bParagraphMode = bValue;
//initial calls mustn't insert or remove elements
if(!mxFrameSet->GetItemCount())
return;
// set 12 border types for Writer, otherwise 15 for Calc.
bool bTableMode = ( mxFrameSet->GetItemCount() == static_cast<size_t>(m_bIsWriter ? 12 : 15) );
bool bResize = false;
if ( bTableMode && bParagraphMode )
{
for ( sal_uInt16 i = (m_bIsWriter ? 9 : 11); i < (m_bIsWriter ? 13 : 16); i++ )
mxFrameSet->RemoveItem(i);
bResize = true;
}
else if ( !bTableMode && !bParagraphMode )
{
for ( sal_uInt16 i = (m_bIsWriter ? 9 : 11); i < (m_bIsWriter ? 13 : 16); i++ )
mxFrameSet->InsertItem(i, Image(aImgVec[i-1].first), aImgVec[i-1].second);
bResize = true;
}
if ( bResize )
{
CalcSizeValueSet();
}
}
void SvxFrameWindow_Impl::CalcSizeValueSet()
{
weld::DrawingArea* pDrawingArea = mxFrameSet->GetDrawingArea();
const OutputDevice& rDevice = pDrawingArea->get_ref_device();
Size aItemSize( 20 * rDevice.GetDPIScaleFactor(), 20 * rDevice.GetDPIScaleFactor() );
Size aSize = mxFrameSet->CalcWindowSizePixel( aItemSize );
pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
mxFrameSet->SetOutputSizePixel(aSize);
}
void SvxFrameWindow_Impl::InitImageList()
{
if (m_bIsWriter)
{
// Writer-specific aImgVec.
// Since Writer doesn't have diagonal borders,
// we have to use 12 border types here.
aImgVec = {
{BitmapEx(RID_SVXBMP_FRAME1), SvxResId(RID_SVXSTR_TABLE_PRESET_NONE)},
{BitmapEx(RID_SVXBMP_FRAME2), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYLEFT)},
{BitmapEx(RID_SVXBMP_FRAME3), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYRIGHT)},
{BitmapEx(RID_SVXBMP_FRAME4), SvxResId(RID_SVXSTR_PARA_PRESET_LEFTRIGHT)},
{BitmapEx(RID_SVXBMP_FRAME5), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYTOP)},
{BitmapEx(RID_SVXBMP_FRAME6), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYTBOTTOM)},
{BitmapEx(RID_SVXBMP_FRAME7), SvxResId(RID_SVXSTR_PARA_PRESET_TOPBOTTOM)},
{BitmapEx(RID_SVXBMP_FRAME8), SvxResId(RID_SVXSTR_TABLE_PRESET_ONLYOUTER)},
{BitmapEx(RID_SVXBMP_FRAME9), SvxResId(RID_SVXSTR_PARA_PRESET_TOPBOTTOMHORI)},
{BitmapEx(RID_SVXBMP_FRAME10), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERHORI)},
{BitmapEx(RID_SVXBMP_FRAME11), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERVERI)},
{BitmapEx(RID_SVXBMP_FRAME12), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERALL)}
};
}
else
{
// Calc has diagonal borders feature.
// Therefore use additional 3 diagonal border types,
// which make border types 15 in total.
aImgVec = {
{BitmapEx(RID_SVXBMP_FRAME1), SvxResId(RID_SVXSTR_TABLE_PRESET_NONE)},
{BitmapEx(RID_SVXBMP_FRAME2), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYLEFT)},
{BitmapEx(RID_SVXBMP_FRAME3), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYRIGHT)},
{BitmapEx(RID_SVXBMP_FRAME4), SvxResId(RID_SVXSTR_PARA_PRESET_LEFTRIGHT)},
{BitmapEx(RID_SVXBMP_FRAME14), SvxResId(RID_SVXSTR_PARA_PRESET_DIAGONALDOWN)}, // diagonal down border
{BitmapEx(RID_SVXBMP_FRAME5), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYTOP)},
{BitmapEx(RID_SVXBMP_FRAME6), SvxResId(RID_SVXSTR_PARA_PRESET_ONLYTBOTTOM)},
{BitmapEx(RID_SVXBMP_FRAME7), SvxResId(RID_SVXSTR_PARA_PRESET_TOPBOTTOM)},
{BitmapEx(RID_SVXBMP_FRAME8), SvxResId(RID_SVXSTR_TABLE_PRESET_ONLYOUTER)},
{BitmapEx(RID_SVXBMP_FRAME13), SvxResId(RID_SVXSTR_PARA_PRESET_DIAGONALUP)}, // diagonal up border
{BitmapEx(RID_SVXBMP_FRAME9), SvxResId(RID_SVXSTR_PARA_PRESET_TOPBOTTOMHORI)},
{BitmapEx(RID_SVXBMP_FRAME10), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERHORI)},
{BitmapEx(RID_SVXBMP_FRAME11), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERVERI)},
{BitmapEx(RID_SVXBMP_FRAME12), SvxResId(RID_SVXSTR_TABLE_PRESET_OUTERALL)},
{BitmapEx(RID_SVXBMP_FRAME15), SvxResId(RID_SVXSTR_PARA_PRESET_CRISSCROSS)} // criss-cross border
};
}
}
static Color lcl_mediumColor( Color aMain, Color /*aDefault*/ )
{
return SvxBorderLine::threeDMediumColor( aMain );
}
SvxLineWindow_Impl::SvxLineWindow_Impl(SvxFrameToolBoxControl* pControl, weld::Widget* pParent)
: WeldToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/floatingframeborder.ui", "FloatingFrameBorder")
, m_xControl(pControl)
, m_xLineStyleLb(new LineListBox)
, m_xLineStyleLbWin(new weld::CustomWeld(*m_xBuilder, "valueset", *m_xLineStyleLb))
, m_bIsWriter(false)
{
try
{
Reference< lang::XServiceInfo > xServices(m_xFrame->getController()->getModel(), UNO_QUERY_THROW);
m_bIsWriter = xServices->supportsService("com.sun.star.text.TextDocument");
}
catch(const uno::Exception& )
{
}
m_xLineStyleLb->SetStyle( WinBits(WB_FLATVALUESET | WB_ITEMBORDER | WB_3DLOOK | WB_NO_DIRECTSELECT | WB_TABSTOP) );
m_xLineStyleLb->SetSourceUnit( FieldUnit::TWIP );
m_xLineStyleLb->SetNone( comphelper::LibreOfficeKit::isActive() ? SvxResId(RID_SVXSTR_INVISIBLE)
:SvxResId(RID_SVXSTR_NONE) );
m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::SOLID ), SvxBorderLineStyle::SOLID );
m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::DOTTED ), SvxBorderLineStyle::DOTTED );
m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::DASHED ), SvxBorderLineStyle::DASHED );
// Double lines
m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::DOUBLE ), SvxBorderLineStyle::DOUBLE );
m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THINTHICK_SMALLGAP ), SvxBorderLineStyle::THINTHICK_SMALLGAP, 20 );
m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THINTHICK_MEDIUMGAP ), SvxBorderLineStyle::THINTHICK_MEDIUMGAP );
m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THINTHICK_LARGEGAP ), SvxBorderLineStyle::THINTHICK_LARGEGAP );
m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THICKTHIN_SMALLGAP ), SvxBorderLineStyle::THICKTHIN_SMALLGAP, 20 );
m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THICKTHIN_MEDIUMGAP ), SvxBorderLineStyle::THICKTHIN_MEDIUMGAP );
m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::THICKTHIN_LARGEGAP ), SvxBorderLineStyle::THICKTHIN_LARGEGAP );
// Engraved / Embossed
m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::EMBOSSED ), SvxBorderLineStyle::EMBOSSED, 15,
&SvxBorderLine::threeDLightColor, &SvxBorderLine::threeDDarkColor,
&lcl_mediumColor );
m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::ENGRAVED ), SvxBorderLineStyle::ENGRAVED, 15,
&SvxBorderLine::threeDDarkColor, &SvxBorderLine::threeDLightColor,
&lcl_mediumColor );
// Inset / Outset
m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::OUTSET ), SvxBorderLineStyle::OUTSET, 10,
&SvxBorderLine::lightColor, &SvxBorderLine::darkColor );
m_xLineStyleLb->InsertEntry( SvxBorderLine::getWidthImpl( SvxBorderLineStyle::INSET ), SvxBorderLineStyle::INSET, 10,
&SvxBorderLine::darkColor, &SvxBorderLine::lightColor );
Size aSize = m_xLineStyleLb->SetWidth( 20 ); // 1pt by default
m_xLineStyleLb->SetSelectHdl( LINK( this, SvxLineWindow_Impl, SelectHdl ) );
m_xContainer->set_help_id(HID_POPUP_LINE);
aSize.AdjustWidth(6);
aSize.AdjustHeight(6);
aSize = m_xLineStyleLb->CalcWindowSizePixel(aSize);
m_xLineStyleLb->GetDrawingArea()->set_size_request(aSize.Width(), aSize.Height());
m_xLineStyleLb->SetOutputSizePixel(aSize);
}
IMPL_LINK_NOARG(SvxLineWindow_Impl, SelectHdl, ValueSet*, void)
{
SvxLineItem aLineItem( SID_FRAME_LINESTYLE );
SvxBorderLineStyle nStyle = m_xLineStyleLb->GetSelectEntryStyle();
if ( m_xLineStyleLb->GetSelectItemPos( ) > 0 )
{
SvxBorderLine aTmp;
aTmp.SetBorderLineStyle( nStyle );
aTmp.SetWidth( SvxBorderLineWidth::Thin ); // TODO Make it depend on a width field
aLineItem.SetLine( &aTmp );
}
else
aLineItem.SetLine( nullptr );
Any a;
aLineItem.QueryValue( a, m_bIsWriter ? CONVERT_TWIPS : 0 );
Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue("LineStyle", a) };
m_xControl->dispatchCommand( ".uno:LineStyle", aArgs );
m_xControl->EndPopupMode();
}
SfxStyleControllerItem_Impl::SfxStyleControllerItem_Impl(
const Reference< XDispatchProvider >& rDispatchProvider,
sal_uInt16 nSlotId, // Family-ID
const OUString& rCommand, // .uno: command bound to this item
SvxStyleToolBoxControl& rTbxCtl ) // controller instance, which the item is assigned to.
: SfxStatusListener( rDispatchProvider, nSlotId, rCommand ),
rControl( rTbxCtl )
{
}
void SfxStyleControllerItem_Impl::StateChangedAtStatusListener(
SfxItemState eState, const SfxPoolItem* pState )
{
switch ( GetId() )
{
case SID_STYLE_FAMILY1:
case SID_STYLE_FAMILY2:
case SID_STYLE_FAMILY3:
case SID_STYLE_FAMILY4:
case SID_STYLE_FAMILY5:
{
const sal_uInt16 nIdx = GetId() - SID_STYLE_FAMILY_START;
if ( SfxItemState::DEFAULT == eState )
{
const SfxTemplateItem* pStateItem =
dynamic_cast<const SfxTemplateItem*>( pState );
DBG_ASSERT( pStateItem != nullptr, "SfxTemplateItem expected" );
rControl.SetFamilyState( nIdx, pStateItem );
}
else
rControl.SetFamilyState( nIdx, nullptr );
break;
}
}
}
struct SvxStyleToolBoxControl::Impl
{
OUString aClearForm;
OUString aMore;
::std::vector< std::pair< OUString, OUString > > aDefaultStyles;
bool bSpecModeWriter;
bool bSpecModeCalc;
VclPtr<SvxStyleBox_Impl> m_xVclBox;
std::unique_ptr<SvxStyleBox_Base> m_xWeldBox;
SvxStyleBox_Base* m_pBox;
Impl()
:aClearForm ( SvxResId( RID_SVXSTR_CLEARFORM ) )
,aMore ( SvxResId( RID_SVXSTR_MORE_STYLES ) )
,bSpecModeWriter ( false )
,bSpecModeCalc ( false )
,m_pBox ( nullptr )
{
}
void InitializeStyles(const Reference < frame::XModel >& xModel)
{
aDefaultStyles.clear();
//now convert the default style names to the localized names
try
{
Reference< style::XStyleFamiliesSupplier > xStylesSupplier( xModel, UNO_QUERY_THROW );
Reference< lang::XServiceInfo > xServices( xModel, UNO_QUERY_THROW );
bSpecModeWriter = xServices->supportsService("com.sun.star.text.TextDocument");
if(bSpecModeWriter)
{
Reference<container::XNameAccess> xParaStyles;
xStylesSupplier->getStyleFamilies()->getByName("ParagraphStyles") >>=
xParaStyles;
static const std::vector<OUString> aWriterStyles =
{
"Standard",
"Text body",
"Title",
"Subtitle",
"Heading 1",
"Heading 2",
"Heading 3",
"Heading 4",
"Quotations",
"Preformatted Text"
};
for( const OUString& aStyle: aWriterStyles )
{
try
{
Reference< beans::XPropertySet > xStyle;
xParaStyles->getByName( aStyle ) >>= xStyle;
OUString sName;
xStyle->getPropertyValue("DisplayName") >>= sName;
if( !sName.isEmpty() )
aDefaultStyles.push_back(
std::pair<OUString, OUString>(aStyle, sName) );
}
catch( const uno::Exception& )
{}
}
}
else if( (
bSpecModeCalc = xServices->supportsService(
"com.sun.star.sheet.SpreadsheetDocument")))
{
static const char* aCalcStyles[] =
{
"Default",
"Accent 1",
"Accent 2",
"Accent 3",
"Heading 1",
"Heading 2",
"Result"
};
Reference<container::XNameAccess> xCellStyles;
xStylesSupplier->getStyleFamilies()->getByName("CellStyles") >>= xCellStyles;
for(const char* pCalcStyle : aCalcStyles)
{
try
{
const OUString sStyleName( OUString::createFromAscii( pCalcStyle ) );
if( xCellStyles->hasByName( sStyleName ) )
{
Reference< beans::XPropertySet > xStyle( xCellStyles->getByName( sStyleName), UNO_QUERY_THROW );
OUString sName;
xStyle->getPropertyValue("DisplayName") >>= sName;
if( !sName.isEmpty() )
aDefaultStyles.push_back(
std::pair<OUString, OUString>(sStyleName, sName) );
}
}
catch( const uno::Exception& )
{}
}
}
}
catch(const uno::Exception& )
{
OSL_FAIL("error while initializing style names");
}
}
};
// mapping table from bound items. BE CAREFUL this table must be in the
// same order as the uno commands bound to the slots SID_STYLE_FAMILY1..n
// MAX_FAMILIES must also be correctly set!
static const char* StyleSlotToStyleCommand[MAX_FAMILIES] =
{
".uno:CharStyle",
".uno:ParaStyle",
".uno:FrameStyle",
".uno:PageStyle",
".uno:TemplateFamily5"
};
SvxStyleToolBoxControl::SvxStyleToolBoxControl()
: pImpl(new Impl)
, pStyleSheetPool(nullptr)
, nActFamily(0xffff)
{
for (sal_uInt16 i = 0; i < MAX_FAMILIES; ++i)
{
m_xBoundItems[i].clear();
pFamilyState[i] = nullptr;
}
}
SvxStyleToolBoxControl::~SvxStyleToolBoxControl()
{
}
void SAL_CALL SvxStyleToolBoxControl::initialize(const Sequence<Any>& rArguments)
{
svt::ToolboxController::initialize(rArguments);
// After initialize we should have a valid frame member where we can retrieve our
// dispatch provider.
if ( !m_xFrame.is() )
return;
pImpl->InitializeStyles(m_xFrame->getController()->getModel());
Reference< XDispatchProvider > xDispatchProvider( m_xFrame->getController(), UNO_QUERY );
for ( sal_uInt16 i=0; i<MAX_FAMILIES; i++ )
{
m_xBoundItems[i] = new SfxStyleControllerItem_Impl( xDispatchProvider,
SID_STYLE_FAMILY_START + i,
OUString::createFromAscii( StyleSlotToStyleCommand[i] ),
*this );
pFamilyState[i] = nullptr;
}
}
// XComponent
void SAL_CALL SvxStyleToolBoxControl::dispose()
{
svt::ToolboxController::dispose();
SolarMutexGuard aSolarMutexGuard;
pImpl->m_xVclBox.disposeAndClear();
pImpl->m_xWeldBox.reset();
pImpl->m_pBox = nullptr;
for (rtl::Reference<SfxStyleControllerItem_Impl>& pBoundItem : m_xBoundItems)
{
if (!pBoundItem)
continue;
pBoundItem->UnBind();
}
unbindListener();
for( sal_uInt16 i=0; i<MAX_FAMILIES; i++ )
{
if ( m_xBoundItems[i].is() )
{
try
{
m_xBoundItems[i]->dispose();
}
catch ( Exception& )
{
}
m_xBoundItems[i].clear();
}
pFamilyState[i].reset();
}
pStyleSheetPool = nullptr;
pImpl.reset();
}
OUString SvxStyleToolBoxControl::getImplementationName()
{
return "com.sun.star.comp.svx.StyleToolBoxControl";
}
sal_Bool SvxStyleToolBoxControl::supportsService( const OUString& rServiceName )
{
return cppu::supportsService( this, rServiceName );
}
css::uno::Sequence< OUString > SvxStyleToolBoxControl::getSupportedServiceNames()
{
return { "com.sun.star.frame.ToolbarController" };
}
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_comp_svx_StyleToolBoxControl_get_implementation(
css::uno::XComponentContext*,
css::uno::Sequence<css::uno::Any> const & )
{
return cppu::acquire( new SvxStyleToolBoxControl() );
}
void SAL_CALL SvxStyleToolBoxControl::update()
{
for (rtl::Reference<SfxStyleControllerItem_Impl>& pBoundItem : m_xBoundItems)
pBoundItem->ReBind();
bindListener();
}
SfxStyleFamily SvxStyleToolBoxControl::GetActFamily() const
{
switch ( nActFamily-1 + SID_STYLE_FAMILY_START )
{
case SID_STYLE_FAMILY1: return SfxStyleFamily::Char;
case SID_STYLE_FAMILY2: return SfxStyleFamily::Para;
case SID_STYLE_FAMILY3: return SfxStyleFamily::Frame;
case SID_STYLE_FAMILY4: return SfxStyleFamily::Page;
case SID_STYLE_FAMILY5: return SfxStyleFamily::Pseudo;
default:
OSL_FAIL( "unknown style family" );
break;
}
return SfxStyleFamily::Para;
}
void SvxStyleToolBoxControl::FillStyleBox()
{
SvxStyleBox_Base* pBox = pImpl->m_pBox;
DBG_ASSERT( pStyleSheetPool, "StyleSheetPool not found!" );
DBG_ASSERT( pBox, "Control not found!" );
if ( !(pStyleSheetPool && pBox && nActFamily!=0xffff) )
return;
const SfxStyleFamily eFamily = GetActFamily();
SfxStyleSheetBase* pStyle = nullptr;
bool bDoFill = false;
auto xIter = pStyleSheetPool->CreateIterator(eFamily, SfxStyleSearchBits::Used);
sal_uInt16 nCount = xIter->Count();
// Check whether fill is necessary
pStyle = xIter->First();
//!!! TODO: This condition isn't right any longer, because we always show some default entries
//!!! so the list doesn't show the count
if ( nCount != pBox->get_count() )
{
bDoFill = true;
}
else
{
sal_uInt16 i= 0;
while ( pStyle && !bDoFill )
{
bDoFill = ( pBox->get_text(i) != pStyle->GetName() );
pStyle = xIter->Next();
i++;
}
}
if ( !bDoFill )
return;
OUString aStrSel(pBox->get_active_text());
pBox->freeze();
pBox->clear();
std::vector<OUString> aStyles;
// add used styles
pStyle = xIter->Next();
while ( pStyle )
{
aStyles.push_back(pStyle->GetName());
pStyle = xIter->Next();
}
if (pImpl->bSpecModeWriter || pImpl->bSpecModeCalc)
{
pBox->append_text(pImpl->aClearForm);
pBox->insert_separator(1, "separator");
// add default styles if less than 12 items
for( const auto &rStyle : pImpl->aDefaultStyles )
{
if ( aStyles.size() + pBox->get_count() > 12)
break;
// insert default style only if not used (and added to rStyle before)
if (std::find(aStyles.begin(), aStyles.end(), rStyle.second) >= aStyles.end())
pBox->append_text(rStyle.second);
}
}
std::sort(aStyles.begin(), aStyles.end());
for (const auto& rStyle : aStyles)
pBox->append_text(rStyle);
if ((pImpl->bSpecModeWriter || pImpl->bSpecModeCalc) && !comphelper::LibreOfficeKit::isActive())
pBox->append_text(pImpl->aMore);
pBox->thaw();
pBox->set_active_or_entry_text(aStrSel);
pBox->SetFamily( eFamily );
}
void SvxStyleToolBoxControl::SelectStyle( const OUString& rStyleName )
{
SvxStyleBox_Base* pBox = pImpl->m_pBox;
DBG_ASSERT( pBox, "Control not found!" );
if ( !pBox )
return;
OUString aStrSel(pBox->get_active_text());
if ( !rStyleName.isEmpty() )
{
OUString aNewStyle = rStyleName;
auto aFound = std::find_if(pImpl->aDefaultStyles.begin(), pImpl->aDefaultStyles.end(),
[rStyleName] (auto it) { return it.first == rStyleName || it.second == rStyleName; }
);
if (aFound != pImpl->aDefaultStyles.end())
aNewStyle = aFound->second;
if ( aNewStyle != aStrSel )
pBox->set_active_or_entry_text( aNewStyle );
}
else
pBox->set_active(-1);
pBox->save_value();
}
void SvxStyleToolBoxControl::Update()
{
SfxStyleSheetBasePool* pPool = nullptr;
SfxObjectShell* pDocShell = SfxObjectShell::Current();
if ( pDocShell )
pPool = pDocShell->GetStyleSheetPool();
sal_uInt16 i;
for ( i=0; i<MAX_FAMILIES; i++ )
if( pFamilyState[i] )
break;
if ( i==MAX_FAMILIES || !pPool )
{
pStyleSheetPool = pPool;
return;
}
const SfxTemplateItem* pItem = nullptr;
if ( nActFamily == 0xffff || nullptr == (pItem = pFamilyState[nActFamily-1].get()) )
// Current range not within allowed ranges or default
{
pStyleSheetPool = pPool;
nActFamily = 2;
pItem = pFamilyState[nActFamily-1].get();
if ( !pItem )
{
nActFamily++;
pItem = pFamilyState[nActFamily-1].get();
}
}
else if ( pPool != pStyleSheetPool )
pStyleSheetPool = pPool;
FillStyleBox(); // Decides by itself whether Fill is needed
if ( pItem )
SelectStyle( pItem->GetStyleName() );
}
void SvxStyleToolBoxControl::SetFamilyState( sal_uInt16 nIdx,
const SfxTemplateItem* pItem )
{
pFamilyState[nIdx].reset( pItem == nullptr ? nullptr : new SfxTemplateItem( *pItem ) );
Update();
}
void SvxStyleToolBoxControl::statusChanged( const css::frame::FeatureStateEvent& rEvent )
{
SolarMutexGuard aGuard;
if (m_pToolbar)
m_pToolbar->set_item_sensitive(m_aCommandURL, rEvent.IsEnabled);
else
{
ToolBox* pToolBox = nullptr;
ToolBoxItemId nId;
if (!getToolboxId( nId, &pToolBox ) )
return;
pToolBox->EnableItem( nId, rEvent.IsEnabled );
}
if (rEvent.IsEnabled)
Update();
}
css::uno::Reference<css::awt::XWindow> SvxStyleToolBoxControl::createItemWindow(const css::uno::Reference< css::awt::XWindow>& rParent)
{
uno::Reference< awt::XWindow > xItemWindow;
if (m_pBuilder)
{
SolarMutexGuard aSolarMutexGuard;
std::unique_ptr<weld::ComboBox> xWidget(m_pBuilder->weld_combo_box("applystyle"));
xItemWindow = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));
pImpl->m_xWeldBox.reset(new SvxStyleBox_Base(std::move(xWidget),
".uno:StyleApply",
SfxStyleFamily::Para,
m_xFrame,
pImpl->aClearForm,
pImpl->aMore,
pImpl->bSpecModeWriter || pImpl->bSpecModeCalc, *this));
pImpl->m_pBox = pImpl->m_xWeldBox.get();
}
else
{
VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow(rParent);
if ( pParent )
{
SolarMutexGuard aSolarMutexGuard;
pImpl->m_xVclBox = VclPtr<SvxStyleBox_Impl>::Create(pParent,
".uno:StyleApply",
SfxStyleFamily::Para,
m_xFrame,
pImpl->aClearForm,
pImpl->aMore,
pImpl->bSpecModeWriter || pImpl->bSpecModeCalc, *this);
pImpl->m_pBox = pImpl->m_xVclBox.get();
xItemWindow = VCLUnoHelper::GetInterface(pImpl->m_xVclBox);
}
}
if (pImpl->m_pBox && !pImpl->aDefaultStyles.empty())
pImpl->m_pBox->SetDefaultStyle(pImpl->aDefaultStyles[0].second);
return xItemWindow;
}
SvxFontNameToolBoxControl::SvxFontNameToolBoxControl()
: m_pBox(nullptr)
{
}
void SvxFontNameBox_Base::statusChanged_Impl( const css::frame::FeatureStateEvent& rEvent )
{
if ( !rEvent.IsEnabled )
{
set_sensitive(false);
Update( nullptr );
}
else
{
set_sensitive(true);
css::awt::FontDescriptor aFontDesc;
if ( rEvent.State >>= aFontDesc )
Update(&aFontDesc);
else {
// no active element; delete value in the display
m_xWidget->set_active(-1);
set_active_or_entry_text("");
}
m_xWidget->save_value();
}
}
void SvxFontNameToolBoxControl::statusChanged( const css::frame::FeatureStateEvent& rEvent )
{
SolarMutexGuard aGuard;
m_pBox->statusChanged_Impl(rEvent);
if (m_pToolbar)
m_pToolbar->set_item_sensitive(m_aCommandURL, rEvent.IsEnabled);
else
{
ToolBox* pToolBox = nullptr;
ToolBoxItemId nId;
if (!getToolboxId( nId, &pToolBox ) )
return;
pToolBox->EnableItem( nId, rEvent.IsEnabled );
}
}
css::uno::Reference<css::awt::XWindow> SvxFontNameToolBoxControl::createItemWindow(const css::uno::Reference<css::awt::XWindow>& rParent)
{
uno::Reference< awt::XWindow > xItemWindow;
if (m_pBuilder)
{
SolarMutexGuard aSolarMutexGuard;
std::unique_ptr<weld::ComboBox> xWidget(m_pBuilder->weld_combo_box("fontnamecombobox"));
xItemWindow = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));
m_xWeldBox.reset(new SvxFontNameBox_Base(std::move(xWidget), m_xFrame, *this));
m_pBox = m_xWeldBox.get();
}
else
{
VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow(rParent);
if ( pParent )
{
SolarMutexGuard aSolarMutexGuard;
m_xVclBox = VclPtr<SvxFontNameBox_Impl>::Create(pParent, m_xFrame, *this);
m_pBox = m_xVclBox.get();
xItemWindow = VCLUnoHelper::GetInterface(m_xVclBox);
}
}
return xItemWindow;
}
void SvxFontNameToolBoxControl::dispose()
{
ToolboxController::dispose();
SolarMutexGuard aSolarMutexGuard;
m_xVclBox.disposeAndClear();
m_xWeldBox.reset();
m_pBox = nullptr;
}
OUString SvxFontNameToolBoxControl::getImplementationName()
{
return "com.sun.star.comp.svx.FontNameToolBoxControl";
}
sal_Bool SvxFontNameToolBoxControl::supportsService( const OUString& rServiceName )
{
return cppu::supportsService( this, rServiceName );
}
css::uno::Sequence< OUString > SvxFontNameToolBoxControl::getSupportedServiceNames()
{
return { "com.sun.star.frame.ToolbarController" };
}
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_comp_svx_FontNameToolBoxControl_get_implementation(
css::uno::XComponentContext*,
css::uno::Sequence<css::uno::Any> const & )
{
return cppu::acquire( new SvxFontNameToolBoxControl() );
}
SvxColorToolBoxControl::SvxColorToolBoxControl( const css::uno::Reference<css::uno::XComponentContext>& rContext ) :
ImplInheritanceHelper( rContext, nullptr, OUString() ),
m_bSplitButton(true),
m_nSlotId(0),
m_aColorSelectFunction(PaletteManager::DispatchColorCommand)
{
}
namespace {
sal_uInt16 MapCommandToSlotId(const OUString& rCommand)
{
if (rCommand == ".uno:Color")
return SID_ATTR_CHAR_COLOR;
else if (rCommand == ".uno:FontColor")
return SID_ATTR_CHAR_COLOR2;
else if (rCommand == ".uno:BackColor") // deprecated - use CharBackColor
return SID_ATTR_CHAR_COLOR_BACKGROUND;
else if (rCommand == ".uno:CharBackColor")
return SID_ATTR_CHAR_BACK_COLOR;
else if (rCommand == ".uno:BackgroundColor")
return SID_BACKGROUND_COLOR;
else if (rCommand == ".uno:TableCellBackgroundColor")
return SID_TABLE_CELL_BACKGROUND_COLOR;
else if (rCommand == ".uno:Extrusion3DColor")
return SID_EXTRUSION_3D_COLOR;
else if (rCommand == ".uno:XLineColor")
return SID_ATTR_LINE_COLOR;
else if (rCommand == ".uno:FillColor")
return SID_ATTR_FILL_COLOR;
else if (rCommand == ".uno:FrameLineColor")
return SID_FRAME_LINECOLOR;
SAL_WARN("svx.tbxcrtls", "Unknown color command: " << rCommand);
return 0;
}
}
void SvxColorToolBoxControl::initialize( const css::uno::Sequence<css::uno::Any>& rArguments )
{
PopupWindowController::initialize( rArguments );
m_nSlotId = MapCommandToSlotId( m_aCommandURL );
if ( m_nSlotId == SID_ATTR_LINE_COLOR || m_nSlotId == SID_ATTR_FILL_COLOR ||
m_nSlotId == SID_FRAME_LINECOLOR || m_nSlotId == SID_BACKGROUND_COLOR )
{
// Sidebar uses wide buttons for those.
m_bSplitButton = !m_bSidebar;
}
auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(getCommandURL(), getModuleName());
OUString aCommandLabel = vcl::CommandInfoProvider::GetLabelForCommand(aProperties);
if (m_pToolbar)
{
mxPopoverContainer.reset(new ToolbarPopupContainer(m_pToolbar));
m_pToolbar->set_item_popover(m_aCommandURL, mxPopoverContainer->getTopLevel());
m_xBtnUpdater.reset(new svx::ToolboxButtonColorUpdater(m_nSlotId, m_aCommandURL, m_pToolbar, !m_bSplitButton, aCommandLabel, m_xFrame));
return;
}
ToolBox* pToolBox = nullptr;
ToolBoxItemId nId;
if (getToolboxId(nId, &pToolBox))
{
m_xBtnUpdater.reset( new svx::VclToolboxButtonColorUpdater( m_nSlotId, nId, pToolBox, !m_bSplitButton, aCommandLabel, m_aCommandURL, m_xFrame ) );
pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ( m_bSplitButton ? ToolBoxItemBits::DROPDOWN : ToolBoxItemBits::DROPDOWNONLY ) );
}
}
void SvxColorToolBoxControl::update()
{
PopupWindowController::update();
switch( m_nSlotId )
{
case SID_ATTR_CHAR_COLOR2:
addStatusListener( ".uno:CharColorExt");
break;
case SID_ATTR_CHAR_BACK_COLOR:
case SID_ATTR_CHAR_COLOR_BACKGROUND:
addStatusListener( ".uno:CharBackgroundExt");
break;
case SID_FRAME_LINECOLOR:
addStatusListener( ".uno:BorderTLBR");
addStatusListener( ".uno:BorderBLTR");
break;
}
}
void SvxColorToolBoxControl::EnsurePaletteManager()
{
if (!m_xPaletteManager)
{
m_xPaletteManager = std::make_shared<PaletteManager>();
m_xPaletteManager->SetBtnUpdater(m_xBtnUpdater.get());
}
}
SvxColorToolBoxControl::~SvxColorToolBoxControl()
{
if (m_xPaletteManager)
m_xPaletteManager->SetBtnUpdater(nullptr);
}
void SvxColorToolBoxControl::setColorSelectFunction(const ColorSelectFunction& aColorSelectFunction)
{
m_aColorSelectFunction = aColorSelectFunction;
if (m_xPaletteManager)
m_xPaletteManager->SetColorSelectFunction(aColorSelectFunction);
}
weld::Window* SvxColorToolBoxControl::GetParentFrame() const
{
const css::uno::Reference<css::awt::XWindow> xParent = m_xFrame->getContainerWindow();
return Application::GetFrameWeld(xParent);
}
std::unique_ptr<WeldToolbarPopup> SvxColorToolBoxControl::weldPopupWindow()
{
EnsurePaletteManager();
auto xPopover = std::make_unique<ColorWindow>(
m_aCommandURL,
m_xPaletteManager,
m_aColorStatus,
m_nSlotId,
m_xFrame,
MenuOrToolMenuButton(m_pToolbar, m_aCommandURL),
[this] { return GetParentFrame(); },
m_aColorSelectFunction);
return xPopover;
}
VclPtr<vcl::Window> SvxColorToolBoxControl::createVclPopupWindow( vcl::Window* pParent )
{
ToolBox* pToolBox = nullptr;
ToolBoxItemId nId;
if (!getToolboxId(nId, &pToolBox))
return nullptr;
EnsurePaletteManager();
auto xPopover = std::make_unique<ColorWindow>(
m_aCommandURL,
m_xPaletteManager,
m_aColorStatus,
m_nSlotId,
m_xFrame,
MenuOrToolMenuButton(this, pToolBox, nId),
[this] { return GetParentFrame(); },
m_aColorSelectFunction);
mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
std::move(xPopover), true);
auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(m_aCommandURL, m_sModuleName);
OUString aWindowTitle = vcl::CommandInfoProvider::GetLabelForCommand(aProperties);
mxInterimPopover->SetText(aWindowTitle);
mxInterimPopover->Show();
return mxInterimPopover;
}
void SvxColorToolBoxControl::statusChanged( const css::frame::FeatureStateEvent& rEvent )
{
ToolBox* pToolBox = nullptr;
ToolBoxItemId nId;
if (!getToolboxId(nId, &pToolBox) && !m_pToolbar)
return;
if ( rEvent.FeatureURL.Complete == m_aCommandURL )
{
if (m_pToolbar)
m_pToolbar->set_item_sensitive(m_aCommandURL, rEvent.IsEnabled);
else
pToolBox->EnableItem( nId, rEvent.IsEnabled );
}
bool bValue;
if ( !m_bSplitButton )
{
m_aColorStatus.statusChanged( rEvent );
m_xBtnUpdater->Update( m_aColorStatus.GetColor() );
}
else if ( rEvent.State >>= bValue )
{
if (m_pToolbar)
m_pToolbar->set_item_active(m_aCommandURL, bValue);
else if (pToolBox)
pToolBox->CheckItem( nId, bValue );
}
}
void SvxColorToolBoxControl::execute(sal_Int16 /*nSelectModifier*/)
{
if ( !m_bSplitButton )
{
if (m_pToolbar)
{
// Toggle the popup also when toolbutton is activated
m_pToolbar->set_menu_item_active(m_aCommandURL, !m_pToolbar->get_menu_item_active(m_aCommandURL));
}
else
{
// Open the popup also when Enter key is pressed.
createPopupWindow();
}
return;
}
OUString aCommand = m_aCommandURL;
Color aColor = m_xBtnUpdater->GetCurrentColor();
switch( m_nSlotId )
{
case SID_ATTR_CHAR_COLOR2 :
aCommand = ".uno:CharColorExt";
break;
}
auto aArgs( comphelper::InitPropertySequence( {
{ m_aCommandURL.copy(5), css::uno::Any(aColor) }
} ) );
dispatchCommand( aCommand, aArgs );
EnsurePaletteManager();
OUString sColorName = m_xBtnUpdater->GetCurrentColorName();
m_xPaletteManager->AddRecentColor(aColor, sColorName);
}
sal_Bool SvxColorToolBoxControl::opensSubToolbar()
{
// We mark this controller as a sub-toolbar controller, so we get notified
// (through updateImage method) on button image changes, and could redraw
// the last used color on top of it.
return true;
}
void SvxColorToolBoxControl::updateImage()
{
m_xBtnUpdater->Update(m_xBtnUpdater->GetCurrentColor(), true);
}
OUString SvxColorToolBoxControl::getSubToolbarName()
{
return OUString();
}
void SvxColorToolBoxControl::functionSelected( const OUString& /*rCommand*/ )
{
}
OUString SvxColorToolBoxControl::getImplementationName()
{
return "com.sun.star.comp.svx.ColorToolBoxControl";
}
css::uno::Sequence<OUString> SvxColorToolBoxControl::getSupportedServiceNames()
{
return { "com.sun.star.frame.ToolbarController" };
}
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_comp_svx_ColorToolBoxControl_get_implementation(
css::uno::XComponentContext* rContext,
css::uno::Sequence<css::uno::Any> const & )
{
return cppu::acquire( new SvxColorToolBoxControl( rContext ) );
}
SvxFrameToolBoxControl::SvxFrameToolBoxControl( const css::uno::Reference< css::uno::XComponentContext >& rContext )
: svt::PopupWindowController( rContext, nullptr, OUString() )
{
}
void SAL_CALL SvxFrameToolBoxControl::execute(sal_Int16 /*KeyModifier*/)
{
if (m_pToolbar)
{
// Toggle the popup also when toolbutton is activated
m_pToolbar->set_menu_item_active(m_aCommandURL, !m_pToolbar->get_menu_item_active(m_aCommandURL));
}
else
{
// Open the popup also when Enter key is pressed.
createPopupWindow();
}
}
void SvxFrameToolBoxControl::initialize( const css::uno::Sequence< css::uno::Any >& rArguments )
{
svt::PopupWindowController::initialize( rArguments );
if (m_pToolbar)
{
mxPopoverContainer.reset(new ToolbarPopupContainer(m_pToolbar));
m_pToolbar->set_item_popover(m_aCommandURL, mxPopoverContainer->getTopLevel());
}
ToolBox* pToolBox = nullptr;
ToolBoxItemId nId;
if (getToolboxId(nId, &pToolBox))
pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ToolBoxItemBits::DROPDOWNONLY );
}
std::unique_ptr<WeldToolbarPopup> SvxFrameToolBoxControl::weldPopupWindow()
{
if ( m_aCommandURL == ".uno:LineStyle" )
return std::make_unique<SvxLineWindow_Impl>(this, m_pToolbar);
return std::make_unique<SvxFrameWindow_Impl>(this, m_pToolbar);
}
VclPtr<vcl::Window> SvxFrameToolBoxControl::createVclPopupWindow( vcl::Window* pParent )
{
if ( m_aCommandURL == ".uno:LineStyle" )
{
mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
std::make_unique<SvxLineWindow_Impl>(this, pParent->GetFrameWeld()), true);
mxInterimPopover->Show();
mxInterimPopover->SetText(SvxResId(RID_SVXSTR_FRAME_STYLE));
return mxInterimPopover;
}
mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
std::make_unique<SvxFrameWindow_Impl>(this, pParent->GetFrameWeld()), true);
mxInterimPopover->Show();
mxInterimPopover->SetText(SvxResId(RID_SVXSTR_FRAME));
return mxInterimPopover;
}
OUString SvxFrameToolBoxControl::getImplementationName()
{
return "com.sun.star.comp.svx.FrameToolBoxControl";
}
css::uno::Sequence< OUString > SvxFrameToolBoxControl::getSupportedServiceNames()
{
return { "com.sun.star.frame.ToolbarController" };
}
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_comp_svx_FrameToolBoxControl_get_implementation(
css::uno::XComponentContext* rContext,
css::uno::Sequence<css::uno::Any> const & )
{
return cppu::acquire( new SvxFrameToolBoxControl( rContext ) );
}
SvxCurrencyToolBoxControl::SvxCurrencyToolBoxControl( const css::uno::Reference<css::uno::XComponentContext>& rContext ) :
PopupWindowController( rContext, nullptr, OUString() ),
m_eLanguage( Application::GetSettings().GetLanguageTag().getLanguageType() ),
m_nFormatKey( NUMBERFORMAT_ENTRY_NOT_FOUND )
{
}
SvxCurrencyToolBoxControl::~SvxCurrencyToolBoxControl() {}
namespace
{
/** Implementation of the currency combo widget **/
class SvxCurrencyList_Impl : public WeldToolbarPopup
{
private:
rtl::Reference<SvxCurrencyToolBoxControl> m_xControl;
std::unique_ptr<weld::Label> m_xLabel;
std::unique_ptr<weld::TreeView> m_xCurrencyLb;
std::unique_ptr<weld::Button> m_xOkBtn;
OUString& m_rSelectedFormat;
LanguageType& m_eSelectedLanguage;
std::vector<OUString> m_aFormatEntries;
LanguageType m_eFormatLanguage;
DECL_LINK(RowActivatedHdl, weld::TreeView&, bool);
DECL_LINK(OKHdl, weld::Button&, void);
virtual void GrabFocus() override;
public:
SvxCurrencyList_Impl(SvxCurrencyToolBoxControl* pControl, weld::Widget* pParent, OUString& rSelectedFormat, LanguageType& eSelectedLanguage)
: WeldToolbarPopup(pControl->getFrameInterface(), pParent, "svx/ui/currencywindow.ui", "CurrencyWindow")
, m_xControl(pControl)
, m_xLabel(m_xBuilder->weld_label("label"))
, m_xCurrencyLb(m_xBuilder->weld_tree_view("currency"))
, m_xOkBtn(m_xBuilder->weld_button("ok"))
, m_rSelectedFormat(rSelectedFormat)
, m_eSelectedLanguage(eSelectedLanguage)
{
const NfCurrencyTable& rCurrencyTable = SvNumberFormatter::GetTheCurrencyTable();
sal_uInt16 nLen = rCurrencyTable.size();
SvNumberFormatter aFormatter( m_xControl->getContext(), LANGUAGE_SYSTEM );
m_eFormatLanguage = aFormatter.GetLanguage();
const SvxCurrencyToolBoxControl::SvxCurrencyVect_t &rCurrencies = pControl->GetCurrencySymbols( );
sal_uInt16 nPos = 0, nCount = 0;
sal_Int32 nSelectedPos = -1;
bool bIsSymbol;
NfWSStringsDtor aStringsDtor;
OUString sLongestString;
m_xCurrencyLb->freeze();
for( const SvxCurrencyToolBoxControl::SvxCurrencyData& curr : rCurrencies )
{
const OUString& rItem = curr.m_label;
sal_uInt16 rCurrencyIndex = rCurrencies[ nCount ].m_currencyIdx;
if ( rCurrencyIndex < nLen )
{
m_xCurrencyLb->append_text(rItem);
if (rItem.getLength() > sLongestString.getLength())
sLongestString = rItem;
bIsSymbol = nPos >= nLen;
sal_uInt16 nDefaultFormat;
const NfCurrencyEntry& rCurrencyEntry = rCurrencyTable[ rCurrencyIndex ];
if (rCurrencyIndex == 0)
{
// Stored with system locale, but we want the resolved
// full LCID format string. For example
// "[$$-409]#,##0.00" instead of "[$$]#,##0.00".
NfCurrencyEntry aCurrencyEntry( rCurrencyEntry);
aCurrencyEntry.SetLanguage( LanguageTag( aCurrencyEntry.GetLanguage()).getLanguageType());
nDefaultFormat = aFormatter.GetCurrencyFormatStrings( aStringsDtor, aCurrencyEntry, bIsSymbol);
}
else
{
nDefaultFormat = aFormatter.GetCurrencyFormatStrings( aStringsDtor, rCurrencyEntry, bIsSymbol);
}
const OUString& rFormatStr = aStringsDtor[ nDefaultFormat ];
m_aFormatEntries.push_back( rFormatStr );
if( rFormatStr == m_rSelectedFormat )
nSelectedPos = nPos;
++nPos;
}
++nCount;
}
m_xCurrencyLb->thaw();
// enable multiple selection enabled so we can start with nothing selected
m_xCurrencyLb->set_selection_mode(SelectionMode::Multiple);
m_xCurrencyLb->connect_row_activated( LINK( this, SvxCurrencyList_Impl, RowActivatedHdl ) );
m_xLabel->set_label(SvxResId(RID_SVXSTR_TBLAFMT_CURRENCY));
m_xCurrencyLb->select( nSelectedPos );
m_xOkBtn->connect_clicked(LINK(this, SvxCurrencyList_Impl, OKHdl));
// gtk will initially make a best guess depending on the first few entries, so copy the probable
// longest entry to the start temporarily and force in the width at this point
m_xCurrencyLb->insert_text(0, sLongestString);
m_xCurrencyLb->set_size_request(m_xCurrencyLb->get_preferred_size().Width(), m_xCurrencyLb->get_height_rows(12));
m_xCurrencyLb->remove(0);
}
};
void SvxCurrencyList_Impl::GrabFocus()
{
m_xCurrencyLb->grab_focus();
}
IMPL_LINK_NOARG(SvxCurrencyList_Impl, OKHdl, weld::Button&, void)
{
RowActivatedHdl(*m_xCurrencyLb);
}
IMPL_LINK_NOARG(SvxCurrencyList_Impl, RowActivatedHdl, weld::TreeView&, bool)
{
if (!m_xControl.is())
return true;
// multiple selection enabled so we can start with nothing selected,
// so force single selection after something is picked
int nSelected = m_xCurrencyLb->get_selected_index();
if (nSelected == -1)
return true;
m_xCurrencyLb->set_selection_mode(SelectionMode::Single);
m_rSelectedFormat = m_aFormatEntries[nSelected];
m_eSelectedLanguage = m_eFormatLanguage;
m_xControl->execute(nSelected + 1);
m_xCurrencyLb->scroll_to_row(0);
m_xControl->EndPopupMode();
return true;
}
}
void SvxCurrencyToolBoxControl::initialize( const css::uno::Sequence< css::uno::Any >& rArguments )
{
PopupWindowController::initialize(rArguments);
if (m_pToolbar)
{
mxPopoverContainer.reset(new ToolbarPopupContainer(m_pToolbar));
m_pToolbar->set_item_popover(m_aCommandURL, mxPopoverContainer->getTopLevel());
return;
}
ToolBox* pToolBox = nullptr;
ToolBoxItemId nId;
if (getToolboxId(nId, &pToolBox) && pToolBox->GetItemCommand(nId) == m_aCommandURL)
pToolBox->SetItemBits(nId, ToolBoxItemBits::DROPDOWN | pToolBox->GetItemBits(nId));
}
const SvxCurrencyToolBoxControl::SvxCurrencyVect_t &SvxCurrencyToolBoxControl::GetCurrencySymbols( ) {
inner_GetCurrencySymbols( true, m_currencies, m_mru_currencies );
return m_currencies;
}
void SvxCurrencyToolBoxControl::addMruCurrency(sal_Int16 currencyPosition) {
if (currencyPosition == 1)
return;
const SvxCurrencyData& curr = m_currencies[currencyPosition];
auto currencyIter = std::find( m_mru_currencies.begin(), m_mru_currencies.end(), curr );
if ( currencyIter != m_mru_currencies.end() )
m_mru_currencies.erase( currencyIter );
m_mru_currencies.insert( m_mru_currencies.begin(), curr );
if (m_mru_currencies.size() > MAX_MRU_CURRENCIES)
m_mru_currencies.resize( MAX_MRU_CURRENCIES );
}
std::unique_ptr<WeldToolbarPopup> SvxCurrencyToolBoxControl::weldPopupWindow()
{
return std::make_unique<SvxCurrencyList_Impl>(this, m_pToolbar, m_aFormatString, m_eLanguage);
}
VclPtr<vcl::Window> SvxCurrencyToolBoxControl::createVclPopupWindow( vcl::Window* pParent )
{
mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
std::make_unique<SvxCurrencyList_Impl>(this, pParent->GetFrameWeld(), m_aFormatString, m_eLanguage));
mxInterimPopover->Show();
return mxInterimPopover;
}
void SvxCurrencyToolBoxControl::execute( sal_Int16 nSelectModifier )
{
sal_uInt32 nFormatKey;
if (m_aFormatString.isEmpty())
nFormatKey = NUMBERFORMAT_ENTRY_NOT_FOUND;
else
{
if ( nSelectModifier > 0 )
{
try
{
uno::Reference< util::XNumberFormatsSupplier > xRef( m_xFrame->getController()->getModel(), uno::UNO_QUERY );
uno::Reference< util::XNumberFormats > rxNumberFormats( xRef->getNumberFormats(), uno::UNO_SET_THROW );
css::lang::Locale aLocale = LanguageTag::convertToLocale( m_eLanguage );
nFormatKey = rxNumberFormats->queryKey( m_aFormatString, aLocale, false );
if ( nFormatKey == NUMBERFORMAT_ENTRY_NOT_FOUND )
nFormatKey = rxNumberFormats->addNew( m_aFormatString, aLocale );
addMruCurrency(nSelectModifier);
}
catch( const uno::Exception& )
{
nFormatKey = m_nFormatKey;
}
}
else
nFormatKey = m_nFormatKey;
}
if( nFormatKey != NUMBERFORMAT_ENTRY_NOT_FOUND )
{
Sequence< PropertyValue > aArgs{ comphelper::makePropertyValue("NumberFormatCurrency",
nFormatKey) };
dispatchCommand( m_aCommandURL, aArgs );
m_nFormatKey = nFormatKey;
}
else
PopupWindowController::execute( nSelectModifier );
}
OUString SvxCurrencyToolBoxControl::getImplementationName()
{
return "com.sun.star.comp.svx.CurrencyToolBoxControl";
}
css::uno::Sequence<OUString> SvxCurrencyToolBoxControl::getSupportedServiceNames()
{
return { "com.sun.star.frame.ToolbarController" };
}
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_comp_svx_CurrencyToolBoxControl_get_implementation(
css::uno::XComponentContext* rContext,
css::uno::Sequence<css::uno::Any> const & )
{
return cppu::acquire( new SvxCurrencyToolBoxControl( rContext ) );
}
Reference< css::accessibility::XAccessible > SvxFontNameBox_Impl::CreateAccessible()
{
FillList();
return InterimItemWindow::CreateAccessible();
}
//static
sal_uInt16 const SvxCurrencyToolBoxControl::SvxCurrencyData::InvalidCurrency = INVALID_CURRENCY;
SvxCurrencyToolBoxControl::SvxCurrencyData::SvxCurrencyData(
sal_uInt16 currencyIdx,
bool onlyIsoCode
) :
m_currencyIdx(currencyIdx),
m_onlyIsoCode(onlyIsoCode)
{}
bool SvxCurrencyToolBoxControl::SvxCurrencyData::operator == (const SvxCurrencyData& other) const
{
return
(m_currencyIdx == other.m_currencyIdx) &&
(m_onlyIsoCode == other.m_onlyIsoCode);
}
//static
void SvxCurrencyToolBoxControl::GetCurrencySymbols( std::vector<OUString>& rList, bool bFlag,
std::vector<sal_uInt16>& rCurrencyList )
{
SvxCurrencyVect_t currencies, mru_currencies;
inner_GetCurrencySymbols(bFlag, currencies, mru_currencies);
rList.resize(currencies.size());
rCurrencyList.resize(currencies.size());
for (size_t j = 0; j < currencies.size(); j++) {
rList[j] = std::move(currencies[j].m_label);
rCurrencyList[j] = currencies[j].m_currencyIdx;
}
}
//static
void SvxCurrencyToolBoxControl::inner_GetCurrencySymbols(
bool bFlag,
SvxCurrencyVect_t &pCurrencies,
SvxCurrencyVect_t &p_mru_currencies)
{
const NfCurrencyTable& rCurrencyTable = SvNumberFormatter::GetTheCurrencyTable();
sal_uInt16 nCount = rCurrencyTable.size();
// reserving space for mru currencies on top of vector after -1 element
pCurrencies.resize( p_mru_currencies.size() + 1);
std::fill( pCurrencies.begin() + 1, pCurrencies.end(), SvxCurrencyData() );
// lambda for vector insertion: mru currencies are on top
auto addCurrency = [&pCurrencies, &p_mru_currencies]
(SvxCurrencyData& curr, size_t position = SIZE_MAX)
{
auto mruIter = std::find(p_mru_currencies.begin(), p_mru_currencies.end(), curr);
if (mruIter == p_mru_currencies.end()) {
if (position == SIZE_MAX)
pCurrencies.push_back( std::move(curr) );
else
pCurrencies.insert( pCurrencies.begin() + position, std::move(curr) );
}
else {
size_t index = mruIter - p_mru_currencies.begin();
pCurrencies[index] = std::move(curr);
}
};
SvxCurrencyData aCurr( sal_uInt16(-1) );
aCurr.m_label = ApplyLreOrRleEmbedding( rCurrencyTable[0].GetSymbol() ) + " ";
aCurr.m_label += ApplyLreOrRleEmbedding( SvtLanguageTable::GetLanguageString(
rCurrencyTable[0].GetLanguage() ) );
pCurrencies[0] = aCurr;
if( bFlag ) {
aCurr.m_currencyIdx = 0;
addCurrency( aCurr );
}
sal_uInt16 nStart = pCurrencies.size();
CollatorWrapper aCollator( ::comphelper::getProcessComponentContext() );
aCollator.loadDefaultCollator( Application::GetSettings().GetLanguageTag().getLocale(), 0 );
static constexpr OUStringLiteral aTwoSpace(u" ");
// appending "long symbol" list
for( sal_uInt16 i = 1; i < nCount; ++i )
{
SvxCurrencyData curr( i );
curr.m_label = ApplyLreOrRleEmbedding( rCurrencyTable[i].GetBankSymbol() );
curr.m_label += aTwoSpace;
curr.m_label += ApplyLreOrRleEmbedding( rCurrencyTable[i].GetSymbol() );
curr.m_label += aTwoSpace;
curr.m_label += ApplyLreOrRleEmbedding( SvtLanguageTable::GetLanguageString(
rCurrencyTable[i].GetLanguage() ) );
SvxCurrencyVect_t::size_type j = nStart;
for( ; j < pCurrencies.size(); ++j )
if ( aCollator.compareString( curr.m_label, pCurrencies[j].m_label ) < 0 )
break; // insert before first greater than
addCurrency( curr, j );
}
// Append ISO codes to symbol list.
// XXX If this is to be changed, various other places would had to be
// adapted that assume this order!
size_t nCont = pCurrencies.size();
for ( sal_uInt16 i = 1; i < nCount; ++i )
{
bool bInsert = true;
SvxCurrencyData curr( i, true );
curr.m_label = ApplyLreOrRleEmbedding(rCurrencyTable[i].GetBankSymbol());
size_t j = nCont;
for ( ; j < pCurrencies.size() && bInsert; ++j )
{
if( pCurrencies[j].m_label == curr.m_label )
bInsert = false;
else if ( aCollator.compareString( curr.m_label, pCurrencies[j].m_label ) < 0 )
break; // insert before first greater than
}
if ( bInsert )
addCurrency( curr, j );
}
for ( int j = p_mru_currencies.size() - 1; j > 0; j-- )
if ( pCurrencies[j].m_currencyIdx == SvxCurrencyData::InvalidCurrency )
pCurrencies.erase( pCurrencies.begin() + j );
}
ListBoxColorWrapper::ListBoxColorWrapper(ColorListBox* pControl)
: mpControl(pControl)
{
}
void ListBoxColorWrapper::operator()(
[[maybe_unused]] const OUString& /*rCommand*/, const NamedColor& rColor)
{
mpControl->Selected(rColor);
}
void ColorListBox::EnsurePaletteManager()
{
if (!m_xPaletteManager)
{
m_xPaletteManager = std::make_shared<PaletteManager>();
m_xPaletteManager->SetColorSelectFunction(std::ref(m_aColorWrapper));
}
}
void ColorListBox::SetSlotId(sal_uInt16 nSlotId, bool bShowNoneButton)
{
m_nSlotId = nSlotId;
m_bShowNoneButton = bShowNoneButton;
m_xButton->set_popover(nullptr);
m_xColorWindow.reset();
m_aSelectedColor = bShowNoneButton ? GetNoneColor() : GetAutoColor(m_nSlotId);
ShowPreview(m_aSelectedColor);
createColorWindow();
}
ColorListBox::ColorListBox(std::unique_ptr<weld::MenuButton> pControl,
TopLevelParentFunction aTopLevelParentFunction,
const ColorListBox* pCache)
: m_xButton(std::move(pControl))
, m_aColorWrapper(this)
, m_aAutoDisplayColor(Application::GetSettings().GetStyleSettings().GetDialogColor())
, m_nSlotId(0)
, m_bShowNoneButton(false)
, m_aTopLevelParentFunction(std::move(aTopLevelParentFunction))
{
m_xButton->connect_toggled(LINK(this, ColorListBox, ToggleHdl));
m_aSelectedColor = GetAutoColor(m_nSlotId);
if (!pCache)
LockWidthRequest(CalcBestWidthRequest());
else
{
LockWidthRequest(pCache->m_xButton->get_size_request().Width());
m_xPaletteManager.reset(pCache->m_xPaletteManager->Clone());
m_xPaletteManager->SetColorSelectFunction(std::ref(m_aColorWrapper));
}
ShowPreview(m_aSelectedColor);
}
IMPL_LINK(ColorListBox, ToggleHdl, weld::Toggleable&, rButton, void)
{
if (rButton.get_active())
{
ColorWindow* pColorWindow = getColorWindow();
if (pColorWindow && !comphelper::LibreOfficeKit::isActive())
pColorWindow->GrabFocus();
}
}
ColorListBox::~ColorListBox()
{
}
ColorWindow* ColorListBox::getColorWindow() const
{
if (!m_xColorWindow)
const_cast<ColorListBox*>(this)->createColorWindow();
return m_xColorWindow.get();
}
void ColorListBox::createColorWindow()
{
const SfxViewFrame* pViewFrame = SfxViewFrame::Current();
const SfxFrame* pFrame = pViewFrame ? &pViewFrame->GetFrame() : nullptr;
css::uno::Reference<css::frame::XFrame> xFrame(pFrame ? pFrame->GetFrameInterface() : uno::Reference<css::frame::XFrame>());
EnsurePaletteManager();
m_xColorWindow.reset(new ColorWindow(
OUString() /*m_aCommandURL*/,
m_xPaletteManager,
m_aColorStatus,
m_nSlotId,
xFrame,
m_xButton.get(),
m_aTopLevelParentFunction,
m_aColorWrapper));
SetNoSelection();
m_xButton->set_popover(m_xColorWindow->getTopLevel());
if (m_bShowNoneButton)
m_xColorWindow->ShowNoneButton();
m_xColorWindow->SelectEntry(m_aSelectedColor);
}
void ColorListBox::SelectEntry(const NamedColor& rColor)
{
if (o3tl::trim(rColor.m_aName).empty())
{
SelectEntry(rColor.m_aColor);
return;
}
ColorWindow* pColorWindow = getColorWindow();
pColorWindow->SelectEntry(rColor);
m_aSelectedColor = pColorWindow->GetSelectEntryColor();
ShowPreview(m_aSelectedColor);
}
void ColorListBox::SelectEntry(const Color& rColor)
{
ColorWindow* pColorWindow = getColorWindow();
pColorWindow->SelectEntry(rColor);
m_aSelectedColor = pColorWindow->GetSelectEntryColor();
ShowPreview(m_aSelectedColor);
}
void ColorListBox::Selected(const NamedColor& rColor)
{
ShowPreview(rColor);
m_aSelectedColor = rColor;
if (m_aSelectedLink.IsSet())
m_aSelectedLink.Call(*this);
}
//to avoid the box resizing every time the color is changed to
//the optimal size of the individual color, get the longest
//standard color and stick with that as the size for all
int ColorListBox::CalcBestWidthRequest()
{
NamedColor aLongestColor;
tools::Long nMaxStandardColorTextWidth = 0;
XColorListRef const xColorTable = XColorList::CreateStdColorList();
for (tools::Long i = 0; i != xColorTable->Count(); ++i)
{
XColorEntry& rEntry = *xColorTable->GetColor(i);
auto nColorTextWidth = m_xButton->get_pixel_size(rEntry.GetName()).Width();
if (nColorTextWidth > nMaxStandardColorTextWidth)
{
nMaxStandardColorTextWidth = nColorTextWidth;
aLongestColor.m_aName = rEntry.GetName();
}
}
ShowPreview(aLongestColor);
return m_xButton->get_preferred_size().Width();
}
void ColorListBox::LockWidthRequest(int nWidth)
{
m_xButton->set_size_request(nWidth, -1);
}
void ColorListBox::ShowPreview(const NamedColor &rColor)
{
// ScGridWindow::UpdateAutoFilterFromMenu is similar
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
Size aImageSize(rStyleSettings.GetListBoxPreviewDefaultPixelSize());
ScopedVclPtrInstance<VirtualDevice> xDevice;
xDevice->SetOutputSize(aImageSize);
const tools::Rectangle aRect(Point(0, 0), aImageSize);
if (m_bShowNoneButton && rColor.m_aColor == COL_NONE_COLOR)
{
const Color aW(COL_WHITE);
const Color aG(0xef, 0xef, 0xef);
int nMinDim = std::min(aImageSize.Width(), aImageSize.Height()) + 1;
int nCheckSize = nMinDim / 3;
xDevice->DrawCheckered(aRect.TopLeft(), aRect.GetSize(), std::min(nCheckSize, 8), aW, aG);
xDevice->SetFillColor();
}
else
{
if (rColor.m_aColor == COL_AUTO)
xDevice->SetFillColor(m_aAutoDisplayColor);
else
xDevice->SetFillColor(rColor.m_aColor);
}
xDevice->SetLineColor(rStyleSettings.GetDisableColor());
xDevice->DrawRect(aRect);
m_xButton->set_image(xDevice.get());
m_xButton->set_label(rColor.m_aName);
}
MenuOrToolMenuButton::MenuOrToolMenuButton(weld::MenuButton* pMenuButton)
: m_pMenuButton(pMenuButton)
, m_pToolbar(nullptr)
, m_pControl(nullptr)
, m_nId(0)
{
}
MenuOrToolMenuButton::MenuOrToolMenuButton(weld::Toolbar* pToolbar, OUString aIdent)
: m_pMenuButton(nullptr)
, m_pToolbar(pToolbar)
, m_aIdent(std::move(aIdent))
, m_pControl(nullptr)
, m_nId(0)
{
}
MenuOrToolMenuButton::MenuOrToolMenuButton(SvxColorToolBoxControl* pControl, ToolBox* pToolbar, ToolBoxItemId nId)
: m_pMenuButton(nullptr)
, m_pToolbar(nullptr)
, m_pControl(pControl)
, m_xToolBox(pToolbar)
, m_nId(nId)
{
}
MenuOrToolMenuButton::~MenuOrToolMenuButton()
{
}
bool MenuOrToolMenuButton::get_active() const
{
if (m_pMenuButton)
return m_pMenuButton->get_active();
if (m_pToolbar)
return m_pToolbar->get_menu_item_active(m_aIdent);
return m_xToolBox->GetDownItemId() == m_nId;
}
void MenuOrToolMenuButton::set_inactive() const
{
if (m_pMenuButton)
{
if (m_pMenuButton->get_active())
m_pMenuButton->set_active(false);
return;
}
if (m_pToolbar)
{
if (m_pToolbar->get_menu_item_active(m_aIdent))
m_pToolbar->set_menu_item_active(m_aIdent, false);
return;
}
m_pControl->EndPopupMode();
}
weld::Widget* MenuOrToolMenuButton::get_widget() const
{
if (m_pMenuButton)
return m_pMenuButton;
if (m_pToolbar)
return m_pToolbar;
return m_xToolBox->GetFrameWeld();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|