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
|
/* -*- 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/.
*/
#include <memory>
#include <com/sun/star/packages/zip/ZipFileAccess.hpp>
#include <i18nutil/unicode.hxx>
#include <osl/module.hxx>
#include <osl/file.hxx>
#include <sal/log.hxx>
#include <unotools/resmgr.hxx>
#include <vcl/builder.hxx>
#include <vcl/button.hxx>
#include <vcl/dialog.hxx>
#include <vcl/edit.hxx>
#include <vcl/field.hxx>
#include <vcl/fixed.hxx>
#include <vcl/fixedhyper.hxx>
#include <vcl/IPrioritable.hxx>
#include <vcl/layout.hxx>
#include <vcl/lstbox.hxx>
#include <vcl/menubtn.hxx>
#include <vcl/mnemonic.hxx>
#include <vcl/prgsbar.hxx>
#include <vcl/scrbar.hxx>
#include <vcl/svapp.hxx>
#include <vcl/tabctrl.hxx>
#include <vcl/tabpage.hxx>
#include <vcl/throbber.hxx>
#include <vcl/toolbox.hxx>
#include <vcl/vclmedit.hxx>
#include <vcl/settings.hxx>
#include <vcl/slider.hxx>
#include <vcl/listctrl.hxx>
#include <vcl/weld.hxx>
#include <vcl/commandinfoprovider.hxx>
#include <svdata.hxx>
#include <bitmaps.hlst>
#include <messagedialog.hxx>
#include <window.h>
#include <xmlreader/xmlreader.hxx>
#include <desktop/crashreport.hxx>
#include <salinst.hxx>
#include <strings.hrc>
#include <tools/svlibrary.h>
#include <tools/diagnose_ex.h>
#ifdef DISABLE_DYNLOADING
#include <dlfcn.h>
#endif
bool toBool(const OString &rValue)
{
return (!rValue.isEmpty() && (rValue[0] == 't' || rValue[0] == 'T' || rValue[0] == '1'));
}
namespace
{
OUString mapStockToImageResource(const OUString& sType)
{
if (sType == "gtk-index")
return OUString(SV_RESID_BITMAP_INDEX);
else if (sType == "gtk-refresh")
return OUString(SV_RESID_BITMAP_REFRESH);
return OUString();
}
SymbolType mapStockToSymbol(const OUString& sType)
{
SymbolType eRet = SymbolType::DONTKNOW;
if (sType == "gtk-media-next")
eRet = SymbolType::NEXT;
else if (sType == "gtk-media-previous")
eRet = SymbolType::PREV;
else if (sType == "gtk-media-play")
eRet = SymbolType::PLAY;
else if (sType == "gtk-media-stop")
eRet = SymbolType::STOP;
else if (sType == "gtk-goto-first")
eRet = SymbolType::FIRST;
else if (sType == "gtk-goto-last")
eRet = SymbolType::LAST;
else if (sType == "gtk-go-back")
eRet = SymbolType::ARROW_LEFT;
else if (sType == "gtk-go-forward")
eRet = SymbolType::ARROW_RIGHT;
else if (sType == "gtk-go-up")
eRet = SymbolType::ARROW_UP;
else if (sType == "gtk-go-down")
eRet = SymbolType::ARROW_DOWN;
else if (sType == "gtk-missing-image")
eRet = SymbolType::IMAGE;
else if (sType == "gtk-help")
eRet = SymbolType::HELP;
else if (sType == "gtk-close")
eRet = SymbolType::CLOSE;
else if (!mapStockToImageResource(sType).isEmpty())
eRet = SymbolType::IMAGE;
return eRet;
}
void setupFromActionName(Button *pButton, VclBuilder::stringmap &rMap, const css::uno::Reference<css::frame::XFrame>& rFrame);
}
#if defined SAL_LOG_WARN
namespace
{
bool isButtonType(WindowType nType)
{
return nType == WindowType::PUSHBUTTON ||
nType == WindowType::OKBUTTON ||
nType == WindowType::CANCELBUTTON ||
nType == WindowType::HELPBUTTON ||
nType == WindowType::IMAGEBUTTON ||
nType == WindowType::MENUBUTTON ||
nType == WindowType::MOREBUTTON ||
nType == WindowType::SPINBUTTON;
}
}
#endif
weld::Builder* Application::CreateBuilder(weld::Widget* pParent, const OUString &rUIFile)
{
return ImplGetSVData()->mpDefInst->CreateBuilder(pParent, VclBuilderContainer::getUIRootDir(), rUIFile);
}
weld::MessageDialog* Application::CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType,
VclButtonsType eButtonType, const OUString& rPrimaryMessage)
{
return ImplGetSVData()->mpDefInst->CreateMessageDialog(pParent, eMessageType, eButtonType, rPrimaryMessage);
}
weld::Window* Application::GetFrameWeld(const css::uno::Reference<css::awt::XWindow>& rWindow)
{
return ImplGetSVData()->mpDefInst->GetFrameWeld(rWindow);
}
namespace
{
const OUString MetricToString(FieldUnit rUnit)
{
FieldUnitStringList* pList = ImplGetFieldUnits();
if (pList)
{
// return unit's default string (ie, the first one )
for (auto it = pList->begin(); it != pList->end(); ++it)
{
if (it->second == rUnit)
return it->first;
}
}
return OUString();
}
}
namespace weld
{
IMPL_LINK_NOARG(MetricSpinButton, spin_button_value_changed, SpinButton&, void)
{
signal_value_changed();
}
IMPL_LINK(MetricSpinButton, spin_button_output, SpinButton&, rSpinButton, void)
{
rSpinButton.set_text(format_number(rSpinButton.get_value()));
}
void MetricSpinButton::update_width_chars()
{
int min, max;
m_xSpinButton->get_range(min, max);
auto width = std::max(m_xSpinButton->get_pixel_size(format_number(min)).Width(),
m_xSpinButton->get_pixel_size(format_number(max)).Width());
int chars = ceil(width / m_xSpinButton->get_approximate_digit_width());
m_xSpinButton->set_width_chars(chars);
}
unsigned int SpinButton::Power10(unsigned int n)
{
unsigned int nValue = 1;
for (unsigned int i = 0; i < n; ++i)
nValue *= 10;
return nValue;
}
int SpinButton::denormalize(int nValue) const
{
const int nFactor = Power10(get_digits());
if ((nValue < (SAL_MIN_INT32 + nFactor)) || (nValue > (SAL_MAX_INT32 - nFactor)))
{
return nValue / nFactor;
}
const int nHalf = nFactor / 2;
if (nValue < 0)
return (nValue - nHalf) / nFactor;
return (nValue + nHalf) / nFactor;
}
OUString MetricSpinButton::format_number(int nValue) const
{
OUString aStr;
unsigned int nDecimalDigits = m_xSpinButton->get_digits();
//pawn percent off to icu to decide whether percent is separated from its number for this locale
if (m_eSrcUnit == FUNIT_PERCENT)
{
double fValue = nValue;
fValue /= SpinButton::Power10(nDecimalDigits);
aStr = unicode::formatPercent(fValue, Application::GetSettings().GetUILanguageTag());
}
else
{
const SvtSysLocale aSysLocale;
const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData();
aStr = rLocaleData.getNum(nValue, nDecimalDigits, true, true);
if (m_eSrcUnit != FUNIT_NONE && m_eSrcUnit != FUNIT_DEGREE)
aStr += " ";
assert(m_eSrcUnit != FUNIT_PERCENT);
aStr += MetricToString(m_eSrcUnit);
}
return aStr;
}
int MetricSpinButton::ConvertValue(int nValue, FieldUnit eInUnit, FieldUnit eOutUnit) const
{
return MetricField::ConvertValue(nValue, 0, m_xSpinButton->get_digits(), eInUnit, eOutUnit);
}
}
VclBuilder::VclBuilder(vcl::Window *pParent, const OUString& sUIDir, const OUString& sUIFile, const OString& sID,
const css::uno::Reference<css::frame::XFrame>& rFrame, bool bLegacy)
: m_sID(sID)
, m_sHelpRoot(OUStringToOString(sUIFile, RTL_TEXTENCODING_UTF8))
, m_pStringReplace(Translate::GetReadStringHook())
, m_pParent(pParent)
, m_bToplevelParentFound(false)
, m_bLegacy(bLegacy)
, m_pParserState(new ParserState)
, m_xFrame(rFrame)
{
m_bToplevelHasDeferredInit = pParent &&
((pParent->IsSystemWindow() && static_cast<SystemWindow*>(pParent)->isDeferredInit()) ||
(pParent->IsDockingWindow() && static_cast<DockingWindow*>(pParent)->isDeferredInit()));
m_bToplevelHasDeferredProperties = m_bToplevelHasDeferredInit;
sal_Int32 nIdx = m_sHelpRoot.lastIndexOf('.');
if (nIdx != -1)
m_sHelpRoot = m_sHelpRoot.copy(0, nIdx);
m_sHelpRoot = m_sHelpRoot + OString('/');
OUString sUri = sUIDir + sUIFile;
try
{
xmlreader::XmlReader reader(sUri);
handleChild(pParent, reader);
}
catch (const css::uno::Exception &rExcept)
{
DBG_UNHANDLED_EXCEPTION("vcl.layout", "Unable to read .ui file");
CrashReporter::AddKeyValue("VclBuilderException", "Unable to read .ui file: " + rExcept.Message);
throw;
}
//Set Mnemonic widgets when everything has been imported
for (auto const& mnemonicWidget : m_pParserState->m_aMnemonicWidgetMaps)
{
FixedText *pOne = get<FixedText>(mnemonicWidget.m_sID);
vcl::Window *pOther = get<vcl::Window>(mnemonicWidget.m_sValue.toUtf8());
SAL_WARN_IF(!pOne || !pOther, "vcl", "missing either source " << mnemonicWidget.m_sID
<< " or target " << mnemonicWidget.m_sValue << " member of Mnemonic Widget Mapping");
if (pOne && pOther)
pOne->set_mnemonic_widget(pOther);
}
//Set a11y relations when everything has been imported
for (auto const& elemAtk : m_pParserState->m_aAtkInfo)
{
vcl::Window *pSource = elemAtk.first;
const stringmap &rMap = elemAtk.second;
for (auto const& elemMap : rMap)
{
const OUString &rTarget = elemMap.second;
vcl::Window *pTarget = get<vcl::Window>(rTarget.toUtf8());
SAL_WARN_IF(!pTarget, "vcl", "missing member of a11y relation: " << rTarget);
if (!pTarget)
continue;
const OString &rType = elemMap.first;
if (rType == "labelled-by")
pSource->SetAccessibleRelationLabeledBy(pTarget);
else if (rType == "label-for")
pSource->SetAccessibleRelationLabelFor(pTarget);
else if (rType == "member-of")
pSource->SetAccessibleRelationMemberOf(pTarget);
else
{
SAL_INFO("vcl.layout", "unhandled a11y relation :" << rType);
}
}
}
//Set radiobutton groups when everything has been imported
for (auto const& elem : m_pParserState->m_aGroupMaps)
{
RadioButton *pOne = get<RadioButton>(elem.m_sID);
RadioButton *pOther = get<RadioButton>(elem.m_sValue);
SAL_WARN_IF(!pOne || !pOther, "vcl", "missing member of radiobutton group");
if (pOne && pOther)
{
if (m_bLegacy)
pOne->group(*pOther);
else
pOther->group(*pOne);
}
}
//Set ComboBox models when everything has been imported
for (auto const& elem : m_pParserState->m_aModelMaps)
{
ListBox *pTarget = get<ListBox>(elem.m_sID);
// pStore may be empty
const ListStore *pStore = get_model_by_name(elem.m_sValue.toUtf8());
SAL_WARN_IF(!pTarget, "vcl", "missing elements of combobox");
if (pTarget && pStore)
mungeModel(*pTarget, *pStore, elem.m_nActiveId);
}
//Set TextView buffers when everything has been imported
for (auto const& elem : m_pParserState->m_aTextBufferMaps)
{
VclMultiLineEdit *pTarget = get<VclMultiLineEdit>(elem.m_sID);
const TextBuffer *pBuffer = get_buffer_by_name(elem.m_sValue.toUtf8());
SAL_WARN_IF(!pTarget || !pBuffer, "vcl", "missing elements of textview/textbuffer");
if (pTarget && pBuffer)
mungeTextBuffer(*pTarget, *pBuffer);
}
//Set SpinButton adjustments when everything has been imported
for (auto const& elem : m_pParserState->m_aNumericFormatterAdjustmentMaps)
{
NumericFormatter *pTarget = dynamic_cast<NumericFormatter*>(get<vcl::Window>(elem.m_sID));
const Adjustment *pAdjustment = get_adjustment_by_name(elem.m_sValue.toUtf8());
SAL_WARN_IF(!pTarget, "vcl", "missing NumericFormatter element of spinbutton/adjustment");
SAL_WARN_IF(!pAdjustment, "vcl", "missing Adjustment element of spinbutton/adjustment");
if (pTarget && pAdjustment)
mungeAdjustment(*pTarget, *pAdjustment);
}
for (auto const& elem : m_pParserState->m_aTimeFormatterAdjustmentMaps)
{
TimeField *pTarget = dynamic_cast<TimeField*>(get<vcl::Window>(elem.m_sID));
const Adjustment *pAdjustment = get_adjustment_by_name(elem.m_sValue.toUtf8());
SAL_WARN_IF(!pTarget || !pAdjustment, "vcl", "missing elements of spinbutton/adjustment");
if (pTarget && pAdjustment)
mungeAdjustment(*pTarget, *pAdjustment);
}
for (auto const& elem : m_pParserState->m_aDateFormatterAdjustmentMaps)
{
DateField *pTarget = dynamic_cast<DateField*>(get<vcl::Window>(elem.m_sID));
const Adjustment *pAdjustment = get_adjustment_by_name(elem.m_sValue.toUtf8());
SAL_WARN_IF(!pTarget || !pAdjustment, "vcl", "missing elements of spinbutton/adjustment");
if (pTarget && pAdjustment)
mungeAdjustment(*pTarget, *pAdjustment);
}
//Set ScrollBar adjustments when everything has been imported
for (auto const& elem : m_pParserState->m_aScrollAdjustmentMaps)
{
ScrollBar *pTarget = get<ScrollBar>(elem.m_sID);
const Adjustment *pAdjustment = get_adjustment_by_name(elem.m_sValue.toUtf8());
SAL_WARN_IF(!pTarget || !pAdjustment, "vcl", "missing elements of scrollbar/adjustment");
if (pTarget && pAdjustment)
mungeAdjustment(*pTarget, *pAdjustment);
}
//Set Scale(Slider) adjustments
for (auto const& elem : m_pParserState->m_aSliderAdjustmentMaps)
{
Slider* pTarget = dynamic_cast<Slider*>(get<vcl::Window>(elem.m_sID));
const Adjustment* pAdjustment = get_adjustment_by_name(elem.m_sValue.toUtf8());
SAL_WARN_IF(!pTarget || !pAdjustment, "vcl", "missing elements of scale(slider)/adjustment");
if (pTarget && pAdjustment)
{
mungeAdjustment(*pTarget, *pAdjustment);
}
}
//Set size-groups when all widgets have been imported
for (auto const& sizeGroup : m_pParserState->m_aSizeGroups)
{
std::shared_ptr<VclSizeGroup> xGroup(std::make_shared<VclSizeGroup>());
for (auto const& elem : sizeGroup.m_aProperties)
{
const OString &rKey = elem.first;
const OUString &rValue = elem.second;
xGroup->set_property(rKey, rValue);
}
for (auto const& elem : sizeGroup.m_aWidgets)
{
vcl::Window* pWindow = get<vcl::Window>(elem.getStr());
pWindow->add_to_size_group(xGroup);
}
}
//Set button images when everything has been imported
std::set<OUString> aImagesToBeRemoved;
for (auto const& elem : m_pParserState->m_aButtonImageWidgetMaps)
{
PushButton *pTargetButton = nullptr;
RadioButton *pTargetRadio = nullptr;
Button *pTarget = nullptr;
if (!elem.m_bRadio)
{
pTargetButton = get<PushButton>(elem.m_sID);
pTarget = pTargetButton;
}
else
{
pTargetRadio = get<RadioButton>(elem.m_sID);
pTarget = pTargetRadio;
}
FixedImage *pImage = get<FixedImage>(elem.m_sValue.toUtf8());
SAL_WARN_IF(!pTarget || !pImage,
"vcl", "missing elements of button/image/stock");
if (!pTarget || !pImage)
continue;
aImagesToBeRemoved.insert(elem.m_sValue);
VclBuilder::StockMap::iterator aFind = m_pParserState->m_aStockMap.find(elem.m_sValue.toUtf8());
if (aFind == m_pParserState->m_aStockMap.end())
{
if (!elem.m_bRadio)
pTargetButton->SetModeImage(pImage->GetImage());
else
pTargetRadio->SetModeRadioImage(pImage->GetImage());
}
else
{
const stockinfo &rImageInfo = aFind->second;
SymbolType eType = mapStockToSymbol(rImageInfo.m_sStock);
SAL_WARN_IF(eType == SymbolType::DONTKNOW, "vcl", "missing stock image element for button");
if (eType == SymbolType::DONTKNOW)
continue;
if (!elem.m_bRadio)
{
pTargetButton->SetSymbol(eType);
//fdo#76457 keep symbol images small e.g. tools->customize->menu
//but images the right size. Really the PushButton::CalcMinimumSize
//and PushButton::ImplDrawPushButton are the better place to handle
//this, but its such a train-wreck
if (eType != SymbolType::IMAGE)
pTargetButton->SetStyle(pTargetButton->GetStyle() | WB_SMALLSTYLE);
}
else
SAL_WARN_IF(eType != SymbolType::IMAGE, "vcl.layout", "inimplemented symbol type for radiobuttons");
if (eType == SymbolType::IMAGE)
{
BitmapEx aBitmap(mapStockToImageResource(rImageInfo.m_sStock));
Image const aImage(aBitmap);
if (!elem.m_bRadio)
pTargetButton->SetModeImage(aImage);
else
pTargetRadio->SetModeRadioImage(aImage);
}
switch (rImageInfo.m_nSize)
{
case 1:
pTarget->SetSmallSymbol();
break;
case 4:
break;
default:
SAL_WARN("vcl.layout", "unsupported image size " << rImageInfo.m_nSize);
break;
}
}
}
//There may be duplicate use of an Image, so we used a set to collect and
//now we can remove them from the tree after their final munge
for (auto const& elem : aImagesToBeRemoved)
{
delete_by_name(elem.toUtf8());
}
//Set button menus when everything has been imported
for (auto const& elem : m_pParserState->m_aButtonMenuMaps)
{
MenuButton *pTarget = get<MenuButton>(elem.m_sID);
PopupMenu *pMenu = get_menu(elem.m_sValue.toUtf8());
SAL_WARN_IF(!pTarget || !pMenu,
"vcl", "missing elements of button/menu");
if (!pTarget || !pMenu)
continue;
pTarget->SetPopupMenu(pMenu);
}
//Remove ScrollWindow parent widgets whose children in vcl implement scrolling
//internally.
for (auto const& elem : m_pParserState->m_aRedundantParentWidgets)
{
delete_by_window(elem.first);
}
//fdo#67378 merge the label into the disclosure button
for (auto const& elem : m_pParserState->m_aExpanderWidgets)
{
vcl::Window *pChild = elem->get_child();
vcl::Window* pLabel = elem->GetWindow(GetWindowType::LastChild);
if (pLabel && pLabel != pChild && pLabel->GetType() == WindowType::FIXEDTEXT)
{
FixedText *pLabelWidget = static_cast<FixedText*>(pLabel);
elem->set_label(pLabelWidget->GetText());
delete_by_window(pLabel);
}
}
// create message dialog message area now
for (auto const& elem : m_pParserState->m_aMessageDialogs)
elem->create_message_area();
//drop maps, etc. that we don't need again
m_pParserState.reset();
SAL_WARN_IF(!m_sID.isEmpty() && (!m_bToplevelParentFound && !get_by_name(m_sID)), "vcl.layout",
"Requested top level widget \"" << m_sID << "\" not found in " << sUIFile);
#if defined SAL_LOG_WARN
if (m_bToplevelParentFound && m_pParent->IsDialog())
{
int nButtons = 0;
bool bHasDefButton = false;
for (auto const& child : m_aChildren)
{
if (isButtonType(child.m_pWindow->GetType()))
{
++nButtons;
if (child.m_pWindow->GetStyle() & WB_DEFBUTTON)
{
bHasDefButton = true;
break;
}
}
}
SAL_WARN_IF(nButtons && !bHasDefButton, "vcl.layout", "No default button defined in " << sUIFile);
}
#endif
}
VclBuilder::~VclBuilder()
{
disposeBuilder();
}
void VclBuilder::disposeBuilder()
{
for (std::vector<WinAndId>::reverse_iterator aI = m_aChildren.rbegin(),
aEnd = m_aChildren.rend(); aI != aEnd; ++aI)
{
aI->m_pWindow.disposeAndClear();
}
m_aChildren.clear();
for (std::vector<MenuAndId>::reverse_iterator aI = m_aMenus.rbegin(),
aEnd = m_aMenus.rend(); aI != aEnd; ++aI)
{
aI->m_pMenu.disposeAndClear();
}
m_aMenus.clear();
m_pParent.clear();
}
namespace
{
bool extractDrawValue(VclBuilder::stringmap& rMap)
{
bool bDrawValue = true;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("draw_value"));
if (aFind != rMap.end())
{
bDrawValue = toBool(aFind->second);
rMap.erase(aFind);
}
return bDrawValue;
}
OUString extractValuePos(VclBuilder::stringmap& rMap)
{
OUString sRet("top");
VclBuilder::stringmap::iterator aFind = rMap.find(OString("value_pos"));
if (aFind != rMap.end())
{
sRet = aFind->second;
rMap.erase(aFind);
}
return sRet;
}
OUString extractTypeHint(VclBuilder::stringmap &rMap)
{
OUString sRet("normal");
VclBuilder::stringmap::iterator aFind = rMap.find(OString("type-hint"));
if (aFind != rMap.end())
{
sRet = aFind->second;
rMap.erase(aFind);
}
return sRet;
}
bool extractResizable(VclBuilder::stringmap &rMap)
{
bool bResizable = true;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("resizable"));
if (aFind != rMap.end())
{
bResizable = toBool(aFind->second);
rMap.erase(aFind);
}
return bResizable;
}
bool extractDecorated(VclBuilder::stringmap &rMap)
{
bool bDecorated = true;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("decorated"));
if (aFind != rMap.end())
{
bDecorated = toBool(aFind->second);
rMap.erase(aFind);
}
return bDecorated;
}
bool extractCloseable(VclBuilder::stringmap &rMap)
{
bool bCloseable = true;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("deletable"));
if (aFind != rMap.end())
{
bCloseable = toBool(aFind->second);
rMap.erase(aFind);
}
return bCloseable;
}
bool extractEntry(VclBuilder::stringmap &rMap)
{
bool bHasEntry = false;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("has-entry"));
if (aFind != rMap.end())
{
bHasEntry = toBool(aFind->second);
rMap.erase(aFind);
}
return bHasEntry;
}
bool extractOrientation(VclBuilder::stringmap &rMap)
{
bool bVertical = false;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("orientation"));
if (aFind != rMap.end())
{
bVertical = aFind->second.equalsIgnoreAsciiCase("vertical");
rMap.erase(aFind);
}
return bVertical;
}
bool extractInconsistent(VclBuilder::stringmap &rMap)
{
bool bInconsistent = false;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("inconsistent"));
if (aFind != rMap.end())
{
bInconsistent = toBool(aFind->second);
rMap.erase(aFind);
}
return bInconsistent;
}
OUString extractIconName(VclBuilder::stringmap &rMap)
{
OUString sIconName;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("icon-name"));
if (aFind != rMap.end())
{
sIconName = aFind->second;
rMap.erase(aFind);
}
return sIconName;
}
OUString getStockText(const OUString &rType)
{
if (rType == "gtk-ok")
return VclResId(SV_BUTTONTEXT_OK);
else if (rType == "gtk-cancel")
return VclResId(SV_BUTTONTEXT_CANCEL);
else if (rType == "gtk-help")
return VclResId(SV_BUTTONTEXT_HELP);
else if (rType == "gtk-close")
return VclResId(SV_BUTTONTEXT_CLOSE);
else if (rType == "gtk-revert-to-saved")
return VclResId(SV_BUTTONTEXT_RESET);
else if (rType == "gtk-add")
return VclResId(SV_BUTTONTEXT_ADD);
else if (rType == "gtk-delete")
return VclResId(SV_BUTTONTEXT_DELETE);
else if (rType == "gtk-remove")
return VclResId(SV_BUTTONTEXT_REMOVE);
else if (rType == "gtk-new")
return VclResId(SV_BUTTONTEXT_NEW);
else if (rType == "gtk-edit")
return VclResId(SV_BUTTONTEXT_EDIT);
else if (rType == "gtk-apply")
return VclResId(SV_BUTTONTEXT_APPLY);
else if (rType == "gtk-save")
return VclResId(SV_BUTTONTEXT_SAVE);
else if (rType == "gtk-open")
return VclResId(SV_BUTTONTEXT_OPEN);
else if (rType == "gtk-undo")
return VclResId(SV_BUTTONTEXT_UNDO);
else if (rType == "gtk-paste")
return VclResId(SV_BUTTONTEXT_PASTE);
else if (rType == "gtk-media-next")
return VclResId(SV_BUTTONTEXT_NEXT);
else if (rType == "gtk-media-previous")
return VclResId(SV_BUTTONTEXT_PREV);
else if (rType == "gtk-go-up")
return VclResId(SV_BUTTONTEXT_GO_UP);
else if (rType == "gtk-go-down")
return VclResId(SV_BUTTONTEXT_GO_DOWN);
else if (rType == "gtk-clear")
return VclResId(SV_BUTTONTEXT_CLEAR);
else if (rType == "gtk-media-play")
return VclResId(SV_BUTTONTEXT_PLAY);
else if (rType == "gtk-find")
return VclResId(SV_BUTTONTEXT_FIND);
else if (rType == "gtk-stop")
return VclResId(SV_BUTTONTEXT_STOP);
else if (rType == "gtk-connect")
return VclResId(SV_BUTTONTEXT_CONNECT);
else if (rType == "gtk-yes")
return VclResId(SV_BUTTONTEXT_YES);
else if (rType == "gtk-no")
return VclResId(SV_BUTTONTEXT_NO);
SAL_WARN("vcl.layout", "unknown stock type: " << rType);
return OUString();
}
bool extractStock(VclBuilder::stringmap &rMap)
{
bool bIsStock = false;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("use-stock"));
if (aFind != rMap.end())
{
bIsStock = toBool(aFind->second);
rMap.erase(aFind);
}
return bIsStock;
}
WinBits extractRelief(VclBuilder::stringmap &rMap)
{
WinBits nBits = WB_3DLOOK;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("relief"));
if (aFind != rMap.end())
{
if (aFind->second == "half")
nBits = WB_FLATBUTTON | WB_BEVELBUTTON;
else if (aFind->second == "none")
nBits = WB_FLATBUTTON;
rMap.erase(aFind);
}
return nBits;
}
OUString extractLabel(VclBuilder::stringmap &rMap)
{
OUString sType;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("label"));
if (aFind != rMap.end())
{
sType = aFind->second;
rMap.erase(aFind);
}
return sType;
}
OUString extractActionName(VclBuilder::stringmap &rMap)
{
OUString sActionName;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("action-name"));
if (aFind != rMap.end())
{
sActionName = aFind->second;
rMap.erase(aFind);
}
return sActionName;
}
bool extractVisible(VclBuilder::stringmap &rMap)
{
VclBuilder::stringmap::iterator aFind = rMap.find(OString("visible"));
if (aFind != rMap.end())
{
return toBool(aFind->second);
}
return false;
}
Size extractSizeRequest(VclBuilder::stringmap &rMap)
{
OUString sWidthRequest("0");
OUString sHeightRequest("0");
VclBuilder::stringmap::iterator aFind = rMap.find(OString("width-request"));
if (aFind != rMap.end())
{
sWidthRequest = aFind->second;
rMap.erase(aFind);
}
aFind = rMap.find(OString("height-request"));
if (aFind != rMap.end())
{
sHeightRequest = aFind->second;
rMap.erase(aFind);
}
return Size(sWidthRequest.toInt32(), sHeightRequest.toInt32());
}
OUString extractTooltipText(VclBuilder::stringmap &rMap)
{
OUString sTooltipText;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("tooltip-text"));
if (aFind == rMap.end())
aFind = rMap.find(OString("tooltip-markup"));
if (aFind != rMap.end())
{
sTooltipText = aFind->second;
rMap.erase(aFind);
}
return sTooltipText;
}
void setupFromActionName(Button *pButton, VclBuilder::stringmap &rMap, const css::uno::Reference<css::frame::XFrame>& rFrame)
{
if (!rFrame.is())
return;
OUString aCommand(extractActionName(rMap));
if (aCommand.isEmpty())
return;
OUString aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(rFrame));
OUString aLabel(vcl::CommandInfoProvider::GetLabelForCommand(aCommand, aModuleName));
if (!aLabel.isEmpty())
pButton->SetText(aLabel);
OUString aTooltip(vcl::CommandInfoProvider::GetTooltipForCommand(aCommand, rFrame));
if (!aTooltip.isEmpty())
pButton->SetQuickHelpText(aTooltip);
Image aImage(vcl::CommandInfoProvider::GetImageForCommand(aCommand, rFrame));
pButton->SetModeImage(aImage);
pButton->SetCommandHandler(aCommand);
}
VclPtr<Button> extractStockAndBuildPushButton(vcl::Window *pParent, VclBuilder::stringmap &rMap, bool bLegacy)
{
WinBits nBits = WB_CLIPCHILDREN|WB_CENTER|WB_VCENTER;
nBits |= extractRelief(rMap);
VclPtr<Button> xWindow;
if (extractStock(rMap))
{
OUString sType = extractLabel(rMap);
if (bLegacy)
{
if (sType == "gtk-ok")
xWindow = VclPtr<OKButton>::Create(pParent, nBits);
else if (sType == "gtk-cancel")
xWindow = VclPtr<CancelButton>::Create(pParent, nBits);
else if (sType == "gtk-close")
xWindow = VclPtr<CloseButton>::Create(pParent, nBits);
else if (sType == "gtk-help")
xWindow = VclPtr<HelpButton>::Create(pParent, nBits);
}
if (!xWindow)
{
xWindow = VclPtr<PushButton>::Create(pParent, nBits);
xWindow->SetText(getStockText(sType));
}
}
if (!xWindow)
xWindow = VclPtr<PushButton>::Create(pParent, nBits);
return xWindow;
}
VclPtr<Button> extractStockAndBuildMenuButton(vcl::Window *pParent, VclBuilder::stringmap &rMap)
{
WinBits nBits = WB_CLIPCHILDREN|WB_CENTER|WB_VCENTER|WB_3DLOOK;
nBits |= extractRelief(rMap);
VclPtr<Button> xWindow = VclPtr<MenuButton>::Create(pParent, nBits);
if (extractStock(rMap))
{
xWindow->SetText(getStockText(extractLabel(rMap)));
}
return xWindow;
}
VclPtr<Button> extractStockAndBuildMenuToggleButton(vcl::Window *pParent, VclBuilder::stringmap &rMap)
{
WinBits nBits = WB_CLIPCHILDREN|WB_CENTER|WB_VCENTER|WB_3DLOOK;
nBits |= extractRelief(rMap);
VclPtr<Button> xWindow = VclPtr<MenuToggleButton>::Create(pParent, nBits);
if (extractStock(rMap))
{
xWindow->SetText(getStockText(extractLabel(rMap)));
}
return xWindow;
}
OUString extractUnit(const OUString& sPattern)
{
OUString sUnit(sPattern);
for (sal_Int32 i = 0; i < sPattern.getLength(); ++i)
{
if (sPattern[i] != '.' && sPattern[i] != ',' && sPattern[i] != '0')
{
sUnit = sPattern.copy(i);
break;
}
}
return sUnit;
}
int extractDecimalDigits(const OUString& sPattern)
{
int nDigits = 0;
bool bAfterPoint = false;
for (sal_Int32 i = 0; i < sPattern.getLength(); ++i)
{
if (sPattern[i] == '.' || sPattern[i] == ',')
bAfterPoint = true;
else if (sPattern[i] == '0')
{
if (bAfterPoint)
++nDigits;
}
else
break;
}
return nDigits;
}
FieldUnit detectMetricUnit(const OUString& sUnit)
{
FieldUnit eUnit = FUNIT_NONE;
if (sUnit == "mm")
eUnit = FUNIT_MM;
else if (sUnit == "cm")
eUnit = FUNIT_CM;
else if (sUnit == "m")
eUnit = FUNIT_M;
else if (sUnit == "km")
eUnit = FUNIT_KM;
else if ((sUnit == "twips") || (sUnit == "twip"))
eUnit = FUNIT_TWIP;
else if (sUnit == "pt")
eUnit = FUNIT_POINT;
else if (sUnit == "pc")
eUnit = FUNIT_PICA;
else if (sUnit == "\"" || (sUnit == "in") || (sUnit == "inch"))
eUnit = FUNIT_INCH;
else if ((sUnit == "'") || (sUnit == "ft") || (sUnit == "foot") || (sUnit == "feet"))
eUnit = FUNIT_FOOT;
else if (sUnit == "mile" || (sUnit == "miles"))
eUnit = FUNIT_MILE;
else if (sUnit == "ch")
eUnit = FUNIT_CHAR;
else if (sUnit == "line")
eUnit = FUNIT_LINE;
else if (sUnit == "%")
eUnit = FUNIT_PERCENT;
else if ((sUnit == "pixels") || (sUnit == "pixel") || (sUnit == "px"))
eUnit = FUNIT_PIXEL;
else if ((sUnit == "degrees") || (sUnit == "degree"))
eUnit = FUNIT_DEGREE;
else if ((sUnit == "sec") || (sUnit == "seconds") || (sUnit == "second"))
eUnit = FUNIT_SECOND;
else if ((sUnit == "ms") || (sUnit == "milliseconds") || (sUnit == "millisecond"))
eUnit = FUNIT_MILLISECOND;
else if (sUnit != "0")
eUnit = FUNIT_CUSTOM;
return eUnit;
}
WinBits extractDeferredBits(VclBuilder::stringmap &rMap)
{
WinBits nBits = WB_3DLOOK|WB_HIDE;
if (extractResizable(rMap))
nBits |= WB_SIZEABLE;
if (extractCloseable(rMap))
nBits |= WB_CLOSEABLE;
OUString sBorder = BuilderUtils::extractCustomProperty(rMap);
if (!sBorder.isEmpty())
nBits |= WB_BORDER;
if (!extractDecorated(rMap))
nBits |= WB_OWNERDRAWDECORATION;
OUString sType(extractTypeHint(rMap));
if (sType == "utility")
nBits |= WB_SYSTEMWINDOW | WB_DIALOGCONTROL | WB_MOVEABLE;
else if (sType == "popup-menu")
nBits |= WB_SYSTEMWINDOW | WB_DIALOGCONTROL | WB_POPUP;
else if (sType == "dock")
nBits |= WB_DOCKABLE | WB_MOVEABLE;
else
nBits |= WB_MOVEABLE;
return nBits;
}
}
void VclBuilder::extractGroup(const OString &id, stringmap &rMap)
{
VclBuilder::stringmap::iterator aFind = rMap.find(OString("group"));
if (aFind != rMap.end())
{
OUString sID = aFind->second;
sal_Int32 nDelim = sID.indexOf(':');
if (nDelim != -1)
sID = sID.copy(0, nDelim);
m_pParserState->m_aGroupMaps.emplace_back(id, sID.toUtf8());
rMap.erase(aFind);
}
}
void VclBuilder::connectNumericFormatterAdjustment(const OString &id, const OUString &rAdjustment)
{
if (!rAdjustment.isEmpty())
m_pParserState->m_aNumericFormatterAdjustmentMaps.emplace_back(id, rAdjustment);
}
void VclBuilder::connectTimeFormatterAdjustment(const OString &id, const OUString &rAdjustment)
{
if (!rAdjustment.isEmpty())
m_pParserState->m_aTimeFormatterAdjustmentMaps.emplace_back(id, rAdjustment);
}
void VclBuilder::connectDateFormatterAdjustment(const OString &id, const OUString &rAdjustment)
{
if (!rAdjustment.isEmpty())
m_pParserState->m_aDateFormatterAdjustmentMaps.emplace_back(id, rAdjustment);
}
bool VclBuilder::extractAdjustmentToMap(const OString& id, VclBuilder::stringmap& rMap, std::vector<WidgetAdjustmentMap>& rAdjustmentMap)
{
VclBuilder::stringmap::iterator aFind = rMap.find(OString("adjustment"));
if (aFind != rMap.end())
{
rAdjustmentMap.emplace_back(id, aFind->second);
rMap.erase(aFind);
return true;
}
return false;
}
namespace
{
sal_Int32 extractActive(VclBuilder::stringmap &rMap)
{
sal_Int32 nActiveId = 0;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("active"));
if (aFind != rMap.end())
{
nActiveId = aFind->second.toInt32();
rMap.erase(aFind);
}
return nActiveId;
}
bool extractSelectable(VclBuilder::stringmap &rMap)
{
bool bSelectable = false;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("selectable"));
if (aFind != rMap.end())
{
bSelectable = toBool(aFind->second);
rMap.erase(aFind);
}
return bSelectable;
}
OUString extractAdjustment(VclBuilder::stringmap &rMap)
{
OUString sAdjustment;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("adjustment"));
if (aFind != rMap.end())
{
sAdjustment= aFind->second;
rMap.erase(aFind);
return sAdjustment;
}
return sAdjustment;
}
}
void VclBuilder::extractModel(const OString &id, stringmap &rMap)
{
VclBuilder::stringmap::iterator aFind = rMap.find(OString("model"));
if (aFind != rMap.end())
{
m_pParserState->m_aModelMaps.emplace_back(id, aFind->second,
extractActive(rMap));
rMap.erase(aFind);
}
}
void VclBuilder::extractBuffer(const OString &id, stringmap &rMap)
{
VclBuilder::stringmap::iterator aFind = rMap.find(OString("buffer"));
if (aFind != rMap.end())
{
m_pParserState->m_aTextBufferMaps.emplace_back(id, aFind->second);
rMap.erase(aFind);
}
}
void VclBuilder::extractStock(const OString &id, stringmap &rMap)
{
VclBuilder::stringmap::iterator aFind = rMap.find(OString("stock"));
if (aFind != rMap.end())
{
stockinfo aInfo;
aInfo.m_sStock = aFind->second;
rMap.erase(aFind);
aFind = rMap.find(OString("icon-size"));
if (aFind != rMap.end())
{
aInfo.m_nSize = aFind->second.toInt32();
rMap.erase(aFind);
}
m_pParserState->m_aStockMap[id] = aInfo;
}
}
void VclBuilder::extractButtonImage(const OString &id, stringmap &rMap, bool bRadio)
{
VclBuilder::stringmap::iterator aFind = rMap.find(OString("image"));
if (aFind != rMap.end())
{
m_pParserState->m_aButtonImageWidgetMaps.emplace_back(id, aFind->second, bRadio);
rMap.erase(aFind);
}
}
void VclBuilder::extractMnemonicWidget(const OString &rLabelID, stringmap &rMap)
{
VclBuilder::stringmap::iterator aFind = rMap.find(OString("mnemonic-widget"));
if (aFind != rMap.end())
{
OUString sID = aFind->second;
sal_Int32 nDelim = sID.indexOf(':');
if (nDelim != -1)
sID = sID.copy(0, nDelim);
m_pParserState->m_aMnemonicWidgetMaps.emplace_back(rLabelID, sID);
rMap.erase(aFind);
}
}
vcl::Window* VclBuilder::prepareWidgetOwnScrolling(vcl::Window *pParent, WinBits &rWinStyle)
{
//For Widgets that manage their own scrolling, if one appears as a child of
//a scrolling window shoehorn that scrolling settings to this widget and
//return the real parent to use
if (pParent && pParent->GetType() == WindowType::SCROLLWINDOW)
{
WinBits nScrollBits = pParent->GetStyle();
nScrollBits &= (WB_AUTOHSCROLL|WB_HSCROLL|WB_AUTOVSCROLL|WB_VSCROLL);
rWinStyle |= nScrollBits;
pParent = pParent->GetParent();
}
return pParent;
}
void VclBuilder::cleanupWidgetOwnScrolling(vcl::Window *pScrollParent, vcl::Window *pWindow, stringmap &rMap)
{
//remove the redundant scrolling parent
sal_Int32 nWidthReq = pScrollParent->get_width_request();
rMap[OString("width-request")] = OUString::number(nWidthReq);
sal_Int32 nHeightReq = pScrollParent->get_height_request();
rMap[OString("height-request")] = OUString::number(nHeightReq);
m_pParserState->m_aRedundantParentWidgets[pScrollParent] = pWindow;
}
#ifndef DISABLE_DYNLOADING
extern "C" { static void thisModule() {} }
// We store these forever, closing modules is non-ideal from a performance
// perspective, code pages will be freed up by the OS anyway if unused for
// a while in many cases, and this helps us pre-init.
typedef std::map<OUString, std::shared_ptr<osl::Module>> ModuleMap;
static ModuleMap g_aModuleMap;
#if ENABLE_MERGELIBS
static std::shared_ptr<osl::Module> g_pMergedLib = std::make_shared<osl::Module>();
#endif
#ifndef SAL_DLLPREFIX
# define SAL_DLLPREFIX ""
#endif
#endif
void VclBuilder::preload()
{
#ifndef DISABLE_DYNLOADING
#if ENABLE_MERGELIBS
g_pMergedLib->loadRelative(&thisModule, SVLIBRARY("merged"));
#else
// find -name '*ui*' | xargs grep 'class=".*lo-' |
// sed 's/.*class="//' | sed 's/-.*$//' | sort | uniq
static const char *aWidgetLibs[] = {
"sfxlo", "svtlo", "svxcorelo", "foruilo",
"vcllo", "svxlo", "cuilo", "swlo",
"swuilo", "sclo", "sdlo", "chartcontrollerlo",
"smlo", "scuilo", "basctllo", "sduilo",
"scnlo", "xsltdlglo", "pcrlo" // "dbulo"
};
for (auto & lib : aWidgetLibs)
{
OUStringBuffer sModuleBuf;
sModuleBuf.append(SAL_DLLPREFIX);
sModuleBuf.append(OUString::createFromAscii(lib));
sModuleBuf.append(SAL_DLLEXTENSION);
osl::Module* pModule = new osl::Module;
OUString sModule = sModuleBuf.makeStringAndClear();
if (pModule->loadRelative(&thisModule, sModule))
g_aModuleMap.insert(std::make_pair(sModule, std::unique_ptr<osl::Module>(pModule)));
else
delete pModule;
}
#endif // ENABLE_MERGELIBS
#endif // DISABLE_DYNLOADING
}
VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OString &name, const OString &id,
stringmap &rMap)
{
bool bIsPlaceHolder = name.isEmpty();
bool bVertical = false;
if (pParent && pParent->GetType() == WindowType::TABCONTROL)
{
//We have to add a page
//make default pageid == position
TabControl *pTabControl = static_cast<TabControl*>(pParent);
sal_uInt16 nNewPageCount = pTabControl->GetPageCount()+1;
sal_uInt16 nNewPageId = nNewPageCount;
pTabControl->InsertPage(nNewPageId, OUString());
pTabControl->SetCurPageId(nNewPageId);
SAL_WARN_IF(bIsPlaceHolder, "vcl.layout", "we should have no placeholders for tabpages");
if (!bIsPlaceHolder)
{
VclPtrInstance<TabPage> pPage(pTabControl);
pPage->Show();
//Make up a name for it
OString sTabPageId = get_by_window(pParent) +
OString("-page") +
OString::number(nNewPageCount);
m_aChildren.emplace_back(sTabPageId, pPage, false);
pPage->SetHelpId(m_sHelpRoot + sTabPageId);
pParent = pPage;
pTabControl->SetTabPage(nNewPageId, pPage);
}
}
if (bIsPlaceHolder || name == "GtkTreeSelection")
return nullptr;
extractButtonImage(id, rMap, name == "GtkRadioButton");
VclPtr<vcl::Window> xWindow;
if (name == "GtkDialog")
{
WinBits nBits = WB_MOVEABLE|WB_3DLOOK|WB_CLOSEABLE;
if (extractResizable(rMap))
nBits |= WB_SIZEABLE;
xWindow = VclPtr<Dialog>::Create(pParent, nBits, !pParent ? Dialog::InitFlag::NoParent : Dialog::InitFlag::Default);
}
else if (name == "GtkMessageDialog")
{
WinBits nBits = WB_MOVEABLE|WB_3DLOOK|WB_CLOSEABLE;
if (extractResizable(rMap))
nBits |= WB_SIZEABLE;
VclPtr<MessageDialog> xDialog(VclPtr<MessageDialog>::Create(pParent, nBits));
m_pParserState->m_aMessageDialogs.push_back(xDialog);
xWindow = xDialog;
#if defined WNT
xWindow->set_border_width(3);
#else
xWindow->set_border_width(12);
#endif
}
else if (name == "GtkBox")
{
bVertical = extractOrientation(rMap);
if (bVertical)
xWindow = VclPtr<VclVBox>::Create(pParent);
else
xWindow = VclPtr<VclHBox>::Create(pParent);
}
else if (name == "GtkPaned")
{
bVertical = extractOrientation(rMap);
assert(bVertical && "hori not implemented, shouldn't be hard though");
xWindow = VclPtr<VclVPaned>::Create(pParent);
}
else if (name == "GtkHBox")
xWindow = VclPtr<VclHBox>::Create(pParent);
else if (name == "GtkVBox")
xWindow = VclPtr<VclVBox>::Create(pParent);
else if (name == "GtkButtonBox")
{
bVertical = extractOrientation(rMap);
if (bVertical)
xWindow = VclPtr<VclVButtonBox>::Create(pParent);
else
xWindow = VclPtr<VclHButtonBox>::Create(pParent);
}
else if (name == "GtkHButtonBox")
xWindow = VclPtr<VclHButtonBox>::Create(pParent);
else if (name == "GtkVButtonBox")
xWindow = VclPtr<VclVButtonBox>::Create(pParent);
else if (name == "GtkGrid")
xWindow = VclPtr<VclGrid>::Create(pParent);
else if (name == "GtkFrame")
xWindow = VclPtr<VclFrame>::Create(pParent);
else if (name == "GtkExpander")
{
VclPtrInstance<VclExpander> pExpander(pParent);
m_pParserState->m_aExpanderWidgets.push_back(pExpander);
xWindow = pExpander;
}
else if (name == "GtkAlignment")
xWindow = VclPtr<VclAlignment>::Create(pParent);
else if (name == "GtkButton")
{
VclPtr<Button> xButton;
OUString sMenu = BuilderUtils::extractCustomProperty(rMap);
if (sMenu.isEmpty())
xButton = extractStockAndBuildPushButton(pParent, rMap, m_bLegacy);
else
{
xButton = extractStockAndBuildMenuButton(pParent, rMap);
m_pParserState->m_aButtonMenuMaps.emplace_back(id, sMenu);
}
xButton->SetImageAlign(ImageAlign::Left); //default to left
setupFromActionName(xButton, rMap, m_xFrame);
xWindow = xButton;
}
else if (name == "GtkToggleButton")
{
VclPtr<Button> xButton;
OUString sMenu = BuilderUtils::extractCustomProperty(rMap);
assert(sMenu.getLength() && "not implemented yet");
xButton = extractStockAndBuildMenuToggleButton(pParent, rMap);
m_pParserState->m_aButtonMenuMaps.emplace_back(id, sMenu);
xButton->SetImageAlign(ImageAlign::Left); //default to left
setupFromActionName(xButton, rMap, m_xFrame);
xWindow = xButton;
}
else if (name == "GtkRadioButton")
{
extractGroup(id, rMap);
WinBits nBits = WB_CLIPCHILDREN|WB_CENTER|WB_VCENTER|WB_3DLOOK;
OUString sWrap = BuilderUtils::extractCustomProperty(rMap);
if (!sWrap.isEmpty())
nBits |= WB_WORDBREAK;
VclPtr<RadioButton> xButton = VclPtr<RadioButton>::Create(pParent, nBits);
xButton->SetImageAlign(ImageAlign::Left); //default to left
xWindow = xButton;
if (::extractStock(rMap))
{
xWindow->SetText(getStockText(extractLabel(rMap)));
}
}
else if (name == "GtkCheckButton")
{
WinBits nBits = WB_CLIPCHILDREN|WB_CENTER|WB_VCENTER|WB_3DLOOK;
OUString sWrap = BuilderUtils::extractCustomProperty(rMap);
if (!sWrap.isEmpty())
nBits |= WB_WORDBREAK;
//maybe always import as TriStateBox and enable/disable tristate
bool bIsTriState = extractInconsistent(rMap);
VclPtr<CheckBox> xCheckBox;
if (bIsTriState)
xCheckBox = VclPtr<TriStateBox>::Create(pParent, nBits);
else
xCheckBox = VclPtr<CheckBox>::Create(pParent, nBits);
if (bIsTriState)
xCheckBox->SetState(TRISTATE_INDET);
xCheckBox->SetImageAlign(ImageAlign::Left); //default to left
xWindow = xCheckBox;
if (::extractStock(rMap))
{
xWindow->SetText(getStockText(extractLabel(rMap)));
}
}
else if (name == "GtkSpinButton")
{
OUString sAdjustment = extractAdjustment(rMap);
OUString sPattern = BuilderUtils::extractCustomProperty(rMap);
OUString sUnit = extractUnit(sPattern);
WinBits nBits = WB_CLIPCHILDREN|WB_LEFT|WB_BORDER|WB_3DLOOK;
if (!id.endsWith("-nospin"))
nBits |= WB_SPIN | WB_REPEAT;
if (sPattern.isEmpty())
{
connectNumericFormatterAdjustment(id, sAdjustment);
SAL_INFO("vcl.layout", "making numeric field for " << name << " " << sUnit);
xWindow = VclPtr<NumericField>::Create(pParent, nBits);
}
else
{
if (sPattern == "hh:mm")
{
connectTimeFormatterAdjustment(id, sAdjustment);
SAL_INFO("vcl.layout", "making time field for " << name << " " << sUnit);
xWindow = VclPtr<TimeField>::Create(pParent, nBits);
}
else if (sPattern == "yy:mm:dd")
{
connectDateFormatterAdjustment(id, sAdjustment);
SAL_INFO("vcl.layout", "making date field for " << name << " " << sUnit);
xWindow = VclPtr<DateField>::Create(pParent, nBits);
}
else
{
connectNumericFormatterAdjustment(id, sAdjustment);
FieldUnit eUnit = detectMetricUnit(sUnit);
SAL_INFO("vcl.layout", "making metric field for " << name << " " << sUnit);
VclPtrInstance<MetricField> xField(pParent, nBits);
xField->SetUnit(eUnit);
if (eUnit == FUNIT_CUSTOM)
xField->SetCustomUnitText(sUnit);
xWindow = xField;
}
}
}
else if (name == "GtkLinkButton")
xWindow = VclPtr<FixedHyperlink>::Create(pParent, WB_CENTER|WB_VCENTER|WB_3DLOOK|WB_NOLABEL);
else if ((name == "GtkComboBox") || (name == "GtkComboBoxText") || (name == "VclComboBoxText"))
{
OUString sPattern = BuilderUtils::extractCustomProperty(rMap);
extractModel(id, rMap);
WinBits nBits = WB_CLIPCHILDREN|WB_LEFT|WB_VCENTER|WB_3DLOOK;
bool bDropdown = BuilderUtils::extractDropdown(rMap);
if (bDropdown)
nBits |= WB_DROPDOWN;
if (!sPattern.isEmpty())
{
OUString sAdjustment = extractAdjustment(rMap);
connectNumericFormatterAdjustment(id, sAdjustment);
OUString sUnit = extractUnit(sPattern);
FieldUnit eUnit = detectMetricUnit(sUnit);
SAL_WARN("vcl.layout", "making metric box for type: " << name
<< " unit: " << sUnit
<< " name: " << id
<< " use a VclComboBoxNumeric instead");
VclPtrInstance<MetricBox> xBox(pParent, nBits);
xBox->EnableAutoSize(true);
xBox->SetUnit(eUnit);
xBox->SetDecimalDigits(extractDecimalDigits(sPattern));
if (eUnit == FUNIT_CUSTOM)
xBox->SetCustomUnitText(sUnit);
xWindow = xBox;
}
else if (extractEntry(rMap))
{
VclPtrInstance<ComboBox> xComboBox(pParent, nBits);
xComboBox->EnableAutoSize(true);
xWindow = xComboBox;
}
else
{
VclPtrInstance<ListBox> xListBox(pParent, nBits|WB_SIMPLEMODE);
xListBox->EnableAutoSize(true);
xWindow = xListBox;
}
}
else if (name == "VclComboBoxNumeric")
{
OUString sPattern = BuilderUtils::extractCustomProperty(rMap);
OUString sAdjustment = extractAdjustment(rMap);
extractModel(id, rMap);
WinBits nBits = WB_CLIPCHILDREN|WB_LEFT|WB_VCENTER|WB_3DLOOK;
bool bDropdown = BuilderUtils::extractDropdown(rMap);
if (bDropdown)
nBits |= WB_DROPDOWN;
if (!sPattern.isEmpty())
{
connectNumericFormatterAdjustment(id, sAdjustment);
OUString sUnit = extractUnit(sPattern);
FieldUnit eUnit = detectMetricUnit(sUnit);
SAL_INFO("vcl.layout", "making metric box for " << name << " " << sUnit);
VclPtrInstance<MetricBox> xBox(pParent, nBits);
xBox->EnableAutoSize(true);
xBox->SetUnit(eUnit);
xBox->SetDecimalDigits(extractDecimalDigits(sPattern));
if (eUnit == FUNIT_CUSTOM)
xBox->SetCustomUnitText(sUnit);
xWindow = xBox;
}
else
{
SAL_INFO("vcl.layout", "making numeric box for " << name);
connectNumericFormatterAdjustment(id, sAdjustment);
VclPtrInstance<NumericBox> xBox(pParent, nBits);
if (bDropdown)
xBox->EnableAutoSize(true);
xWindow = xBox;
}
}
else if (name == "GtkTreeView")
{
//To-Do
//a) move svtools SvTreeViewBox into vcl
//b) make that the default target for GtkTreeView
//c) remove the non-drop down mode of ListBox and convert
// everything over to SvTreeViewBox
//d) remove the users of makeSvTreeViewBox
extractModel(id, rMap);
WinBits nWinStyle = WB_CLIPCHILDREN|WB_LEFT|WB_VCENTER|WB_3DLOOK|WB_SIMPLEMODE;
if (m_bLegacy)
{
OUString sBorder = BuilderUtils::extractCustomProperty(rMap);
if (!sBorder.isEmpty())
nWinStyle |= WB_BORDER;
}
//ListBox manages its own scrolling,
vcl::Window *pRealParent = prepareWidgetOwnScrolling(pParent, nWinStyle);
if (pRealParent != pParent)
nWinStyle |= WB_BORDER;
xWindow = VclPtr<ListBox>::Create(pRealParent, nWinStyle);
if (pRealParent != pParent)
cleanupWidgetOwnScrolling(pParent, xWindow, rMap);
}
else if (name == "GtkLabel")
{
WinBits nWinStyle = WB_CENTER|WB_VCENTER|WB_3DLOOK;
OUString sBorder = BuilderUtils::extractCustomProperty(rMap);
if (!sBorder.isEmpty())
nWinStyle |= WB_BORDER;
extractMnemonicWidget(id, rMap);
if (extractSelectable(rMap))
xWindow = VclPtr<SelectableFixedText>::Create(pParent, nWinStyle);
else
xWindow = VclPtr<FixedText>::Create(pParent, nWinStyle);
}
else if (name == "GtkImage")
{
extractStock(id, rMap);
xWindow = VclPtr<FixedImage>::Create(pParent, WB_CENTER|WB_VCENTER|WB_3DLOOK|WB_SCALE);
//such parentless GtkImages are temps used to set icons on buttons
//default them to hidden to stop e.g. insert->index entry flicking temp
//full screen windows
if (!pParent)
{
rMap["visible"] = "false";
}
}
else if (name == "GtkSeparator")
{
bVertical = extractOrientation(rMap);
xWindow = VclPtr<FixedLine>::Create(pParent, bVertical ? WB_VERT : WB_HORZ);
}
else if (name == "GtkScrollbar")
{
extractAdjustmentToMap(id, rMap, m_pParserState->m_aScrollAdjustmentMaps);
bVertical = extractOrientation(rMap);
xWindow = VclPtr<ScrollBar>::Create(pParent, bVertical ? WB_VERT : WB_HORZ);
}
else if (name == "GtkProgressBar")
{
extractAdjustmentToMap(id, rMap, m_pParserState->m_aScrollAdjustmentMaps);
bVertical = extractOrientation(rMap);
xWindow = VclPtr<ProgressBar>::Create(pParent, bVertical ? WB_VERT : WB_HORZ);
}
else if (name == "GtkScrolledWindow")
{
xWindow = VclPtr<VclScrolledWindow>::Create(pParent);
}
else if (name == "GtkViewport")
{
xWindow = VclPtr<VclViewport>::Create(pParent);
}
else if (name == "GtkEventBox")
{
xWindow = VclPtr<VclEventBox>::Create(pParent);
}
else if (name == "GtkEntry")
{
xWindow = VclPtr<Edit>::Create(pParent, WB_LEFT|WB_VCENTER|WB_BORDER|WB_3DLOOK);
BuilderUtils::ensureDefaultWidthChars(rMap);
}
else if (name == "GtkNotebook")
{
xWindow = VclPtr<TabControl>::Create(pParent, WB_STDTABCONTROL|WB_3DLOOK);
}
else if (name == "GtkDrawingArea")
{
OUString sBorder = BuilderUtils::extractCustomProperty(rMap);
xWindow = VclPtr<VclDrawingArea>::Create(pParent, sBorder.isEmpty() ? 0 : WB_BORDER);
}
else if (name == "GtkTextView")
{
extractBuffer(id, rMap);
WinBits nWinStyle = WB_CLIPCHILDREN|WB_LEFT;
OUString sBorder = BuilderUtils::extractCustomProperty(rMap);
if (!sBorder.isEmpty())
nWinStyle |= WB_BORDER;
//VclMultiLineEdit manages its own scrolling,
vcl::Window *pRealParent = prepareWidgetOwnScrolling(pParent, nWinStyle);
xWindow = VclPtr<VclMultiLineEdit>::Create(pRealParent, nWinStyle);
if (pRealParent != pParent)
cleanupWidgetOwnScrolling(pParent, xWindow, rMap);
}
else if (name == "GtkSpinner")
{
xWindow = VclPtr<Throbber>::Create(pParent, WB_3DLOOK);
}
else if (name == "GtkScale")
{
extractAdjustmentToMap(id, rMap, m_pParserState->m_aSliderAdjustmentMaps);
bool bDrawValue = extractDrawValue(rMap);
if (bDrawValue)
{
OUString sValuePos = extractValuePos(rMap);
(void)sValuePos;
}
bVertical = extractOrientation(rMap);
WinBits nWinStyle = bVertical ? WB_VERT : WB_HORZ;
xWindow = VclPtr<Slider>::Create(pParent, nWinStyle);
}
else if (name == "GtkToolbar")
{
xWindow = VclPtr<ToolBox>::Create(pParent, WB_3DLOOK | WB_TABSTOP);
}
else if (name == "GtkToolButton" || name == "GtkMenuToolButton" ||
name == "GtkToggleToolButton" || name == "GtkRadioToolButton")
{
ToolBox *pToolBox = dynamic_cast<ToolBox*>(pParent);
if (pToolBox)
{
OUString aCommand(extractActionName(rMap));
sal_uInt16 nItemId = 0;
ToolBoxItemBits nBits = ToolBoxItemBits::NONE;
if (name == "GtkMenuToolButton")
nBits |= ToolBoxItemBits::DROPDOWN;
else if (name == "GtkToggleToolButton")
nBits |= ToolBoxItemBits::AUTOCHECK | ToolBoxItemBits::CHECKABLE;
else if (name == "GtkRadioToolButton")
nBits |= ToolBoxItemBits::AUTOCHECK | ToolBoxItemBits::RADIOCHECK;
if (!aCommand.isEmpty() && m_xFrame.is())
{
pToolBox->InsertItem(aCommand, m_xFrame, nBits, extractSizeRequest(rMap));
nItemId = pToolBox->GetItemId(aCommand);
}
else
{
nItemId = pToolBox->GetItemCount() + 1;
//TODO: ImplToolItems::size_type -> sal_uInt16!
pToolBox->InsertItem(nItemId, extractLabel(rMap), nBits);
pToolBox->SetItemCommand(nItemId, aCommand);
pToolBox->SetHelpId(nItemId, m_sHelpRoot + id);
}
OUString sTooltip(extractTooltipText(rMap));
if (!sTooltip.isEmpty())
pToolBox->SetQuickHelpText(nItemId, sTooltip);
OUString sIconName(extractIconName(rMap));
if (!sIconName.isEmpty())
pToolBox->SetItemImage(nItemId, FixedImage::loadThemeImage(sIconName));
if (!extractVisible(rMap))
pToolBox->HideItem(nItemId);
m_pParserState->m_nLastToolbarId = nItemId;
return nullptr; // no widget to be created
}
}
else if (name == "GtkSeparatorToolItem")
{
ToolBox *pToolBox = dynamic_cast<ToolBox*>(pParent);
if (pToolBox)
{
pToolBox->InsertSeparator();
return nullptr; // no widget to be created
}
}
else if (name == "GtkWindow")
{
WinBits nBits = extractDeferredBits(rMap);
if (nBits & WB_DOCKABLE)
xWindow = VclPtr<DockingWindow>::Create(pParent, nBits|WB_MOVEABLE);
else
xWindow = VclPtr<FloatingWindow>::Create(pParent, nBits|WB_MOVEABLE);
}
else if (name == "GtkListBox")
{
WinBits nBits = extractDeferredBits(rMap);
xWindow = VclPtr<ListControl>::Create(pParent, nBits);
}
else
{
sal_Int32 nDelim = name.indexOf('-');
if (nDelim != -1)
{
OUString sFunction(OStringToOUString(OString("make") + name.copy(nDelim+1), RTL_TEXTENCODING_UTF8));
customMakeWidget pFunction = nullptr;
#ifndef DISABLE_DYNLOADING
OUStringBuffer sModuleBuf;
sModuleBuf.append(SAL_DLLPREFIX);
sModuleBuf.append(OStringToOUString(name.copy(0, nDelim), RTL_TEXTENCODING_UTF8));
sModuleBuf.append(SAL_DLLEXTENSION);
OUString sModule = sModuleBuf.makeStringAndClear();
ModuleMap::iterator aI = g_aModuleMap.find(sModule);
if (aI == g_aModuleMap.end())
{
std::shared_ptr<osl::Module> pModule;
#if ENABLE_MERGELIBS
if (!g_pMergedLib->is())
g_pMergedLib->loadRelative(&thisModule, SVLIBRARY("merged"));
if ((pFunction = reinterpret_cast<customMakeWidget>(g_pMergedLib->getFunctionSymbol(sFunction))))
pModule = g_pMergedLib;
#endif
if (!pFunction)
{
pModule.reset(new osl::Module);
bool ok = pModule->loadRelative(&thisModule, sModule);
assert(ok && "bad module name in .ui");
(void) ok;
pFunction = reinterpret_cast<customMakeWidget>(pModule->getFunctionSymbol(sFunction));
}
g_aModuleMap.insert(std::make_pair(sModule, pModule));
}
else
pFunction = reinterpret_cast<customMakeWidget>(aI->second->getFunctionSymbol(sFunction));
#else
pFunction = reinterpret_cast<customMakeWidget>(osl_getFunctionSymbol((oslModule) RTLD_DEFAULT, sFunction.pData));
#endif
if (pFunction)
{
VclPtr<vcl::Window> xParent(pParent);
pFunction(xWindow, xParent, rMap);
if (xWindow->GetType() == WindowType::PUSHBUTTON)
setupFromActionName(static_cast<Button*>(xWindow.get()), rMap, m_xFrame);
else if (xWindow->GetType() == WindowType::MENUBUTTON)
{
OUString sMenu = BuilderUtils::extractCustomProperty(rMap);
if (!sMenu.isEmpty())
m_pParserState->m_aButtonMenuMaps.emplace_back(id, sMenu);
setupFromActionName(static_cast<Button*>(xWindow.get()), rMap, m_xFrame);
}
}
}
}
SAL_INFO_IF(!xWindow, "vcl.layout", "probably need to implement " << name << " or add a make" << name << " function");
if (xWindow)
{
xWindow->SetHelpId(m_sHelpRoot + id);
SAL_INFO("vcl.layout", "for " << name <<
", created " << xWindow.get() << " child of " <<
pParent << "(" << xWindow->ImplGetWindowImpl()->mpParent.get() << "/" <<
xWindow->ImplGetWindowImpl()->mpRealParent.get() << "/" <<
xWindow->ImplGetWindowImpl()->mpBorderWindow.get() << ") with helpid " <<
xWindow->GetHelpId());
m_aChildren.emplace_back(id, xWindow, bVertical);
}
return xWindow;
}
namespace
{
//return true for window types which exist in vcl but are not themselves
//represented in the .ui format, i.e. only their children exist.
bool isConsideredGtkPseudo(vcl::Window const *pWindow)
{
return pWindow->GetType() == WindowType::TABPAGE;
}
}
//Any properties from .ui load we couldn't set because of potential virtual methods
//during ctor are applied here
void VclBuilder::setDeferredProperties()
{
if (!m_bToplevelHasDeferredProperties)
return;
stringmap aDeferredProperties;
aDeferredProperties.swap(m_aDeferredProperties);
m_bToplevelHasDeferredProperties = false;
BuilderUtils::set_properties(m_pParent, aDeferredProperties);
}
namespace BuilderUtils
{
void set_properties(vcl::Window *pWindow, const VclBuilder::stringmap &rProps)
{
for (auto const& prop : rProps)
{
const OString &rKey = prop.first;
const OUString &rValue = prop.second;
pWindow->set_property(rKey, rValue);
}
}
OUString convertMnemonicMarkup(const OUString &rIn)
{
OUStringBuffer aRet(rIn);
for (sal_Int32 nI = 0; nI < aRet.getLength(); ++nI)
{
if (aRet[nI] == '_' && nI+1 < aRet.getLength())
{
if (aRet[nI+1] != '_')
aRet[nI] = MNEMONIC_CHAR;
else
aRet.remove(nI, 1);
++nI;
}
}
return aRet.makeStringAndClear();
}
OUString extractCustomProperty(VclBuilder::stringmap &rMap)
{
OUString sCustomProperty;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("customproperty"));
if (aFind != rMap.end())
{
sCustomProperty = aFind->second;
rMap.erase(aFind);
}
return sCustomProperty;
}
FieldUnit detectUnit(OUString const& rString)
{
OUString const unit(extractUnit(rString));
return detectMetricUnit(unit);
}
void ensureDefaultWidthChars(VclBuilder::stringmap &rMap)
{
OString sWidthChars("width-chars");
VclBuilder::stringmap::iterator aFind = rMap.find(sWidthChars);
if (aFind == rMap.end())
rMap[sWidthChars] = "25";
}
bool extractDropdown(VclBuilder::stringmap &rMap)
{
bool bDropdown = true;
VclBuilder::stringmap::iterator aFind = rMap.find(OString("dropdown"));
if (aFind != rMap.end())
{
bDropdown = toBool(aFind->second);
rMap.erase(aFind);
}
return bDropdown;
}
void reorderWithinParent(vcl::Window &rWindow, sal_uInt16 nNewPosition)
{
WindowImpl *pWindowImpl = rWindow.ImplGetWindowImpl();
if (pWindowImpl->mpParent != pWindowImpl->mpRealParent)
{
assert(pWindowImpl->mpBorderWindow == pWindowImpl->mpParent);
assert(pWindowImpl->mpBorderWindow->ImplGetWindowImpl()->mpParent == pWindowImpl->mpRealParent);
reorderWithinParent(*pWindowImpl->mpBorderWindow, nNewPosition);
return;
}
rWindow.reorderWithinParent(nNewPosition);
}
void reorderWithinParent(std::vector<vcl::Window*>& rChilds, bool bIsButtonBox)
{
for (size_t i = 0; i < rChilds.size(); ++i)
{
reorderWithinParent(*rChilds[i], i);
if (!bIsButtonBox)
continue;
//The first member of the group for legacy code needs WB_GROUP set and the
//others not
WinBits nBits = rChilds[i]->GetStyle();
nBits &= ~WB_GROUP;
if (i == 0)
nBits |= WB_GROUP;
rChilds[i]->SetStyle(nBits);
}
}
}
VclPtr<vcl::Window> VclBuilder::insertObject(vcl::Window *pParent, const OString &rClass,
const OString &rID, stringmap &rProps, stringmap &rPango, stringmap &rAtk)
{
VclPtr<vcl::Window> pCurrentChild;
if (m_pParent && !isConsideredGtkPseudo(m_pParent) && !m_sID.isEmpty() && rID == m_sID)
{
pCurrentChild = m_pParent;
//toplevels default to resizable and apparently you can't change them
//afterwards, so we need to wait until now before we can truly
//initialize the dialog.
if (pParent && pParent->IsSystemWindow())
{
SystemWindow *pSysWin = static_cast<SystemWindow*>(pCurrentChild.get());
pSysWin->doDeferredInit(extractDeferredBits(rProps));
m_bToplevelHasDeferredInit = false;
}
else if (pParent && pParent->IsDockingWindow())
{
DockingWindow *pDockWin = static_cast<DockingWindow*>(pCurrentChild.get());
pDockWin->doDeferredInit(extractDeferredBits(rProps));
m_bToplevelHasDeferredInit = false;
}
if (pCurrentChild->GetHelpId().isEmpty())
{
pCurrentChild->SetHelpId(m_sHelpRoot + m_sID);
SAL_INFO("vcl.layout", "for toplevel dialog " << this << " " <<
rID << ", set helpid " << pCurrentChild->GetHelpId());
}
m_bToplevelParentFound = true;
}
else
{
//if we're being inserting under a toplevel dialog whose init is
//deferred due to waiting to encounter it in this .ui, and it hasn't
//been seen yet, then make unattached widgets parent-less toplevels
if (pParent == m_pParent.get() && m_bToplevelHasDeferredInit)
pParent = nullptr;
pCurrentChild = makeObject(pParent, rClass, rID, rProps);
}
if (pCurrentChild)
{
pCurrentChild->set_id(OStringToOUString(rID, RTL_TEXTENCODING_UTF8));
if (pCurrentChild == m_pParent.get() && m_bToplevelHasDeferredProperties)
m_aDeferredProperties = rProps;
else
BuilderUtils::set_properties(pCurrentChild, rProps);
for (auto const& elem : rPango)
{
const OString &rKey = elem.first;
const OUString &rValue = elem.second;
pCurrentChild->set_font_attribute(rKey, rValue);
}
m_pParserState->m_aAtkInfo[VclPtr<vcl::Window>(pCurrentChild)] = rAtk;
}
rProps.clear();
rPango.clear();
rAtk.clear();
if (!pCurrentChild)
pCurrentChild = m_aChildren.empty() ? pParent : m_aChildren.back().m_pWindow.get();
return pCurrentChild;
}
void VclBuilder::handleTabChild(vcl::Window *pParent, xmlreader::XmlReader &reader)
{
OString sID;
int nLevel = 1;
stringmap aProperties;
std::vector<vcl::EnumContext::Context> context;
while(true)
{
xmlreader::Span name;
int nsId;
xmlreader::XmlReader::Result res = reader.nextItem(
xmlreader::XmlReader::Text::NONE, &name, &nsId);
if (res == xmlreader::XmlReader::Result::Begin)
{
++nLevel;
if (name.equals("object"))
{
while (reader.nextAttribute(&nsId, &name))
{
if (name.equals("id"))
{
name = reader.getAttributeValue(false);
sID = OString(name.begin, name.length);
sal_Int32 nDelim = sID.indexOf(':');
if (nDelim != -1)
{
OString sPattern = sID.copy(nDelim+1);
aProperties[OString("customproperty")] = OUString::fromUtf8(sPattern);
sID = sID.copy(0, nDelim);
}
}
}
}
else if (name.equals("style"))
{
int nPriority = 0;
context = handleStyle(reader, nPriority);
--nLevel;
}
else if (name.equals("property"))
collectProperty(reader, aProperties);
}
if (res == xmlreader::XmlReader::Result::End)
--nLevel;
if (!nLevel)
break;
if (res == xmlreader::XmlReader::Result::Done)
break;
}
if (!pParent)
return;
TabControl *pTabControl = static_cast<TabControl*>(pParent);
VclBuilder::stringmap::iterator aFind = aProperties.find(OString("label"));
if (aFind != aProperties.end())
{
sal_uInt16 nPageId = pTabControl->GetCurPageId();
pTabControl->SetPageText(nPageId, aFind->second);
pTabControl->SetPageName(nPageId, sID);
if (context.size() != 0)
{
TabPage* pPage = pTabControl->GetTabPage(nPageId);
pPage->SetContext(context);
}
}
else
pTabControl->RemovePage(pTabControl->GetCurPageId());
}
//so that tabbing between controls goes in a visually sensible sequence
//we sort these into a best-tab-order sequence
bool VclBuilder::sortIntoBestTabTraversalOrder::operator()(const vcl::Window *pA, const vcl::Window *pB) const
{
//sort child order within parent list by grid position
sal_Int32 nTopA = pA->get_grid_top_attach();
sal_Int32 nTopB = pB->get_grid_top_attach();
if (nTopA < nTopB)
return true;
if (nTopA > nTopB)
return false;
sal_Int32 nLeftA = pA->get_grid_left_attach();
sal_Int32 nLeftB = pB->get_grid_left_attach();
if (nLeftA < nLeftB)
return true;
if (nLeftA > nLeftB)
return false;
//sort into two groups of pack start and pack end
VclPackType ePackA = pA->get_pack_type();
VclPackType ePackB = pB->get_pack_type();
if (ePackA < ePackB)
return true;
if (ePackA > ePackB)
return false;
bool bVerticalContainer = m_pBuilder->get_window_packing_data(pA->GetParent()).m_bVerticalOrient;
bool bPackA = pA->get_secondary();
bool bPackB = pB->get_secondary();
if (!bVerticalContainer)
{
//for horizontal boxes group secondaries before primaries
if (bPackA > bPackB)
return true;
if (bPackA < bPackB)
return false;
}
else
{
//for vertical boxes group secondaries after primaries
if (bPackA < bPackB)
return true;
if (bPackA > bPackB)
return false;
}
//honour relative box positions with pack group, (numerical order is reversed
//for VclPackType::End, they are packed from the end back, but here we need
//them in visual layout order so that tabbing works as expected)
sal_Int32 nPackA = m_pBuilder->get_window_packing_data(pA).m_nPosition;
sal_Int32 nPackB = m_pBuilder->get_window_packing_data(pB).m_nPosition;
if (nPackA < nPackB)
return ePackA == VclPackType::Start;
if (nPackA > nPackB)
return ePackA != VclPackType::Start;
//sort labels of Frames before body
if (pA->GetParent() == pB->GetParent())
{
const VclFrame *pFrameParent = dynamic_cast<const VclFrame*>(pA->GetParent());
if (pFrameParent)
{
const vcl::Window *pLabel = pFrameParent->get_label_widget();
int nFramePosA = (pA == pLabel) ? 0 : 1;
int nFramePosB = (pB == pLabel) ? 0 : 1;
return nFramePosA < nFramePosB;
}
}
return false;
}
void VclBuilder::handleChild(vcl::Window *pParent, xmlreader::XmlReader &reader)
{
vcl::Window *pCurrentChild = nullptr;
xmlreader::Span name;
int nsId;
OString sType, sInternalChild;
while (reader.nextAttribute(&nsId, &name))
{
if (name.equals("type"))
{
name = reader.getAttributeValue(false);
sType = OString(name.begin, name.length);
}
else if (name.equals("internal-child"))
{
name = reader.getAttributeValue(false);
sInternalChild = OString(name.begin, name.length);
}
}
if (sType == "tab")
{
handleTabChild(pParent, reader);
return;
}
int nLevel = 1;
while(true)
{
xmlreader::XmlReader::Result res = reader.nextItem(
xmlreader::XmlReader::Text::NONE, &name, &nsId);
if (res == xmlreader::XmlReader::Result::Begin)
{
if (name.equals("object") || name.equals("placeholder"))
{
pCurrentChild = handleObject(pParent, reader).get();
bool bObjectInserted = pCurrentChild && pParent != pCurrentChild;
if (bObjectInserted)
{
//Internal-children default in glade to not having their visible bits set
//even though they are visible (generally anyway)
if (!sInternalChild.isEmpty())
pCurrentChild->Show();
//Select the first page if it's a notebook
if (pCurrentChild->GetType() == WindowType::TABCONTROL)
{
TabControl *pTabControl = static_cast<TabControl*>(pCurrentChild);
pTabControl->SetCurPageId(pTabControl->GetPageId(0));
//To-Do add reorder capability to the TabControl
}
else
{
// We want to sort labels before contents of frames
// for keyboard traversal, especially if there
// are multiple widgets using the same mnemonic
if (sType == "label")
{
if (VclFrame *pFrameParent = dynamic_cast<VclFrame*>(pParent))
pFrameParent->designate_label(pCurrentChild);
}
if (sInternalChild.startsWith("vbox") || sInternalChild.startsWith("messagedialog-vbox"))
{
if (Dialog *pBoxParent = dynamic_cast<Dialog*>(pParent))
pBoxParent->set_content_area(static_cast<VclBox*>(pCurrentChild)); // FIXME-VCLPTR
}
else if (sInternalChild.startsWith("action_area") || sInternalChild.startsWith("messagedialog-action_area"))
{
vcl::Window *pContentArea = pCurrentChild->GetParent();
if (Dialog *pBoxParent = dynamic_cast<Dialog*>(pContentArea ? pContentArea->GetParent() : nullptr))
{
pBoxParent->set_action_area(static_cast<VclButtonBox*>(pCurrentChild)); // FIXME-VCLPTR
}
}
//To-Do make reorder a virtual in Window, move this foo
//there and see above
std::vector<vcl::Window*> aChilds;
for (vcl::Window* pChild = pCurrentChild->GetWindow(GetWindowType::FirstChild); pChild;
pChild = pChild->GetWindow(GetWindowType::Next))
{
aChilds.push_back(pChild);
}
bool bIsButtonBox = dynamic_cast<VclButtonBox*>(pCurrentChild) != nullptr;
//sort child order within parent so that tabbing
//between controls goes in a visually sensible sequence
std::stable_sort(aChilds.begin(), aChilds.end(), sortIntoBestTabTraversalOrder(this));
BuilderUtils::reorderWithinParent(aChilds, bIsButtonBox);
}
}
}
else if (name.equals("packing"))
{
handlePacking(pCurrentChild, pParent, reader);
}
else if (name.equals("interface"))
{
while (reader.nextAttribute(&nsId, &name))
{
if (name.equals("domain"))
{
name = reader.getAttributeValue(false);
sType = OString(name.begin, name.length);
m_pParserState->m_aResLocale = Translate::Create(sType.getStr());
}
}
++nLevel;
}
else
++nLevel;
}
if (res == xmlreader::XmlReader::Result::End)
--nLevel;
if (!nLevel)
break;
if (res == xmlreader::XmlReader::Result::Done)
break;
}
}
void VclBuilder::collectPangoAttribute(xmlreader::XmlReader &reader, stringmap &rMap)
{
xmlreader::Span span;
int nsId;
OString sProperty;
OString sValue;
while (reader.nextAttribute(&nsId, &span))
{
if (span.equals("name"))
{
span = reader.getAttributeValue(false);
sProperty = OString(span.begin, span.length);
}
else if (span.equals("value"))
{
span = reader.getAttributeValue(false);
sValue = OString(span.begin, span.length);
}
}
if (!sProperty.isEmpty())
rMap[sProperty] = OUString::fromUtf8(sValue);
}
void VclBuilder::collectAtkAttribute(xmlreader::XmlReader &reader, stringmap &rMap)
{
xmlreader::Span span;
int nsId;
OString sProperty;
OString sValue;
while (reader.nextAttribute(&nsId, &span))
{
if (span.equals("type"))
{
span = reader.getAttributeValue(false);
sProperty = OString(span.begin, span.length);
}
else if (span.equals("target"))
{
span = reader.getAttributeValue(false);
sValue = OString(span.begin, span.length);
sal_Int32 nDelim = sValue.indexOf(':');
if (nDelim != -1)
sValue = sValue.copy(0, nDelim);
}
}
if (!sProperty.isEmpty())
rMap[sProperty] = OUString::fromUtf8(sValue);
}
void VclBuilder::handleRow(xmlreader::XmlReader &reader, const OString &rID)
{
int nLevel = 1;
ListStore::row aRow;
while(true)
{
xmlreader::Span name;
int nsId;
xmlreader::XmlReader::Result res = reader.nextItem(
xmlreader::XmlReader::Text::NONE, &name, &nsId);
if (res == xmlreader::XmlReader::Result::Done)
break;
if (res == xmlreader::XmlReader::Result::Begin)
{
++nLevel;
if (name.equals("col"))
{
bool bTranslated = false;
sal_uInt32 nId = 0;
OString sContext;
while (reader.nextAttribute(&nsId, &name))
{
if (name.equals("id"))
{
name = reader.getAttributeValue(false);
nId = OString(name.begin, name.length).toInt32();
}
else if (nId == 0 && name.equals("translatable") && reader.getAttributeValue(false).equals("yes"))
{
bTranslated = true;
}
else if (name.equals("context"))
{
name = reader.getAttributeValue(false);
sContext = OString(name.begin, name.length);
}
}
reader.nextItem(
xmlreader::XmlReader::Text::Raw, &name, &nsId);
OString sValue = OString(name.begin, name.length);
OUString sFinalValue;
if (bTranslated)
{
if (!sContext.isEmpty())
sValue = sContext + "\004" + sValue;
sFinalValue = Translate::get(sValue.getStr(), m_pParserState->m_aResLocale);
}
else
sFinalValue = OUString::fromUtf8(sValue);
if (aRow.size() < nId+1)
aRow.resize(nId+1);
aRow[nId] = sFinalValue;
}
}
if (res == xmlreader::XmlReader::Result::End)
{
--nLevel;
}
if (!nLevel)
break;
}
m_pParserState->m_aModels[rID].m_aEntries.push_back(aRow);
}
void VclBuilder::handleListStore(xmlreader::XmlReader &reader, const OString &rID)
{
int nLevel = 1;
sal_Int32 nRowIndex = 0;
while(true)
{
xmlreader::Span name;
int nsId;
xmlreader::XmlReader::Result res = reader.nextItem(
xmlreader::XmlReader::Text::NONE, &name, &nsId);
if (res == xmlreader::XmlReader::Result::Done)
break;
if (res == xmlreader::XmlReader::Result::Begin)
{
if (name.equals("row"))
{
handleRow(reader, rID);
nRowIndex++;
}
else
++nLevel;
}
if (res == xmlreader::XmlReader::Result::End)
{
--nLevel;
}
if (!nLevel)
break;
}
}
void VclBuilder::handleAtkObject(xmlreader::XmlReader &reader, vcl::Window *pWindow)
{
assert(pWindow);
int nLevel = 1;
stringmap aProperties;
while(true)
{
xmlreader::Span name;
int nsId;
xmlreader::XmlReader::Result res = reader.nextItem(
xmlreader::XmlReader::Text::NONE, &name, &nsId);
if (res == xmlreader::XmlReader::Result::Done)
break;
if (res == xmlreader::XmlReader::Result::Begin)
{
++nLevel;
if (name.equals("property"))
collectProperty(reader, aProperties);
}
if (res == xmlreader::XmlReader::Result::End)
{
--nLevel;
}
if (!nLevel)
break;
}
for (auto const& prop : aProperties)
{
const OString &rKey = prop.first;
const OUString &rValue = prop.second;
if (pWindow && rKey.match("AtkObject::"))
pWindow->set_property(rKey.copy(RTL_CONSTASCII_LENGTH("AtkObject::")), rValue);
else
SAL_WARN("vcl.layout", "unhandled atk prop: " << rKey);
}
}
std::vector<OUString> VclBuilder::handleItems(xmlreader::XmlReader &reader) const
{
int nLevel = 1;
std::vector<OUString> aItems;
sal_Int32 nItemIndex = 0;
while(true)
{
xmlreader::Span name;
int nsId;
xmlreader::XmlReader::Result res = reader.nextItem(
xmlreader::XmlReader::Text::NONE, &name, &nsId);
if (res == xmlreader::XmlReader::Result::Done)
break;
if (res == xmlreader::XmlReader::Result::Begin)
{
++nLevel;
if (name.equals("item"))
{
bool bTranslated = false;
OString sContext;
while (reader.nextAttribute(&nsId, &name))
{
if (name.equals("translatable") && reader.getAttributeValue(false).equals("yes"))
{
bTranslated = true;
}
else if (name.equals("context"))
{
name = reader.getAttributeValue(false);
sContext = OString(name.begin, name.length);
}
}
reader.nextItem(
xmlreader::XmlReader::Text::Raw, &name, &nsId);
OString sValue = OString(name.begin, name.length);
OUString sFinalValue;
if (bTranslated)
{
if (!sContext.isEmpty())
sValue = sContext + "\004" + sValue;
sFinalValue = Translate::get(sValue.getStr(), m_pParserState->m_aResLocale);
}
else
sFinalValue = OUString::fromUtf8(sValue);
if (m_pStringReplace)
sFinalValue = (*m_pStringReplace)(sFinalValue);
aItems.push_back(sFinalValue);
++nItemIndex;
}
}
if (res == xmlreader::XmlReader::Result::End)
{
--nLevel;
}
if (!nLevel)
break;
}
return aItems;
}
void VclBuilder::handleMenu(xmlreader::XmlReader &reader, const OString &rID)
{
VclPtr<PopupMenu> pCurrentMenu = VclPtr<PopupMenu>::Create();
int nLevel = 1;
stringmap aProperties;
while(true)
{
xmlreader::Span name;
int nsId;
xmlreader::XmlReader::Result res = reader.nextItem(
xmlreader::XmlReader::Text::NONE, &name, &nsId);
if (res == xmlreader::XmlReader::Result::Done)
break;
if (res == xmlreader::XmlReader::Result::Begin)
{
if (name.equals("child"))
{
handleMenuChild(pCurrentMenu, reader);
}
else
{
++nLevel;
if (name.equals("property"))
collectProperty(reader, aProperties);
}
}
if (res == xmlreader::XmlReader::Result::End)
{
--nLevel;
}
if (!nLevel)
break;
}
m_aMenus.emplace_back(rID, pCurrentMenu);
}
void VclBuilder::handleMenuChild(PopupMenu *pParent, xmlreader::XmlReader &reader)
{
xmlreader::Span name;
int nsId;
int nLevel = 1;
while(true)
{
xmlreader::XmlReader::Result res = reader.nextItem(
xmlreader::XmlReader::Text::NONE, &name, &nsId);
if (res == xmlreader::XmlReader::Result::Begin)
{
if (name.equals("object") || name.equals("placeholder"))
{
handleMenuObject(pParent, reader);
}
else
++nLevel;
}
if (res == xmlreader::XmlReader::Result::End)
--nLevel;
if (!nLevel)
break;
if (res == xmlreader::XmlReader::Result::Done)
break;
}
}
void VclBuilder::handleMenuObject(PopupMenu *pParent, xmlreader::XmlReader &reader)
{
OString sClass;
OString sID;
OUString sCustomProperty;
PopupMenu *pSubMenu = nullptr;
xmlreader::Span name;
int nsId;
while (reader.nextAttribute(&nsId, &name))
{
if (name.equals("class"))
{
name = reader.getAttributeValue(false);
sClass = OString(name.begin, name.length);
}
else if (name.equals("id"))
{
name = reader.getAttributeValue(false);
sID = OString(name.begin, name.length);
sal_Int32 nDelim = sID.indexOf(':');
if (nDelim != -1)
{
sCustomProperty = OUString::fromUtf8(sID.copy(nDelim+1));
sID = sID.copy(0, nDelim);
}
}
}
int nLevel = 1;
stringmap aProperties;
accelmap aAccelerators;
if (!sCustomProperty.isEmpty())
aProperties[OString("customproperty")] = sCustomProperty;
while(true)
{
xmlreader::XmlReader::Result res = reader.nextItem(
xmlreader::XmlReader::Text::NONE, &name, &nsId);
if (res == xmlreader::XmlReader::Result::Done)
break;
if (res == xmlreader::XmlReader::Result::Begin)
{
if (name.equals("child"))
{
size_t nChildMenuIdx = m_aMenus.size();
handleChild(nullptr, reader);
assert(m_aMenus.size() > nChildMenuIdx && "menu not inserted");
pSubMenu = m_aMenus[nChildMenuIdx].m_pMenu;
}
else
{
++nLevel;
if (name.equals("property"))
collectProperty(reader, aProperties);
else if (name.equals("accelerator"))
collectAccelerator(reader, aAccelerators);
}
}
if (res == xmlreader::XmlReader::Result::End)
{
--nLevel;
}
if (!nLevel)
break;
}
insertMenuObject(pParent, pSubMenu, sClass, sID, aProperties, aAccelerators);
}
void VclBuilder::handleSizeGroup(xmlreader::XmlReader &reader)
{
m_pParserState->m_aSizeGroups.emplace_back();
SizeGroup &rSizeGroup = m_pParserState->m_aSizeGroups.back();
int nLevel = 1;
while(true)
{
xmlreader::Span name;
int nsId;
xmlreader::XmlReader::Result res = reader.nextItem(
xmlreader::XmlReader::Text::NONE, &name, &nsId);
if (res == xmlreader::XmlReader::Result::Done)
break;
if (res == xmlreader::XmlReader::Result::Begin)
{
++nLevel;
if (name.equals("widget"))
{
while (reader.nextAttribute(&nsId, &name))
{
if (name.equals("name"))
{
name = reader.getAttributeValue(false);
OString sWidget = OString(name.begin, name.length);
sal_Int32 nDelim = sWidget.indexOf(':');
if (nDelim != -1)
sWidget = sWidget.copy(0, nDelim);
rSizeGroup.m_aWidgets.push_back(sWidget);
}
}
}
else
{
if (name.equals("property"))
collectProperty(reader, rSizeGroup.m_aProperties);
}
}
if (res == xmlreader::XmlReader::Result::End)
{
--nLevel;
}
if (!nLevel)
break;
}
}
namespace
{
vcl::KeyCode makeKeyCode(const std::pair<OString,OString> &rKey)
{
bool bShift = rKey.second.indexOf("GDK_SHIFT_MASK") != -1;
bool bMod1 = rKey.second.indexOf("GDK_CONTROL_MASK") != -1;
bool bMod2 = rKey.second.indexOf("GDK_MOD1_MASK") != -1;
bool bMod3 = rKey.second.indexOf("GDK_MOD2_MASK") != -1;
if (rKey.first == "Insert")
return vcl::KeyCode(KEY_INSERT, bShift, bMod1, bMod2, bMod3);
else if (rKey.first == "Delete")
return vcl::KeyCode(KEY_DELETE, bShift, bMod1, bMod2, bMod3);
assert (rKey.first.getLength() == 1);
sal_Char cChar = rKey.first.toChar();
if (cChar >= 'a' && cChar <= 'z')
return vcl::KeyCode(KEY_A + (cChar - 'a'), bShift, bMod1, bMod2, bMod3);
else if (cChar >= 'A' && cChar <= 'Z')
return vcl::KeyCode(KEY_A + (cChar - 'A'), bShift, bMod1, bMod2, bMod3);
else if (cChar >= '0' && cChar <= '9')
return vcl::KeyCode(KEY_0 + (cChar - 'A'), bShift, bMod1, bMod2, bMod3);
return vcl::KeyCode(cChar, bShift, bMod1, bMod2, bMod3);
}
}
void VclBuilder::insertMenuObject(PopupMenu *pParent, PopupMenu *pSubMenu, const OString &rClass, const OString &rID,
stringmap &rProps, accelmap &rAccels)
{
sal_uInt16 nOldCount = pParent->GetItemCount();
sal_uInt16 nNewId = ++m_pParserState->m_nLastMenuItemId;
if (rClass == "GtkMenuItem")
{
OUString sLabel(BuilderUtils::convertMnemonicMarkup(extractLabel(rProps)));
OUString aCommand(extractActionName(rProps));
pParent->InsertItem(nNewId, sLabel, MenuItemBits::TEXT, rID);
pParent->SetItemCommand(nNewId, aCommand);
if (pSubMenu)
pParent->SetPopupMenu(nNewId, pSubMenu);
}
else if (rClass == "GtkCheckMenuItem")
{
OUString sLabel(BuilderUtils::convertMnemonicMarkup(extractLabel(rProps)));
OUString aCommand(extractActionName(rProps));
pParent->InsertItem(nNewId, sLabel, MenuItemBits::CHECKABLE, rID);
pParent->SetItemCommand(nNewId, aCommand);
}
else if (rClass == "GtkRadioMenuItem")
{
OUString sLabel(BuilderUtils::convertMnemonicMarkup(extractLabel(rProps)));
OUString aCommand(extractActionName(rProps));
pParent->InsertItem(nNewId, sLabel, MenuItemBits::AUTOCHECK | MenuItemBits::RADIOCHECK, rID);
pParent->SetItemCommand(nNewId, aCommand);
}
else if (rClass == "GtkSeparatorMenuItem")
{
pParent->InsertSeparator(rID);
}
SAL_WARN_IF(nOldCount == pParent->GetItemCount(), "vcl.layout", "probably need to implement " << rClass);
if (nOldCount != pParent->GetItemCount())
{
pParent->SetHelpId(nNewId, m_sHelpRoot + rID);
for (auto const& prop : rProps)
{
const OString &rKey = prop.first;
const OUString &rValue = prop.second;
if (rKey == "tooltip-markup")
pParent->SetTipHelpText(nNewId, rValue);
else if (rKey == "tooltip-text")
pParent->SetTipHelpText(nNewId, rValue);
else if (rKey == "visible")
pParent->ShowItem(nNewId, toBool(rValue));
else if (rKey == "has-default" && toBool(rValue))
pParent->SetSelectedEntry(nNewId);
else
SAL_INFO("vcl.layout", "unhandled property: " << rKey);
}
for (auto const& accel : rAccels)
{
const OString &rSignal = accel.first;
const auto &rValue = accel.second;
if (rSignal == "activate")
pParent->SetAccelKey(nNewId, makeKeyCode(rValue));
else
SAL_INFO("vcl.layout", "unhandled accelerator for: " << rSignal);
}
}
rProps.clear();
}
/// Insert items to a ComboBox or a ListBox.
/// They have no common ancestor that would have 'InsertEntry()', so use a template.
template<typename T> bool insertItems(vcl::Window *pWindow, VclBuilder::stringmap &rMap, const std::vector<OUString> &rItems)
{
T *pContainer = dynamic_cast<T*>(pWindow);
if (!pContainer)
return false;
sal_uInt16 nActiveId = extractActive(rMap);
for (auto const& item : rItems)
pContainer->InsertEntry(item);
if (nActiveId < rItems.size())
pContainer->SelectEntryPos(nActiveId);
return true;
}
VclPtr<vcl::Window> VclBuilder::handleObject(vcl::Window *pParent, xmlreader::XmlReader &reader)
{
OString sClass;
OString sID;
OUString sCustomProperty;
xmlreader::Span name;
int nsId;
while (reader.nextAttribute(&nsId, &name))
{
if (name.equals("class"))
{
name = reader.getAttributeValue(false);
sClass = OString(name.begin, name.length);
}
else if (name.equals("id"))
{
name = reader.getAttributeValue(false);
sID = OString(name.begin, name.length);
sal_Int32 nDelim = sID.indexOf(':');
if (nDelim != -1)
{
sCustomProperty = OUString::fromUtf8(sID.copy(nDelim+1));
sID = sID.copy(0, nDelim);
}
}
}
if (sClass == "GtkListStore")
{
handleListStore(reader, sID);
return nullptr;
}
else if (sClass == "GtkMenu")
{
handleMenu(reader, sID);
return nullptr;
}
else if (sClass == "GtkSizeGroup")
{
handleSizeGroup(reader);
return nullptr;
}
else if (sClass == "AtkObject")
{
handleAtkObject(reader, pParent);
return nullptr;
}
int nLevel = 1;
stringmap aProperties, aPangoAttributes;
stringmap aAtkAttributes;
std::vector<OUString> aItems;
if (!sCustomProperty.isEmpty())
aProperties[OString("customproperty")] = sCustomProperty;
VclPtr<vcl::Window> pCurrentChild;
while(true)
{
xmlreader::XmlReader::Result res = reader.nextItem(
xmlreader::XmlReader::Text::NONE, &name, &nsId);
if (res == xmlreader::XmlReader::Result::Done)
break;
if (res == xmlreader::XmlReader::Result::Begin)
{
if (name.equals("child"))
{
if (!pCurrentChild)
{
pCurrentChild = insertObject(pParent, sClass, sID,
aProperties, aPangoAttributes, aAtkAttributes);
}
handleChild(pCurrentChild, reader);
}
else if (name.equals("items"))
aItems = handleItems(reader);
else if (name.equals("style"))
{
int nPriority = 0;
std::vector<vcl::EnumContext::Context> aContext = handleStyle(reader, nPriority);
if (nPriority != 0)
{
vcl::IPrioritable* pPrioritable = dynamic_cast<vcl::IPrioritable*>(pCurrentChild.get());
SAL_WARN_IF(!pPrioritable, "vcl", "priority set for not supported item");
if (pPrioritable)
pPrioritable->SetPriority(nPriority);
}
if (aContext.size() != 0)
{
vcl::IContext* pContextControl = dynamic_cast<vcl::IContext*>(pCurrentChild.get());
SAL_WARN_IF(!pContextControl, "vcl", "context set for not supported item");
if (pContextControl)
pContextControl->SetContext(aContext);
}
}
else
{
++nLevel;
if (name.equals("property"))
collectProperty(reader, aProperties);
else if (name.equals("attribute"))
collectPangoAttribute(reader, aPangoAttributes);
else if (name.equals("relation"))
collectAtkAttribute(reader, aAtkAttributes);
else if (name.equals("action-widget"))
handleActionWidget(reader);
}
}
if (res == xmlreader::XmlReader::Result::End)
{
--nLevel;
}
if (!nLevel)
break;
}
if (sClass == "GtkAdjustment")
{
m_pParserState->m_aAdjustments[sID] = aProperties;
return nullptr;
}
else if (sClass == "GtkTextBuffer")
{
m_pParserState->m_aTextBuffers[sID] = aProperties;
return nullptr;
}
if (!pCurrentChild)
{
pCurrentChild = insertObject(pParent, sClass, sID, aProperties,
aPangoAttributes, aAtkAttributes);
}
if (!aItems.empty())
{
// try to fill-in the items
if (!insertItems<ComboBox>(pCurrentChild, aProperties, aItems))
insertItems<ListBox>(pCurrentChild, aProperties, aItems);
}
return pCurrentChild;
}
void VclBuilder::handlePacking(vcl::Window *pCurrent, vcl::Window *pParent, xmlreader::XmlReader &reader)
{
xmlreader::Span name;
int nsId;
int nLevel = 1;
while(true)
{
xmlreader::XmlReader::Result res = reader.nextItem(
xmlreader::XmlReader::Text::NONE, &name, &nsId);
if (res == xmlreader::XmlReader::Result::Done)
break;
if (res == xmlreader::XmlReader::Result::Begin)
{
++nLevel;
if (name.equals("property"))
applyPackingProperty(pCurrent, pParent, reader);
}
if (res == xmlreader::XmlReader::Result::End)
{
--nLevel;
}
if (!nLevel)
break;
}
}
void VclBuilder::applyPackingProperty(vcl::Window *pCurrent,
vcl::Window *pParent,
xmlreader::XmlReader &reader)
{
if (!pCurrent)
return;
//ToolBoxItems are not true widgets just elements
//of the ToolBox itself
ToolBox *pToolBoxParent = nullptr;
if (pCurrent == pParent)
pToolBoxParent = dynamic_cast<ToolBox*>(pParent);
xmlreader::Span name;
int nsId;
if (pCurrent->GetType() == WindowType::SCROLLWINDOW)
{
auto aFind = m_pParserState->m_aRedundantParentWidgets.find(VclPtr<vcl::Window>(pCurrent));
if (aFind != m_pParserState->m_aRedundantParentWidgets.end())
{
pCurrent = aFind->second;
assert(pCurrent);
}
}
while (reader.nextAttribute(&nsId, &name))
{
if (name.equals("name"))
{
name = reader.getAttributeValue(false);
OString sKey(name.begin, name.length);
sKey = sKey.replace('_', '-');
reader.nextItem(
xmlreader::XmlReader::Text::Raw, &name, &nsId);
OString sValue(name.begin, name.length);
if (sKey == "expand" || sKey == "resize")
{
bool bTrue = (!sValue.isEmpty() && (sValue[0] == 't' || sValue[0] == 'T' || sValue[0] == '1'));
if (pToolBoxParent)
pToolBoxParent->SetItemExpand(m_pParserState->m_nLastToolbarId, bTrue);
else
pCurrent->set_expand(bTrue);
continue;
}
if (pToolBoxParent)
continue;
if (sKey == "fill")
{
bool bTrue = (!sValue.isEmpty() && (sValue[0] == 't' || sValue[0] == 'T' || sValue[0] == '1'));
pCurrent->set_fill(bTrue);
}
else if (sKey == "pack-type")
{
VclPackType ePackType = (!sValue.isEmpty() && (sValue[0] == 'e' || sValue[0] == 'E')) ? VclPackType::End : VclPackType::Start;
pCurrent->set_pack_type(ePackType);
}
else if (sKey == "left-attach")
{
pCurrent->set_grid_left_attach(sValue.toInt32());
}
else if (sKey == "top-attach")
{
pCurrent->set_grid_top_attach(sValue.toInt32());
}
else if (sKey == "width")
{
pCurrent->set_grid_width(sValue.toInt32());
}
else if (sKey == "height")
{
pCurrent->set_grid_height(sValue.toInt32());
}
else if (sKey == "padding")
{
pCurrent->set_padding(sValue.toInt32());
}
else if (sKey == "position")
{
set_window_packing_position(pCurrent, sValue.toInt32());
}
else if (sKey == "secondary")
{
pCurrent->set_secondary(toBool(sValue));
}
else if (sKey == "non-homogeneous")
{
pCurrent->set_non_homogeneous(toBool(sValue));
}
else if (sKey == "homogeneous")
{
pCurrent->set_non_homogeneous(!toBool(sValue));
}
else
{
SAL_WARN("vcl.layout", "unknown packing: " << sKey);
}
}
}
}
std::vector<vcl::EnumContext::Context> VclBuilder::handleStyle(xmlreader::XmlReader &reader, int &nPriority)
{
std::vector<vcl::EnumContext::Context> aContext;
xmlreader::Span name;
int nsId;
int nLevel = 1;
while(true)
{
xmlreader::XmlReader::Result res = reader.nextItem(
xmlreader::XmlReader::Text::NONE, &name, &nsId);
if (res == xmlreader::XmlReader::Result::Done)
break;
if (res == xmlreader::XmlReader::Result::Begin)
{
++nLevel;
if (name.equals("class"))
{
OString classStyle = getStyleClass(reader);
if (classStyle.startsWith("context-"))
{
OString sContext = classStyle.copy(classStyle.indexOf('-') + 1);
OUString sContext2 = OUString(sContext.getStr(), sContext.getLength(), RTL_TEXTENCODING_UTF8);
aContext.push_back(vcl::EnumContext::GetContextEnum(sContext2));
}
else if (classStyle.startsWith("priority-"))
{
OString aPriority = classStyle.copy(classStyle.indexOf('-') + 1);
OUString aPriority2 = OUString(aPriority.getStr(), aPriority.getLength(), RTL_TEXTENCODING_UTF8);
nPriority = aPriority2.toInt32();
}
else
{
SAL_WARN("vcl.layout", "unknown class: " << classStyle);
}
}
}
if (res == xmlreader::XmlReader::Result::End)
{
--nLevel;
}
if (!nLevel)
break;
}
return aContext;
}
OString VclBuilder::getStyleClass(xmlreader::XmlReader &reader)
{
xmlreader::Span name;
int nsId;
OString aRet;
while (reader.nextAttribute(&nsId, &name))
{
if (name.equals("name"))
{
name = reader.getAttributeValue(false);
aRet = OString (name.begin, name.length);
}
}
return aRet;
}
void VclBuilder::collectProperty(xmlreader::XmlReader &reader, stringmap &rMap) const
{
xmlreader::Span name;
int nsId;
OString sProperty, sContext;
bool bTranslated = false;
while (reader.nextAttribute(&nsId, &name))
{
if (name.equals("name"))
{
name = reader.getAttributeValue(false);
sProperty = OString(name.begin, name.length);
}
else if (name.equals("context"))
{
name = reader.getAttributeValue(false);
sContext = OString(name.begin, name.length);
}
else if (name.equals("translatable") && reader.getAttributeValue(false).equals("yes"))
{
bTranslated = true;
}
}
reader.nextItem(xmlreader::XmlReader::Text::Raw, &name, &nsId);
OString sValue = OString(name.begin, name.length);
OUString sFinalValue;
if (bTranslated)
{
if (!sContext.isEmpty())
sValue = sContext + "\004" + sValue;
sFinalValue = Translate::get(sValue.getStr(), m_pParserState->m_aResLocale);
}
else
sFinalValue = OUString::fromUtf8(sValue);
if (!sProperty.isEmpty())
{
sProperty = sProperty.replace('_', '-');
if (m_pStringReplace)
sFinalValue = (*m_pStringReplace)(sFinalValue);
rMap[sProperty] = sFinalValue;
}
}
void VclBuilder::handleActionWidget(xmlreader::XmlReader &reader)
{
xmlreader::Span name;
int nsId;
OString sResponse;
while (reader.nextAttribute(&nsId, &name))
{
if (name.equals("response"))
{
name = reader.getAttributeValue(false);
sResponse = OString(name.begin, name.length);
}
}
reader.nextItem(xmlreader::XmlReader::Text::Raw, &name, &nsId);
OString sID = OString(name.begin, name.length);
sal_Int32 nDelim = sID.indexOf(':');
if (nDelim != -1)
sID = sID.copy(0, nDelim);
set_response(sID, sResponse.toInt32());
}
void VclBuilder::collectAccelerator(xmlreader::XmlReader &reader, accelmap &rMap)
{
xmlreader::Span name;
int nsId;
OString sProperty;
OString sValue;
OString sModifiers;
while (reader.nextAttribute(&nsId, &name))
{
if (name.equals("key"))
{
name = reader.getAttributeValue(false);
sValue = OString(name.begin, name.length);
}
else if (name.equals("signal"))
{
name = reader.getAttributeValue(false);
sProperty = OString(name.begin, name.length);
}
else if (name.equals("modifiers"))
{
name = reader.getAttributeValue(false);
sModifiers = OString(name.begin, name.length);
}
}
if (!sProperty.isEmpty() && !sValue.isEmpty())
{
rMap[sProperty] = std::make_pair(sValue, sModifiers);
}
}
vcl::Window *VclBuilder::get_widget_root()
{
return m_aChildren.empty() ? nullptr : m_aChildren[0].m_pWindow.get();
}
vcl::Window *VclBuilder::get_by_name(const OString& sID)
{
for (auto const& child : m_aChildren)
{
if (child.m_sID == sID)
return child.m_pWindow;
}
return nullptr;
}
PopupMenu *VclBuilder::get_menu(const OString& sID)
{
for (auto const& menu : m_aMenus)
{
if (menu.m_sID == sID)
return menu.m_pMenu;
}
return nullptr;
}
void VclBuilder::set_response(const OString& sID, short nResponse)
{
switch (nResponse)
{
case -5:
nResponse = RET_OK;
break;
case -6:
nResponse = RET_CANCEL;
break;
case -7:
nResponse = RET_CLOSE;
break;
case -8:
nResponse = RET_YES;
break;
case -9:
nResponse = RET_NO;
break;
case -11:
nResponse = RET_HELP;
break;
};
assert(nResponse >= 0);
for (auto & child : m_aChildren)
{
if (child.m_sID == sID)
{
PushButton* pPushButton = dynamic_cast<PushButton*>(child.m_pWindow.get());
assert(pPushButton);
Dialog* pDialog = pPushButton->GetParentDialog();
assert(pDialog);
pDialog->add_button(pPushButton, nResponse, false);
return;
}
}
assert(false);
}
void VclBuilder::delete_by_name(const OString& sID)
{
for (std::vector<WinAndId>::iterator aI = m_aChildren.begin(),
aEnd = m_aChildren.end(); aI != aEnd; ++aI)
{
if (aI->m_sID == sID)
{
aI->m_pWindow.disposeAndClear();
m_aChildren.erase(aI);
break;
}
}
}
void VclBuilder::delete_by_window(vcl::Window *pWindow)
{
drop_ownership(pWindow);
pWindow->disposeOnce();
}
void VclBuilder::drop_ownership(const vcl::Window *pWindow)
{
for (std::vector<WinAndId>::iterator aI = m_aChildren.begin(),
aEnd = m_aChildren.end(); aI != aEnd; ++aI)
{
if (aI->m_pWindow == pWindow)
{
m_aChildren.erase(aI);
break;
}
}
}
OString VclBuilder::get_by_window(const vcl::Window *pWindow) const
{
for (auto const& child : m_aChildren)
{
if (child.m_pWindow == pWindow)
return child.m_sID;
}
return OString();
}
VclBuilder::PackingData VclBuilder::get_window_packing_data(const vcl::Window *pWindow) const
{
//We've stored the return of new Control, some of these get
//border windows placed around them which are what you get
//from GetChild, so scoot up a level if necessary to get the
//window whose position value we have
const vcl::Window *pPropHolder = pWindow->ImplGetWindowImpl()->mpClientWindow ?
pWindow->ImplGetWindowImpl()->mpClientWindow : pWindow;
for (auto const& child : m_aChildren)
{
if (child.m_pWindow == pPropHolder)
return child.m_aPackingData;
}
return PackingData();
}
void VclBuilder::set_window_packing_position(const vcl::Window *pWindow, sal_Int32 nPosition)
{
for (auto & child : m_aChildren)
{
if (child.m_pWindow == pWindow)
child.m_aPackingData.m_nPosition = nPosition;
}
}
const VclBuilder::ListStore *VclBuilder::get_model_by_name(const OString& sID) const
{
std::map<OString, ListStore>::const_iterator aI = m_pParserState->m_aModels.find(sID);
if (aI != m_pParserState->m_aModels.end())
return &(aI->second);
return nullptr;
}
const VclBuilder::TextBuffer *VclBuilder::get_buffer_by_name(const OString& sID) const
{
std::map<OString, TextBuffer>::const_iterator aI = m_pParserState->m_aTextBuffers.find(sID);
if (aI != m_pParserState->m_aTextBuffers.end())
return &(aI->second);
return nullptr;
}
const VclBuilder::Adjustment *VclBuilder::get_adjustment_by_name(const OString& sID) const
{
std::map<OString, Adjustment>::const_iterator aI = m_pParserState->m_aAdjustments.find(sID);
if (aI != m_pParserState->m_aAdjustments.end())
return &(aI->second);
return nullptr;
}
void VclBuilder::mungeModel(ListBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId)
{
for (auto const& entry : rStore.m_aEntries)
{
const ListStore::row &rRow = entry;
sal_uInt16 nEntry = rTarget.InsertEntry(rRow[0]);
if (rRow.size() > 1)
{
sal_IntPtr nValue = rRow[1].toInt32();
rTarget.SetEntryData(nEntry, reinterpret_cast<void*>(nValue));
}
}
if (nActiveId < rStore.m_aEntries.size())
rTarget.SelectEntryPos(nActiveId);
}
void VclBuilder::mungeAdjustment(NumericFormatter &rTarget, const Adjustment &rAdjustment)
{
int nMul = rtl_math_pow10Exp(1, rTarget.GetDecimalDigits());
for (auto const& elem : rAdjustment)
{
const OString &rKey = elem.first;
const OUString &rValue = elem.second;
if (rKey == "upper")
{
sal_Int64 nUpper = rValue.toDouble() * nMul;
rTarget.SetMax(nUpper);
rTarget.SetLast(nUpper);
}
else if (rKey == "lower")
{
sal_Int64 nLower = rValue.toDouble() * nMul;
rTarget.SetMin(nLower);
rTarget.SetFirst(nLower);
}
else if (rKey == "value")
{
sal_Int64 nValue = rValue.toDouble() * nMul;
rTarget.SetValue(nValue);
}
else if (rKey == "step-increment")
{
sal_Int64 nSpinSize = rValue.toDouble() * nMul;
rTarget.SetSpinSize(nSpinSize);
}
else
{
SAL_INFO("vcl.layout", "unhandled property :" << rKey);
}
}
}
void VclBuilder::mungeAdjustment(TimeField &rTarget, const Adjustment &rAdjustment)
{
for (auto const& elem : rAdjustment)
{
const OString &rKey = elem.first;
const OUString &rValue = elem.second;
if (rKey == "upper")
{
tools::Time aUpper(rValue.toInt32());
rTarget.SetMax(aUpper);
rTarget.SetLast(aUpper);
}
else if (rKey == "lower")
{
tools::Time aLower(rValue.toInt32());
rTarget.SetMin(aLower);
rTarget.SetFirst(aLower);
}
else if (rKey == "value")
{
tools::Time aValue(rValue.toInt32());
rTarget.SetTime(aValue);
}
else
{
SAL_INFO("vcl.layout", "unhandled property :" << rKey);
}
}
}
void VclBuilder::mungeAdjustment(DateField &rTarget, const Adjustment &rAdjustment)
{
for (auto const& elem : rAdjustment)
{
const OString &rKey = elem.first;
const OUString &rValue = elem.second;
if (rKey == "upper")
{
Date aUpper(rValue.toInt32());
rTarget.SetMax(aUpper);
rTarget.SetLast(aUpper);
}
else if (rKey == "lower")
{
Date aLower(rValue.toInt32());
rTarget.SetMin(aLower);
rTarget.SetFirst(aLower);
}
else if (rKey == "value")
{
Date aValue(rValue.toInt32());
rTarget.SetDate(aValue);
}
else
{
SAL_INFO("vcl.layout", "unhandled property :" << rKey);
}
}
}
void VclBuilder::mungeAdjustment(ScrollBar &rTarget, const Adjustment &rAdjustment)
{
for (auto const& elem : rAdjustment)
{
const OString &rKey = elem.first;
const OUString &rValue = elem.second;
if (rKey == "upper")
rTarget.SetRangeMax(rValue.toInt32());
else if (rKey == "lower")
rTarget.SetRangeMin(rValue.toInt32());
else if (rKey == "value")
rTarget.SetThumbPos(rValue.toInt32());
else if (rKey == "step-increment")
rTarget.SetLineSize(rValue.toInt32());
else if (rKey == "page-increment")
rTarget.SetPageSize(rValue.toInt32());
else
{
SAL_INFO("vcl.layout", "unhandled property :" << rKey);
}
}
}
void VclBuilder::mungeAdjustment(Slider& rTarget, const Adjustment& rAdjustment)
{
for (auto const& elem : rAdjustment)
{
const OString &rKey = elem.first;
const OUString &rValue = elem.second;
if (rKey == "upper")
rTarget.SetRangeMax(rValue.toInt32());
else if (rKey == "lower")
rTarget.SetRangeMin(rValue.toInt32());
else if (rKey == "value")
rTarget.SetThumbPos(rValue.toInt32());
else if (rKey == "step-increment")
rTarget.SetLineSize(rValue.toInt32());
else if (rKey == "page-increment")
rTarget.SetPageSize(rValue.toInt32());
else
{
SAL_INFO("vcl.layout", "unhandled property :" << rKey);
}
}
}
void VclBuilder::mungeTextBuffer(VclMultiLineEdit &rTarget, const TextBuffer &rTextBuffer)
{
for (auto const& elem : rTextBuffer)
{
const OString &rKey = elem.first;
const OUString &rValue = elem.second;
if (rKey == "text")
rTarget.SetText(rValue);
else
{
SAL_INFO("vcl.layout", "unhandled property :" << rKey);
}
}
}
VclBuilder::ParserState::ParserState()
: m_nLastToolbarId(0)
, m_nLastMenuItemId(0)
{}
VclBuilder::MenuAndId::MenuAndId(const OString &rId, PopupMenu *pMenu)
: m_sID(rId)
, m_pMenu(pMenu)
{};
VclBuilder::MenuAndId::~MenuAndId() {}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|