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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <tools/diagnose_ex.h>
#include <tools/stream.hxx>
#include <sal/log.hxx>
#include <comphelper/lok.hxx>
#include <vcl/svapp.hxx>
#include <vcl/mnemonic.hxx>
#include <vcl/image.hxx>
#include <vcl/event.hxx>
#include <vcl/help.hxx>
#include <vcl/floatwin.hxx>
#include <vcl/wrkwin.hxx>
#include <vcl/timer.hxx>
#include <vcl/decoview.hxx>
#include <vcl/bitmap.hxx>
#include <vcl/menu.hxx>
#include <vcl/button.hxx>
#include <vcl/gradient.hxx>
#include <vcl/i18nhelp.hxx>
#include <vcl/taskpanelist.hxx>
#include <vcl/controllayout.hxx>
#include <vcl/toolbox.hxx>
#include <vcl/dockingarea.hxx>
#include <vcl/settings.hxx>
#include <vcl/commandinfoprovider.hxx>
#include <vcl/IDialogRenderable.hxx>
#include <impglyphitem.hxx>
#include <salinst.hxx>
#include <svdata.hxx>
#include <strings.hrc>
#include <window.h>
#include <salmenu.hxx>
#include <salframe.hxx>
#include "menubarwindow.hxx"
#include "menufloatingwindow.hxx"
#include "menuitemlist.hxx"
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/accessibility/XAccessible.hpp>
#include <com/sun/star/accessibility/AccessibleRole.hpp>
#include <vcl/toolkit/unowrap.hxx>
#include <vcl/unohelp.hxx>
#include <vcl/configsettings.hxx>
#include <vcl/lazydelete.hxx>
#include <vcl/vcllayout.hxx>
#include <map>
#include <string_view>
#include <vector>
namespace vcl
{
struct MenuLayoutData : public ControlLayoutData
{
std::vector< sal_uInt16 > m_aLineItemIds;
std::map< sal_uInt16, tools::Rectangle > m_aVisibleItemBoundRects;
};
}
using namespace vcl;
#define EXTRAITEMHEIGHT 4
#define SPACE_AROUND_TITLE 4
static bool ImplAccelDisabled()
{
// display of accelerator strings may be suppressed via configuration
static int nAccelDisabled = -1;
if( nAccelDisabled == -1 )
{
OUString aStr =
vcl::SettingsConfigItem::get()->
getValue( "Menu", "SuppressAccelerators" );
nAccelDisabled = aStr.equalsIgnoreAsciiCase("true") ? 1 : 0;
}
return nAccelDisabled == 1;
}
static void ImplSetMenuItemData( MenuItemData* pData )
{
// convert data
if ( !pData->aImage )
pData->eType = MenuItemType::STRING;
else if ( pData->aText.isEmpty() )
pData->eType = MenuItemType::IMAGE;
else
pData->eType = MenuItemType::STRINGIMAGE;
}
namespace {
void ImplClosePopupToolBox( const VclPtr<vcl::Window>& pWin )
{
if ( pWin->GetType() == WindowType::TOOLBOX && ImplGetDockingManager()->IsInPopupMode( pWin ) )
{
ImplDockingWindowWrapper* pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( pWin );
if ( pWrapper && pWrapper->GetFloatingWindow() )
pWrapper->GetFloatingWindow()->EndPopupMode( FloatWinPopupEndFlags::CloseAll );
}
}
// TODO: Move to common code with the same function in toolbox
// Draw the ">>" - more indicator at the coordinates
void lclDrawMoreIndicator(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
{
rRenderContext.Push(PushFlags::FILLCOLOR | PushFlags::LINECOLOR);
rRenderContext.SetLineColor();
if (rRenderContext.GetSettings().GetStyleSettings().GetFaceColor().IsDark())
rRenderContext.SetFillColor(COL_WHITE);
else
rRenderContext.SetFillColor(COL_BLACK);
float fScaleFactor = rRenderContext.GetDPIScaleFactor();
int linewidth = 1 * fScaleFactor;
int space = 4 * fScaleFactor;
long width = 8 * fScaleFactor;
long height = 5 * fScaleFactor;
//Keep odd b/c drawing code works better
if ( height % 2 == 0 )
height--;
long heightOrig = height;
long x = rRect.Left() + (rRect.getWidth() - width)/2 + 1;
long y = rRect.Top() + (rRect.getHeight() - height)/2 + 1;
while( height >= 1)
{
rRenderContext.DrawRect( tools::Rectangle( x, y, x + linewidth, y ) );
x += space;
rRenderContext.DrawRect( tools::Rectangle( x, y, x + linewidth, y ) );
x -= space;
y++;
if( height <= heightOrig / 2 + 1) x--;
else x++;
height--;
}
rRenderContext.Pop();
}
} // end anonymous namespace
Menu::Menu()
: mpFirstDel(nullptr),
pItemList(new MenuItemList),
pStartedFrom(nullptr),
pWindow(nullptr),
nTitleHeight(0),
nEventId(nullptr),
mnHighlightedItemPos(ITEMPOS_INVALID),
nMenuFlags(MenuFlags::NONE),
nSelectedId(0),
nImgOrChkPos(0),
nTextPos(0),
bCanceled(false),
bInCallback(false),
bKilled(false)
{
}
Menu::~Menu()
{
disposeOnce();
}
void Menu::dispose()
{
ImplCallEventListeners( VclEventId::ObjectDying, ITEMPOS_INVALID );
// at the window free the reference to the accessible component
// and make sure the MenuFloatingWindow knows about our destruction
if ( pWindow )
{
MenuFloatingWindow* pFloat = static_cast<MenuFloatingWindow*>(pWindow.get());
if( pFloat->pMenu.get() == this )
pFloat->pMenu.clear();
pWindow->SetAccessible( css::uno::Reference< css::accessibility::XAccessible >() );
}
// dispose accessible components
if ( mxAccessible.is() )
{
css::uno::Reference< css::lang::XComponent> xComponent( mxAccessible, css::uno::UNO_QUERY );
if ( xComponent.is() )
xComponent->dispose();
}
if ( nEventId )
Application::RemoveUserEvent( nEventId );
// Notify deletion of this menu
ImplMenuDelData* pDelData = mpFirstDel;
while ( pDelData )
{
pDelData->mpMenu = nullptr;
pDelData = pDelData->mpNext;
}
bKilled = true;
pItemList->Clear();
mpLayoutData.reset();
// Native-support: destroy SalMenu
ImplClearSalMenu();
pStartedFrom.clear();
pWindow.clear();
VclReferenceBase::dispose();
}
void Menu::CreateAutoMnemonics()
{
MnemonicGenerator aMnemonicGenerator;
size_t n;
for ( n = 0; n < pItemList->size(); n++ )
{
MenuItemData* pData = pItemList->GetDataFromPos( n );
if ( ! (pData->nBits & MenuItemBits::NOSELECT ) )
aMnemonicGenerator.RegisterMnemonic( pData->aText );
}
for ( n = 0; n < pItemList->size(); n++ )
{
MenuItemData* pData = pItemList->GetDataFromPos( n );
if ( ! (pData->nBits & MenuItemBits::NOSELECT ) )
pData->aText = aMnemonicGenerator.CreateMnemonic( pData->aText );
}
}
void Menu::Activate()
{
bInCallback = true;
ImplMenuDelData aDelData( this );
ImplCallEventListeners( VclEventId::MenuActivate, ITEMPOS_INVALID );
if( !aDelData.isDeleted() )
{
if ( !aActivateHdl.Call( this ) )
{
if( !aDelData.isDeleted() )
{
Menu* pStartMenu = ImplGetStartMenu();
if ( pStartMenu && ( pStartMenu != this ) )
{
pStartMenu->bInCallback = true;
// MT 11/01: Call EventListener here? I don't know...
pStartMenu->aActivateHdl.Call( this );
pStartMenu->bInCallback = false;
}
}
}
bInCallback = false;
}
if (!aDelData.isDeleted() && !(nMenuFlags & MenuFlags::NoAutoMnemonics))
CreateAutoMnemonics();
}
void Menu::Deactivate()
{
for ( size_t n = pItemList->size(); n; )
{
MenuItemData* pData = pItemList->GetDataFromPos( --n );
if ( pData->bIsTemporary )
{
if ( ImplGetSalMenu() )
ImplGetSalMenu()->RemoveItem( n );
pItemList->Remove( n );
}
}
bInCallback = true;
ImplMenuDelData aDelData( this );
Menu* pStartMenu = ImplGetStartMenu();
ImplCallEventListeners( VclEventId::MenuDeactivate, ITEMPOS_INVALID );
if( !aDelData.isDeleted() )
{
if ( !aDeactivateHdl.Call( this ) )
{
if( !aDelData.isDeleted() )
{
if ( pStartMenu && ( pStartMenu != this ) )
{
pStartMenu->bInCallback = true;
pStartMenu->aDeactivateHdl.Call( this );
pStartMenu->bInCallback = false;
}
}
}
}
if( !aDelData.isDeleted() )
{
bInCallback = false;
}
}
void Menu::ImplSelect()
{
MenuItemData* pData = GetItemList()->GetData( nSelectedId );
if ( pData && (pData->nBits & MenuItemBits::AUTOCHECK) )
{
bool bChecked = IsItemChecked( nSelectedId );
if ( pData->nBits & MenuItemBits::RADIOCHECK )
{
if ( !bChecked )
CheckItem( nSelectedId );
}
else
CheckItem( nSelectedId, !bChecked );
}
// call select
ImplSVData* pSVData = ImplGetSVData();
pSVData->maAppData.mpActivePopupMenu = nullptr; // if new execute in select()
nEventId = Application::PostUserEvent( LINK( this, Menu, ImplCallSelect ) );
}
void Menu::Select()
{
ImplMenuDelData aDelData( this );
ImplCallEventListeners( VclEventId::MenuSelect, GetItemPos( GetCurItemId() ) );
if (aDelData.isDeleted())
return;
if (aSelectHdl.Call(this))
return;
if (aDelData.isDeleted())
return;
Menu* pStartMenu = ImplGetStartMenu();
if (!pStartMenu || (pStartMenu == this))
return;
pStartMenu->nSelectedId = nSelectedId;
pStartMenu->sSelectedIdent = sSelectedIdent;
pStartMenu->aSelectHdl.Call( this );
}
#if defined(MACOSX)
void Menu::ImplSelectWithStart( Menu* pSMenu )
{
auto pOldStartedFrom = pStartedFrom;
pStartedFrom = pSMenu;
auto pOldStartedStarted = pOldStartedFrom ? pOldStartedFrom->pStartedFrom : VclPtr<Menu>();
Select();
if( pOldStartedFrom )
pOldStartedFrom->pStartedFrom = pOldStartedStarted;
pStartedFrom = pOldStartedFrom;
}
#endif
void Menu::ImplCallEventListeners( VclEventId nEvent, sal_uInt16 nPos )
{
ImplMenuDelData aDelData( this );
VclMenuEvent aEvent( this, nEvent, nPos );
// This is needed by atk accessibility bridge
if ( nEvent == VclEventId::MenuHighlight )
{
Application::ImplCallEventListeners( aEvent );
}
if ( !aDelData.isDeleted() )
{
// Copy the list, because this can be destroyed when calling a Link...
std::list<Link<VclMenuEvent&,void>> aCopy( maEventListeners );
for ( const auto& rLink : aCopy )
{
if( std::find(maEventListeners.begin(), maEventListeners.end(), rLink) != maEventListeners.end() )
rLink.Call( aEvent );
}
}
}
void Menu::AddEventListener( const Link<VclMenuEvent&,void>& rEventListener )
{
maEventListeners.push_back( rEventListener );
}
void Menu::RemoveEventListener( const Link<VclMenuEvent&,void>& rEventListener )
{
maEventListeners.remove( rEventListener );
}
MenuItemData* Menu::NbcInsertItem(sal_uInt16 nId, MenuItemBits nBits,
const OUString& rStr, Menu* pMenu,
size_t nPos, const OString &rIdent)
{
// put Item in MenuItemList
MenuItemData* pData = pItemList->Insert(nId, MenuItemType::STRING,
nBits, rStr, pMenu, nPos, rIdent);
// update native menu
if (ImplGetSalMenu() && pData->pSalMenuItem)
ImplGetSalMenu()->InsertItem(pData->pSalMenuItem.get(), nPos);
return pData;
}
void Menu::InsertItem(sal_uInt16 nItemId, const OUString& rStr, MenuItemBits nItemBits,
const OString &rIdent, sal_uInt16 nPos)
{
SAL_WARN_IF( !nItemId, "vcl", "Menu::InsertItem(): ItemId == 0" );
SAL_WARN_IF( GetItemPos( nItemId ) != MENU_ITEM_NOTFOUND, "vcl",
"Menu::InsertItem(): ItemId already exists" );
// if Position > ItemCount, append
if ( nPos >= pItemList->size() )
nPos = MENU_APPEND;
// put Item in MenuItemList
NbcInsertItem(nItemId, nItemBits, rStr, this, nPos, rIdent);
vcl::Window* pWin = ImplGetWindow();
mpLayoutData.reset();
if ( pWin )
{
ImplCalcSize( pWin );
if ( pWin->IsVisible() )
pWin->Invalidate();
}
ImplCallEventListeners( VclEventId::MenuInsertItem, nPos );
}
void Menu::InsertItem(sal_uInt16 nItemId, const Image& rImage,
MenuItemBits nItemBits, const OString &rIdent, sal_uInt16 nPos)
{
InsertItem(nItemId, OUString(), nItemBits, rIdent, nPos);
SetItemImage( nItemId, rImage );
}
void Menu::InsertItem(sal_uInt16 nItemId, const OUString& rStr,
const Image& rImage, MenuItemBits nItemBits,
const OString &rIdent, sal_uInt16 nPos)
{
InsertItem(nItemId, rStr, nItemBits, rIdent, nPos);
SetItemImage( nItemId, rImage );
}
void Menu::InsertItem(const OUString& rCommand, const css::uno::Reference<css::frame::XFrame>& rFrame)
{
sal_uInt16 nItemId = GetItemCount() + 1;
if (rFrame.is())
{
OUString aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(rFrame));
OUString aLabel(CommandInfoProvider::GetPopupLabelForCommand(rCommand, aModuleName));
OUString aTooltip(CommandInfoProvider::GetTooltipForCommand(rCommand, rFrame));
Image aImage(CommandInfoProvider::GetImageForCommand(rCommand, rFrame));
InsertItem(nItemId, aLabel, aImage);
SetHelpText(nItemId, aTooltip);
}
else
InsertItem(nItemId, OUString());
SetItemCommand(nItemId, rCommand);
}
void Menu::InsertSeparator(const OString &rIdent, sal_uInt16 nPos)
{
// do nothing if it's a menu bar
if (IsMenuBar())
return;
// if position > ItemCount, append
if ( nPos >= pItemList->size() )
nPos = MENU_APPEND;
// put separator in item list
pItemList->InsertSeparator(rIdent, nPos);
// update native menu
size_t itemPos = ( nPos != MENU_APPEND ) ? nPos : pItemList->size() - 1;
MenuItemData *pData = pItemList->GetDataFromPos( itemPos );
if( ImplGetSalMenu() && pData && pData->pSalMenuItem )
ImplGetSalMenu()->InsertItem( pData->pSalMenuItem.get(), nPos );
mpLayoutData.reset();
ImplCallEventListeners( VclEventId::MenuInsertItem, nPos );
}
void Menu::RemoveItem( sal_uInt16 nPos )
{
bool bRemove = false;
if ( nPos < GetItemCount() )
{
// update native menu
if( ImplGetSalMenu() )
ImplGetSalMenu()->RemoveItem( nPos );
pItemList->Remove( nPos );
bRemove = true;
}
vcl::Window* pWin = ImplGetWindow();
if ( pWin )
{
ImplCalcSize( pWin );
if ( pWin->IsVisible() )
pWin->Invalidate();
}
mpLayoutData.reset();
if ( bRemove )
ImplCallEventListeners( VclEventId::MenuRemoveItem, nPos );
}
static void ImplCopyItem( Menu* pThis, const Menu& rMenu, sal_uInt16 nPos, sal_uInt16 nNewPos )
{
MenuItemType eType = rMenu.GetItemType( nPos );
if ( eType == MenuItemType::DONTKNOW )
return;
if ( eType == MenuItemType::SEPARATOR )
pThis->InsertSeparator( OString(), nNewPos );
else
{
sal_uInt16 nId = rMenu.GetItemId( nPos );
SAL_WARN_IF( pThis->GetItemPos( nId ) != MENU_ITEM_NOTFOUND, "vcl",
"Menu::CopyItem(): ItemId already exists" );
MenuItemData* pData = rMenu.GetItemList()->GetData( nId );
if (!pData)
return;
if ( eType == MenuItemType::STRINGIMAGE )
pThis->InsertItem( nId, pData->aText, pData->aImage, pData->nBits, pData->sIdent, nNewPos );
else if ( eType == MenuItemType::STRING )
pThis->InsertItem( nId, pData->aText, pData->nBits, pData->sIdent, nNewPos );
else
pThis->InsertItem( nId, pData->aImage, pData->nBits, pData->sIdent, nNewPos );
if ( rMenu.IsItemChecked( nId ) )
pThis->CheckItem( nId );
if ( !rMenu.IsItemEnabled( nId ) )
pThis->EnableItem( nId, false );
pThis->SetHelpId( nId, pData->aHelpId );
pThis->SetHelpText( nId, pData->aHelpText );
pThis->SetAccelKey( nId, pData->aAccelKey );
pThis->SetItemCommand( nId, pData->aCommandStr );
pThis->SetHelpCommand( nId, pData->aHelpCommandStr );
PopupMenu* pSubMenu = rMenu.GetPopupMenu( nId );
if ( pSubMenu )
{
// create auto-copy
VclPtr<PopupMenu> pNewMenu = VclPtr<PopupMenu>::Create( *pSubMenu );
pThis->SetPopupMenu( nId, pNewMenu );
}
}
}
void Menu::Clear()
{
for ( sal_uInt16 i = GetItemCount(); i; i-- )
RemoveItem( 0 );
}
sal_uInt16 Menu::GetItemCount() const
{
return static_cast<sal_uInt16>(pItemList->size());
}
sal_uInt16 Menu::ImplGetVisibleItemCount() const
{
sal_uInt16 nItems = 0;
for ( size_t n = pItemList->size(); n; )
{
if ( ImplIsVisible( --n ) )
nItems++;
}
return nItems;
}
sal_uInt16 Menu::ImplGetFirstVisible() const
{
for ( size_t n = 0; n < pItemList->size(); n++ )
{
if ( ImplIsVisible( n ) )
return n;
}
return ITEMPOS_INVALID;
}
sal_uInt16 Menu::ImplGetPrevVisible( sal_uInt16 nPos ) const
{
for ( size_t n = nPos; n; )
{
if (ImplIsVisible(--n))
return n;
}
return ITEMPOS_INVALID;
}
sal_uInt16 Menu::ImplGetNextVisible( sal_uInt16 nPos ) const
{
for ( size_t n = nPos+1; n < pItemList->size(); n++ )
{
if ( ImplIsVisible( n ) )
return n;
}
return ITEMPOS_INVALID;
}
sal_uInt16 Menu::GetItemId(sal_uInt16 nPos) const
{
MenuItemData* pData = pItemList->GetDataFromPos( nPos );
if ( pData )
return pData->nId;
else
return 0;
}
sal_uInt16 Menu::GetItemId(const OString &rIdent) const
{
for (size_t n = 0; n < pItemList->size(); ++n)
{
MenuItemData* pData = pItemList->GetDataFromPos(n);
if (pData && pData->sIdent == rIdent)
return pData->nId;
}
return MENU_ITEM_NOTFOUND;
}
sal_uInt16 Menu::GetItemPos( sal_uInt16 nItemId ) const
{
size_t nPos;
MenuItemData* pData = pItemList->GetData( nItemId, nPos );
if ( pData )
return static_cast<sal_uInt16>(nPos);
else
return MENU_ITEM_NOTFOUND;
}
MenuItemType Menu::GetItemType( sal_uInt16 nPos ) const
{
MenuItemData* pData = pItemList->GetDataFromPos( nPos );
if ( pData )
return pData->eType;
else
return MenuItemType::DONTKNOW;
}
OString Menu::GetItemIdent(sal_uInt16 nId) const
{
const MenuItemData* pData = pItemList->GetData(nId);
return pData ? pData->sIdent : OString();
}
void Menu::SetItemBits( sal_uInt16 nItemId, MenuItemBits nBits )
{
size_t nPos;
MenuItemData* pData = pItemList->GetData(nItemId, nPos);
if (pData && (pData->nBits != nBits))
{
pData->nBits = nBits;
// update native menu
if (ImplGetSalMenu())
ImplGetSalMenu()->SetItemBits(nPos, nBits);
}
}
MenuItemBits Menu::GetItemBits( sal_uInt16 nItemId ) const
{
MenuItemBits nBits = MenuItemBits::NONE;
MenuItemData* pData = pItemList->GetData( nItemId );
if ( pData )
nBits = pData->nBits;
return nBits;
}
void Menu::SetUserValue(sal_uInt16 nItemId, void* nUserValue, MenuUserDataReleaseFunction aFunc)
{
MenuItemData* pData = pItemList->GetData(nItemId);
if (pData)
{
if (pData->aUserValueReleaseFunc)
pData->aUserValueReleaseFunc(pData->nUserValue);
pData->aUserValueReleaseFunc = aFunc;
pData->nUserValue = nUserValue;
}
}
void* Menu::GetUserValue( sal_uInt16 nItemId ) const
{
MenuItemData* pData = pItemList->GetData( nItemId );
return pData ? pData->nUserValue : nullptr;
}
void Menu::SetPopupMenu( sal_uInt16 nItemId, PopupMenu* pMenu )
{
size_t nPos;
MenuItemData* pData = pItemList->GetData( nItemId, nPos );
// Item does not exist -> return NULL
if ( !pData )
return;
// same menu, nothing to do
if ( static_cast<PopupMenu*>(pData->pSubMenu.get()) == pMenu )
return;
// remove old menu
auto oldSubMenu = pData->pSubMenu;
// data exchange
pData->pSubMenu = pMenu;
// #112023# Make sure pStartedFrom does not point to invalid (old) data
if ( pData->pSubMenu )
pData->pSubMenu->pStartedFrom = nullptr;
// set native submenu
if( ImplGetSalMenu() && pData->pSalMenuItem )
{
if( pMenu )
ImplGetSalMenu()->SetSubMenu( pData->pSalMenuItem.get(), pMenu->ImplGetSalMenu(), nPos );
else
ImplGetSalMenu()->SetSubMenu( pData->pSalMenuItem.get(), nullptr, nPos );
}
oldSubMenu.disposeAndClear();
ImplCallEventListeners( VclEventId::MenuSubmenuChanged, nPos );
}
PopupMenu* Menu::GetPopupMenu( sal_uInt16 nItemId ) const
{
MenuItemData* pData = pItemList->GetData( nItemId );
if ( pData )
return static_cast<PopupMenu*>(pData->pSubMenu.get());
else
return nullptr;
}
void Menu::SetAccelKey( sal_uInt16 nItemId, const KeyCode& rKeyCode )
{
size_t nPos;
MenuItemData* pData = pItemList->GetData( nItemId, nPos );
if ( !pData )
return;
if ( pData->aAccelKey == rKeyCode )
return;
pData->aAccelKey = rKeyCode;
// update native menu
if( ImplGetSalMenu() && pData->pSalMenuItem )
ImplGetSalMenu()->SetAccelerator( nPos, pData->pSalMenuItem.get(), rKeyCode, rKeyCode.GetName() );
}
KeyCode Menu::GetAccelKey( sal_uInt16 nItemId ) const
{
MenuItemData* pData = pItemList->GetData( nItemId );
if ( pData )
return pData->aAccelKey;
else
return KeyCode();
}
KeyEvent Menu::GetActivationKey( sal_uInt16 nItemId ) const
{
KeyEvent aRet;
MenuItemData* pData = pItemList->GetData( nItemId );
if( pData )
{
sal_Int32 nPos = pData->aText.indexOf( '~' );
if( nPos != -1 && nPos < pData->aText.getLength()-1 )
{
sal_uInt16 nCode = 0;
sal_Unicode cAccel = pData->aText[nPos+1];
if( cAccel >= 'a' && cAccel <= 'z' )
nCode = KEY_A + (cAccel-'a');
else if( cAccel >= 'A' && cAccel <= 'Z' )
nCode = KEY_A + (cAccel-'A');
else if( cAccel >= '0' && cAccel <= '9' )
nCode = KEY_0 + (cAccel-'0');
aRet = KeyEvent( cAccel, KeyCode( nCode, KEY_MOD2 ) );
}
}
return aRet;
}
void Menu::CheckItem( sal_uInt16 nItemId, bool bCheck )
{
size_t nPos;
MenuItemData* pData = pItemList->GetData( nItemId, nPos );
if ( !pData || pData->bChecked == bCheck )
return;
// if radio-check, then uncheck previous
if ( bCheck && (pData->nBits & MenuItemBits::AUTOCHECK) &&
(pData->nBits & MenuItemBits::RADIOCHECK) )
{
MenuItemData* pGroupData;
sal_uInt16 nGroupPos;
sal_uInt16 nItemCount = GetItemCount();
bool bFound = false;
nGroupPos = nPos;
while ( nGroupPos )
{
pGroupData = pItemList->GetDataFromPos( nGroupPos-1 );
if ( pGroupData->nBits & MenuItemBits::RADIOCHECK )
{
if ( IsItemChecked( pGroupData->nId ) )
{
CheckItem( pGroupData->nId, false );
bFound = true;
break;
}
}
else
break;
nGroupPos--;
}
if ( !bFound )
{
nGroupPos = nPos+1;
while ( nGroupPos < nItemCount )
{
pGroupData = pItemList->GetDataFromPos( nGroupPos );
if ( pGroupData->nBits & MenuItemBits::RADIOCHECK )
{
if ( IsItemChecked( pGroupData->nId ) )
{
CheckItem( pGroupData->nId, false );
break;
}
}
else
break;
nGroupPos++;
}
}
}
pData->bChecked = bCheck;
// update native menu
if( ImplGetSalMenu() )
ImplGetSalMenu()->CheckItem( nPos, bCheck );
ImplCallEventListeners( bCheck ? VclEventId::MenuItemChecked : VclEventId::MenuItemUnchecked, nPos );
}
void Menu::CheckItem( const OString &rIdent , bool bCheck )
{
CheckItem( GetItemId( rIdent ), bCheck );
}
bool Menu::IsItemChecked( sal_uInt16 nItemId ) const
{
size_t nPos;
MenuItemData* pData = pItemList->GetData( nItemId, nPos );
if ( !pData )
return false;
return pData->bChecked;
}
void Menu::EnableItem( sal_uInt16 nItemId, bool bEnable )
{
size_t nPos;
MenuItemData* pItemData = pItemList->GetData( nItemId, nPos );
if ( pItemData && ( pItemData->bEnabled != bEnable ) )
{
pItemData->bEnabled = bEnable;
vcl::Window* pWin = ImplGetWindow();
if ( pWin && pWin->IsVisible() )
{
SAL_WARN_IF(!IsMenuBar(), "vcl", "Menu::EnableItem - Popup visible!" );
long nX = 0;
size_t nCount = pItemList->size();
for ( size_t n = 0; n < nCount; n++ )
{
MenuItemData* pData = pItemList->GetDataFromPos( n );
if ( n == nPos )
{
pWin->Invalidate( tools::Rectangle( Point( nX, 0 ), Size( pData->aSz.Width(), pData->aSz.Height() ) ) );
break;
}
nX += pData->aSz.Width();
}
}
// update native menu
if( ImplGetSalMenu() )
ImplGetSalMenu()->EnableItem( nPos, bEnable );
ImplCallEventListeners( bEnable ? VclEventId::MenuEnable : VclEventId::MenuDisable, nPos );
}
}
bool Menu::IsItemEnabled( sal_uInt16 nItemId ) const
{
size_t nPos;
MenuItemData* pData = pItemList->GetData( nItemId, nPos );
if ( !pData )
return false;
return pData->bEnabled;
}
void Menu::ShowItem( sal_uInt16 nItemId, bool bVisible )
{
size_t nPos;
MenuItemData* pData = pItemList->GetData( nItemId, nPos );
SAL_WARN_IF(IsMenuBar(), "vcl", "Menu::ShowItem - ignored for menu bar entries!");
if (!IsMenuBar()&& pData && (pData->bVisible != bVisible))
{
vcl::Window* pWin = ImplGetWindow();
if ( pWin && pWin->IsVisible() )
{
SAL_WARN( "vcl", "Menu::ShowItem - ignored for visible popups!" );
return;
}
pData->bVisible = bVisible;
// update native menu
if( ImplGetSalMenu() )
ImplGetSalMenu()->ShowItem( nPos, bVisible );
}
}
void Menu::SetItemText( sal_uInt16 nItemId, const OUString& rStr )
{
size_t nPos;
MenuItemData* pData = pItemList->GetData( nItemId, nPos );
if ( !pData )
return;
if ( rStr != pData->aText )
{
pData->aText = rStr;
// Clear layout for aText.
pData->aTextGlyphs.Invalidate();
ImplSetMenuItemData( pData );
// update native menu
if( ImplGetSalMenu() && pData->pSalMenuItem )
ImplGetSalMenu()->SetItemText( nPos, pData->pSalMenuItem.get(), rStr );
vcl::Window* pWin = ImplGetWindow();
mpLayoutData.reset();
if (pWin && IsMenuBar())
{
ImplCalcSize( pWin );
if ( pWin->IsVisible() )
pWin->Invalidate();
}
ImplCallEventListeners( VclEventId::MenuItemTextChanged, nPos );
}
}
OUString Menu::GetItemText( sal_uInt16 nItemId ) const
{
size_t nPos;
MenuItemData* pData = pItemList->GetData( nItemId, nPos );
if ( pData )
return pData->aText;
return OUString();
}
void Menu::SetItemImage( sal_uInt16 nItemId, const Image& rImage )
{
size_t nPos;
MenuItemData* pData = pItemList->GetData( nItemId, nPos );
if ( !pData )
return;
pData->aImage = rImage;
ImplSetMenuItemData( pData );
// update native menu
if( ImplGetSalMenu() && pData->pSalMenuItem )
ImplGetSalMenu()->SetItemImage( nPos, pData->pSalMenuItem.get(), rImage );
}
Image Menu::GetItemImage( sal_uInt16 nItemId ) const
{
MenuItemData* pData = pItemList->GetData( nItemId );
if ( pData )
return pData->aImage;
else
return Image();
}
void Menu::SetItemCommand( sal_uInt16 nItemId, const OUString& rCommand )
{
size_t nPos;
MenuItemData* pData = pItemList->GetData( nItemId, nPos );
if ( pData )
pData->aCommandStr = rCommand;
}
OUString Menu::GetItemCommand( sal_uInt16 nItemId ) const
{
MenuItemData* pData = pItemList->GetData( nItemId );
if (pData)
return pData->aCommandStr;
return OUString();
}
void Menu::SetHelpCommand( sal_uInt16 nItemId, const OUString& rStr )
{
MenuItemData* pData = pItemList->GetData( nItemId );
if ( pData )
pData->aHelpCommandStr = rStr;
}
OUString Menu::GetHelpCommand( sal_uInt16 nItemId ) const
{
MenuItemData* pData = pItemList->GetData( nItemId );
if ( pData )
return pData->aHelpCommandStr;
return OUString();
}
void Menu::SetHelpText( sal_uInt16 nItemId, const OUString& rStr )
{
MenuItemData* pData = pItemList->GetData( nItemId );
if ( pData )
pData->aHelpText = rStr;
}
OUString Menu::ImplGetHelpText( sal_uInt16 nItemId ) const
{
MenuItemData* pData = pItemList->GetData( nItemId );
if ( pData && pData->aHelpText.isEmpty() &&
(( !pData->aHelpId.isEmpty() ) || ( !pData->aCommandStr.isEmpty() )))
{
Help* pHelp = Application::GetHelp();
if ( pHelp )
{
if (!pData->aCommandStr.isEmpty())
pData->aHelpText = pHelp->GetHelpText( pData->aCommandStr, static_cast<weld::Widget*>(nullptr) );
if (pData->aHelpText.isEmpty() && !pData->aHelpId.isEmpty())
pData->aHelpText = pHelp->GetHelpText( OStringToOUString( pData->aHelpId, RTL_TEXTENCODING_UTF8 ), static_cast<weld::Widget*>(nullptr) );
}
}
return OUString();
}
OUString Menu::GetHelpText( sal_uInt16 nItemId ) const
{
return ImplGetHelpText( nItemId );
}
void Menu::SetTipHelpText( sal_uInt16 nItemId, const OUString& rStr )
{
MenuItemData* pData = pItemList->GetData( nItemId );
if ( pData )
pData->aTipHelpText = rStr;
}
OUString Menu::GetTipHelpText( sal_uInt16 nItemId ) const
{
MenuItemData* pData = pItemList->GetData( nItemId );
if ( pData )
return pData->aTipHelpText;
return OUString();
}
void Menu::SetHelpId( sal_uInt16 nItemId, const OString& rHelpId )
{
MenuItemData* pData = pItemList->GetData( nItemId );
if ( pData )
pData->aHelpId = rHelpId;
}
OString Menu::GetHelpId( sal_uInt16 nItemId ) const
{
OString aRet;
MenuItemData* pData = pItemList->GetData( nItemId );
if ( pData )
{
if ( !pData->aHelpId.isEmpty() )
aRet = pData->aHelpId;
else
aRet = OUStringToOString( pData->aCommandStr, RTL_TEXTENCODING_UTF8 );
}
return aRet;
}
Menu& Menu::operator=( const Menu& rMenu )
{
// clean up
Clear();
// copy items
sal_uInt16 nCount = rMenu.GetItemCount();
for ( sal_uInt16 i = 0; i < nCount; i++ )
ImplCopyItem( this, rMenu, i, MENU_APPEND );
aActivateHdl = rMenu.aActivateHdl;
aDeactivateHdl = rMenu.aDeactivateHdl;
aSelectHdl = rMenu.aSelectHdl;
aTitleText = rMenu.aTitleText;
nTitleHeight = rMenu.nTitleHeight;
return *this;
}
// Returns true if the item is completely hidden on the GUI and shouldn't
// be possible to interact with
bool Menu::ImplCurrentlyHiddenOnGUI(sal_uInt16 nPos) const
{
MenuItemData* pData = pItemList->GetDataFromPos(nPos);
if (pData)
{
MenuItemData* pPreviousData = pItemList->GetDataFromPos( nPos - 1 );
if (pPreviousData && pPreviousData->bHiddenOnGUI)
{
return true;
}
}
return false;
}
bool Menu::ImplIsVisible( sal_uInt16 nPos ) const
{
bool bVisible = true;
MenuItemData* pData = pItemList->GetDataFromPos( nPos );
// check general visibility first
if( pData && !pData->bVisible )
bVisible = false;
if ( bVisible && pData && pData->eType == MenuItemType::SEPARATOR )
{
if( nPos == 0 ) // no separator should be shown at the very beginning
bVisible = false;
else
{
// always avoid adjacent separators
size_t nCount = pItemList->size();
size_t n;
MenuItemData* pNextData = nullptr;
// search next visible item
for( n = nPos + 1; n < nCount; n++ )
{
pNextData = pItemList->GetDataFromPos( n );
if( pNextData && pNextData->bVisible )
{
if( pNextData->eType == MenuItemType::SEPARATOR || ImplIsVisible(n) )
break;
}
}
if( n == nCount ) // no next visible item
bVisible = false;
// check for separator
if( pNextData && pNextData->bVisible && pNextData->eType == MenuItemType::SEPARATOR )
bVisible = false;
if( bVisible )
{
for( n = nPos; n > 0; n-- )
{
pNextData = pItemList->GetDataFromPos( n-1 );
if( pNextData && pNextData->bVisible )
{
if( pNextData->eType != MenuItemType::SEPARATOR && ImplIsVisible(n-1) )
break;
}
}
if( n == 0 ) // no previous visible item
bVisible = false;
}
}
}
// not allowed for menubar, as I do not know
// whether a menu-entry will disappear or will appear
if (bVisible && !IsMenuBar() && (nMenuFlags & MenuFlags::HideDisabledEntries) &&
!(nMenuFlags & MenuFlags::AlwaysShowDisabledEntries))
{
if( !pData ) // e.g. nPos == ITEMPOS_INVALID
bVisible = false;
else if ( pData->eType != MenuItemType::SEPARATOR ) // separators handled above
{
// tdf#86850 Always display clipboard functions
if ( pData->aCommandStr == ".uno:Cut" || pData->aCommandStr == ".uno:Copy" || pData->aCommandStr == ".uno:Paste" )
bVisible = true;
else
// bVisible = pData->bEnabled && ( !pData->pSubMenu || pData->pSubMenu->HasValidEntries( true ) );
bVisible = pData->bEnabled; // do not check submenus as they might be filled at Activate().
}
}
return bVisible;
}
bool Menu::IsItemPosVisible( sal_uInt16 nItemPos ) const
{
return IsMenuVisible() && ImplIsVisible( nItemPos );
}
bool Menu::IsMenuVisible() const
{
return pWindow && pWindow->IsReallyVisible();
}
bool Menu::ImplIsSelectable( sal_uInt16 nPos ) const
{
bool bSelectable = true;
MenuItemData* pData = pItemList->GetDataFromPos( nPos );
// check general visibility first
if ( pData && ( pData->nBits & MenuItemBits::NOSELECT ) )
bSelectable = false;
return bSelectable;
}
css::uno::Reference<css::accessibility::XAccessible> Menu::GetAccessible()
{
// Since PopupMenu are sometimes shared by different instances of MenuBar, the mxAccessible member gets
// overwritten and may contain a disposed object when the initial menubar gets set again. So use the
// mxAccessible member only for sub menus.
if ( pStartedFrom )
{
for ( sal_uInt16 i = 0, nCount = pStartedFrom->GetItemCount(); i < nCount; ++i )
{
sal_uInt16 nItemId = pStartedFrom->GetItemId( i );
if ( static_cast< Menu* >( pStartedFrom->GetPopupMenu( nItemId ) ) == this )
{
css::uno::Reference<css::accessibility::XAccessible> xParent = pStartedFrom->GetAccessible();
if ( xParent.is() )
{
css::uno::Reference<css::accessibility::XAccessibleContext> xParentContext( xParent->getAccessibleContext() );
if (xParentContext.is())
return xParentContext->getAccessibleChild( i );
}
}
}
}
else if ( !mxAccessible.is() )
{
UnoWrapperBase* pWrapper = UnoWrapperBase::GetUnoWrapper();
if ( pWrapper )
mxAccessible = pWrapper->CreateAccessible(this, IsMenuBar());
}
return mxAccessible;
}
void Menu::SetAccessible(const css::uno::Reference<css::accessibility::XAccessible>& rxAccessible )
{
mxAccessible = rxAccessible;
}
Size Menu::ImplGetNativeCheckAndRadioSize(vcl::RenderContext const & rRenderContext, long& rCheckHeight, long& rRadioHeight ) const
{
long nCheckWidth = 0, nRadioWidth = 0;
rCheckHeight = rRadioHeight = 0;
if (!IsMenuBar())
{
ImplControlValue aVal;
tools::Rectangle aNativeBounds;
tools::Rectangle aNativeContent;
tools::Rectangle aCtrlRegion(tools::Rectangle(Point(), Size(100, 15)));
if (rRenderContext.IsNativeControlSupported(ControlType::MenuPopup, ControlPart::MenuItemCheckMark))
{
if (rRenderContext.GetNativeControlRegion(ControlType::MenuPopup, ControlPart::MenuItemCheckMark,
aCtrlRegion, ControlState::ENABLED, aVal,
aNativeBounds, aNativeContent))
{
rCheckHeight = aNativeBounds.GetHeight();
nCheckWidth = aNativeContent.GetWidth();
}
}
if (rRenderContext.IsNativeControlSupported(ControlType::MenuPopup, ControlPart::MenuItemRadioMark))
{
if (rRenderContext.GetNativeControlRegion(ControlType::MenuPopup, ControlPart::MenuItemRadioMark,
aCtrlRegion, ControlState::ENABLED, aVal,
aNativeBounds, aNativeContent))
{
rRadioHeight = aNativeBounds.GetHeight();
nRadioWidth = aNativeContent.GetWidth();
}
}
}
return Size(std::max(nCheckWidth, nRadioWidth), std::max(rCheckHeight, rRadioHeight));
}
bool Menu::ImplGetNativeSubmenuArrowSize(vcl::RenderContext const & rRenderContext, Size& rArrowSize, long& rArrowSpacing)
{
ImplControlValue aVal;
tools::Rectangle aNativeBounds;
tools::Rectangle aNativeContent;
tools::Rectangle aCtrlRegion(tools::Rectangle(Point(), Size(100, 15)));
if (rRenderContext.IsNativeControlSupported(ControlType::MenuPopup, ControlPart::SubmenuArrow))
{
if (rRenderContext.GetNativeControlRegion(ControlType::MenuPopup, ControlPart::SubmenuArrow,
aCtrlRegion, ControlState::ENABLED,
aVal, aNativeBounds, aNativeContent))
{
Size aSize(aNativeContent.GetWidth(), aNativeContent.GetHeight());
rArrowSize = aSize;
rArrowSpacing = aNativeBounds.GetWidth() - aNativeContent.GetWidth();
return true;
}
}
return false;
}
void Menu::ImplAddDel( ImplMenuDelData& rDel )
{
SAL_WARN_IF( rDel.mpMenu, "vcl", "Menu::ImplAddDel(): cannot add ImplMenuDelData twice !" );
if( !rDel.mpMenu )
{
rDel.mpMenu = this;
rDel.mpNext = mpFirstDel;
mpFirstDel = &rDel;
}
}
void Menu::ImplRemoveDel( ImplMenuDelData& rDel )
{
rDel.mpMenu = nullptr;
if ( mpFirstDel == &rDel )
{
mpFirstDel = rDel.mpNext;
}
else
{
ImplMenuDelData* pData = mpFirstDel;
while ( pData && (pData->mpNext != &rDel) )
pData = pData->mpNext;
SAL_WARN_IF( !pData, "vcl", "Menu::ImplRemoveDel(): ImplMenuDelData not registered !" );
if( pData )
pData->mpNext = rDel.mpNext;
}
}
Size Menu::ImplCalcSize( vcl::Window* pWin )
{
// | Check/Radio/Image| Text| Accel/Popup|
// for symbols: nFontHeight x nFontHeight
long nFontHeight = pWin->GetTextHeight();
long nExtra = nFontHeight/4;
long nMinMenuItemHeight = nFontHeight;
long nCheckHeight = 0, nRadioHeight = 0;
Size aMaxSize = ImplGetNativeCheckAndRadioSize(*pWin, nCheckHeight, nRadioHeight); // FIXME
if( aMaxSize.Height() > nMinMenuItemHeight )
nMinMenuItemHeight = aMaxSize.Height();
Size aMaxImgSz;
const StyleSettings& rSettings = pWin->GetSettings().GetStyleSettings();
if ( rSettings.GetUseImagesInMenus() )
{
if ( 16 > nMinMenuItemHeight )
nMinMenuItemHeight = 16;
for ( size_t i = pItemList->size(); i; )
{
MenuItemData* pData = pItemList->GetDataFromPos( --i );
if ( ImplIsVisible( i )
&& ( ( pData->eType == MenuItemType::IMAGE )
|| ( pData->eType == MenuItemType::STRINGIMAGE )
)
)
{
Size aImgSz = pData->aImage.GetSizePixel();
if ( aImgSz.Height() > aMaxImgSz.Height() )
aMaxImgSz.setHeight( aImgSz.Height() );
if ( aImgSz.Height() > nMinMenuItemHeight )
nMinMenuItemHeight = aImgSz.Height();
break;
}
}
}
Size aSz;
long nCheckWidth = 0;
long nMaxWidth = 0;
for ( size_t n = pItemList->size(); n; )
{
MenuItemData* pData = pItemList->GetDataFromPos( --n );
pData->aSz.setHeight( 0 );
pData->aSz.setWidth( 0 );
if ( ImplIsVisible( n ) )
{
long nWidth = 0;
// Separator
if (!IsMenuBar()&& (pData->eType == MenuItemType::SEPARATOR))
{
//Useless: SAL_WARN_IF( IsMenuBar(), "vcl", "Separator in MenuBar ?! " );
pData->aSz.setHeight( 4 );
}
// Image:
if (!IsMenuBar() && ((pData->eType == MenuItemType::IMAGE) || (pData->eType == MenuItemType::STRINGIMAGE)))
{
Size aImgSz = pData->aImage.GetSizePixel();
aImgSz.AdjustHeight(4 ); // add a border for native marks
aImgSz.AdjustWidth(4 ); // add a border for native marks
if ( aImgSz.Width() > aMaxImgSz.Width() )
aMaxImgSz.setWidth( aImgSz.Width() );
if ( aImgSz.Height() > aMaxImgSz.Height() )
aMaxImgSz.setHeight( aImgSz.Height() );
if ( aImgSz.Height() > pData->aSz.Height() )
pData->aSz.setHeight( aImgSz.Height() );
}
// Check Buttons:
if (!IsMenuBar() && pData->HasCheck())
{
nCheckWidth = aMaxSize.Width();
// checks / images take the same place
if( ! ( ( pData->eType == MenuItemType::IMAGE ) || ( pData->eType == MenuItemType::STRINGIMAGE ) ) )
nWidth += nCheckWidth + nExtra * 2;
}
// Text:
if ( (pData->eType == MenuItemType::STRING) || (pData->eType == MenuItemType::STRINGIMAGE) )
{
const SalLayoutGlyphs* pGlyphs = pData->GetTextGlyphs(pWin);
long nTextWidth = pWin->GetCtrlTextWidth(pData->aText, pGlyphs);
long nTextHeight = pWin->GetTextHeight();
if (IsMenuBar())
{
if ( nTextHeight > pData->aSz.Height() )
pData->aSz.setHeight( nTextHeight );
pData->aSz.setWidth( nTextWidth + 4*nExtra );
aSz.AdjustWidth(pData->aSz.Width() );
}
else
pData->aSz.setHeight( std::max( std::max( nTextHeight, pData->aSz.Height() ), nMinMenuItemHeight ) );
nWidth += nTextWidth;
}
// Accel
if (!IsMenuBar()&& pData->aAccelKey.GetCode() && !ImplAccelDisabled())
{
OUString aName = pData->aAccelKey.GetName();
long nAccWidth = pWin->GetTextWidth( aName );
nAccWidth += nExtra;
nWidth += nAccWidth;
}
// SubMenu?
if (!IsMenuBar() && pData->pSubMenu)
{
if ( nFontHeight > nWidth )
nWidth += nFontHeight;
pData->aSz.setHeight( std::max( std::max( nFontHeight, pData->aSz.Height() ), nMinMenuItemHeight ) );
}
pData->aSz.AdjustHeight(EXTRAITEMHEIGHT ); // little bit more distance
if (!IsMenuBar())
aSz.AdjustHeight(pData->aSz.Height() );
if ( nWidth > nMaxWidth )
nMaxWidth = nWidth;
}
}
// Additional space for title
nTitleHeight = 0;
if (!IsMenuBar() && aTitleText.getLength() > 0) {
// Set expected font
pWin->Push(PushFlags::FONT);
vcl::Font aFont = pWin->GetFont();
aFont.SetWeight(WEIGHT_BOLD);
pWin->SetFont(aFont);
// Compute text bounding box
tools::Rectangle aTextBoundRect;
pWin->GetTextBoundRect(aTextBoundRect, aTitleText);
// Vertically, one height of char + extra space for decoration
nTitleHeight = aTextBoundRect.GetSize().Height() + 4 * SPACE_AROUND_TITLE ;
aSz.AdjustHeight(nTitleHeight );
long nWidth = aTextBoundRect.GetSize().Width() + 4 * SPACE_AROUND_TITLE;
pWin->Pop();
if ( nWidth > nMaxWidth )
nMaxWidth = nWidth;
}
if (!IsMenuBar())
{
// popup menus should not be wider than half the screen
// except on rather small screens
// TODO: move GetScreenNumber from SystemWindow to Window ?
// currently we rely on internal privileges
unsigned int nDisplayScreen = pWin->ImplGetWindowImpl()->mpFrame->maGeometry.nDisplayScreenNumber;
tools::Rectangle aDispRect( Application::GetScreenPosSizePixel( nDisplayScreen ) );
long nScreenWidth = aDispRect.GetWidth() >= 800 ? aDispRect.GetWidth() : 800;
if( nMaxWidth > nScreenWidth/2 )
nMaxWidth = nScreenWidth/2;
sal_uInt16 gfxExtra = static_cast<sal_uInt16>(std::max( nExtra, 7L )); // #107710# increase space between checkmarks/images/text
nImgOrChkPos = static_cast<sal_uInt16>(nExtra);
long nImgOrChkWidth = 0;
if( aMaxSize.Height() > 0 ) // NWF case
nImgOrChkWidth = aMaxSize.Height() + nExtra;
else // non NWF case
nImgOrChkWidth = nFontHeight/2 + gfxExtra;
nImgOrChkWidth = std::max( nImgOrChkWidth, aMaxImgSz.Width() + gfxExtra );
nTextPos = static_cast<sal_uInt16>(nImgOrChkPos + nImgOrChkWidth);
nTextPos = nTextPos + gfxExtra;
aSz.setWidth( nTextPos + nMaxWidth + nExtra );
aSz.AdjustWidth(4*nExtra ); // a _little_ more ...
aSz.AdjustWidth(2*ImplGetSVData()->maNWFData.mnMenuFormatBorderX );
aSz.AdjustHeight(2*ImplGetSVData()->maNWFData.mnMenuFormatBorderY );
}
else
{
nTextPos = static_cast<sal_uInt16>(2*nExtra);
aSz.setHeight( nFontHeight+6 );
// get menubar height from native methods if supported
if( pWindow->IsNativeControlSupported( ControlType::Menubar, ControlPart::Entire ) )
{
ImplControlValue aVal;
tools::Rectangle aNativeBounds;
tools::Rectangle aNativeContent;
Point tmp( 0, 0 );
tools::Rectangle aCtrlRegion( tmp, Size( 100, 15 ) );
if( pWindow->GetNativeControlRegion( ControlType::Menubar,
ControlPart::Entire,
aCtrlRegion,
ControlState::ENABLED,
aVal,
aNativeBounds,
aNativeContent )
)
{
int nNativeHeight = aNativeBounds.GetHeight();
if( nNativeHeight > aSz.Height() )
aSz.setHeight( nNativeHeight );
}
}
// account for the size of the close button, which actually is a toolbox
// due to NWF this is variable
long nCloseButtonHeight = static_cast<MenuBarWindow*>(pWindow.get())->MinCloseButtonSize().Height();
if (aSz.Height() < nCloseButtonHeight)
aSz.setHeight( nCloseButtonHeight );
}
return aSz;
}
static void ImplPaintCheckBackground(vcl::RenderContext & rRenderContext, vcl::Window const & rWindow, const tools::Rectangle& i_rRect, bool i_bHighlight)
{
bool bNativeOk = false;
if (rRenderContext.IsNativeControlSupported(ControlType::Toolbar, ControlPart::Button))
{
ImplControlValue aControlValue;
aControlValue.setTristateVal(ButtonValue::On);
bNativeOk = rRenderContext.DrawNativeControl(ControlType::Toolbar, ControlPart::Button,
i_rRect,
ControlState::PRESSED | ControlState::ENABLED,
aControlValue,
OUString());
}
if (!bNativeOk)
{
const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings();
Color aColor( i_bHighlight ? rSettings.GetMenuHighlightTextColor() : rSettings.GetHighlightColor() );
RenderTools::DrawSelectionBackground(rRenderContext, rWindow, i_rRect, 0, i_bHighlight, true, false, nullptr, 2, &aColor);
}
}
static OUString getShortenedString( const OUString& i_rLong, vcl::RenderContext const & rRenderContext, long i_nMaxWidth )
{
sal_Int32 nPos = -1;
OUString aNonMnem(OutputDevice::GetNonMnemonicString(i_rLong, nPos));
aNonMnem = rRenderContext.GetEllipsisString( aNonMnem, i_nMaxWidth, DrawTextFlags::CenterEllipsis);
// re-insert mnemonic
if (nPos != -1)
{
if (nPos < aNonMnem.getLength() && i_rLong[nPos+1] == aNonMnem[nPos])
{
OUStringBuffer aBuf( i_rLong.getLength() );
aBuf.append( std::u16string_view(aNonMnem).substr(0, nPos) );
aBuf.append( '~' );
aBuf.append( std::u16string_view(aNonMnem).substr(nPos) );
aNonMnem = aBuf.makeStringAndClear();
}
}
return aNonMnem;
}
void Menu::ImplPaintMenuTitle(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) const
{
// Save previous graphical settings, set new one
rRenderContext.Push(PushFlags::FONT | PushFlags::FILLCOLOR);
Wallpaper aOldBackground = rRenderContext.GetBackground();
Color aBackgroundColor = rRenderContext.GetSettings().GetStyleSettings().GetMenuBarColor();
rRenderContext.SetBackground(Wallpaper(aBackgroundColor));
rRenderContext.SetFillColor(aBackgroundColor);
vcl::Font aFont = rRenderContext.GetFont();
aFont.SetWeight(WEIGHT_BOLD);
rRenderContext.SetFont(aFont);
// Draw background rectangle
tools::Rectangle aBgRect(rRect);
int nOuterSpaceX = ImplGetSVData()->maNWFData.mnMenuFormatBorderX;
aBgRect.setX(aBgRect.getX() + SPACE_AROUND_TITLE);
aBgRect.setWidth(aBgRect.getWidth() - 2 * SPACE_AROUND_TITLE - 2 * nOuterSpaceX);
aBgRect.setY(aBgRect.getY() + SPACE_AROUND_TITLE);
aBgRect.setHeight(nTitleHeight - 2 * SPACE_AROUND_TITLE);
rRenderContext.DrawRect(aBgRect);
// Draw the text centered
Point aTextTopLeft(aBgRect.TopLeft());
tools::Rectangle aTextBoundRect;
rRenderContext.GetTextBoundRect( aTextBoundRect, aTitleText );
aTextTopLeft.AdjustX((aBgRect.getWidth() - aTextBoundRect.GetSize().Width()) / 2 );
aTextTopLeft.AdjustY((aBgRect.GetHeight() - aTextBoundRect.GetSize().Height()) / 2
- aTextBoundRect.TopLeft().Y() );
rRenderContext.DrawText(aTextTopLeft, aTitleText, 0, aTitleText.getLength());
// Restore
rRenderContext.Pop();
rRenderContext.SetBackground(aOldBackground);
}
void Menu::ImplPaint(vcl::RenderContext& rRenderContext, Size const & rSize,
sal_uInt16 nBorder, long nStartY, MenuItemData const * pThisItemOnly,
bool bHighlighted, bool bLayout, bool bRollover) const
{
// for symbols: nFontHeight x nFontHeight
long nFontHeight = rRenderContext.GetTextHeight();
long nExtra = nFontHeight / 4;
long nCheckHeight = 0, nRadioHeight = 0;
ImplGetNativeCheckAndRadioSize(rRenderContext, nCheckHeight, nRadioHeight);
DecorationView aDecoView(&rRenderContext);
const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings();
Point aTopLeft, aTmpPos;
int nOuterSpaceX = 0;
if (!IsMenuBar())
{
nOuterSpaceX = ImplGetSVData()->maNWFData.mnMenuFormatBorderX;
aTopLeft.AdjustX(nOuterSpaceX );
aTopLeft.AdjustY(ImplGetSVData()->maNWFData.mnMenuFormatBorderY );
}
// for the computations, use size of the underlying window, not of RenderContext
Size aOutSz(rSize);
size_t nCount = pItemList->size();
if (bLayout)
mpLayoutData->m_aVisibleItemBoundRects.clear();
// Paint title
if (!pThisItemOnly && !IsMenuBar() && nTitleHeight > 0)
ImplPaintMenuTitle(rRenderContext, tools::Rectangle(aTopLeft, aOutSz));
bool bHiddenItems = false; // are any items on the GUI hidden
for (size_t n = 0; n < nCount; n++)
{
MenuItemData* pData = pItemList->GetDataFromPos( n );
if (ImplIsVisible(n) && (!pThisItemOnly || (pData == pThisItemOnly)))
{
if (pThisItemOnly)
{
if (IsMenuBar())
{
if (!ImplGetSVData()->maNWFData.mbRolloverMenubar)
{
if (bRollover)
rRenderContext.SetTextColor(rSettings.GetMenuBarRolloverTextColor());
else if (bHighlighted)
rRenderContext.SetTextColor(rSettings.GetMenuBarHighlightTextColor());
}
else
{
if (bHighlighted)
rRenderContext.SetTextColor(rSettings.GetMenuBarHighlightTextColor());
else if (bRollover)
rRenderContext.SetTextColor(rSettings.GetMenuBarRolloverTextColor());
}
if (!bRollover && !bHighlighted)
rRenderContext.SetTextColor(rSettings.GetMenuBarTextColor());
}
else if (bHighlighted)
rRenderContext.SetTextColor(rSettings.GetMenuHighlightTextColor());
}
Point aPos(aTopLeft);
aPos.AdjustY(nBorder );
aPos.AdjustY(nStartY );
if (aPos.Y() >= 0)
{
long nTextOffsetY = (pData->aSz.Height() - nFontHeight) / 2;
if (IsMenuBar())
nTextOffsetY += (aOutSz.Height()-pData->aSz.Height()) / 2;
DrawTextFlags nTextStyle = DrawTextFlags::NONE;
DrawSymbolFlags nSymbolStyle = DrawSymbolFlags::NONE;
DrawImageFlags nImageStyle = DrawImageFlags::NONE;
// submenus without items are not disabled when no items are
// contained. The application itself should check for this!
// Otherwise it could happen entries are disabled due to
// asynchronous loading
if (!pData->bEnabled || !pWindow->IsEnabled())
{
nTextStyle |= DrawTextFlags::Disable;
nSymbolStyle |= DrawSymbolFlags::Disable;
nImageStyle |= DrawImageFlags::Disable;
}
// Separator
if (!bLayout && !IsMenuBar() && (pData->eType == MenuItemType::SEPARATOR))
{
bool bNativeOk = false;
if (rRenderContext.IsNativeControlSupported(ControlType::MenuPopup, ControlPart::Separator))
{
ControlState nState = ControlState::NONE;
if (pData->bEnabled && pWindow->IsEnabled())
nState |= ControlState::ENABLED;
if (bHighlighted)
nState |= ControlState::SELECTED;
int nSepPad = ImplGetSVData()->maNWFData.mnMenuSeparatorBorderX;
Point aMpos (aPos);
aMpos.AdjustX(nSepPad );
Size aSz(pData->aSz);
aSz.setWidth( aOutSz.Width() - 2*nOuterSpaceX - 2 * nSepPad );
tools::Rectangle aItemRect(aMpos, aSz);
MenupopupValue aVal(nTextPos - GUTTERBORDER, aItemRect);
bNativeOk = rRenderContext.DrawNativeControl(ControlType::MenuPopup, ControlPart::Separator,
aItemRect, nState, aVal, OUString());
}
if (!bNativeOk)
{
aTmpPos.setY( aPos.Y() + ((pData->aSz.Height() - 2) / 2) );
aTmpPos.setX( aPos.X() + 2 + nOuterSpaceX );
rRenderContext.SetLineColor(rSettings.GetShadowColor());
rRenderContext.DrawLine(aTmpPos, Point(aOutSz.Width() - 3 - 2 * nOuterSpaceX, aTmpPos.Y()));
aTmpPos.AdjustY( 1 );
rRenderContext.SetLineColor(rSettings.GetLightColor());
rRenderContext.DrawLine(aTmpPos, Point(aOutSz.Width() - 3 - 2 * nOuterSpaceX, aTmpPos.Y()));
rRenderContext.SetLineColor();
}
}
tools::Rectangle aOuterCheckRect(Point(aPos.X()+nImgOrChkPos, aPos.Y()),
Size(pData->aSz.Height(), pData->aSz.Height()));
aOuterCheckRect.AdjustLeft(1 );
aOuterCheckRect.AdjustRight( -1 );
aOuterCheckRect.AdjustTop(1 );
aOuterCheckRect.AdjustBottom( -1 );
// CheckMark
if (!bLayout && !IsMenuBar() && pData->HasCheck())
{
// draw selection transparent marker if checked
// onto that either a checkmark or the item image
// will be painted
// however do not do this if native checks will be painted since
// the selection color too often does not fit the theme's check and/or radio
if( !((pData->eType == MenuItemType::IMAGE) || (pData->eType == MenuItemType::STRINGIMAGE)))
{
if (rRenderContext.IsNativeControlSupported(ControlType::MenuPopup,
(pData->nBits & MenuItemBits::RADIOCHECK)
? ControlPart::MenuItemCheckMark
: ControlPart::MenuItemRadioMark))
{
ControlPart nPart = ((pData->nBits & MenuItemBits::RADIOCHECK)
? ControlPart::MenuItemRadioMark
: ControlPart::MenuItemCheckMark);
ControlState nState = ControlState::NONE;
if (pData->bChecked)
nState |= ControlState::PRESSED;
if (pData->bEnabled && pWindow->IsEnabled())
nState |= ControlState::ENABLED;
if (bHighlighted)
nState |= ControlState::SELECTED;
long nCtrlHeight = (pData->nBits & MenuItemBits::RADIOCHECK) ? nCheckHeight : nRadioHeight;
aTmpPos.setX( aOuterCheckRect.Left() + (aOuterCheckRect.GetWidth() - nCtrlHeight) / 2 );
aTmpPos.setY( aOuterCheckRect.Top() + (aOuterCheckRect.GetHeight() - nCtrlHeight) / 2 );
tools::Rectangle aCheckRect(aTmpPos, Size(nCtrlHeight, nCtrlHeight));
Size aSz(pData->aSz);
aSz.setWidth( aOutSz.Width() - 2 * nOuterSpaceX );
tools::Rectangle aItemRect(aPos, aSz);
MenupopupValue aVal(nTextPos - GUTTERBORDER, aItemRect);
rRenderContext.DrawNativeControl(ControlType::MenuPopup, nPart, aCheckRect,
nState, aVal, OUString());
}
else if (pData->bChecked) // by default do nothing for unchecked items
{
ImplPaintCheckBackground(rRenderContext, *pWindow, aOuterCheckRect, pThisItemOnly && bHighlighted);
SymbolType eSymbol;
Size aSymbolSize;
if (pData->nBits & MenuItemBits::RADIOCHECK)
{
eSymbol = SymbolType::RADIOCHECKMARK;
aSymbolSize = Size(nFontHeight / 2, nFontHeight / 2);
}
else
{
eSymbol = SymbolType::CHECKMARK;
aSymbolSize = Size((nFontHeight * 25) / 40, nFontHeight / 2);
}
aTmpPos.setX( aOuterCheckRect.Left() + (aOuterCheckRect.GetWidth() - aSymbolSize.Width()) / 2 );
aTmpPos.setY( aOuterCheckRect.Top() + (aOuterCheckRect.GetHeight() - aSymbolSize.Height()) / 2 );
tools::Rectangle aRect(aTmpPos, aSymbolSize);
aDecoView.DrawSymbol(aRect, eSymbol, rRenderContext.GetTextColor(), nSymbolStyle);
}
}
}
// Image:
if (!bLayout && !IsMenuBar() && ((pData->eType == MenuItemType::IMAGE) || (pData->eType == MenuItemType::STRINGIMAGE)))
{
// Don't render an image for a check thing
if (pData->bChecked)
ImplPaintCheckBackground(rRenderContext, *pWindow, aOuterCheckRect, pThisItemOnly && bHighlighted);
Image aImage = pData->aImage;
aTmpPos = aOuterCheckRect.TopLeft();
aTmpPos.AdjustX((aOuterCheckRect.GetWidth() - aImage.GetSizePixel().Width()) / 2 );
aTmpPos.AdjustY((aOuterCheckRect.GetHeight() - aImage.GetSizePixel().Height()) / 2 );
rRenderContext.DrawImage(aTmpPos, aImage, nImageStyle);
}
// Text:
if ((pData->eType == MenuItemType::STRING ) || (pData->eType == MenuItemType::STRINGIMAGE))
{
aTmpPos.setX( aPos.X() + nTextPos );
aTmpPos.setY( aPos.Y() );
aTmpPos.AdjustY(nTextOffsetY );
DrawTextFlags nStyle = nTextStyle | DrawTextFlags::Mnemonic;
const Menu *pMenu = this;
while (!pMenu->IsMenuBar() && pMenu->pStartedFrom)
pMenu = pMenu->pStartedFrom;
if (pMenu->IsMenuBar() && static_cast<MenuBarWindow*>(pMenu->pWindow.get())->GetMBWHideAccel())
nStyle |= DrawTextFlags::HideMnemonic;
if (pData->bIsTemporary)
nStyle |= DrawTextFlags::Disable;
MetricVector* pVector = bLayout ? &mpLayoutData->m_aUnicodeBoundRects : nullptr;
OUString* pDisplayText = bLayout ? &mpLayoutData->m_aDisplayText : nullptr;
if (bLayout)
{
mpLayoutData->m_aLineIndices.push_back(mpLayoutData->m_aDisplayText.getLength());
mpLayoutData->m_aLineItemIds.push_back(pData->nId);
}
// #i47946# with NWF painted menus the background is transparent
// since DrawCtrlText can depend on the background (e.g. for
// DrawTextFlags::Disable), temporarily set a background which
// hopefully matches the NWF background since it is read
// from the system style settings
bool bSetTmpBackground = !rRenderContext.IsBackground()
&& rRenderContext.IsNativeControlSupported(ControlType::MenuPopup, ControlPart::Entire);
if (bSetTmpBackground)
{
Color aBg = IsMenuBar() ? rRenderContext.GetSettings().GetStyleSettings().GetMenuBarColor()
: rRenderContext.GetSettings().GetStyleSettings().GetMenuColor();
rRenderContext.SetBackground(Wallpaper(aBg));
}
// how much space is there for the text ?
long nMaxItemTextWidth = aOutSz.Width() - aTmpPos.X() - nExtra - nOuterSpaceX;
if (!IsMenuBar() && pData->aAccelKey.GetCode() && !ImplAccelDisabled())
{
OUString aAccText = pData->aAccelKey.GetName();
nMaxItemTextWidth -= rRenderContext.GetTextWidth(aAccText) + 3 * nExtra;
}
if (!IsMenuBar() && pData->pSubMenu)
{
nMaxItemTextWidth -= nFontHeight - nExtra;
}
OUString aItemText(pData->aText);
pData->bHiddenOnGUI = false;
if (IsMenuBar()) // In case of menubar if we are out of bounds we shouldn't paint the item
{
if (nMaxItemTextWidth < rRenderContext.GetTextWidth(aItemText))
{
aItemText = "";
pData->bHiddenOnGUI = true;
bHiddenItems = true;
}
}
else
{
aItemText = getShortenedString(aItemText, rRenderContext, nMaxItemTextWidth);
pData->bHiddenOnGUI = false;
}
const SalLayoutGlyphs* pGlyphs = pData->GetTextGlyphs(&rRenderContext);
if (aItemText != pData->aText)
// Can't use pre-computed glyphs, item text was
// changed.
pGlyphs = nullptr;
rRenderContext.DrawCtrlText(aTmpPos, aItemText, 0, aItemText.getLength(),
nStyle, pVector, pDisplayText, pGlyphs);
if (bSetTmpBackground)
rRenderContext.SetBackground();
}
// Accel
if (!bLayout && !IsMenuBar() && pData->aAccelKey.GetCode() && !ImplAccelDisabled())
{
OUString aAccText = pData->aAccelKey.GetName();
aTmpPos.setX( aOutSz.Width() - rRenderContext.GetTextWidth(aAccText) );
aTmpPos.AdjustX( -(4 * nExtra) );
aTmpPos.AdjustX( -nOuterSpaceX );
aTmpPos.setY( aPos.Y() );
aTmpPos.AdjustY(nTextOffsetY );
rRenderContext.DrawCtrlText(aTmpPos, aAccText, 0, aAccText.getLength(), nTextStyle);
}
// SubMenu?
if (!bLayout && !IsMenuBar() && pData->pSubMenu)
{
bool bNativeOk = false;
if (rRenderContext.IsNativeControlSupported(ControlType::MenuPopup, ControlPart::SubmenuArrow))
{
ControlState nState = ControlState::NONE;
Size aTmpSz(0, 0);
long aSpacing = 0;
if (!ImplGetNativeSubmenuArrowSize(rRenderContext, aTmpSz, aSpacing))
{
aTmpSz = Size(nFontHeight, nFontHeight);
aSpacing = nOuterSpaceX;
}
if (pData->bEnabled && pWindow->IsEnabled())
nState |= ControlState::ENABLED;
if (bHighlighted)
nState |= ControlState::SELECTED;
aTmpPos.setX( aOutSz.Width() - aTmpSz.Width() - aSpacing - nOuterSpaceX );
aTmpPos.setY( aPos.Y() + ( pData->aSz.Height() - aTmpSz.Height() ) / 2 );
aTmpPos.AdjustY(nExtra / 2 );
tools::Rectangle aItemRect(aTmpPos, aTmpSz);
MenupopupValue aVal(nTextPos - GUTTERBORDER, aItemRect);
bNativeOk = rRenderContext.DrawNativeControl(ControlType::MenuPopup, ControlPart::SubmenuArrow,
aItemRect, nState, aVal, OUString());
}
if (!bNativeOk)
{
aTmpPos.setX( aOutSz.Width() - nFontHeight + nExtra - nOuterSpaceX );
aTmpPos.setY( aPos.Y() );
aTmpPos.AdjustY(nExtra/2 );
aTmpPos.AdjustY((pData->aSz.Height() / 2) - (nFontHeight / 4) );
if (pData->nBits & MenuItemBits::POPUPSELECT)
{
rRenderContext.SetTextColor(rSettings.GetMenuTextColor());
Point aTmpPos2(aPos);
aTmpPos2.setX( aOutSz.Width() - nFontHeight - nFontHeight/4 );
aDecoView.DrawFrame(tools::Rectangle(aTmpPos2, Size(nFontHeight + nFontHeight / 4,
pData->aSz.Height())),
DrawFrameStyle::Group);
}
aDecoView.DrawSymbol(tools::Rectangle(aTmpPos, Size(nFontHeight / 2, nFontHeight / 2)),
SymbolType::SPIN_RIGHT, rRenderContext.GetTextColor(), nSymbolStyle);
}
}
if (pThisItemOnly && bHighlighted)
{
// This restores the normal menu or menu bar text
// color for when it is no longer highlighted.
if (IsMenuBar())
rRenderContext.SetTextColor(rSettings.GetMenuBarTextColor());
else
rRenderContext.SetTextColor(rSettings.GetMenuTextColor());
}
}
if( bLayout )
{
if (!IsMenuBar())
mpLayoutData->m_aVisibleItemBoundRects[ n ] = tools::Rectangle(aTopLeft, Size(aOutSz.Width(), pData->aSz.Height()));
else
mpLayoutData->m_aVisibleItemBoundRects[ n ] = tools::Rectangle(aTopLeft, pData->aSz);
}
}
if (!IsMenuBar())
aTopLeft.AdjustY(pData->aSz.Height() );
else
aTopLeft.AdjustX(pData->aSz.Width() );
}
// draw "more" (">>") indicator if some items have been hidden as they go out of visible area
if (bHiddenItems)
{
sal_Int32 nSize = nFontHeight;
tools::Rectangle aRectangle(Point(aOutSz.Width() - nSize, (aOutSz.Height() / 2) - (nSize / 2)), Size(nSize, nSize));
lclDrawMoreIndicator(rRenderContext, aRectangle);
}
}
Menu* Menu::ImplGetStartMenu()
{
Menu* pStart = this;
while ( pStart && pStart->pStartedFrom && ( pStart->pStartedFrom != pStart ) )
pStart = pStart->pStartedFrom;
return pStart;
}
void Menu::ImplCallHighlight(sal_uInt16 nItem)
{
ImplMenuDelData aDelData( this );
nSelectedId = 0;
sSelectedIdent.clear();
MenuItemData* pData = pItemList->GetDataFromPos(nItem);
if (pData)
{
nSelectedId = pData->nId;
sSelectedIdent = pData->sIdent;
}
ImplCallEventListeners( VclEventId::MenuHighlight, GetItemPos( GetCurItemId() ) );
if( !aDelData.isDeleted() )
{
nSelectedId = 0;
sSelectedIdent.clear();
}
}
IMPL_LINK_NOARG(Menu, ImplCallSelect, void*, void)
{
nEventId = nullptr;
Select();
}
Menu* Menu::ImplFindSelectMenu()
{
Menu* pSelMenu = nEventId ? this : nullptr;
for ( size_t n = GetItemList()->size(); n && !pSelMenu; )
{
MenuItemData* pData = GetItemList()->GetDataFromPos( --n );
if ( pData->pSubMenu )
pSelMenu = pData->pSubMenu->ImplFindSelectMenu();
}
return pSelMenu;
}
Menu* Menu::ImplFindMenu( sal_uInt16 nItemId )
{
Menu* pSelMenu = nullptr;
for ( size_t n = GetItemList()->size(); n && !pSelMenu; )
{
MenuItemData* pData = GetItemList()->GetDataFromPos( --n );
if( pData->nId == nItemId )
pSelMenu = this;
else if ( pData->pSubMenu )
pSelMenu = pData->pSubMenu->ImplFindMenu( nItemId );
}
return pSelMenu;
}
void Menu::RemoveDisabledEntries( bool bCheckPopups, bool bRemoveEmptyPopups )
{
for ( sal_uInt16 n = 0; n < GetItemCount(); n++ )
{
bool bRemove = false;
MenuItemData* pItem = pItemList->GetDataFromPos( n );
if ( pItem->eType == MenuItemType::SEPARATOR )
{
if ( !n || ( GetItemType( n-1 ) == MenuItemType::SEPARATOR ) )
bRemove = true;
}
else
bRemove = !pItem->bEnabled;
if ( bCheckPopups && pItem->pSubMenu )
{
pItem->pSubMenu->RemoveDisabledEntries();
if ( bRemoveEmptyPopups && !pItem->pSubMenu->GetItemCount() )
bRemove = true;
}
if ( bRemove )
RemoveItem( n-- );
}
if ( GetItemCount() )
{
sal_uInt16 nLast = GetItemCount() - 1;
MenuItemData* pItem = pItemList->GetDataFromPos( nLast );
if ( pItem->eType == MenuItemType::SEPARATOR )
RemoveItem( nLast );
}
mpLayoutData.reset();
}
void Menu::UpdateNativeMenu()
{
if ( ImplGetSalMenu() )
ImplGetSalMenu()->Update();
}
void Menu::MenuBarKeyInput(const KeyEvent&)
{
}
void Menu::ImplKillLayoutData() const
{
mpLayoutData.reset();
}
void Menu::ImplFillLayoutData() const
{
if (pWindow && pWindow->IsReallyVisible())
{
mpLayoutData.reset(new MenuLayoutData);
if (IsMenuBar())
{
ImplPaint(*pWindow, pWindow->GetOutputSizePixel(), 0, 0, nullptr, false, true); // FIXME
}
else
{
MenuFloatingWindow* pFloat = static_cast<MenuFloatingWindow*>(pWindow.get());
ImplPaint(*pWindow, pWindow->GetOutputSizePixel(), pFloat->nScrollerHeight, pFloat->ImplGetStartY(),
nullptr, false, true); //FIXME
}
}
}
tools::Rectangle Menu::GetCharacterBounds( sal_uInt16 nItemID, long nIndex ) const
{
long nItemIndex = -1;
if( ! mpLayoutData )
ImplFillLayoutData();
if( mpLayoutData )
{
for( size_t i = 0; i < mpLayoutData->m_aLineItemIds.size(); i++ )
{
if( mpLayoutData->m_aLineItemIds[i] == nItemID )
{
nItemIndex = mpLayoutData->m_aLineIndices[i];
break;
}
}
}
return (mpLayoutData && nItemIndex != -1) ? mpLayoutData->GetCharacterBounds( nItemIndex+nIndex ) : tools::Rectangle();
}
long Menu::GetIndexForPoint( const Point& rPoint, sal_uInt16& rItemID ) const
{
long nIndex = -1;
rItemID = 0;
if( ! mpLayoutData )
ImplFillLayoutData();
if( mpLayoutData )
{
nIndex = mpLayoutData->GetIndexForPoint( rPoint );
for( size_t i = 0; i < mpLayoutData->m_aLineIndices.size(); i++ )
{
if( mpLayoutData->m_aLineIndices[i] <= nIndex &&
(i == mpLayoutData->m_aLineIndices.size()-1 || mpLayoutData->m_aLineIndices[i+1] > nIndex) )
{
// make index relative to item
nIndex -= mpLayoutData->m_aLineIndices[i];
rItemID = mpLayoutData->m_aLineItemIds[i];
break;
}
}
}
return nIndex;
}
tools::Rectangle Menu::GetBoundingRectangle( sal_uInt16 nPos ) const
{
tools::Rectangle aRet;
if (!mpLayoutData )
ImplFillLayoutData();
if (mpLayoutData)
{
std::map< sal_uInt16, tools::Rectangle >::const_iterator it = mpLayoutData->m_aVisibleItemBoundRects.find( nPos );
if( it != mpLayoutData->m_aVisibleItemBoundRects.end() )
aRet = it->second;
}
return aRet;
}
OUString Menu::GetAccessibleName( sal_uInt16 nItemId ) const
{
MenuItemData* pData = pItemList->GetData( nItemId );
if ( pData )
return pData->aAccessibleName;
return OUString();
}
void Menu::ImplClearSalMenu()
{
mpSalMenu.reset();
}
void Menu::GetSystemMenuData( SystemMenuData* pData ) const
{
Menu* pMenu = const_cast<Menu*>(this);
if( pData && pMenu->ImplGetSalMenu() )
{
pMenu->ImplGetSalMenu()->GetSystemMenuData( pData );
}
}
bool Menu::IsHighlighted( sal_uInt16 nItemPos ) const
{
bool bRet = false;
if( pWindow )
{
if (IsMenuBar())
bRet = ( nItemPos == static_cast< MenuBarWindow * > (pWindow.get())->GetHighlightedItem() );
else
bRet = ( nItemPos == static_cast< MenuFloatingWindow * > (pWindow.get())->GetHighlightedItem() );
}
return bRet;
}
void Menu::HighlightItem( sal_uInt16 nItemPos )
{
if ( pWindow )
{
if (IsMenuBar())
{
MenuBarWindow* pMenuWin = static_cast< MenuBarWindow* >( pWindow.get() );
pMenuWin->SetAutoPopup( false );
pMenuWin->ChangeHighlightItem( nItemPos, false );
}
else
{
static_cast< MenuFloatingWindow* >( pWindow.get() )->ChangeHighlightItem( nItemPos, false );
}
}
}
MenuBarWindow* MenuBar::getMenuBarWindow()
{
// so far just a dynamic_cast, hopefully to be turned into something saner
// at some stage
MenuBarWindow *pWin = dynamic_cast<MenuBarWindow*>(pWindow.get());
//either there is no window (fdo#87663) or it is a MenuBarWindow
assert(!pWindow || pWin);
return pWin;
}
MenuBar::MenuBar()
: Menu(),
mbCloseBtnVisible(false),
mbFloatBtnVisible(false),
mbHideBtnVisible(false),
mbDisplayable(true)
{
mpSalMenu = ImplGetSVData()->mpDefInst->CreateMenu(true, this);
}
MenuBar::MenuBar( const MenuBar& rMenu )
: Menu(),
mbCloseBtnVisible(false),
mbFloatBtnVisible(false),
mbHideBtnVisible(false),
mbDisplayable(true)
{
mpSalMenu = ImplGetSVData()->mpDefInst->CreateMenu(true, this);
*this = rMenu;
}
MenuBar::~MenuBar()
{
disposeOnce();
}
void MenuBar::dispose()
{
ImplDestroy( this, true );
Menu::dispose();
}
void MenuBar::ClosePopup(Menu *pMenu)
{
MenuBarWindow* pMenuWin = getMenuBarWindow();
if (!pMenuWin)
return;
pMenuWin->PopupClosed(pMenu);
}
void MenuBar::MenuBarKeyInput(const KeyEvent& rEvent)
{
pWindow->KeyInput(rEvent);
}
void MenuBar::ShowCloseButton(bool bShow)
{
ShowButtons( bShow, mbFloatBtnVisible, mbHideBtnVisible );
}
void MenuBar::ShowButtons( bool bClose, bool bFloat, bool bHide )
{
if ((bClose != mbCloseBtnVisible) ||
(bFloat != mbFloatBtnVisible) ||
(bHide != mbHideBtnVisible))
{
mbCloseBtnVisible = bClose;
mbFloatBtnVisible = bFloat;
mbHideBtnVisible = bHide;
MenuBarWindow* pMenuWin = getMenuBarWindow();
if (pMenuWin)
pMenuWin->ShowButtons(bClose, bFloat, bHide);
}
}
void MenuBar::LayoutChanged()
{
MenuBarWindow* pMenuWin = getMenuBarWindow();
if (pMenuWin)
pMenuWin->LayoutChanged();
}
void MenuBar::SetDisplayable( bool bDisplayable )
{
if( bDisplayable != mbDisplayable )
{
if ( ImplGetSalMenu() )
ImplGetSalMenu()->ShowMenuBar( bDisplayable );
mbDisplayable = bDisplayable;
LayoutChanged();
}
}
VclPtr<vcl::Window> MenuBar::ImplCreate(vcl::Window* pParent, vcl::Window* pWindow, MenuBar* pMenu)
{
VclPtr<MenuBarWindow> pMenuBarWindow = dynamic_cast<MenuBarWindow*>(pWindow);
if (!pMenuBarWindow)
{
pWindow = pMenuBarWindow = VclPtr<MenuBarWindow>::Create( pParent );
}
pMenu->pStartedFrom = nullptr;
pMenu->pWindow = pWindow;
pMenuBarWindow->SetMenu(pMenu);
long nHeight = pWindow ? pMenu->ImplCalcSize(pWindow).Height() : 0;
// depending on the native implementation or the displayable flag
// the menubar windows is suppressed (ie, height=0)
if (!pMenu->IsDisplayable() || (pMenu->ImplGetSalMenu() && pMenu->ImplGetSalMenu()->VisibleMenuBar()))
{
nHeight = 0;
}
pMenuBarWindow->SetHeight(nHeight);
return pWindow;
}
void MenuBar::ImplDestroy( MenuBar* pMenu, bool bDelete )
{
vcl::Window *pWindow = pMenu->ImplGetWindow();
if (pWindow && bDelete)
{
MenuBarWindow* pMenuWin = pMenu->getMenuBarWindow();
if (pMenuWin)
pMenuWin->KillActivePopup();
pWindow->disposeOnce();
}
pMenu->pWindow = nullptr;
}
bool MenuBar::ImplHandleKeyEvent( const KeyEvent& rKEvent )
{
// No keyboard processing when our menubar is invisible
if (!IsDisplayable())
return false;
// No keyboard processing when system handles the menu.
SalMenu *pNativeMenu = ImplGetSalMenu();
if (pNativeMenu && pNativeMenu->VisibleMenuBar())
{
// Except when the event is the F6 cycle pane event and we can put our
// focus into it (i.e. the gtk3 menubar case but not the mac/unity case
// where it's not part of the application window)
if (!TaskPaneList::IsCycleKey(rKEvent.GetKeyCode()))
return false;
if (!pNativeMenu->CanGetFocus())
return false;
}
bool bDone = false;
// check for enabled, if this method is called from another window...
vcl::Window* pWin = ImplGetWindow();
if (pWin && pWin->IsEnabled() && pWin->IsInputEnabled() && !pWin->IsInModalMode())
{
MenuBarWindow* pMenuWin = getMenuBarWindow();
bDone = pMenuWin && pMenuWin->HandleKeyEvent(rKEvent, false/*bFromMenu*/);
}
return bDone;
}
bool MenuBar::ImplHandleCmdEvent( const CommandEvent& rCEvent )
{
// No keyboard processing when system handles the menu or our menubar is invisible
if( !IsDisplayable() ||
( ImplGetSalMenu() && ImplGetSalMenu()->VisibleMenuBar() ) )
return false;
// check for enabled, if this method is called from another window...
MenuBarWindow* pWin = static_cast<MenuBarWindow*>(ImplGetWindow());
if ( pWin && pWin->IsEnabled() && pWin->IsInputEnabled() && ! pWin->IsInModalMode() )
{
if (rCEvent.GetCommand() == CommandEventId::ModKeyChange && ImplGetSVData()->maNWFData.mbAutoAccel)
{
const CommandModKeyData* pCData = rCEvent.GetModKeyData ();
if (pWin->nHighlightedItem == ITEMPOS_INVALID)
{
if (pCData && pCData->IsMod2() && pCData->IsDown())
pWin->SetMBWHideAccel(false);
else
pWin->SetMBWHideAccel(true);
pWin->Invalidate(InvalidateFlags::Update);
}
return true;
}
}
return false;
}
void MenuBar::SelectItem(sal_uInt16 nId)
{
if (pWindow)
{
pWindow->GrabFocus();
nId = GetItemPos( nId );
MenuBarWindow* pMenuWin = getMenuBarWindow();
if (pMenuWin)
{
// #99705# popup the selected menu
pMenuWin->SetAutoPopup( true );
if (ITEMPOS_INVALID != pMenuWin->GetHighlightedItem())
{
pMenuWin->KillActivePopup();
pMenuWin->ChangeHighlightItem( ITEMPOS_INVALID, false );
}
if (nId != ITEMPOS_INVALID)
pMenuWin->ChangeHighlightItem( nId, false );
}
}
}
// handler for native menu selection and command events
bool Menu::HandleMenuActivateEvent( Menu *pMenu ) const
{
if( pMenu )
{
ImplMenuDelData aDelData( this );
pMenu->pStartedFrom = const_cast<Menu*>(this);
pMenu->bInCallback = true;
pMenu->Activate();
if( !aDelData.isDeleted() )
pMenu->bInCallback = false;
}
return true;
}
bool Menu::HandleMenuDeActivateEvent( Menu *pMenu ) const
{
if( pMenu )
{
ImplMenuDelData aDelData( this );
pMenu->pStartedFrom = const_cast<Menu*>(this);
pMenu->bInCallback = true;
pMenu->Deactivate();
if( !aDelData.isDeleted() )
pMenu->bInCallback = false;
}
return true;
}
bool MenuBar::HandleMenuHighlightEvent( Menu *pMenu, sal_uInt16 nHighlightEventId ) const
{
if( !pMenu )
pMenu = const_cast<MenuBar*>(this)->ImplFindMenu(nHighlightEventId);
if( pMenu )
{
ImplMenuDelData aDelData( pMenu );
if( mnHighlightedItemPos != ITEMPOS_INVALID )
pMenu->ImplCallEventListeners( VclEventId::MenuDehighlight, mnHighlightedItemPos );
if( !aDelData.isDeleted() )
{
pMenu->mnHighlightedItemPos = pMenu->GetItemPos( nHighlightEventId );
pMenu->nSelectedId = nHighlightEventId;
pMenu->sSelectedIdent = pMenu->GetItemIdent( nHighlightEventId );
pMenu->pStartedFrom = const_cast<MenuBar*>(this);
pMenu->ImplCallHighlight( pMenu->mnHighlightedItemPos );
}
return true;
}
else
return false;
}
bool Menu::HandleMenuCommandEvent( Menu *pMenu, sal_uInt16 nCommandEventId ) const
{
if( !pMenu )
pMenu = const_cast<Menu*>(this)->ImplFindMenu(nCommandEventId);
if( pMenu )
{
pMenu->nSelectedId = nCommandEventId;
pMenu->sSelectedIdent = pMenu->GetItemIdent(nCommandEventId);
pMenu->pStartedFrom = const_cast<Menu*>(this);
pMenu->ImplSelect();
return true;
}
else
return false;
}
sal_uInt16 MenuBar::AddMenuBarButton( const Image& i_rImage, const Link<MenuBar::MenuBarButtonCallbackArg&,bool>& i_rLink, const OUString& i_rToolTip )
{
MenuBarWindow* pMenuWin = getMenuBarWindow();
return pMenuWin ? pMenuWin->AddMenuBarButton(i_rImage, i_rLink, i_rToolTip) : 0;
}
void MenuBar::SetMenuBarButtonHighlightHdl( sal_uInt16 nId, const Link<MenuBar::MenuBarButtonCallbackArg&,bool>& rLink )
{
MenuBarWindow* pMenuWin = getMenuBarWindow();
if (!pMenuWin)
return;
pMenuWin->SetMenuBarButtonHighlightHdl(nId, rLink);
}
void MenuBar::RemoveMenuBarButton( sal_uInt16 nId )
{
MenuBarWindow* pMenuWin = getMenuBarWindow();
if (!pMenuWin)
return;
pMenuWin->RemoveMenuBarButton(nId);
}
tools::Rectangle MenuBar::GetMenuBarButtonRectPixel( sal_uInt16 nId )
{
MenuBarWindow* pMenuWin = getMenuBarWindow();
return pMenuWin ? pMenuWin->GetMenuBarButtonRectPixel(nId) : tools::Rectangle();
}
bool MenuBar::HandleMenuButtonEvent( sal_uInt16 i_nButtonId )
{
MenuBarWindow* pMenuWin = getMenuBarWindow();
return pMenuWin && pMenuWin->HandleMenuButtonEvent(i_nButtonId);
}
int MenuBar::GetMenuBarHeight() const
{
MenuBar* pMenuBar = const_cast<MenuBar*>(this);
const SalMenu *pNativeMenu = pMenuBar->ImplGetSalMenu();
int nMenubarHeight;
if (pNativeMenu)
nMenubarHeight = pNativeMenu->GetMenuBarHeight();
else
{
vcl::Window* pMenubarWin = GetWindow();
nMenubarHeight = pMenubarWin ? pMenubarWin->GetOutputHeightPixel() : 0;
}
return nMenubarHeight;
}
// bool PopupMenu::bAnyPopupInExecute = false;
MenuFloatingWindow * PopupMenu::ImplGetFloatingWindow() const {
return static_cast<MenuFloatingWindow *>(Menu::ImplGetWindow());
}
PopupMenu::PopupMenu()
: mpLOKNotifier(nullptr)
{
mpSalMenu = ImplGetSVData()->mpDefInst->CreateMenu(false, this);
}
PopupMenu::PopupMenu( const PopupMenu& rMenu )
: Menu(),
mpLOKNotifier(nullptr)
{
mpSalMenu = ImplGetSVData()->mpDefInst->CreateMenu(false, this);
*this = rMenu;
}
PopupMenu::~PopupMenu()
{
disposeOnce();
}
void PopupMenu::ClosePopup(Menu* pMenu)
{
MenuFloatingWindow* p = dynamic_cast<MenuFloatingWindow*>(ImplGetWindow());
PopupMenu *pPopup = dynamic_cast<PopupMenu*>(pMenu);
if (p && pPopup)
p->KillActivePopup(pPopup);
}
bool PopupMenu::IsInExecute()
{
return GetActivePopupMenu() != nullptr;
}
PopupMenu* PopupMenu::GetActivePopupMenu()
{
ImplSVData* pSVData = ImplGetSVData();
return pSVData->maAppData.mpActivePopupMenu;
}
void PopupMenu::EndExecute()
{
if ( ImplGetWindow() )
ImplGetFloatingWindow()->EndExecute( 0 );
}
void PopupMenu::SelectItem(sal_uInt16 nId)
{
if ( ImplGetWindow() )
{
if( nId != ITEMPOS_INVALID )
{
size_t nPos = 0;
MenuItemData* pData = GetItemList()->GetData( nId, nPos );
if (pData && pData->pSubMenu)
ImplGetFloatingWindow()->ChangeHighlightItem( nPos, true );
else
ImplGetFloatingWindow()->EndExecute( nId );
}
else
{
MenuFloatingWindow* pFloat = ImplGetFloatingWindow();
pFloat->GrabFocus();
for( size_t nPos = 0; nPos < GetItemList()->size(); nPos++ )
{
MenuItemData* pData = GetItemList()->GetDataFromPos( nPos );
if( pData->pSubMenu )
{
pFloat->KillActivePopup();
}
}
pFloat->ChangeHighlightItem( ITEMPOS_INVALID, false );
}
}
}
void PopupMenu::SetSelectedEntry( sal_uInt16 nId )
{
nSelectedId = nId;
sSelectedIdent = GetItemIdent(nId);
}
sal_uInt16 PopupMenu::Execute( vcl::Window* pExecWindow, const Point& rPopupPos )
{
return Execute( pExecWindow, tools::Rectangle( rPopupPos, rPopupPos ), PopupMenuFlags::ExecuteDown );
}
sal_uInt16 PopupMenu::Execute( vcl::Window* pExecWindow, const tools::Rectangle& rRect, PopupMenuFlags nFlags )
{
ENSURE_OR_RETURN( pExecWindow, "PopupMenu::Execute: need a non-NULL window!", 0 );
FloatWinPopupFlags nPopupModeFlags = FloatWinPopupFlags::NONE;
if ( nFlags & PopupMenuFlags::ExecuteDown )
nPopupModeFlags = FloatWinPopupFlags::Down;
else if ( nFlags & PopupMenuFlags::ExecuteUp )
nPopupModeFlags = FloatWinPopupFlags::Up;
else if ( nFlags & PopupMenuFlags::ExecuteLeft )
nPopupModeFlags = FloatWinPopupFlags::Left;
else if ( nFlags & PopupMenuFlags::ExecuteRight )
nPopupModeFlags = FloatWinPopupFlags::Right;
else
nPopupModeFlags = FloatWinPopupFlags::Down;
if (nFlags & PopupMenuFlags::NoMouseUpClose ) // allow popup menus to stay open on mouse button up
nPopupModeFlags |= FloatWinPopupFlags::NoMouseUpClose; // useful if the menu was opened on mousebutton down (eg toolbox configuration)
if (nFlags & PopupMenuFlags::NoHorzPlacement)
nPopupModeFlags |= FloatWinPopupFlags::NoHorzPlacement;
return ImplExecute( pExecWindow, rRect, nPopupModeFlags, nullptr, false );
}
void PopupMenu::ImplFlushPendingSelect()
{
// is there still Select?
Menu* pSelect = ImplFindSelectMenu();
if (pSelect)
{
// Select should be called prior to leaving execute in a popup menu!
Application::RemoveUserEvent( pSelect->nEventId );
pSelect->nEventId = nullptr;
pSelect->Select();
}
}
sal_uInt16 PopupMenu::ImplExecute( const VclPtr<vcl::Window>& pW, const tools::Rectangle& rRect, FloatWinPopupFlags nPopupModeFlags, Menu* pSFrom, bool bPreSelectFirst )
{
if ( !pSFrom && ( PopupMenu::IsInExecute() || !GetItemCount() ) )
return 0;
// set the flag to hide or show accelerators in the menu depending on whether the menu was launched by mouse or keyboard shortcut
if( pSFrom && pSFrom->IsMenuBar())
{
auto pMenuBarWindow = static_cast<MenuBarWindow*>(pSFrom->pWindow.get());
pMenuBarWindow->SetMBWHideAccel( !(pMenuBarWindow->GetMBWMenuKey()) );
}
mpLayoutData.reset();
ImplSVData* pSVData = ImplGetSVData();
pStartedFrom = pSFrom;
nSelectedId = 0;
sSelectedIdent.clear();
bCanceled = false;
VclPtr<vcl::Window> xFocusId;
bool bRealExecute = false;
if ( !pStartedFrom )
{
pSVData->maWinData.mbNoDeactivate = true;
xFocusId = Window::SaveFocus();
bRealExecute = true;
}
else
{
// assure that only one menu is open at a time
if (pStartedFrom->IsMenuBar() && pSVData->maWinData.mpFirstFloat)
pSVData->maWinData.mpFirstFloat->EndPopupMode( FloatWinPopupEndFlags::Cancel | FloatWinPopupEndFlags::CloseAll );
}
SAL_WARN_IF( ImplGetWindow(), "vcl", "Win?!" );
tools::Rectangle aRect( rRect );
aRect.SetPos( pW->OutputToScreenPixel( aRect.TopLeft() ) );
if (bRealExecute)
nPopupModeFlags |= FloatWinPopupFlags::NewLevel;
nPopupModeFlags |= FloatWinPopupFlags::NoKeyClose | FloatWinPopupFlags::AllMouseButtonClose;
bInCallback = true; // set it here, if Activate overridden
Activate();
bInCallback = false;
if ( pW->IsDisposed() )
return 0; // Error
if ( bCanceled || bKilled )
return 0;
if ( !GetItemCount() )
return 0;
// The flag MenuFlags::HideDisabledEntries is inherited.
if ( pSFrom )
{
if ( pSFrom->nMenuFlags & MenuFlags::HideDisabledEntries )
nMenuFlags |= MenuFlags::HideDisabledEntries;
else
nMenuFlags &= ~MenuFlags::HideDisabledEntries;
}
else
// #102790# context menus shall never show disabled entries
nMenuFlags |= MenuFlags::HideDisabledEntries;
sal_uInt16 nVisibleEntries = ImplGetVisibleItemCount();
if ( !nVisibleEntries )
{
OUString aTmpEntryText(VclResId(SV_RESID_STRING_NOSELECTIONPOSSIBLE));
MenuItemData* pData = NbcInsertItem(0xFFFF, MenuItemBits::NONE, aTmpEntryText, nullptr, 0xFFFF, OString());
size_t nPos = 0;
pData = pItemList->GetData( pData->nId, nPos );
assert(pData);
if (pData)
{
pData->bIsTemporary = true;
}
ImplCallEventListeners(VclEventId::MenuSubmenuChanged, nPos);
}
VclPtrInstance<MenuFloatingWindow> pWin( this, pW, WB_BORDER | WB_SYSTEMWINDOW );
if (comphelper::LibreOfficeKit::isActive() && mpLOKNotifier)
pWin->SetLOKNotifier(mpLOKNotifier);
if( pSVData->maNWFData.mbFlatMenu )
pWin->SetBorderStyle( WindowBorderStyle::NOBORDER );
else
pWin->SetBorderStyle( pWin->GetBorderStyle() | WindowBorderStyle::MENU );
pWindow = pWin;
Size aSz = ImplCalcSize( pWin );
tools::Rectangle aDesktopRect(pWin->GetDesktopRectPixel());
if( Application::GetScreenCount() > 1 && Application::IsUnifiedDisplay() )
{
vcl::Window* pDeskW = pWindow->GetWindow( GetWindowType::RealParent );
if( ! pDeskW )
pDeskW = pWindow;
Point aDesktopTL( pDeskW->OutputToAbsoluteScreenPixel( aRect.TopLeft() ) );
aDesktopRect = Application::GetScreenPosSizePixel(
Application::GetBestScreen( tools::Rectangle( aDesktopTL, aRect.GetSize() ) ));
}
long nMaxHeight = aDesktopRect.GetHeight();
//rhbz#1021915. If a menu won't fit in the desired location the default
//mode is to place it somewhere it will fit. e.g. above, left, right. For
//some cases, e.g. menubars, it's desirable to limit the options to
//above/below and force the menu to scroll if it won't fit
if (nPopupModeFlags & FloatWinPopupFlags::NoHorzPlacement)
{
vcl::Window* pRef = pWin;
if ( pRef->GetParent() )
pRef = pRef->GetParent();
tools::Rectangle devRect( pRef->OutputToAbsoluteScreenPixel( aRect.TopLeft() ),
pRef->OutputToAbsoluteScreenPixel( aRect.BottomRight() ) );
long nHeightAbove = devRect.Top() - aDesktopRect.Top();
long nHeightBelow = aDesktopRect.Bottom() - devRect.Bottom();
nMaxHeight = std::min(nMaxHeight, std::max(nHeightAbove, nHeightBelow));
}
if (pStartedFrom && pStartedFrom->IsMenuBar())
nMaxHeight -= pW->GetSizePixel().Height();
sal_Int32 nLeft, nTop, nRight, nBottom;
pWindow->GetBorder( nLeft, nTop, nRight, nBottom );
nMaxHeight -= nTop+nBottom;
if ( aSz.Height() > nMaxHeight )
{
pWin->EnableScrollMenu( true );
sal_uInt16 nStart = ImplGetFirstVisible();
sal_uInt16 nEntries = ImplCalcVisEntries( nMaxHeight, nStart );
aSz.setHeight( ImplCalcHeight( nEntries ) );
}
pWin->SetFocusId( xFocusId );
pWin->SetOutputSizePixel( aSz );
if ( GetItemCount() )
{
SalMenu* pMenu = ImplGetSalMenu();
if( pMenu && bRealExecute && pMenu->ShowNativePopupMenu( pWin, aRect, nPopupModeFlags | FloatWinPopupFlags::GrabFocus ) )
{
pWin->StopExecute();
pWin->doShutdown();
pWindow->SetParentToDefaultWindow();
pWindow.disposeAndClear();
ImplClosePopupToolBox(pW);
ImplFlushPendingSelect();
return nSelectedId;
}
else
{
pWin->StartPopupMode( aRect, nPopupModeFlags | FloatWinPopupFlags::GrabFocus );
}
if( pSFrom )
{
sal_uInt16 aPos;
if (pSFrom->IsMenuBar())
aPos = static_cast<MenuBarWindow *>(pSFrom->pWindow.get())->GetHighlightedItem();
else
aPos = static_cast<MenuFloatingWindow *>(pSFrom->pWindow.get())->GetHighlightedItem();
pWin->SetPosInParent( aPos ); // store position to be sent in SUBMENUDEACTIVATE
pSFrom->ImplCallEventListeners( VclEventId::MenuSubmenuActivate, aPos );
}
}
if ( bPreSelectFirst )
{
size_t nCount = pItemList->size();
for ( size_t n = 0; n < nCount; n++ )
{
MenuItemData* pData = pItemList->GetDataFromPos( n );
if ( ( pData->bEnabled
|| !Application::GetSettings().GetStyleSettings().GetSkipDisabledInMenus()
)
&& ( pData->eType != MenuItemType::SEPARATOR )
&& ImplIsVisible( n )
&& ImplIsSelectable( n )
)
{
pWin->ChangeHighlightItem( n, false );
break;
}
}
}
if ( bRealExecute )
{
pWin->Execute();
if (pWin->IsDisposed())
return 0;
xFocusId = pWin->GetFocusId();
assert(xFocusId == nullptr && "Focus should already be restored by MenuFloatingWindow::End");
pWin->ImplEndPopupMode(FloatWinPopupEndFlags::NONE, xFocusId);
if ( nSelectedId ) // then clean up .. ( otherwise done by TH )
{
PopupMenu* pSub = pWin->GetActivePopup();
while ( pSub )
{
pSub->ImplGetFloatingWindow()->EndPopupMode();
pSub = pSub->ImplGetFloatingWindow()->GetActivePopup();
}
}
pWin->doShutdown();
pWindow->SetParentToDefaultWindow();
pWindow.disposeAndClear();
ImplClosePopupToolBox(pW);
ImplFlushPendingSelect();
}
return bRealExecute ? nSelectedId : 0;
}
sal_uInt16 PopupMenu::ImplCalcVisEntries( long nMaxHeight, sal_uInt16 nStartEntry, sal_uInt16* pLastVisible ) const
{
nMaxHeight -= 2 * ImplGetFloatingWindow()->GetScrollerHeight();
long nHeight = 0;
size_t nEntries = pItemList->size();
sal_uInt16 nVisEntries = 0;
if ( pLastVisible )
*pLastVisible = 0;
for ( size_t n = nStartEntry; n < nEntries; n++ )
{
if ( ImplIsVisible( n ) )
{
MenuItemData* pData = pItemList->GetDataFromPos( n );
nHeight += pData->aSz.Height();
if ( nHeight > nMaxHeight )
break;
if ( pLastVisible )
*pLastVisible = n;
nVisEntries++;
}
}
return nVisEntries;
}
long PopupMenu::ImplCalcHeight( sal_uInt16 nEntries ) const
{
long nHeight = 0;
sal_uInt16 nFound = 0;
for ( size_t n = 0; ( nFound < nEntries ) && ( n < pItemList->size() ); n++ )
{
if ( ImplIsVisible( static_cast<sal_uInt16>(n) ) )
{
MenuItemData* pData = pItemList->GetDataFromPos( n );
nHeight += pData->aSz.Height();
nFound++;
}
}
nHeight += 2*ImplGetFloatingWindow()->GetScrollerHeight();
return nHeight;
}
ImplMenuDelData::ImplMenuDelData( const Menu* pMenu )
: mpNext( nullptr )
, mpMenu( nullptr )
{
if( pMenu )
const_cast< Menu* >( pMenu )->ImplAddDel( *this );
}
ImplMenuDelData::~ImplMenuDelData()
{
if( mpMenu )
const_cast< Menu* >( mpMenu.get() )->ImplRemoveDel( *this );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|