[r8766]: main / branches / 4.1 / trunk / extensions / platform / windows / oodialog / oodMenu.cpp Maximize Restore History

Download this file

oodMenu.cpp    6427 lines (5712 with data), 200.8 kB

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
/*----------------------------------------------------------------------------*/
/* */
/* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
/* Copyright (c) 2005-2013 Rexx Language Association. All rights reserved. */
/* */
/* This program and the accompanying materials are made available under */
/* the terms of the Common Public License v1.0 which accompanies this */
/* distribution. A copy is also available at the following address: */
/* http://www.oorexx.org/license.html */
/* */
/* Redistribution and use in source and binary forms, with or */
/* without modification, are permitted provided that the following */
/* conditions are met: */
/* */
/* Redistributions of source code must retain the above copyright */
/* notice, this list of conditions and the following disclaimer. */
/* Redistributions in binary form must reproduce the above copyright */
/* notice, this list of conditions and the following disclaimer in */
/* the documentation and/or other materials provided with the distribution. */
/* */
/* Neither the name of Rexx Language Association nor the names */
/* of its contributors may be used to endorse or promote products */
/* derived from this software without specific prior written permission. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
/* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
/* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* */
/*----------------------------------------------------------------------------*/
#include "ooDialog.hpp" // Must be first, includes windows.h, commctrl.h, and oorexxapi.h
#include <stdio.h>
#include <dlgs.h>
#include <limits.h>
#include <shlwapi.h>
#include "APICommon.hpp"
#include "oodCommon.hpp"
#include "oodMessaging.hpp"
#include "oodMenu.hpp"
/** NOTES:
* This approach is taken with exceptions:
*
* When a method is to return a new Menu object (Rexx object) always raise
* exceptions for errors. (Except for setting the context help ID, which will
* not fail but set .SystemErrorCode().)
*
* After the Menu object is constructed, don't raise exceptions, but rather set
* the .SystemErrorCode for failures and indicate a failure in the return. Many
* methods will work well with returning true of success and false for failure.
* The OS seems to be good about accepting NULL for menu and window handles and
* then setting the appropriate error code.
*
* DO raise exceptions for any invalid Rexx arguments, bad resouce ID, item ID,
* wrong object type, wrong ranges, etc..
*
* Users can check for valid menu handles using isValid(), getHandle(), etc.
*
* When it is impossible to indicate by the return that the method failed, then
* set .SystemErrorCode and raise an exception. There is also the method
* isValidItemID() which can be used to check if an itemID would raise an
* exception (The programmer can decide whether she wants to set up a trap
* handler or use isValidItemID() for those methods that might raise an
* exception.)
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* Always use the term Popup for submenus in method names.
*
*/
/* System Error codes that might be useful:
*
* ERROR_INVALID_FUNCTION 1 -
* Incorrect function.
*
* ERROR_NOT_ENOUGH_MEMORY 8 -
* Not enough storage is available to process this command.
*
* ERROR_INVALID_PARAMETER 87 -
* The parameter is incorrect.
*
*
* ERROR_INVALID_WINDOW_HANDLE 1400 -
* Invalid window handle.
*
* ERROR_INVALID_MENU_HANDLE 1401 -
* Invalid menu handle.
*
* ERROR_WINDOW_NOT_DIALOG 1420 -
* The window is not a valid dialog window.
*
* ERROR_MENU_ITEM_NOT_FOUND 1456 -
* A menu item was not found.
*
* ERROR_INVALID_ENVIRONMENT 1805 -
* The environment specified is invalid.
*
* OR_INVALID_OID 1911 -
* The object specified was not found.
*
* ERROR_INVALID_WINDOW_STYLE 2002 -
* The window style or class attribute is invalid for this operation.
*
*
*/
// Local function prototypes.
static uint32_t resolveItemID(RexxMethodContext *, RexxObjectPtr, logical_t, size_t);
static bool getMII(CppMenu *, RexxObjectPtr, BOOL, uint32_t, uint32_t *, UINT, MENUITEMINFO *);
static UINT getPopupTypeOpts(const char *, UINT);
static UINT getPopupStateOpts(const char *, UINT);
static UINT getItemStateOpts(const char *, UINT);
static UINT getItemTypeOpts(const char *, UINT);
static UINT getSeparatorTypeOpts(const char *opts, UINT type);
static UINT getTrackFlags(const char *);
static uint32_t deleteSeparatorByID(HMENU, uint32_t);
static uint32_t menuHelpID(HMENU hMenu, DWORD helpID, BOOL recurse, uint32_t *id);
static uint32_t menuConnectItems(HMENU hMenu, pCEventNotification pcen, RexxMethodContext *, CSTRING msg, bool isSysMenu);
/**
* Calls addCommandMessage() to connect a menu item to a method in a dialog.
*
* addCommandMessage() only fails if the message table is full, (well also some
* other things that are not valid here, like a zero length msg.) So, if it
* fails ERROR_NOT_ENOUGH_MEMORY is a good system error code.
*
* Note that resource IDs, 1, 2, and 9 are connected automaticaly when a dialog
* is initialized.
*
* @param pcen EventNotification CSelf for the dialog we are adding the method
* connection to.
*
* @param c Rexx method context we are operating in.
*
* @param id Menu ID to connect.
*
* @param msg Method name we are connecting to.
*
* @return 0 on success, ERROR_NOT_ENOUGH_MEMORY on failure.
*
* @remarks The WPARAM filter (menu id filter) needs to be 0xFFFFFFFF. This
* filters out dialog control notifications that use WM_COMMAND. The
* high word of WPARAM is the notification code for dialog controls, it
* is 0 for menu command items.
*/
inline uint32_t _connectItem(pCEventNotification pcen, RexxMethodContext *c, uint32_t id, CSTRING msg)
{
if ( id < 3 || id == 9 )
{
return 0;
}
return addCommandMessage(pcen, c, id, 0xFFFFFFFF, 0, 0, msg, TAG_NOTHING) ? 0 : ERROR_NOT_ENOUGH_MEMORY;
}
/* Same as above but connects a System Menu item */
inline BOOL _connectSysItem(pCEventNotification pcen, RexxMethodContext *c, uint32_t id, CSTRING msg)
{
uint32_t tag = TAG_DIALOG | TAG_SYSMENUCOMMAND;
return addMiscMessage(pcen, c, WM_SYSCOMMAND, UINT32_MAX, id, 0x0000FFF0, 0, 0, msg, tag) ? 0 : ERROR_NOT_ENOUGH_MEMORY;
}
/**
* Checks if CppMenu::attachToDlg() would succeed with the specified object.
*
* @param c
* @param dlg
* @param argPos
*
* @return true if attachToDlg() is expected to succeed, otherwise false.
*
* @note If false is returned, an exception has been raised.
*/
static bool validAttachTo(RexxMethodContext *c, RexxObjectPtr dlg, size_t argPos)
{
TCHAR buf[256];
if ( ! c->IsOfType(dlg, "PLAINBASEDIALOG") )
{
_snprintf(buf, sizeof(buf), "can not attach menu unless arg %d 'attachTo' is a dialog object", argPos);
userDefinedMsgException(c, buf);
return false;
}
// The underlying dialog needs to exist, and it can not already have a menu
// bar attached.
pCPlainBaseDialog pcpbd = dlgToCSelf(c, dlg);
if ( ! pcpbd->isDlgHwndSet )
{
_snprintf(buf, sizeof(buf), "can not attach menu when the underlying arg %d 'attachTo' dialog does not exist",
argPos);
userDefinedMsgException(c, buf);
return false;
}
if ( c->SendMessage0(dlg, "HASMENUBAR") == TheTrueObj )
{
_snprintf(buf, sizeof(buf), "can not attach menu when the arg %d 'attachTo' dialog already has a menu bar",
argPos);
userDefinedMsgException(c, buf);
return false;
}
return true;
}
/**
* Tries to get a pointer to the EventNotification CSelf from the specified
* dialog.
*
* @param c Method context we are operating in.
* @param dialog A presumed ooDialog dialog object.
*
* @return The EventNotification CSelf for the specified dialog on success, null
* on failure.
*
* @note This function fails if dialog is not a PlainBaseDialog or one of its
* subclasses. In this case the .SystemErrorCode is set, but no
* condition is raised.
*/
pCEventNotification _getPCEN(RexxMethodContext *c, RexxObjectPtr dialog)
{
oodResetSysErrCode(c->threadContext);
if ( dialog != NULLOBJECT && c->IsOfType(dialog, "PLAINBASEDIALOG") )
{
return dlgToEventNotificationCSelf(c, dialog);
}
oodSetSysErrCode(c->threadContext, ERROR_WINDOW_NOT_DIALOG);
return NULL;
}
CSTRING CppMenu::name()
{
switch ( type )
{
case BinaryMenuBar :
return "BinaryMenuBar";
case PopupMenu :
return "PopupMenu";
case ScriptMenuBar :
return "ScriptMenuBar";
case UserMenuBar :
return "UserMenuBar";
default :
break;
}
return "ERROR unknown menu";
}
logical_t CppMenu::addTemplateSepartor(RexxObjectPtr rxID, CSTRING opts)
{
logical_t success = FALSE;
oodResetSysErrCode(c->threadContext);
int32_t id = oodGlobalID(c, rxID, 1, false);
if ( id == OOD_ID_EXCEPTION )
{
goto done_out;
}
if ( isFinal )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_FUNCTION);
goto done_out;
}
WORD resInfo = 0;
DWORD dwType = MFT_SEPARATOR;
if ( opts != NULL )
{
dwType = getSeparatorTypeOpts(opts, dwType);
if ( StrStrI(opts, "END") )
{
resInfo = MFR_END;
}
}
success = addTemplateMenuItem(id, dwType, 0, 0, resInfo, "");
done_out:
return success;
}
/**
*
*
* @param rxID
* @param text
* @param opts
* @param method
*
* @return logical_t
*
* @note text is required to be not null, the empty string is okay.
*/
logical_t CppMenu::addTemplateItem(RexxObjectPtr rxID, CSTRING text, CSTRING opts, CSTRING method)
{
logical_t success = FALSE;
oodResetSysErrCode(c->threadContext);
int32_t id = oodGlobalID(c, rxID, 1, true);
if ( id == OOD_ID_EXCEPTION )
{
goto done_out;
}
if ( isFinal )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_FUNCTION);
goto done_out;
}
if ( method != NULL && *method == '\0' )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_PARAMETER);
goto done_out;
}
WORD resInfo = 0;
DWORD dwState = 0;
DWORD dwType = 0;
if ( opts != NULL )
{
dwState = getItemStateOpts(opts, 0);
dwType = getItemTypeOpts(opts, MFT_STRING);
if ( StrStrI(opts, "END") )
{
resInfo = MFR_END;
}
}
if ( ! addTemplateMenuItem(id, dwType, dwState, 0, resInfo, text) )
{
goto done_out;
}
success = TRUE;
if ( method != NULL )
{
addToConnectionQ(id, method);
}
done_out:
return success;
}
/**
*
*
* @param rxID
* @param text
* @param opts
* @param helpID
*
* @return logical_t
*
* @note Text is required to not be null, the empty string is okay.
*
* @remarks We need to allow 0 for rxID, so don't use 'strict' with
* oodGlobalID().
*/
logical_t CppMenu::addTemplatePopup(RexxObjectPtr rxID, CSTRING text, CSTRING opts, RexxObjectPtr helpID)
{
logical_t success = FALSE;
oodResetSysErrCode(c->threadContext);
int32_t id = oodGlobalID(c, rxID, 1, false);
if ( id == OOD_ID_EXCEPTION )
{
goto done_out;
}
DWORD dwHelpID = 0;
if ( helpID != NULLOBJECT )
{
dwHelpID = oodGlobalID(c, helpID, 4, false);
if ( id == OOD_ID_EXCEPTION )
{
goto done_out;
}
}
if ( isFinal )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_FUNCTION);
goto done_out;
}
WORD resInfo = MFR_POPUP;
DWORD dwState = 0;
DWORD dwType = 0;
if ( opts != NULL )
{
dwState = getPopupStateOpts(opts, 0);
dwType = getPopupTypeOpts(opts, MFT_STRING);
if ( StrStrI(opts, "END") )
{
resInfo |= MFR_END;
}
}
success = addTemplateMenuItem(id, dwType, dwState, dwHelpID, resInfo, text);
done_out:
return success;
}
bool CppMenu::initTemplate(uint32_t count, uint32_t _helpID)
{
WORD *p;
bool success = false;
helpID = _helpID;
// Allocate the memory for the template, which is a guess based on the
// expected count of menu items. We add 1 to account for the header and use
// an arbitrarily picked menu item size. (Which is probably much bigger
// than a typical menu item size.
size_t size = (++count) * ARBITRARY_MENU_ITEM_SIZE;
hTemplateMemory = (PDWORD)GlobalAlloc(GPTR, size);
if ( hTemplateMemory == NULL )
{
systemServiceExceptionCode(c->threadContext, API_FAILED_MSG, "GlobalAlloc");
goto done_out;
}
p = (PWORD)hTemplateMemory;
isFinal = false;
endOfTemplate = (byte *)p + size - 1;
/* Write the menu header template. Extended menu headers and extended menu
* item templates must be DWORD aligned. Begin by aligning the starting
* pointer. Note that lpwAlign aligns to a DWORD, not a word. (Haven't
* changed the name because it is used in other, non-reviewed, code.
*/
p = lpwAlign(p);
// Save the start of the template so we can load it when we are done.
pTemplate = (DWORD *)p;
*p++ = EXTENDED_MENU_VERSION; // wVersion (word): 1 for extended menu.
*p++ = 4; // wOffset (word): 4 since we are already aligned.
/* The context help ID is a DWORD value. Note that setting the help ID does
* not seem to work as Microsoft documents it. After this, our current
* position pointer ends up pointing to the start of the 1st menu item,
* already aligned.
*/
pCurrentTemplatePos = (DWORD *)p;
*pCurrentTemplatePos++ = helpID;
success = true;
done_out:
return success;
}
/**
* Adds a menu item to the in memory template.
*
* @param menuID
* @param dwType
* @param dwState
* @param dwHelpID
* @param resInfo
* @param text Must not be null, use the empty string.
*
* @return bool
*
* @assumes Caller has checked that the memory template state is valid.
*/
BOOL CppMenu::addTemplateMenuItem(DWORD menuID, DWORD dwType, DWORD dwState, DWORD dwHelpID, WORD resInfo, CSTRING text)
{
WORD *p;
BOOL success = TRUE;
if ( ! haveTemplateRoom(strlen(text) + 1, (byte *)pCurrentTemplatePos) )
{
executionErrorException(c->threadContext, TEMPLATE_TOO_SMALL_MSG);
return FALSE;
}
// Our current position pointer is DWORD aligned pointing to the next menu
// item to add.
*pCurrentTemplatePos++ = dwType;
*pCurrentTemplatePos++ = dwState;
*pCurrentTemplatePos++ = menuID;
// Next fields are WORD in size.
p = (WORD *)pCurrentTemplatePos;
*p++ = resInfo;
// The menu item strings must be unicode. This works correctly for the
// empty string. p now points to the position in the template for the
// string. If there is no string, then this position still needs to be set
// with the wide character null. putUnicodeText() will handle both the
// empty string or text == NULL.
p += putUnicodeText(p, text);
// Need to be double word aligned now.
pCurrentTemplatePos = (DWORD *)lpwAlign(p);
// The dwHelpId field must be included, even if it is 0, if the item is a
// popup, must not be included otherwise.
if (resInfo & MFR_POPUP)
{
*pCurrentTemplatePos++ = dwHelpID;
}
return success;
}
void CppMenu::deleteTemplate()
{
GlobalFree(hTemplateMemory);
isFinal = true;
pTemplate = NULL;
pCurrentTemplatePos = NULL;
hTemplateMemory = NULL;
}
bool CppMenu::finishTemplate()
{
bool result = false;
oodResetSysErrCode(c->threadContext);
if ( isFinal )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_FUNCTION);
goto done_out;
}
// Load the menu and save last error to be sure it does not get changed by
// some internal Windows API while we are doing clean up.
hMenu = LoadMenuIndirect(pTemplate);
uint32_t rc = GetLastError();
// No matter what, we are done with the memory allocated for the menu
// template and we set ourself to finialized.
deleteTemplate();
if ( hMenu == NULL )
{
systemServiceExceptionCode(c->threadContext, API_FAILED_MSG, "LoadMenuIndirect", rc);
goto done_out;
}
result = true;
uint32_t ret = menuHelpID(hMenu, helpID, TRUE, NULL);
if ( ret != 0 )
{
oodSetSysErrCode(c->threadContext, ret);
}
done_out:
noTempHelpID();
return result;
}
CppMenu::~CppMenu()
{
printf("In destructor connectionQ=%p\n", connectionQ);
}
CppMenu::CppMenu(RexxObjectPtr s, MenuType t, RexxMethodContext *context) : self(s), type(t), c(context)
{
defaultResult = NULLOBJECT;
hMenu = NULL;
wID = -1;
dlg = TheNilObj;
dlgHwnd = NULL;
connectionRequested = false;
connectionQ = NULL;
connectionQIndex = 0;
connectionQSize = 0;
autoConnect = false;
connectionMethod = NULL;
hTemplateMemory = NULL;
pTemplate = NULL;
pCurrentTemplatePos = NULL;
isFinal = true;
uint32_t helpID = (uint32_t)-1;
}
/**
* Sets the menu ID for this menu. The default ID of -1 is already set.
*
* @param menuID The ID of the menu, or 0 or -1 to signal no ID.
*
* @return No return.
*
* @remarks A menu ID was not used in earlier versions of ooDialog and it is
* not clear if ooDialog programmers will use it much now that it is available.
* wID is already set to -1 to signal no ID when the CppMenu is constructed.
* So this method only needs to be called if the programmer does use an ID.
*
* This could be inline of course, just saving this for the remarks.
*/
void CppMenu::setMenuID(int menuID)
{
if ( menuID > 0 )
{
wID = menuID;
}
}
RexxDirectoryObject CppMenu::autoConnectionStatus()
{
RexxDirectoryObject result = c->NewDirectory();
c->DirectoryPut(result, autoConnect ? TheTrueObj : TheFalseObj, "AUTOCONNECT");
if ( connectionMethod != NULL )
{
c->DirectoryPut(result, c->CString(connectionMethod), "METHODNAME");
}
return result;
}
/**
* Given the arguments and the current state of the menu, determines if the
* programmer wants the menu item automatically connected to a method.
*
* @param id The id of the menu item.
* @param text The menu item text (label.)
* @param connect True if programmer requested the item to be connected.
* @param methodName Optional method name for connection request, may be NULL.
* If null, use a method name constructed from the text of
* the item
*
* @return True if no errors, if either the item was connected or there was no
* request to connect the item. Return false if the item was suppossed
* to be connected, but an error ocurred.
*
* @note We connect the item under two circumstances: 1.) connect is true, the
* programmer requested it. 2.) Autoconnection is on and the menu is
* attached to a dialog.
*
* If the programmer has both turned on Autoconnection and requests the
* item be connected, then the outcome is undefined. The programmer
* shouldn't do that.
*
* @assumes id is a resource ID and not a by position ID. This menu is a menu
* bar.
*/
BOOL CppMenu::maybeConnectItem(uint32_t id, CSTRING text, logical_t connect, CSTRING methodName)
{
BOOL success = TRUE;
char * _methodName = NULL;
bool doAutoConnection = autoConnect && (dlg != TheNilObj);
if ( ! connect && ! doAutoConnection )
{
goto done_out;
}
success = FALSE;
uint32_t rc = 0;
pCPlainBaseDialog pcpbd = NULL;
if ( dlg != TheNilObj )
{
pcpbd = dlgToCSelf(c, dlg);
}
if ( doAutoConnection )
{
if ( connectionMethod == NULL )
{
_methodName = strdup_2methodName(text);
if ( _methodName == NULL )
{
oodSetSysErrCode(c->threadContext, ERROR_NOT_ENOUGH_MEMORY);
goto done_out;
}
// Method name can not be the empty string.
if ( *_methodName == '\0' )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_PARAMETER);
goto done_out;
}
}
else if ( *connectionMethod == '\0' )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_PARAMETER);
goto done_out;
}
rc = _connectItem(pcpbd->enCSelf, c, id, connectionMethod == NULL ? _methodName : connectionMethod);
if ( rc != 0 )
{
oodSetSysErrCode(c->threadContext, rc);
goto done_out;
}
}
if ( connect )
{
if ( methodName == NULL )
{
// We may have already constructed _methodName ...
if ( _methodName == NULL )
{
_methodName = strdup_2methodName(text);
if ( _methodName = NULL )
{
oodSetSysErrCode(c->threadContext, ERROR_NOT_ENOUGH_MEMORY);
goto done_out;
}
// Method name can not be the empty string.
if ( *_methodName == '\0' )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_PARAMETER);
goto done_out;
}
}
methodName = _methodName;
}
else if ( *methodName == '\0' )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_PARAMETER);
goto done_out;
}
// If we have an owner dialog, connect the menu item now, otherwise
// add it to the connection queue.
if ( pcpbd != NULL )
{
rc = _connectItem(pcpbd->enCSelf, c, id, methodName);
if ( rc != 0 )
{
oodSetSysErrCode(c->threadContext, rc);
goto done_out;
}
}
else
{
if ( ! addToConnectionQ(id, methodName) )
{
// Couldn't allocate memory
goto done_out;
}
}
}
success = TRUE;
done_out:
safeFree(_methodName);
return success;
}
/**
* Adds a menu command item to the connection queue so that the command event
* can be connected to a dialog at a later time.
*
* @param id
* @param methodName
*
* @return bool
*
* @remarks Default menu item count is 100, which should be adequate most of
* the time. The idea was to increase the queue using GlobalReAlloc()
* if a programmer is using more menu items.
*
* However, in a real world program where the menu items equal 114,
* GlobalReAlloc() always returns null at the point the queue needs to
* be increased. Testing shows that GlobalAlloc() succeeds in
* allocating the new memory amount. Not sure if that is user error,
* or what. So, for now, we just do it the hard way.
*/
bool CppMenu::addToConnectionQ(uint32_t id, CSTRING methodName)
{
bool result = false;
// If we have never had a connection request, allocate the connecion queue.
if ( ! connectionRequested )
{
connectionQ = (MapItem **)GlobalAlloc(GPTR, DEFAULT_MENUITEM_COUNT * sizeof(MapItem *));
if ( connectionQ == NULL )
{
outOfMemoryException(c->threadContext);
goto done_out;
}
connectionQSize = DEFAULT_MENUITEM_COUNT;
connectionQIndex = 0;
connectionRequested = true;
}
// If the connection queue is full, double its size.
if ( connectionQIndex >= connectionQSize )
{
MapItem **pNew = (MapItem **)GlobalAlloc(GPTR, 2 * connectionQSize * sizeof(MapItem *));
if ( pNew == NULL )
{
releaseConnectionQ();
outOfMemoryException(c->threadContext);
goto done_out;
}
memmove(pNew, connectionQ, connectionQSize * sizeof(MapItem *));
GlobalFree(connectionQ);
connectionQ = pNew;
connectionQSize = 2 * connectionQSize;
}
// Add the new item to the connection queue.
MapItem *m = (MapItem *)GlobalAlloc(GMEM_FIXED, sizeof(MapItem));
if ( m == NULL )
{
releaseConnectionQ();
outOfMemoryException(c->threadContext);
goto done_out;
}
m->id = id;
m->methodName = (char *)GlobalAlloc(GMEM_FIXED, strlen(methodName) + 1);
if ( m->methodName == NULL )
{
GlobalFree(m);
releaseConnectionQ();
outOfMemoryException(c->threadContext);
goto done_out;
}
strcpy(m->methodName, methodName);
connectionQ[connectionQIndex++] = m;
result = true;
done_out:
return result;
}
void CppMenu::releaseConnectionQ()
{
if ( connectionQ == NULL )
{
return;
}
MapItem *m;
for ( size_t i = 0; i < connectionQIndex; i++ )
{
m = connectionQ[i];
if ( m != NULL )
{
if ( m->methodName != NULL )
{
GlobalFree(m->methodName);
}
GlobalFree(m);
}
}
GlobalFree(connectionQ);
connectionQ = NULL;
connectionQSize = 0;
connectionQIndex = 0;
connectionRequested = false;
}
logical_t CppMenu::attachToDlg(RexxObjectPtr dialog, uint32_t countRows)
{
oodResetSysErrCode(c->threadContext);
// Check all of our required conditions.
if ( hMenu == NULL )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_MENU_HANDLE);
goto no_change;
}
if ( ! c->IsOfType(dialog, "PLAINBASEDIALOG") )
{
oodSetSysErrCode(c->threadContext, ERROR_WINDOW_NOT_DIALOG);
goto no_change;
}
if ( dlg != TheNilObj )
{
// Already attached to a dialog.
oodSetSysErrCode(c->threadContext, ERROR_INVALID_FUNCTION);
goto no_change;
}
pCPlainBaseDialog pcpbd = dlgToCSelf(c, dialog);
if ( pcpbd->hDlg == NULL )
{
// Underlying Windows dialog has not been created.
oodSetSysErrCode(c->threadContext, ERROR_INVALID_WINDOW_HANDLE);
goto no_change;
}
if ( c->SendMessage0(dialog, "HASMENUBAR") == TheTrueObj || GetMenu(pcpbd->hDlg) != NULL )
{
// Dialog already has a menu attached. User needs to remove it first.
oodSetSysErrCode(c->threadContext, ERROR_INVALID_WINDOW_STYLE);
goto no_change;
}
RECT r;
uint32_t flags = SWP_NOZORDER | SWP_NOSENDCHANGING | SWP_NOREDRAW | SWP_NOMOVE;
if ( countRows > 0 )
{
GetWindowRect(pcpbd->hDlg, &r);
int32_t newHeight = (r.bottom - r.top) + (countRows * GetSystemMetrics(SM_CYMENU));
SetWindowPos(pcpbd->hDlg, 0, r.left, r.top, r.right - r.left, newHeight, flags);
}
if ( SetMenu(pcpbd->hDlg, hMenu) == 0 )
{
SetWindowPos(pcpbd->hDlg, 0, r.left, r.top, r.right - r.left, r.bottom - r.top, flags);
oodSetSysErrCode(c->threadContext);
goto no_change;
}
dlg = dialog;
dlgHwnd = pcpbd->hDlg;
c->SendMessage1(dlg, "LINKMENU", self);
return checkPendingConnections();
no_change:
return FALSE;
}
logical_t CppMenu::assignToDlg(RexxObjectPtr dialog, logical_t _autoConnect, CSTRING methodName)
{
oodResetSysErrCode(c->threadContext);
logical_t success = FALSE;
if ( hMenu == NULL )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_MENU_HANDLE);
goto done_out;
}
if ( ! c->IsOfType(dialog, "PLAINBASEDIALOG") )
{
oodSetSysErrCode(c->threadContext, ERROR_WINDOW_NOT_DIALOG);
goto done_out;
}
// We don't care if there is already an assigned dialog, we just replace it.
// But, we want to be sure we don't half way replace it.
pCPlainBaseDialog pcpbd = dlgToCSelf(c, dialog);
if ( pcpbd->hDlg == NULL )
{
// Underlying Windows dialog has not been created.
oodSetSysErrCode(c->threadContext, ERROR_INVALID_WINDOW_HANDLE);
goto done_out;
}
dlg = dialog;
dlgHwnd = pcpbd->hDlg;
// _autoConnect could be 0 if it was omitted, or if the programmer actually
// passed in .false.
if ( argExists(2) )
{
if ( ! setAutoConnection(_autoConnect, methodName) )
{
goto done_out;
}
}
success = checkAutoConnect(pcpbd->enCSelf);
done_out:
return success;
}
/**
* Detaches this menu bar from its owner dialog and sets the state of both the
* dialog and this menu bar to not attached.
*
* @param skipChecks If true don't bother checking for an attached dialog, the
* check has already been done.
*
* @return true on success and false on failure.
*
* @note Resets .SystemErrorCode.
*/
BOOL CppMenu::detach(bool skipChecks)
{
oodResetSysErrCode(c->threadContext);
BOOL success = FALSE;
if ( ! skipChecks )
{
if ( ! isMenuBar() || dlg == TheNilObj )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_FUNCTION);
goto done_out;
}
}
success = SetMenu(dlgHwnd, NULL);
if ( ! success )
{
oodSetSysErrCode(c->threadContext);
}
c->SendMessage0(dlg, "UNLINKMENU");
dlg = TheNilObj;
done_out:
return success;
}
/**
* Replaces this menu bar attached to its owner dialog with a new menu bar.
*
* @param newMenuBar The replacement menu bar.
*
* @return The old menu bar on success, or .nil on error
*
* @note Resets .SystemErrorCode.
*/
RexxObjectPtr CppMenu::replace(RexxObjectPtr newMenuBar)
{
oodResetSysErrCode(c->threadContext);
RexxObjectPtr oldMenuBar = TheNilObj;
if ( ! c->IsOfType(newMenuBar, "MENUBAR") )
{
wrongClassException(c->threadContext, 1, "MenuBar");
goto done_out;
}
if ( ! isAttached() )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_FUNCTION);
goto done_out;
}
CppMenu *cMenubar = (CppMenu *)c->ObjectToCSelf(newMenuBar);
if ( SetMenu(dlgHwnd, cMenubar->getHMenu()) == 0 )
{
oodSetSysErrCode(c->threadContext);
goto done_out;
}
oldMenuBar = c->SendMessage1(dlg, "LINKMENU", cMenubar->getSelf());
maybeRedraw(false);
pCEventNotification pcen = dlgToEventNotificationCSelf(c, dlg);
cMenubar->checkAutoConnect(pcen);
done_out:
return oldMenuBar;
}
/**
* Called from the Rexx uninit() method.
*
*/
void CppMenu::uninitMenu()
{
if ( connectionMethod != NULL )
{
LocalFree(connectionMethod);
connectionMethod = NULL;
}
if ( isMenuBar() && dlg != TheNilObj && hMenu != NULL )
{
DestroyMenu(hMenu);
}
}
/**
* Destroys the underlying menu.
*
* Normally this would never be called when the menu is attached to a dialog,
* but if it is attached, it is first detached (any errors from detach() are
* just ignored.)
*
* @return True on success, false on failure.
*
* @note Resets .SystemErrorCode.
*/
BOOL CppMenu::destroy()
{
if ( isMenuBar() && dlg != TheNilObj )
{
detach(true);
}
oodResetSysErrCode(c->threadContext);
BOOL success = DestroyMenu(hMenu);
if ( ! success )
{
oodSetSysErrCode(c->threadContext);
}
hMenu = NULL;
releaseConnectionQ();
// TODO any other clean up need to be done here ???
return success;
}
logical_t CppMenu::setMaxHeight(uint32_t height, logical_t recurse)
{
logical_t success = FALSE;
oodResetSysErrCode(c->threadContext);
MENUINFO mi = {0};
mi.cbSize = sizeof(MENUINFO);
mi.fMask = MIM_MAXHEIGHT;
mi.cyMax = height;
if ( recurse )
{
mi.fMask |= MIM_APPLYTOSUBMENUS;
}
success = SetMenuInfo(hMenu, &mi);
if ( ! success )
{
oodSetSysErrCode(c->threadContext);
}
return success;
}
int CppMenu::getMaxHeight()
{
int result = -1;
oodResetSysErrCode(c->threadContext);
MENUINFO mi = {0};
mi.cbSize = sizeof(MENUINFO);
mi.fMask = MIM_MAXHEIGHT;
if ( GetMenuInfo(hMenu, &mi) == 0 )
{
oodSetSysErrCode(c->threadContext);
}
else
{
result = mi.cyMax;
}
return result;
}
void CppMenu::putSysCommands()
{
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF000), "SC_SIZE");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF010), "SC_MOVE");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF020), "SC_MINIMIZE");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF030), "SC_MAXIMIZE");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF040), "SC_NEXTWINDOW");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF050), "SC_PREVWINDOW");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF060), "SC_CLOSE");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF070), "SC_VSCROLL");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF080), "SC_HSCROLL");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF090), "SC_MOUSEMENU");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF100), "SC_KEYMENU");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF110), "SC_ARRANGE");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF120), "SC_RESTORE");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF130), "SC_TASKLIST");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF140), "SC_SCREENSAVE");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF150), "SC_HOTKEY");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF160), "SC_DEFAULT");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF170), "SC_MONITORPOWER");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF180), "SC_CONTEXTHELP");
c->DirectoryPut(TheConstDir, c->UnsignedInt32(0xF00F), "SC_SEPARATOR");
}
/**
* Finishes up the .SystemMenu init().
*
* @param dialog The Rexx dialog object.
*
* @return bool
*
* @remarks The caller has ensured that dialog is a .PlainBaseDialog. We
* ensure that the underlying Windows dialog has been created.
*/
bool CppMenu::setUpSysMenu(RexxObjectPtr dialog)
{
oodResetSysErrCode(c->threadContext);
bool success = false;
pCPlainBaseDialog pcpbd = dlgToCSelf(c, dialog);
if ( pcpbd->hDlg == NULL )
{
failedToRetrieveException(c->threadContext, "window handle", dialog);
goto done_out;
}
hMenu = GetSystemMenu(pcpbd->hDlg, FALSE);
if ( hMenu == NULL || ! IsMenu(hMenu) )
{
hMenu = NULL;
failedToRetrieveException(c->threadContext, "system menu", dialog);
goto done_out;
}
dlg = dialog;
dlgHwnd = pcpbd->hDlg;
putSysCommands();
success = true;
// TODO need to think about putting this Rexx object in the data word of the menu.
done_out:
return success;
}
logical_t CppMenu::revertSysMenu()
{
oodResetSysErrCode(c->threadContext);
logical_t success = FALSE;
if ( hMenu == NULL )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_MENU_HANDLE);
goto done_out;
}
if ( connectionMethod != NULL )
{
LocalFree(connectionMethod);
connectionMethod = NULL;
}
// It looks as though the system destroys the existing menu handle on its own.
GetSystemMenu(dlgHwnd, TRUE);
success = TRUE;
done_out:
hMenu = NULL;
dlg = TheNilObj;
dlgHwnd = NULL;
return success;
}
/**
* If the menu is a menu bar attached to a dialog, has the Window redraw the
* menu bar.
*
* @param failOnNoDlg If not being attached to a dialog is considered an error
* or no. Usually it is not an error, that's why it is
* *maybe* redraw. But in some cases, the caller may want
* an error if there is no owener dialog.
*
* @return True for no error, false otherwise.
*
* @assumes The caller has already reset .SystemErrorCode to 0 and is only
* calling this function when not in an error state. If DrawMenuBar()
* fails, this function then sets .SystemErrorCode. This seems
* unlikely.
*/
BOOL CppMenu::maybeRedraw(bool failOnNoDlg)
{
BOOL success = TRUE;
if ( dlg != TheNilObj && isMenuBar() )
{
success = DrawMenuBar(dlgHwnd);
if ( ! success )
{
oodSetSysErrCode(c->threadContext);
}
}
else if ( failOnNoDlg )
{
success = FALSE;
oodSetSysErrCode(c->threadContext, ERROR_INVALID_FUNCTION);
}
return success;
}
logical_t CppMenu::connectCommandEvent(RexxObjectPtr rxID, CSTRING methodName, RexxObjectPtr dialog)
{
logical_t success = FALSE;
pCEventNotification pcen = basicConnectSetup(dialog);
if ( pcen == NULL )
{
goto done_out;
}
int32_t id = oodGlobalID(c, rxID, 1, true);
if ( id == OOD_ID_EXCEPTION )
{
goto done_out;
}
if ( *methodName == '\0' )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_PARAMETER);
goto done_out;
}
uint32_t rc;
if ( isSystemMenu() )
{
rc = _connectSysItem(pcen, c, id, methodName);
}
else
{
rc = _connectItem(pcen, c, id, methodName);
}
if ( rc == 0 )
{
success = TRUE;
}
else
{
oodSetSysErrCode(c->threadContext, rc);
}
done_out:
return success;
}
logical_t CppMenu::connectAllCommandEvents(CSTRING methodName, RexxObjectPtr dialog)
{
logical_t success = FALSE;
pCEventNotification pcen = basicConnectSetup(dialog);
if ( pcen == NULL )
{
goto done_out;
}
// We can just pass methodName along. If it was omitted, it is NULL, and
// menuConnectItems() handles that correctly.
uint32_t rc = menuConnectItems(hMenu, pcen, c, methodName, isSystemMenu());
if ( rc == 0 )
{
success = TRUE;
}
else
{
oodSetSysErrCode(c->threadContext, rc);
}
done_out:
return success;
}
logical_t CppMenu::connectSomeCommandEvents(RexxObjectPtr rxItemIds, CSTRING method, logical_t byPosition,
RexxObjectPtr _dlg)
{
logical_t success = FALSE;
uint32_t *ids = NULL;
char *name = NULL;
pCEventNotification pcen = basicConnectSetup(_dlg);
if ( pcen == NULL )
{
goto done_out;
}
if ( ! c->IsOfType(rxItemIds, "COLLECTION") )
{
wrongClassException(c->threadContext, 1, "Collection");
goto done_out;
}
// The 'method' argument is optional in the Rexx method, so NULL is okay.
// But, if the user does supply a method name, it can not be the emptry
// strin.
if ( method != NULL && *method == '\0' )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_PARAMETER);
goto done_out;
}
size_t count;
ids = getAllIDs(rxItemIds, &count, byPosition);
if ( ids == NULL )
{
goto done_out;
}
uint32_t id;
uint32_t rc;
char buf[256];
MENUITEMINFO mii;
for ( size_t i = 0; i < count; i++ )
{
id = ids[i];
// We don't want to connect the item if it is not a menu command item,
// so we go ahead and get the menu item text, even though we might not
// use it. That gives us access to a filled in mii to use to check the
// type of the menu item.
if ( ! getItemText(id, byPosition, buf, sizeof(buf), &mii) )
{
goto done_out;
}
if ( _isSeparator(&mii) || _isSubMenu(&mii) )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_PARAMETER);
goto done_out;
}
if ( method == NULL )
{
name = strdup_2methodName(buf);
if ( name == NULL )
{
oodSetSysErrCode(c->threadContext, ERROR_NOT_ENOUGH_MEMORY);
goto done_out;
}
// If the programmer used a menu name like "..." we now have the
// empty string. This is an error, but it might be hard for the
// programmer to figure what the problem is.
if ( *name == '\0' )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_PARAMETER);
goto done_out;
}
}
if ( isSystemMenu() )
{
rc = _connectSysItem(pcen, c, id, method == NULL ? name : method);
}
else
{
rc = _connectItem(pcen, c, id, method == NULL ? name : method);
}
if ( rc != 0 )
{
oodSetSysErrCode(c->threadContext, rc);
goto done_out;
}
}
success = TRUE;
done_out:
safeFree(ids);
safeFree(name);
return success;
}
#define MENU_MESSAGE_KEYWORDS "INITMENU, INITMENUPOPUP, or CONTEXTMENU"
uint32_t CppMenu::string2WM(CSTRING keyWord)
{
uint32_t wm = 0;
if ( stricmp(keyWord, "CONTEXTMENU") == 0 )
{
wm = WM_CONTEXTMENU;
}
else if ( stricmp(keyWord, "INITMENU") == 0 )
{
wm = WM_INITMENU;
}
else if ( stricmp(keyWord, "INITMENUPOPUP") == 0 )
{
wm = WM_INITMENUPOPUP;
}
return wm;
}
logical_t CppMenu::connectMenuMessage(CSTRING methodName, CSTRING keyWord, HWND hFilter, RexxObjectPtr dialog)
{
logical_t success = FALSE;
pCEventNotification pcen = basicConnectSetup(dialog);
if ( pcen == NULL )
{
goto done_out;
}
uint32_t windowMessage = string2WM(keyWord);
if ( windowMessage == 0 )
{
wrongArgValueException(c->threadContext, 2, MENU_MESSAGE_KEYWORDS, keyWord);
return FALSE;
}
uint32_t tag = TAG_DIALOG;
switch ( windowMessage )
{
case WM_CONTEXTMENU :
{
tag |= TAG_CONTEXTMENU;
if ( hFilter != NULL )
{
success = addMiscMessage(pcen, c, WM_CONTEXTMENU, UINT32_MAX, (WPARAM)hFilter, UINTPTR_MAX, 0, 0, methodName, tag);
}
else
{
success = addMiscMessage(pcen, c, WM_CONTEXTMENU, UINT32_MAX, 0, 0, 0, 0, methodName, tag);
}
}
break;
case WM_INITMENU :
tag |= TAG_MENUMESSAGE;
success = addMiscMessage(pcen, c, WM_INITMENU, UINT32_MAX, (WPARAM)hMenu, UINTPTR_MAX, 0, 0, methodName, tag);
break;
case WM_INITMENUPOPUP :
tag |= TAG_MENUMESSAGE;
if ( isMenuBar() )
{
if ( hFilter != NULL )
{
// This will trap WM_INITPOPUP messages for the specified submenu.
success = addMiscMessage(pcen, c, WM_INITMENUPOPUP, UINT32_MAX, (WPARAM)hFilter, UINTPTR_MAX, 0, 0, methodName, tag);
}
else
{
// This will trap all WM_INITPOPU messages sent to the dialog the menubar is attached to.
success = addMiscMessage(pcen, c, WM_INITMENUPOPUP, UINT32_MAX, 0, 0, 0, 0, methodName, tag);
}
}
else
{
// This will trap only WM_INITPOPUP messages for *this* menu.
success = addMiscMessage(pcen, c, WM_INITMENUPOPUP, UINT32_MAX, (WPARAM)hMenu, UINTPTR_MAX, 0, 0, methodName, tag);
}
break;
default :
break;
}
if ( ! success )
{
oodSetSysErrCode(c->threadContext, ERROR_NOT_ENOUGH_MEMORY);
}
done_out:
return success;
}
pCEventNotification CppMenu::basicConnectSetup(RexxObjectPtr dialog)
{
oodResetSysErrCode(c->threadContext);
pCEventNotification pcen = NULL;
if ( hMenu == NULL )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_MENU_HANDLE);
goto done_out;
}
if ( dialog == NULLOBJECT )
{
if ( dlg == TheNilObj )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_FUNCTION);
goto done_out;
}
dialog = dlg;
}
else
{
if ( ! c->IsOfType(dialog, "PLAINBASEDIALOG") )
{
oodSetSysErrCode(c->threadContext, ERROR_WINDOW_NOT_DIALOG);
goto done_out;
}
}
pcen = dlgToEventNotificationCSelf(c, dialog);
done_out:
return pcen;
}
logical_t CppMenu::getItemText(uint32_t id, logical_t byPosition, char *text, uint32_t cch, MENUITEMINFO *mii)
{
// MIIM_FTYPE and MIIM_SUBMENU are added so the caller can determine the
// type of the menu item.
ZeroMemory(mii, sizeof(MENUITEMINFO));
mii->cbSize = sizeof(MENUITEMINFO);
mii->fMask = MIIM_STRING | MIIM_FTYPE | MIIM_SUBMENU;
mii->dwTypeData = (LPSTR)text;
mii->cch = cch;
if ( GetMenuItemInfo(hMenu, id, (BOOL)byPosition, mii) == 0 )
{
oodSetSysErrCode(c->threadContext);
return FALSE;
}
return TRUE;
}
/**
* Checks whether there are menu items to be connected to the owner / assigned
* dialog, and, if so, makes the connections.
*
* @return True on success, false if an error happend while making a connection.
*
* @note If an error occurs, then .SystemErrorCode gets set. If there is
* 'connectionRequested' then on return the connection queue has been
* released, even if there was an error.
*
* @assumes This method is *only* called when there is an owner dialog.
*/
BOOL CppMenu::checkPendingConnections()
{
BOOL result = FALSE;
uint32_t rc = 0;
pCEventNotification pcen = dlgToEventNotificationCSelf(c, dlg);
if ( connectionRequested )
{
MapItem *m;
for ( size_t i = 0; i < connectionQIndex ; i++ )
{
m = connectionQ[i];
// We could run out of message table entries.
rc = _connectItem(pcen, c, m->id, m->methodName);
if ( rc != 0 )
{
oodSetSysErrCode(c->threadContext, rc);
break;
}
}
releaseConnectionQ();
if ( rc != 0 )
{
goto done_out;
}
}
result = checkAutoConnect(pcen);
done_out:
return result;
}
BOOL CppMenu::checkAutoConnect(pCEventNotification pcen)
{
if ( autoConnect )
{
uint32_t rc = menuConnectItems(hMenu, pcen, c, connectionMethod, isSystemMenu());
if ( rc != 0 )
{
oodSetSysErrCode(c->threadContext, rc);
return FALSE;
}
}
return TRUE;
}
/**
* Initially sets, or changes, the autoconnection status.
*
* @param on Set autoconnection on or off.
* @param methodName A method name to connect all the items to one method.
*
* @return True on success, false on error. The only error would be a memory
* allocation error.
*
* @remarks In order to allow the user to change the current status of
* autoconnection, we allow the method name to be the empty string.
* When changing the current status, if the user omits the method name
* argument, then connectionMethod is left alone. That is, if there
* is already a method name, it is left the same, if it is null it is
* left null.
*
* However, if there is already a method name set, but the user wants
* to change that to no method name, (which means each menu item is
* connected to a unique method based on the text of the item,) that
* can be done by passing in the empty string.
*/
bool CppMenu::setAutoConnection(logical_t on, CSTRING methodName)
{
if ( on )
{
autoConnect = true;
if ( methodName != NULL )
{
size_t len = strlen(methodName);
if ( connectionMethod != NULL )
{
LocalFree(connectionMethod);
connectionMethod = NULL;
}
// If len is 0, we're done. The existing method name, if it
// existed, is removed.
if ( len > 0 )
{
connectionMethod = (char *)LocalAlloc(LPTR, len + 1);
if ( connectionMethod == NULL )
{
return false;
}
}
}
}
else
{
autoConnect = false;
if ( connectionMethod != NULL )
{
LocalFree(connectionMethod);
connectionMethod = NULL;
}
}
return true;
}
/**
* This is the implemntation for both popMenu_track and popMenu_show. See the
* documentation for either one of those native methods.
*
* @param location
* @param opts
* @param bothButtons
* @param excludeRect
* @param doTrack
*
* @return RexxObjectPtr
*
* @remarks The TrackPopupEx() function needs to run in the same thread as the
* window loop, so we use SendMessage with our own user method. We
* set up a TRACKPOP structure to pass on the parameters that
* TrackPopupEx() needs.
*
* NOTE that currently the Rexx event handler method is invoked using
* invokeDispatch(), so the event handler *is* running in a different
* thread. If that should change for some reason, then we need to
* check here for the thread ID and determine whether or not to use
* SendMessage().
*
* TrackPopupEx expects screen coordinates, be sure to document that
* and how to use dlg~clientToScreen() to get the right values. Also
* note that MS doc on WM_CONTEXTMENU is wrong. x value is in low
* word, not high word of LPARAM. TODO FIXME remove this comment and
* put into doc.
*
*/
RexxObjectPtr CppMenu::trackPopup(RexxObjectPtr location, RexxObjectPtr _dlg, CSTRING opts,
logical_t bothButtons, RexxObjectPtr excludeRect, bool doTrack)
{
oodResetSysErrCode(c->threadContext);
RexxObjectPtr result = TheNegativeOneObj;
TRACKPOP tp = {0};
TPMPARAMS tpm;
HWND ownerWindow;
if ( _dlg == NULLOBJECT )
{
if ( dlg == TheNilObj )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_FUNCTION);
goto done_out;
}
ownerWindow = dlgHwnd;
}
else
{
if ( ! c->IsOfType(_dlg, "PLAINBASEDIALOG") )
{
oodSetSysErrCode(c->threadContext, ERROR_WINDOW_NOT_DIALOG);
goto done_out;
}
pCPlainBaseDialog pcpbd = dlgToCSelf(c, _dlg);
ownerWindow = pcpbd->hDlg;
if ( ownerWindow == NULL )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_WINDOW_HANDLE);
goto done_out;
}
// TODO revisit - should we now make this passed in dialog the internal
// assigned dialog? Depends on what is easier for the user, but I'm not
// sure what would be easier for the user ???
}
POINT *p = rxGetPoint(c, location, 1);
if ( p == NULL )
{
goto done_out;
}
memcpy(&tp.point, p, sizeof(POINT));
if ( hMenu == NULL )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_MENU_HANDLE);
goto done_out;
}
tp.hMenu = hMenu;
tp.hWnd = ownerWindow;
uint32_t flags = 0;
if ( opts != NULL )
{
flags = getTrackFlags(opts);
}
else
{
flags = TPM_RIGHTALIGN | TPM_BOTTOMALIGN;
}
tp.flags = flags;
tp.flags |= (bothButtons ? TPM_RIGHTBUTTON : TPM_LEFTBUTTON);
if ( doTrack )
{
tp.flags |= TPM_NONOTIFY | TPM_RETURNCMD;
}
if ( excludeRect != NULLOBJECT )
{
PRECT exclude = rxGetRect(c, excludeRect, 5);
if ( exclude == NULL )
{
goto done_out;
}
tpm.cbSize = sizeof(TPMPARAMS);
memcpy(&tpm.rcExclude, exclude, sizeof(RECT));
tp.lptpm = &tpm;
}
// If TPM_RETURNCMD is specified, the return is the menu item selected,
// otherwise the return is true or false for success, or not. If the return
// is BOOL and failed, then tp.dwErr has been set with GetLastError().
uint32_t ret = (uint32_t)SendMessage(tp.hWnd, WM_USER_CONTEXT_MENU, (WPARAM)&tp, 0);
if ( doTrack )
{
result = c->UnsignedInt32(ret);
}
else
{
if ( ret == TRUE )
{
result = TheTrueObj;
}
else
{
oodSetSysErrCode(c->threadContext, tp.dwErr);
result = TheFalseObj;
}
}
done_out:
return result;
}
/**
* Produces a string consisting of a series of keywords that describe the
* (presumed) menu item.
*
* @param type The fType member of the MENUITEMINFO structure.
*
* @param strptr [in / out] Pointer to a buffer for the returned string.
*
* @return No return
*/
void itemType2String(MENUITEMINFO *mii, char *strptr)
{
UINT type = mii->fState;
strptr[0] = '\0';
if ( _isSeparator(mii) )
{
strcat(strptr, "SEPARATOR");
}
else if ( _isCommandItem(mii) )
{
strcat(strptr, "COMMAND");
}
else if ( _isSubMenu(mii) )
{
strcat(strptr, "SUBMENU");
}
if ( type & MFT_MENUBARBREAK)
{
strcat(strptr, " MENUBARBREAK");
}
if ( type & MFT_MENUBREAK )
{
strcat(strptr, " MENUBREAK");
}
if ( type & MFT_OWNERDRAW )
{
strcat(strptr, " OWNERDRAW");
}
if ( type & MFT_RADIOCHECK )
{
strcat(strptr, " RADIO");
}
if ( type & MFT_RIGHTJUSTIFY )
{
strcat(strptr, " RIGHTJUSTIFY");
}
if ( type & MFT_RIGHTORDER )
{
strcat(strptr, " RIGHTORDER");
}
if ( mii->hbmpItem != NULL )
{
strcat(strptr, " BITMAP");
}
if ( mii->cch != 0 )
{
strcat(strptr, " STRING");
}
}
void itemState2String(UINT state, char *strptr, bool isSep, bool isPop)
{
strptr[0] = '\0';
if ( isSep )
{
return;
}
if ( ! isPop )
{
if ( state & MFS_CHECKED )
{
strcat(strptr, "CHECKED");
}
else
{
strcat(strptr, "UNCHECKED");
}
}
/* Grayed and disabled flags are equal. */
if ( state & MFS_DISABLED )
{
strcat(strptr, " DISABLED GRAYED");
}
else
{
strcat(strptr, " ENABLED");
}
if ( state & MFS_DEFAULT )
{
strcat(strptr, " DEFAULT");
}
if ( state & MFS_HILITE )
{
strcat(strptr, " HILITE");
}
else
{
strcat(strptr, " UNHILITE");
}
}
RexxObjectPtr itemFlags2String(CppMenu *cMenu, RexxObjectPtr rxItemID, BOOL byPosition, uint32_t idArgPos, uint32_t mask)
{
RexxObjectPtr result = TheNegativeOneObj;
MENUITEMINFO mii;
if ( ! getMII(cMenu, rxItemID, (BOOL)byPosition, idArgPos, NULL, mask, &mii) )
{
goto done_out;
}
char buf[256];
if ( mask == MIIM_STATE )
{
itemState2String(mii.fState, buf, _isSeparator(&mii), _isSubMenu(&mii));
}
else
{
itemType2String(&mii, buf);
}
result = cMenu->getContext()->CString(buf);
done_out:
return result;
}
static bool getMII(CppMenu *cMenu, RexxObjectPtr rxItemID, BOOL byPosition, uint32_t idArgPos, uint32_t *pID,
UINT fMask, MENUITEMINFO *mii)
{
bool success = false;
oodResetSysErrCode(cMenu->getThreadContext());
// We add FTYPE and SUBMENU so the caller can determine the type of the item
// if needed.
ZeroMemory(mii, sizeof(MENUITEMINFO));
mii->cbSize = sizeof(MENUITEMINFO);
mii->fMask = fMask | MIIM_FTYPE | MIIM_SUBMENU;
uint32_t itemID = resolveItemID(cMenu->getContext(), rxItemID, byPosition, idArgPos);
if ( itemID == OOD_ID_EXCEPTION )
{
goto done_out;
}
if ( GetMenuItemInfo(cMenu->getHMenu(), itemID, (BOOL)byPosition, mii) == 0 )
{
oodSetSysErrCode(cMenu->getThreadContext());
goto done_out;
}
success = true;
if ( pID != NULL )
{
*pID = itemID;
}
done_out:
return success;
}
/**
* Retrieves the submenu handle of the specified menu item, and optionally the
* ID of that submenu and the resolved position ID if byPosition.
*
* @param cMenu
* @param rxItemID
* @param byPosition
* @param pID
* *param pHMenu
*
* @return The valid handld of the submenu on success, or NULL on failure.
*
* @remarks When GetMenuItemInfo() fails with say, 1456 a menu item was not
* found, the mii.hSubMenu member is null. When GetMenuItemInfo()
* does not fail and mii.hSubMenu is null, then the item id was a
* valid menu item, just not a submenu. ERROR_INVALID_FUNCTION does
* get set, as desired.
*
* There is this one odd behaviour. If the Rexx programmer has gotten
* the handle of a submenu, destroyed the menu, and not removed it
* from the parent menu, then queries for the submenu handle again,
* GetMenuItemInfo() will return a handle, but the handle will not be
* a valid menu item. This screws up the logic in a number of places,
* so when the submenu handle is not null, there is an added check
* that the handle is a valid menu handle.
*/
HMENU getSubMenuHandle(CppMenu *cMenu, RexxObjectPtr rxItemID, logical_t byPosition, uint32_t *pID, uint32_t *pPositionID)
{
oodResetSysErrCode(cMenu->getThreadContext());
MENUITEMINFO mii = {0};
uint32_t itemID = resolveItemID(cMenu->getContext(), rxItemID, byPosition, 1);
if ( itemID == OOD_ID_EXCEPTION )
{
goto done_out;
}
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_SUBMENU | MIIM_ID;
if ( GetMenuItemInfo(cMenu->getHMenu(), itemID, (BOOL)byPosition, &mii) == 0 )
{
oodSetSysErrCode(cMenu->getThreadContext());
goto done_out;
}
if ( mii.hSubMenu == NULL )
{
oodSetSysErrCode(cMenu->getThreadContext(), ERROR_INVALID_FUNCTION);
goto done_out;
}
if ( ! IsMenu(mii.hSubMenu) )
{
oodSetSysErrCode(cMenu->getThreadContext(), ERROR_INVALID_MENU_HANDLE);
mii.hSubMenu = NULL;
goto done_out;
}
if ( pID != NULL )
{
*pID = mii.wID;
}
if ( pPositionID != NULL && byPosition )
{
*pPositionID = itemID;
}
done_out:
return mii.hSubMenu;
}
/**
* Given a Rexx object that could be a numeric by position ID, a numeric
* resource ID, or a symbolic ID, resolves it to its unsigned int value, or
* raised an exception if it is not valid.
*
* Most of the menu methods that set or modify information about menu items can
* use either the resource ID of the menu item, or its numeric position. This
* function determines if the item ID is its item position, and if not,
* resolves it symbolic ID, if needed.
*
* Menu item positions are zero-based, we use 1-based for Rexx.
*
* @param rxItemID The item ID which could be a number or a symbolic ID.
*
* @param byPosition If true, item ID must be a non-negative number. If false,
* the item ID must be a valid resource ID.
*
* @param argPos The argument position of rxItemId, used for raised
* exceptions.
*
* @return The resolved number.
*
* @remarks. Note in the code below, if ooResolveSymbolicID() returns
* OOD_ID_EXCEPTION, the exception has already been raised and it
* does not matter what is returned. So, the return need not be
* checked.
*/
static uint32_t resolveItemID(RexxMethodContext *c, RexxObjectPtr rxItemID, logical_t byPosition, size_t argPos)
{
uint32_t itemID = OOD_ID_EXCEPTION;
if ( byPosition )
{
if ( ! c->UnsignedInt32(rxItemID, &itemID) || itemID == 0 )
{
notPositiveException(c->threadContext, argPos, rxItemID);
goto done_out;
}
itemID--;
}
else
{
itemID = (uint32_t)oodGlobalID(c, rxItemID, argPos, true);
}
done_out:
return itemID;
}
/**
* Determines if the menu item specified is a separator, a submenu, or a
* command item.
*
* @param cMenu
* @param rxItemID
* @param byPosition
* @param type
*
* @return BOOL
*
* @note The MF_STRING flag is misleading in that command items could be a
* bitmap only, and submenus could also be a string type. The flag is
* used here internally to signal that we are looking to determine if the
* menu item is a command item.
*
* TODO - I believe that the item ID is *always* Rexx arg 1. If so we could
* eliminate a lot of passing around idArgPos.
*/
BOOL isType(CppMenu *cMenu, RexxObjectPtr rxItemID, logical_t byPosition, uint32_t idArgPos, uint32_t type)
{
BOOL result = FALSE;
MENUITEMINFO mii;
// getMII() will have raised an exception for a bad ID and already set
// .SystemErrorCode for any other error. If an exception is already raised,
// we just let it pass through, otherwise we raise our own.
if ( ! getMII(cMenu, rxItemID, (BOOL)byPosition, idArgPos, NULL, MIIM_FTYPE, &mii) )
{
if ( ! cMenu->getContext()->CheckCondition() )
{
systemServiceExceptionCode(cMenu->getThreadContext(), API_FAILED_MSG, "GetMenuItemInfo",
oodGetSysErrCode(cMenu->getThreadContext()));
}
goto done_out;
}
switch ( type )
{
case MF_SEPARATOR :
result = _isSeparator(&mii);
break;
case MF_STRING :
result = _isCommandItem(&mii);
break;
default :
result = _isSubMenu(&mii);
break;
}
done_out:
return result;
}
/**
* Deletes the specified menu item, if and only if the menu item is the correct
* type.
*
* @param cMenu
* @param rxItemID
* @param byPosition
* @param type
*
* @return BOOL
*
* @note The type argument is one of: MF_POPUP, MF_STRING, or MF_SEPARATOR.
* Assumes the caller has made sure of that.
*
* Unfortunately, it appears DeleteMenu() is an older API that does not
* delete a separator by ID, only by position. So, if this is a delete
* separator by ID, we just do a recursive search for the separator and
* delete it by position when it is found.
*/
BOOL deleteMenuItem(CppMenu *cMenu, RexxObjectPtr rxItemID, logical_t byPosition, uint32_t idArgPos, uint32_t type)
{
BOOL success = FALSE;
uint32_t itemID;
MENUITEMINFO mii;
if ( ! getMII(cMenu, rxItemID, (BOOL)byPosition, idArgPos, &itemID, MIIM_FTYPE, &mii) )
{
goto done_out;
}
switch ( type )
{
case MF_SEPARATOR:
if ( ! _isSeparator(&mii) )
{
oodSetSysErrCode(cMenu->getThreadContext(), ERROR_INVALID_FUNCTION);
goto done_out;
}
if ( ! byPosition )
{
uint32_t rc = deleteSeparatorByID(cMenu->getHMenu(), itemID);
if ( rc == 0 )
{
oodSetSysErrCode(cMenu->getThreadContext(), ERROR_MENU_ITEM_NOT_FOUND);
}
else if ( rc == (uint32_t)-1 )
{
success = TRUE;
cMenu->maybeRedraw(false);
}
else
{
oodSetSysErrCode(cMenu->getThreadContext(), rc);
}
goto done_out;
}
break;
case MF_STRING :
if ( ! _isCommandItem(&mii) )
{
oodSetSysErrCode(cMenu->getThreadContext(), ERROR_INVALID_FUNCTION);
goto done_out;
}
break;
default :
if ( ! _isSubMenu(&mii) )
{
oodSetSysErrCode(cMenu->getThreadContext(), ERROR_INVALID_FUNCTION);
goto done_out;
}
break;
}
success = DeleteMenu(cMenu->getHMenu(), itemID, byPositionFlag(byPosition));
if ( ! success )
{
oodSetSysErrCode(cMenu->getThreadContext());
goto done_out;
}
cMenu->maybeRedraw(false);
done_out:
return success;
}
/**
* Checks that the state of the specified menu item is the same as the state
* specified.
*
* @param cMenu
* @param rxItemID
* @param byPosition
* @param state
*
* @return BOOL
*/
BOOL checkState(CppMenu *cMenu, RexxObjectPtr rxItemID, logical_t byPosition, uint32_t idArgPos, uint32_t state)
{
BOOL result = FALSE;
MENUITEMINFO mii;
if ( ! getMII(cMenu, rxItemID, (BOOL)byPosition, idArgPos, NULL, MIIM_STATE, &mii) )
{
if ( ! cMenu->getContext()->CheckCondition() )
{
systemServiceExceptionCode(cMenu->getThreadContext(), API_FAILED_MSG, "GetMenuItemInfo",
oodGetSysErrCode(cMenu->getThreadContext()));
}
goto done_out;
}
result = (mii.fState & state);
done_out:
return result;
}
/**
* Given a single item ID, or a collection of item IDs, returns an array
* containing all the resolved item IDs. (I.e., RexxObject -> uint32_t)
*
*
* @param rxItemIDs
* @param items [in / out] The number of items in the final array is
* returned here.
* @param byPosition
*
* @return NULL on failure, otherwise a pointer to the array of IDs. When NULL
* is returned, an exception has been raised.
*
* @remarks The itemID arg position in all the native API functions is always
* 1.
*/
uint32_t *CppMenu::getAllIDs(RexxObjectPtr rxItemIDs, size_t *items, logical_t byPosition)
{
size_t count = 0;
uint32_t *result = NULL;
uint32_t itemID;
bool isCollection = false;
RexxArrayObject rxIDs = NULLOBJECT;
if ( c->IsOfType(rxItemIDs, "COLLECTION") )
{
isCollection = true;
rxIDs = (RexxArrayObject)c->SendMessage0(rxItemIDs, "MAKEARRAY");
if ( rxIDs == NULLOBJECT )
{
// A condition should already be raised, but it could be cryptic to
// the programmer. Better to use our own.
c->ClearCondition();
doOverException(c->threadContext, rxItemIDs);
goto done_out;
}
count = c->ArrayItems(rxIDs);
if ( count == 0 )
{
emptyArrayException(c->threadContext, 1);
goto done_out;
}
}
else
{
itemID = resolveItemID(c, rxItemIDs, byPosition, 1);
if ( itemID == OOD_ID_EXCEPTION )
{
goto done_out;
}
count = 1;
}
result = (uint32_t *)malloc(count * sizeof(uint32_t));
if ( result == NULL )
{
outOfMemoryException(c->threadContext);
goto done_out;
}
*items = count;
if ( isCollection )
{
RexxObjectPtr rxID;
for ( size_t i = 0; i < count; i++ )
{
rxID = c->ArrayAt(rxIDs, i + 1);
itemID = resolveItemID(c, rxID, byPosition, 1);
if ( itemID == OOD_ID_EXCEPTION )
{
free(result);
result = NULL;
goto done_out;
}
result[i] = itemID;
}
}
else
{
*result = itemID;
}
done_out:
return result;
}
/**
* Sets the state of a menu item, or a collection of menu items, where only a
* single state flag is changed. The other state flags, if any, remain
* unchanged.
*
* @param cMenu
* @param rxItemIDs A single item ID or a collection of item IDs.
* @param byPosition
* @param state The state flag to change.
*
* @return True on success, false on failure. Non-fatal errors set the
* .SystemErrorCode.
*/
BOOL setSingleState(CppMenu *cMenu, RexxObjectPtr rxItemIDs, logical_t byPosition, uint32_t state)
{
oodResetSysErrCode(cMenu->getThreadContext());
BOOL success = FALSE;
MENUITEMINFO mii = {0};
mii.cbSize = sizeof(MENUITEMINFO);
size_t count = 0;
uint32_t *ids = cMenu->getAllIDs(rxItemIDs, &count, byPosition);
if ( ids == NULL )
{
goto done_out;
}
uint32_t itemID;
for ( size_t i = 0; i < count; i++)
{
itemID = ids[i];
// First get the existing state and type
mii.fMask = MIIM_STATE | MIIM_FTYPE | MIIM_SUBMENU;
if ( GetMenuItemInfo(cMenu->getHMenu(), itemID, (BOOL)byPosition, &mii) == 0 )
{
oodSetSysErrCode(cMenu->getThreadContext());
goto done_out;
}
/*
if ( _isSeparator(&mii) )
{
oodSetSysErrCode(cMenu->getThreadContext(), ERROR_INVALID_FUNCTION);
goto done_out;
}
*/
mii.fMask = MIIM_STATE;
switch ( state )
{
case MFS_ENABLED :
mii.fState &= ~MFS_DISABLED;
break;
case MFS_DISABLED :
mii.fState |= MFS_DISABLED;
break;
case MFS_CHECKED :
mii.fState |= MFS_CHECKED;
break;
case OOD_MFS_UNCHECKED :
mii.fState &= ~MFS_CHECKED;
break;
case MFS_HILITE :
mii.fState |= MFS_HILITE;
break;
case OOD_MFS_UNHILITE :
mii.fState &= ~MFS_HILITE;
break;
default :
printf("SEVERE ERROR HERE\n");
goto done_out;
break;
}
if ( SetMenuItemInfo(cMenu->getHMenu(), itemID, byPositionFlag(byPosition), &mii) == 0 )
{
oodSetSysErrCode(cMenu->getThreadContext());
goto done_out;
}
}
success = TRUE;
done_out:
safeFree(ids);
return success;
}
/**
* Get or Set the help context ID for a menu or submenu.
*
* @param hMenu Handle of menu or submenu.
* @param helpID The ID to set, ignored if get.
* @param recurse If true, the help ID is also set for all submenus of the
* menu, if false only the specified menu has its help ID set.
* Ignored for get.
* @param id [in / out] The help ID is returned here. This determines if
* it is a get or set. If null then it is a set.
*
* @return 0 on success, a system error code on failure.
*/
static uint32_t menuHelpID(HMENU hMenu, DWORD helpID, BOOL recurse, uint32_t *id)
{
MENUINFO mi = {0};
mi.cbSize = sizeof(MENUINFO);
mi.fMask = MIM_HELPID;
uint32_t rc = 0;
if ( id == NULL )
{
mi.dwContextHelpID = helpID;
if ( recurse )
{
mi.fMask |= MIM_APPLYTOSUBMENUS;
}
if ( SetMenuInfo(hMenu, &mi) == 0 )
{
rc = GetLastError();
}
}
else
{
if ( GetMenuInfo(hMenu, &mi) == 0 )
{
rc = GetLastError();
}
else
{
*id = mi.dwContextHelpID;
}
}
return rc;
}
/**
* Creates a new .PopupMenu object from the supplied information.
*
* @param c The method context we are operating under.
* @param hPopup Menu handle of the popup menu.
* @param rxItemID Possible menu ID as a Rexx object.
*
* @param byPosition Determines if rxItemID can be used as the menu ID. If
* true than rxItemID is a position ID and wID must be used
* as the menu ID.
*
* @param wID Menu ID as a non-Rexx object.
* @param self The Menu object requesting the creation of the popup
* object, the parent menu of the popup.
*
* @return The new PopupMenu object on succes or zero (a Rexx object) on
* failure.
*
* @assumes The caller has already done verification on rxItemID and wID; that
* it is only our duty to pick which one to use, dependent on the
* value of byPosition.
*
* @remarks If hPopup already has a help ID, using 0 in the new() message
* allows the help ID to be retained. It is tempting to think about
* querying hPopup for the help ID, and then using that ID in the
* new() message. This is just a waste of time, it just resets the
* help ID that the menu already has.
*/
RexxObjectPtr newPopupFromHandle(RexxMethodContext *c, HMENU hPopup, RexxObjectPtr rxItemID,
logical_t byPosition, uint32_t wID, RexxObjectPtr self)
{
RexxObjectPtr result = TheZeroObj;
RexxObjectPtr subMenuID = rxItemID;
if ( byPosition )
{
subMenuID = c->UnsignedInt32(wID);
}
RexxObjectPtr popupClass = rxGetContextClass(c, "POPUPMENU");
if ( popupClass == NULLOBJECT )
{
// If this happens things are seriously mangled, exception 98.909 has
// been raised.
goto done_out;
}
RexxArrayObject args = c->ArrayOfThree(subMenuID, TheZeroObj, c->NewPointer(hPopup));
RexxObjectPtr popupMenu = c->SendMessage(popupClass, "NEW", args);
if ( popupMenu == NULLOBJECT )
{
// This is a good error code for this, but how could it happen to begin
// with?
c->ClearCondition();
oodSetSysErrCode(c->threadContext, OR_INVALID_OID);
goto done_out;
}
result = popupMenu;
done_out:
return result;
}
/**
* Gets or sets the dwMenuData member for the specified menu. dwMenuData is
* used to store the Rexx object that represents the Windows menu.
*
* @param c The method context we are operating under.
*
* @param hMenu Windows menu handle
*
* @param data [in / out] Pointer to a RexxObjectPtr.
*
* If the RexxObjectPtr is null, then a GetMenuInfo is done and
* the current value of the dwMenuData is returned here. The
* stored value could very well be null if nothing has been put
* there.
*
* If the RexxObjectPtr is not null, then a SetMenuInfo is done
* and the RexxObjectPtr is stored in the dwMenuData member.
*
* @return True on success, fails on failure. On failure, an exception has been
* raised.
*
* @assumes hMenu is a valid menu handle.
*
* @remarks We want to avoid raising exceptions if possible. As long as hMenu
* is a valid menu handle, then this should never fail. If it does,
* things are seriously wrong and an exception seems wise.
*/
bool menuData(RexxMethodContext *c, HMENU hMenu, RexxObjectPtr *data)
{
MENUINFO mi = {0};
mi.cbSize = sizeof(MENUINFO);
mi.fMask = MIM_MENUDATA;
mi.dwMenuData = (ULONG_PTR)*data;
bool success = true;
if ( mi.dwMenuData == NULL )
{
if ( GetMenuInfo(hMenu, &mi) == 0 )
{
systemServiceExceptionCode(c->threadContext, API_FAILED_MSG, "GetMenuInfo");
success = false;
}
else
{
*data = (RexxObjectPtr)mi.dwMenuData;
}
}
else
{
if ( SetMenuInfo(hMenu, &mi) == 0 )
{
systemServiceExceptionCode(c->threadContext, API_FAILED_MSG, "SetMenuInfo");
success = false;
}
}
return success;
}
/**
* Recursively connects all menu command items in a menu to a method composed of
* the text of the command item, or to the single method name specified by msg.
*
* @param hMenu Handle of menu to connect command items.
* @param pcen EventNotification CSelf for the dialog.
* @param msg Name of the method to connect. When this is null, each
* item is connected to a method name composed from the text
* of the item.
* @param isSysMenu If hMenu is a system menu.
*
* @return 0 on success, the system error code on failure.
*/
static uint32_t menuConnectItems(HMENU hMenu, pCEventNotification pcen, RexxMethodContext *c, CSTRING msg, bool isSysMenu)
{
uint32_t rc = 0;
int count = GetMenuItemCount(hMenu);
MENUITEMINFO mii = {0};
unsigned int miiSize = sizeof(MENUITEMINFO);
unsigned int miiFMask = MIIM_FTYPE | MIIM_SUBMENU;
for ( int i = 0; i < count; i++)
{
ZeroMemory(&mii, miiSize);
mii.cbSize = miiSize;
mii.fMask = miiFMask;
if ( GetMenuItemInfo(hMenu, i, TRUE, &mii) == 0 )
{
return GetLastError();
}
if ( _isSubMenu(&mii) )
{
rc = menuConnectItems(mii.hSubMenu, pcen, c, msg, isSysMenu);
if ( rc != 0 )
{
return rc;
}
}
else if ( _isCommandItem(&mii) )
{
TCHAR buf[256];
mii.fMask = MIIM_ID | MIIM_STRING | MIIM_FTYPE;
mii.cch = sizeof(buf);
mii.dwTypeData = buf;
if ( GetMenuItemInfo(hMenu, i, TRUE, &mii) == 0 )
{
return GetLastError();
}
char *pMsg = (char *)msg;
if ( pMsg == NULL )
{
// strdup_2methodName removes any '&' and the trailing ... if any.
pMsg = strdup_2methodName(mii.dwTypeData);
if ( ! pMsg )
{
return ERROR_NOT_ENOUGH_MEMORY;
}
}
/* Can not use the empty string for a method name. */
if ( *pMsg == '\0' )
{
return ERROR_INVALID_FUNCTION;
}
if ( isSysMenu )
{
rc = _connectSysItem(pcen, c, mii.wID, pMsg);
}
else
{
rc = _connectItem(pcen, c, mii.wID, pMsg);
}
if ( pMsg != msg )
{
safeFree(pMsg);
}
if ( rc != 0 )
{
return rc;
}
}
}
return 0;
}
/**
* Recursively searches for a separator that matches the specified ID, and
* removes that separator when found.
*
* @param hMenu Menu to start the recursive search.
* @param id ID of separator we are looking for.
*
* @return (uint32_t)-1 if found and deleted, 0 if not found and no other
* errors, otherwise a system error code if one happenings.
*
* @note A return of 0 is essentially ERROR_MENU_ITEM_NOT_FOUND.
*/
static uint32_t deleteSeparatorByID(HMENU hMenu, uint32_t id)
{
DWORD rc = 0;
int count = GetMenuItemCount(hMenu);
MENUITEMINFO mii = {0};
unsigned int miiSize = sizeof(MENUITEMINFO);
unsigned int miiFMask = MIIM_FTYPE | MIIM_SUBMENU | MIIM_ID;
for ( int i = 0; i < count; i++)
{
ZeroMemory(&mii, miiSize);
mii.cbSize = miiSize;
mii.fMask = miiFMask;
if ( GetMenuItemInfo(hMenu, i, TRUE, &mii) == 0 )
{
return GetLastError();
}
if ( _isSubMenu(&mii) )
{
rc = deleteSeparatorByID(mii.hSubMenu, id);
if ( rc != 0 )
{
return rc;
}
}
else if ( _isSeparator(&mii) && mii.wID == id )
{
if ( DeleteMenu(hMenu, i, MF_BYPOSITION) == 0 )
{
return GetLastError();
}
return (uint32_t)-1;
}
}
return 0;
}
/**
* Methods for the .Menu mixin class.
*/
#define MENU_CLASS "Menu"
/** Menu::connectCommandEvent() [class]
*
* This class method connects a menu command item event with a method in the
* specified dialog.
*
* @param id The resource ID of the menu item to be connected.
*
* @param methodName The method to connect the menu item to.
*
* @param dlg The dlg to connect the menu item too.
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode on error.
*
* The system error code is set this way in addition to what the OS might
* set:
*
* ERROR_INVALID_PARAMETER(87) -> The method name argument can not be the
* empty string.
*
* ERROR_WINDOW_NOT_DIALOG (1420) -> The dialog argument is not a
* .PlainBaseDialog, (or subclass of course.)
*
* ERROR_NOT_ENOUGH_MEMORY (8) -> The dialog message table is full.
*/
RexxMethod4(logical_t, menu_connectCommandEvent_cls, RexxObjectPtr, rxID, CSTRING, methodName,
RexxObjectPtr, dlg, OSELF, self)
{
logical_t success = FALSE;
bool isSystemMenu = isOfClassType(context, self, "SystemMenu");
pCEventNotification pcen = _getPCEN(context, dlg);
if ( pcen == NULL )
{
goto done_out;
}
int32_t id = oodGlobalID(context, rxID, 1, true);
if ( id == OOD_ID_EXCEPTION )
{
goto done_out;
}
if ( *methodName == '\0' )
{
oodSetSysErrCode(context->threadContext, ERROR_INVALID_PARAMETER);
goto done_out;
}
uint32_t rc;
if ( isSystemMenu )
{
rc = _connectSysItem(pcen, context, id, methodName);
}
else
{
rc = _connectItem(pcen, context, id, methodName);
}
(rc == 0) ? success = TRUE : oodSetSysErrCode(context->threadContext, rc);
done_out:
return success;
}
/** Menu::menuInit() [private]
*
* Sets the menu CSelf.
*
* @param cselfObject The CSelf object for all menus.
*
*/
RexxMethod1(RexxObjectPtr, menu_menuInit_pvt, RexxObjectPtr, cselfObject)
{
context->SetObjectVariable("CSELF", cselfObject);
return NULLOBJECT;
}
/** Menu::uninit()
*
*
*
* @return The handle to the menu this object represents.
*/
RexxMethod1(RexxObjectPtr, menu_uninit, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
#if 1
printf("In UNINIT() of Menu class cMenu=%p\n", cMenu);
#endif
if ( cMenu != NULL )
{
cMenu->uninitMenu();
}
return NULLOBJECT;
}
/** Menu::hMenu() [attribute get]
*
* Gets the hMenu attribute.
*
* @return The handle to the menu this object represents.
*/
RexxMethod1(POINTER, menu_getHMenu, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
return cMenu->getHMenu();
}
/** Menu::wID() [attribute get]
*
* The resource ID of this menu
*
* @return The resource ID, which may be -1 if the ID was not assigned when
* this menu was created.
*/
RexxMethod1(int32_t, menu_wID, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return cMenu->wID;
}
/** Menu::getMenuHandle()
*
* Get the raw menu handle of a popup menu, (a submenu,) of this menu.
*
* @param rxItemID The item ID of the popup. This can be a position ID or a
* resource ID, depending on the value of byPosition.
*
* @param byPosition [optional] Whether the popup is found by ID or by
* position. The default is true, found by position,
*
* @return The menu handle on success, 0 on failure.
*
* @note Sets .SystemErrorCode on failure.
*
* If the item ID specified is not a submenu then the .SystemErrorCode is
* set to:
*
* ERROR_INVALID_PARAMETER (87)
*/
RexxMethod3(POINTER, menu_getMenuHandle, RexxObjectPtr, rxItemID, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return getSubMenuHandle(cMenu, rxItemID, byPosition, NULL, NULL);
}
/** Menu::releaseMenuHandle()
*
* Releases (frees) the operating system resources used by a menu. The menu is
* specified by its raw handle. To release the operating system resources for
* an ooDialog Menu object, use the destroy() method.
*
* @param handle The handle of the menu to release. The handle can be in
* .Pointer format or pointer string (0xffff1111) format. An
* exception is raised if the handle is null.
*
* @return True if the Windows API succeeds, otherwise false.
*
* @remarks Sets .SystemErrorCode.
*/
RexxMethod2(logical_t, menu_releaseMenuHandle, RexxObjectPtr, handle, OSELF, self)
{
oodResetSysErrCode(context->threadContext);
RexxMethodContext *c = context;
HMENU hMenu = NULL;
logical_t success = FALSE;
if ( c->IsPointer(handle) )
{
hMenu = (HMENU)c->PointerValue((RexxPointerObject)handle);
}
else if ( c->IsString(handle) )
{
hMenu = (HMENU)string2pointer(c->ObjectToStringValue(handle));
}
if ( hMenu == NULL )
{
invalidTypeException(context->threadContext, 1, INVALID_MENU_HANDLE_MSG);
}
else
{
if ( DestroyMenu(hMenu) == 0 )
{
oodSetSysErrCode(context->threadContext);
}
else
{
success = TRUE;
}
}
return success;
}
/** Menu::getCount()
*
* Returns the number of items in this menu.
*
* @return The number of items on success, -1 on error.
*
* @note Sets .SystemErrorCode on error.
*/
RexxMethod1(int32_t, menu_getCount, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
oodResetSysErrCode(context->threadContext);
int count = GetMenuItemCount(cMenu->getHMenu());
if ( count == -1 )
{
oodSetSysErrCode(context->threadContext);
}
return count;
}
/** Menu::isValidItemID()
*
* Determines if a specific item ID would be valid for this menu.
*
* In most of the methods for the Menu classes, if an invalid item ID is
* specified, the method will fail and .SystemErrorCode is set to the failure
* reason. However, in some methods there is no way to indicate that the method
* failed. For those methods, a syntax error is raised if the item ID is not
* valid.
*
* The isValidItemID() method can be used by the programmer to check if an item
* ID will raise a syntax error. This gives the programmer the option of:
* setting up a trap handler, checking if a item ID is valid before invoking a
* method, or just let the syntax error be raised.
*
* @param rxItemID The item ID.
*
* @param byPosition [optional] Whether the item ID is a by position ID or a
* resource ID. The default is false, a resource ID, just as
* it is in most methods.
*
* @return True if the item id / by position combination is valid, at this
* point in time, false if it is not valid.
*
* @note Will set the .SystemErrorCode if the item ID is not valid. The code
* should indicate the reason why the ID is not valid.
*
* If the ID is a symbolic ID that can not be resolved, or a position ID
* that is not a valid number, .SystemErrorCode is set to:
*
* ERROR_INVALID_PARAMETER (87)
*/
RexxMethod3(logical_t, menu_isValidItemID, RexxObjectPtr, rxItemID, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
oodResetSysErrCode(context->threadContext);
BOOL result = FALSE;
MENUITEMINFO mii = {0};
uint32_t itemID = resolveItemID(context, rxItemID, byPosition, 1);
if ( context->CheckCondition() )
{
context->ClearCondition();
oodSetSysErrCode(context->threadContext, ERROR_INVALID_PARAMETER);
goto done_out;
}
// The MIIM_FTYPE mask should be valid to query any item in a menu, so we
// shouldn't get an error from some invalid combination of flags.
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_FTYPE;
result = GetMenuItemInfo(cMenu->getHMenu(), itemID, (BOOL)byPosition, &mii);
if ( ! result )
{
oodSetSysErrCode(context->threadContext);
}
done_out:
return result;
}
/** Menu::isValidMenu()
*
* Checks if *this* menu is valid. The menu would not be valid if it has been
* destroyed, deleted, or for some other operating system reason.
*
* @return True if this menu is valid, otherwise false.
*/
RexxMethod1(logical_t, menu_isValidMenu, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return IsMenu(cMenu->getHMenu());
}
/** Menu::isValidMenuHandle()
*
* Checks if the specified handle represents a menu that the operating system
* says is valid.
*
* @param handle The handle to check.
*
* @return True if the menu handle is valid, otherwise false.
*
* @remarks The intention of IsMenu() is to check if a handle is a valid menu
* handle. Since, in ooDialog, we are trying to maintain the concept
* that handles are opaque objects, we need to accept any object for
* handle. Even though, in ooDialog, all menu handles are returned as
* a .Pointer.
*/
RexxMethod1(logical_t, menu_isValidMenuHandle, RexxObjectPtr, handle)
{
return IsMenu((HMENU)oodObj2pointer(context, handle));
}
/** Menu::isSeparator()
*
* Determines if the specified menu item is a separator.
*
* @param itemID The ID of the item to query. This can be a position ID
* or a resource ID, depending on the value of byPosition.
*
* @param byPosition [optional] Whether itemID is a resource ID or a position
* ID. The default is false, a resource ID.
*
* @return True if the item is is a separator, otherwise false.
*
* @note Sets .SystemErrorCode on error and also raises a syntax error, since
* there is no way to indicate failure in the return.
*
* The isValidItemID() can be used to check if the item id is valid prior
* to invoking this method or the condition could be trapped. If the
* condition is trapped or if isValidItemID() returns false, the
* .SystemErrorCode can then be examined for the reason why the item ID
* is not valid.
*/
RexxMethod3(logical_t, menu_isSeparator, RexxObjectPtr, itemID, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return isType(cMenu, itemID, byPosition, 1, MF_SEPARATOR);
}
/** Menu::isCommandItem()
*
* Determines if the specified menu item is a command item.
*
* @param rxItemID The item ID to query. This can be a position ID or a
* resource ID, depending on the value of byPosition.
*
* @param byPosition [optional] If true, rxItemID is a positional ID,
* otherwise it is a resource ID. The default is false.
*
* @return True if the item is is a command item, otherwise false.
*
* @note Sets .SystemErrorCode on error and also raises a syntax error, since
* there is no way to indicate failure in the return.
*
* The isValidItemID() can be used to check if the item id is valid prior
* to invoking this method or the condition could be trapped. If the
* condition is trapped or if isValidItemID() returns false, the
* .SystemErrorCode can then be examined for the reason why the item ID
* is not valid.
*/
RexxMethod3(logical_t, menu_isCommandItem, RexxObjectPtr, rxItemID, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return isType(cMenu, rxItemID, byPosition, 1, MF_STRING);
}
/** Menu::isPopup()
*
* Determines if the specified menu item is a submenu.
*
* @param rxItemID The item ID to query. This can be a position ID or a
* resource ID, depending on the value of byPosition.
*
* @param byPosition [optional] If true, rxItemID is a positional ID,
* otherwise it is a resource ID. The default is false.
*
* @return True if the item is is a submenu, otherwise false.
*
* @note Sets .SystemErrorCode on error and also raises a syntax error, since
* there is no way to indicate failure in the return.
*
* The isValidItemID() can be used to check if the item id is valid prior
* to invoking this method or the condition could be trapped. If the
* condition is trapped or if isValidItemID() returns false, the
* .SystemErrorCode can then be examined for the reason why the item ID
* is not valid.
*/
RexxMethod3(logical_t, menu_isPopup, RexxObjectPtr, rxItemID, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return isType(cMenu, rxItemID, byPosition, 1, MF_POPUP);
}
/** Menu::destroy()
*
* Releases the operating system resources for the menu this .Menu represents.
*
* If the menu is a menubar attached to a dialog it is first detached.
* Normally you would not destroy a menu attached to a window, the operating
* system handles that automatically. It is only when a menu is not attached
* to a window that it needs to be destroyed. This includes popup menus that
* are submenus of the menu, but not popup menus that are 'floating' and
* assigned to a window.
*
* @return True on success, othewise false. The system error code is set on
* failure.
*
* @remarks Sets .SystemErrorCode.
*
* Need some comment for the doc on what the Rexx programmer can
* expect after the menu is destroyed.
*/
RexxMethod1(logical_t, menu_destroy, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return cMenu->destroy();
}
/** Menu::isEnabled()
*
* Determines if the specified menu item is enabled.
*
* @param rxItemID The item ID to query. This can be a position ID or a
* resource ID, depending on the value of byPosition.
*
* @param byPosition [optional] If true, rxItemID is a positional ID,
* otherwise it is a resource ID. The default is false.
*
* @return True if the item is enabled, otherwise false.
*
* @note Sets .SystemErrorCode on error and also raises a syntax error, since
* there is no way to indicate failure in the return. The condition
* could be trapped and .SystemErrorCode examined for the reason. (The
* same code is also in the syntax error message.)
*/
RexxMethod3(logical_t, menu_isEnabled, RexxObjectPtr, rxItemID, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return ! checkState(cMenu, rxItemID, byPosition, 1, MFS_DISABLED);
}
/** Menu::isDisabled()
*
* Determines if the specified menu item is disabled.
*
* @param rxItemID The item ID to query. This can be a position ID or a
* resource ID, depending on the value of byPosition.
*
* @param byPosition [optional] If true, rxItemID is a positional ID,
* otherwise it is a resource ID. The default is false.
*
* @return True if the item is disabled, otherwise false.
*
* @note Sets .SystemErrorCode on error and also raises a syntax error, since
* there is no way to indicate failure in the return. The condition
* could be trapped and .SystemErrorCode examined for the reason. (The
* same code is also in the syntax error message.)
*
* Gray and disabled are equivalent.
*
* @remarks Microsoft now treats grayed and disabled as the same. Disabled
* used to be just disabled, but not grayed. The user had no clue as
* to why the menu item wouldn't work. You can still set that state
* by using an older API. We could add a forceDisable() method, but I
* don't see much use for it.
*/
RexxMethod3(logical_t, menu_isDisabled, RexxObjectPtr, rxItemID, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return checkState(cMenu, rxItemID, byPosition, 1, MFS_DISABLED);
}
/** Menu::isChecked()
*
* Determines if the specified menu item is checked.
*
* @param rxItemID The item ID to query. This can be a position ID or a
* resource ID, depending on the value of byPosition.
*
* @param byPosition [optional] If true, rxItemID is a positional ID,
* otherwise it is a resource ID. The default is false.
*
* @return True if the item is checked, otherwise false.
*
* @note Sets .SystemErrorCode on error and also raises a syntax error, since
* there is no way to indicate failure in the return. The condition
* could be trapped and .SystemErrorCode examined for the reason. (The
* same code is also in the syntax error message.)
*/
RexxMethod3(logical_t, menu_isChecked, RexxObjectPtr, rxItemID, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return checkState(cMenu, rxItemID, byPosition, 1, MFS_CHECKED);
}
/** Menu::enable()
*
* Sets the menu item(s) to enabled. Separators can not be enabled.
*
* @param rxItemIDs The item ID(s) to set enabled. This can be a single ID or
* a collection of IDs. The ID(s) can be position IDs or
* resource IDs, depending on the value of byPosition.
* However, if this is a collection of IDs there must be all
* the same type, all resource IDs or all position IDs.
*
* @param byPosition [optional] If true, rxItemIDs is a positional ID,
* otherwise it is a resource ID. The default is false, a
* resource ID.
*
* @return True on success, otherwise false.
*
* @note Sets .SystemErrorCode on error. If the specified menu item is a
* separator, the system error code is set to:
*
* ERROR_INVALID_FUNCTION (1) -> Incorrect function.
*/
RexxMethod3(logical_t, menu_enable, RexxObjectPtr, rxItemIDs, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return setSingleState(cMenu, rxItemIDs, byPosition, MFS_ENABLED);
}
/** Menu::disable()
*
* Disables one or more menu items. Separators can not be disabled. Note that
* disable and gray are the exact same thing.
*
* @param rxItemIDs The item ID(s) to disabled. This can be a single ID or a
* collection of IDs. The ID(s) can be position IDs or
* resource IDs, depending on the value of byPosition.
* However, if this is a collection of IDs there must be all
* the same type, all resource IDs or all position IDs.
*
* @param byPosition [optional] If true, rxItemIDs is a positional ID,
* otherwise it is a resource ID. The default is false, a
* resource ID.
*
* @return True on success, otherwise false.
*
* @note Sets .SystemErrorCode on error. If the specified menu item is a
* separator, the system error code is set to:
*
* ERROR_INVALID_FUNCTION (1) -> Incorrect function.
*/
RexxMethod3(logical_t, menu_disable, RexxObjectPtr, rxItemIDs, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return setSingleState(cMenu, rxItemIDs, byPosition, MFS_DISABLED);
}
/** Menu::hilite()
*
* Sets a menu item to hilited. Separators can not be hilited. A high lighted
* menu item is drawn as though it were the selected item.
*
* There is not much use for this method, in the author's opinion, but it is
* included for completeness. In addition, this method will accept a collection
* of item IDs, as do the enable(), check(), disable() methods, but it makes
* little sense to hilite more than one menu item at a time.
*
* @param rxItemIDs The item ID(s) to be hilited. This can be a single ID or
* a collection of IDs. The ID(s) can be position IDs or
* resource IDs, depending on the value of byPosition.
* However, if this is a collection of IDs there must be all
* the same type, all resource IDs or all position IDs.
*
* @param byPosition [optional] If true, rxItemIDs is a positional ID,
* otherwise it is a resource ID. The default is false, a
* resource ID.
*
* @return True on success, otherwise false.
*
* @note Sets .SystemErrorCode on error. If the specified menu item is a
* separator, the system error code is set to:
*
* ERROR_INVALID_FUNCTION (1) -> Incorrect function.
*/
RexxMethod3(logical_t, menu_hilite, RexxObjectPtr, rxItemIDs, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return setSingleState(cMenu, rxItemIDs, byPosition, MFS_HILITE);
}
/** Menu::unHilite()
*
* Removes the [hilite {link}] from one or more menu items. Separators can not
* be [hilited {link}] or unHilited.
*
* @param rxItemIDs The item ID(s) to be unHilited. This can be a single ID
* or a collection of IDs. The ID(s) can be position IDs or
* resource IDs, depending on the value of byPosition.
* However, if this is a collection of IDs there must be all
* the same type, all resource IDs or all position IDs.
*
* @param byPosition [optional] If true, rxItemIDs is a positional ID,
* otherwise it is a resource ID. The default is false, a
* resource ID.
*
* @return True on success, otherwise false.
*
* @note Sets .SystemErrorCode on error. If the specified menu item is a
* separator, the system error code is set to:
*
* ERROR_INVALID_FUNCTION (1) -> Incorrect function.
*/
RexxMethod3(logical_t, menu_unHilite, RexxObjectPtr, rxItemIDs, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return setSingleState(cMenu, rxItemIDs, byPosition, OOD_MFS_UNHILITE);
}
/** Menu::check()
*
* Checks one or more menu items. Separators can not be checked.
*
* @param rxItemIDs The item ID(s) to be checked. This can be a single ID or
* a collection of IDs. The ID(s) can be position IDs or
* resource IDs, depending on the value of byPosition.
* However, if this is a collection of IDs there must be all
* the same type, all resource IDs or all position IDs.
*
* @param byPosition [optional] If true, rxItemIDs is a positional ID,
* otherwise it is a resource ID. The default is false, a
* resource ID.
*
* @return True on success, otherwise false.
*
* @note Sets .SystemErrorCode on error. If the specified menu item is a
* separator, the system error code is set to:
*
* ERROR_INVALID_FUNCTION (1) -> Incorrect function.
*/
RexxMethod3(logical_t, menu_check, RexxObjectPtr, rxItemIDs, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return setSingleState(cMenu, rxItemIDs, byPosition, MFS_CHECKED);
}
/** Menu::unCheck()
*
* unChecks one or more menu items. Separators can not be checked or unChecked.
*
* @param rxItemIDs The item ID(s) to be unChecked. This can be a single ID
* or a collection of IDs. The ID(s) can be position IDs or
* resource IDs, depending on the value of byPosition.
* However, if this is a collection of IDs there must be all
* the same type, all resource IDs or all position IDs.
*
* @param byPosition [optional] If true, rxItemIDs is a positional ID,
* otherwise it is a resource ID. The default is false, a
* resource ID.
*
* @return True on success, otherwise false.
*
* @note Sets .SystemErrorCode on error. If the specified menu item is a
* separator, the system error code is set to:
*
* ERROR_INVALID_FUNCTION (1) -> Incorrect function.
*/
RexxMethod3(logical_t, menu_unCheck, RexxObjectPtr, rxItemIDs, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return setSingleState(cMenu, rxItemIDs, byPosition, OOD_MFS_UNCHECKED);
}
/** Menu::checkRadio()
*
* Checks a specified menu item and makes it a radio item. At the same time, the
* function clears all other menu items in the associated group and clears the
* radio-item type flag for those items.
*
* The selected item is displayed using a bullet bitmap instead of a check-mark
* bitmap.
*
* @param start The ID of the first item in the group.
* @param end The ID of the last item in the group.
* @param check The ID of the item to check.
* @param byPosition [optional] Whether the IDs are position IDs or resource
* IDs. The default is resource IDs.
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode on error.
*/
RexxMethod5(logical_t, menu_checkRadio, RexxObjectPtr, start, RexxObjectPtr, end, RexxObjectPtr, check,
OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
oodResetSysErrCode(context->threadContext);
logical_t success = FALSE;
int idStart = resolveItemID(context, start, byPosition, 1);
if ( idStart == OOD_ID_EXCEPTION )
{
goto done_out;
}
int idEnd = resolveItemID(context, end, byPosition, 2);
if ( idEnd == OOD_ID_EXCEPTION )
{
goto done_out;
}
int idCheck = resolveItemID(context, check, byPosition, 3);
if ( idCheck == OOD_ID_EXCEPTION )
{
goto done_out;
}
success = CheckMenuRadioItem(cMenu->getHMenu(), idStart, idEnd, idCheck, byPositionFlag(byPosition));
if ( ! success )
{
oodSetSysErrCode(context->threadContext);
}
done_out:
return success;
}
/** Menu::insertSeparator()
*
* Inserts a separator into this menu at the specified position.
*
* @param before Specifies where the separator is inserted. The separator
* is inserted before this item. If the menu does not have
* any items yet, then any ID, or 0, can be used.
*
* @param rxID The ID for the separator.
*
* @param byPosition [optional] Whether the before ID is a position ID or a
* resource ID. The default is false, a resource ID.
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode on error.
*
* It may seem too much to require that separators have resource IDs, but
* in the long run being able to work with menus and not have to use by
* position is so much easier that it makes sense to require it. Simply
* use 0 for the second argument if you are determined to make things
* hard for yourself.
*/
RexxMethod4(logical_t, menu_insertSeparator, RexxObjectPtr, before, RexxObjectPtr, rxID,
OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
oodResetSysErrCode(context->threadContext);
logical_t success = FALSE;
MENUITEMINFO mii = {0};
uint32_t idBefore = resolveItemID(context, before, byPosition, 1);
if ( idBefore == OOD_ID_EXCEPTION )
{
goto done_out;
}
int32_t id = oodGlobalID(context, rxID, 2, false);
if ( id == OOD_ID_EXCEPTION )
{
goto done_out;
}
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_FTYPE;
mii.fType = MFT_SEPARATOR;
if ( id != 0)
{
mii.fMask |= MIIM_ID;
mii.wID = id;
}
success = InsertMenuItem(cMenu->getHMenu(), idBefore, byPositionFlag(byPosition), &mii);
if ( ! success )
{
oodSetSysErrCode(context->threadContext);
goto done_out;
}
cMenu->maybeRedraw(false);
done_out:
return success;
}
/** Menu::insertItem()
*
* Inserts a new menu command item into this menu.
*
* @param rxBefore The menu command item is inserted before this menu item.
* @param rxID The resource ID for the menu command item.
* @param text The text (label) for the menu command item.
* @param stateOpts [optional] String containing keywords to specify the menu
* command item state.
* @param typeOpts [optional] String containing keywords to specify the menu
* command item type.
* @param byPosition [optional] Whether the before ID is a position ID or a
* resource ID. The default is false, a resource ID.
*
* @param connect [opitional] Whether to automatically connect the command
* item to a method in the owning dialog. This is a <link
* linkend="miConnections">connection request</link> type of
* connection type. Do not mix this with <link
* linkend="miConnections">autoconnection</link>. The default
* is false.
*
* @param methodName [optional] If connect is true, then this is the name of
* the method to connect this menu commanditem to. If this
* argument is omitted and connect is true then the method
* name is automatically constructed from the text for the
* menu item. If connect is false or omitted, this argument
* is ignored. If connect is true and this argument is used
* it can not be the empty string.
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode on error.
*
* The system error code is set this way in addition to what the OS might
* set:
*
* ERROR_INVALID_PARAMETER (87) -> When used, the methodName argument can
* not be the empty string.
*
* @note State keywords: DEFAULT NOTDEFAULT DISABLED GRAYED ENABLED UNCHECKED
* CHECKED HILITE UNHILITE.
*
* By default the state will be set to: ENABLED UNHILITE NOTDEFAULT
* UNCHECKED.
*
* Disabled and grayed are the same thing.
*
* High lighted is the appearance drawn when the mouse is over an item,
* or the keyboard is used to move to the item. When the programmer sets
* an item to HILITE, the item will remain high lighted until the mouse
* comes over it and is then removed, or the keyboard is used to go to
* the item and then move away from it.
*
* A default item is drawn with a bolded appearance.
*
* @note Type keywords: MENUBARBREAK MENUBREAK RIGHTJUSTIFY RADIO. By default
* no special type is set.
*
* RightJustify - Right-justifies the menu item and any subsequent items.
* This value is valid only if the menu item is in a menu bar. It has no
* effect if the item is in a popup menu.
*
* Radio - Displays checked menu items using a radio-button mark instead
* of a check mark.
*
* MenuBarBreak - Places the menu item on a new line (for a menu bar) or
* in a new column (for a drop-down menu, submenu, or shortcut menu). For
* a drop-down menu, submenu, or shortcut menu, a vertical line separates
* the new column from the old.
*
* MenuBreak - This is exactly the same as MenuBarBreak, except that no
* vertical line is drawn between the columns when the item is not in a
* menu bar.
*
* @remarks This function forces the new menu item to have a label and does not
* allow for it to have a bitmap. Menu items are allowed to use
* bitmaps instead of (along with?) text. A future enhancement could
* add support for that.
*
* Note to myself: I did check and verify the HILITE behaviour
*/
RexxMethod9(logical_t, menu_insertItem, RexxObjectPtr, rxBefore, RexxObjectPtr, rxID, CSTRING, text,
OPTIONAL_CSTRING, stateOpts, OPTIONAL_CSTRING, typeOpts, OPTIONAL_logical_t, byPosition,
OPTIONAL_logical_t, connect, OPTIONAL_CSTRING, methodName, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
oodResetSysErrCode(context->threadContext);
BOOL success = FALSE;
MENUITEMINFO mii = {0};
uint32_t idBefore = resolveItemID(context, rxBefore, byPosition, 1);
if ( idBefore == OOD_ID_EXCEPTION )
{
goto done_out;
}
int32_t id = oodGlobalID(context, rxID, 2, true);
if ( id == OOD_ID_EXCEPTION )
{
goto done_out;
}
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STRING | MIIM_ID;
mii.fType = MFT_STRING;
mii.dwTypeData = (LPSTR)text;
mii.wID = id;
if ( argumentExists(4) )
{
mii.fState = getItemStateOpts(stateOpts, 0);
mii.fMask |= MIIM_STATE;
}
if ( argumentExists(5) )
{
mii.fType |= getItemTypeOpts(typeOpts, 0);
mii.fMask |= MIIM_FTYPE;
}
if ( ! InsertMenuItem(cMenu->getHMenu(), idBefore, (BOOL)byPosition, &mii) )
{
oodSetSysErrCode(context->threadContext);
goto done_out;
}
success = TRUE;
cMenu->maybeRedraw(false);
if ( cMenu->isMenuBar() && ! byPosition )
{
success = cMenu->maybeConnectItem(id, text, connect, methodName);
}
done_out:
return success;
}
/** Menu::insertPopup()
*
* Inserts a new popup menu into this menu.
*
* @param rxBefore The popup is inserted before this menu item.
* @param rxID The resource ID for the popup menu.
* @param popup The popup menu being inserted.
* @param text The text (label) for the popup menu.
* @param stateOpts [optional] String containing keywords to specify the popup menu
* state.
* @param typeOpts [optional] String containing keywords to specify the
* popup menu type.
* @param byPosition [optional] Whether the before ID is a position ID or a
* resource ID. The default is false, a resource ID.
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode on error.
*
* @note State keywords: DEFAULT NOTDEFAULT DISABLED GRAYED ENABLED HILITE
* UNHILITE. By default the state will be ENABLED UNHILITE NOTDEFAULT
*
* High lighted is the appearance drawn when the mouse is over an item,
* or the keyboard is used to move to the item. When the programmer sets
* an item to HILITE, the item will remain high lighted until the mouse
* comes over it and is then removed, or the keyboard is used to go to
* the item and then move away from it.
*
* A default item is drawn with a bolded appearance.
*
* @note Type keywords: MENUBARBREAK MENUBREAK RIGHTJUSTIFY RIGHTORDER
*
* RightJustify - Right-justifies the popup menu and any subsequent
* items. This value is valid only if the popup menu is in a menu bar. It
* has no effect if the popup menu is in a submenu.
*
* MenuBarBreak - Places the popup menu on a new line (for a menu bar) or
* in a new column (for a drop-down menu, submenu, or shortcut menu). For
* a drop-down menu, submenu, or shortcut menu, a vertical line separates
* the new column from the old.
*
* MenuBreak - This is exactly the same as MenuBarBreak, except that no
* vertical line is drawn between the columns when the popup menu is not
* in a menu bar.
*
* RightOrder - Specifies that menus cascade right-to-left (the default
* is left-to-right). This is used to support right-to-left languages,
* such as Arabic and Hebrew.
*
* @remarks This function forces the new menu item to have a label and does not
* allow for it to have a bitmap. Menu items and I think submenus are
* allowed to use bitmaps instead of (along with?) text. A future
* enhancement could add support for that.
*
* Note to myself, I have tested this several times, setting a
* submenu's state to checked does nothing. I've tested all other
* keywords, MENUBARBREAK, MENUBREAK, RIGHTJUSTIFY, RIGHTORDER,
* DEFAULT, DISABLED, GRAYED, and HILITE all work.
*/
RexxMethod8(logical_t, menu_insertPopup, RexxObjectPtr, rxBefore, RexxObjectPtr, rxID, RexxObjectPtr, popup, CSTRING, text,
OPTIONAL_CSTRING, stateOpts, OPTIONAL_CSTRING, typeOpts, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
RexxMethodContext *c = context;
RexxObjectPtr self = cMenu->getSelf();
oodResetSysErrCode(context->threadContext);
logical_t success = FALSE;
MENUITEMINFO mii = {0};
uint32_t idBefore = resolveItemID(context, rxBefore, byPosition, 1);
if ( idBefore == OOD_ID_EXCEPTION )
{
goto done_out;
}
if ( ! c->IsOfType(popup, "POPUPMENU") )
{
wrongClassException(context->threadContext, 3, "PopupMenu");
goto done_out;
}
int32_t id = oodGlobalID(context, rxID, 2, true);
if ( id == OOD_ID_EXCEPTION )
{
goto done_out;
}
CppMenu *cPopMenu = (CppMenu *)c->ObjectToCSelf(popup);
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STRING | MIIM_SUBMENU | MIIM_ID;
mii.fType = MFT_STRING;
mii.hSubMenu = cPopMenu->getHMenu();
mii.dwTypeData = (LPSTR)text;
mii.wID = id;
if ( argumentExists(5) )
{
mii.fState = getPopupStateOpts(stateOpts, 0);
mii.fMask |= MIIM_STATE;
}
if ( argumentExists(6) )
{
mii.fType |= getPopupTypeOpts(typeOpts, 0);
mii.fMask |= MIIM_FTYPE;
}
success = InsertMenuItem(cMenu->getHMenu(), idBefore, (BOOL)byPosition, &mii);
if ( ! success )
{
oodSetSysErrCode(context->threadContext);
goto done_out;
}
// TODO Now would be the time to add the popup to the self menu submenu bag (?)
cMenu->maybeRedraw(false);
done_out:
return success;
}
/** Menu::removeSeparator()
*
* Removes (deletes) the specified menu separator from the menu.
*
* @param rxItemID The item id of the separator to remove.
*
* @param byPosition [optional] Whether the separator to be removed is found
* by ID or by position. The default is false, found by
* resource ID.
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode on error. If the specified menu item is not a
* separator, then the system error code is set to:
*
* ERROR_INVALID_FUNCTION (1)
*/
RexxMethod3(logical_t, menu_removeSeparator, RexxObjectPtr, rxItemID, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return deleteMenuItem(cMenu, rxItemID, byPosition, 1, MF_SEPARATOR);
}
/** Menu::removeItem()
*
* Removes (deletes) the specified menu command item from the menu.
*
* @param rxItemID The item id of the command item to remove.
*
* @param byPosition [optional] Whether the command item to be removed is
* found by ID or by position. The default is false, found
* by ID.
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode on error. If the specified menu item is not a
* menu command item, then the system error code is set to:
*
* ERROR_INVALID_FUNCTION (1)
*/
RexxMethod3(logical_t, menu_removeItem, RexxObjectPtr, rxItemID, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return deleteMenuItem(cMenu, rxItemID, byPosition, 1, MF_STRING);
}
/** Menu::removePopup()
*
* Removes, but does not delete, the specified popup menu from the menu. See
* deleteMenu() for a discussion of the distinction between removing and
* deleting a popup menu.
*
* @param rxItemID The item id of the popup menu to remove.
*
* @param byPosition [optional] Whether the popup menu to be removed is found
* by ID or by position. The default is false, found by ID.
*
* @return The removed .PopupMenu object on success, or 0 on failure.
*
* @note Sets .SystemErrorCode on error. If the specified menu item is not a
* popup menu, then the system error code is set to:
*
* ERROR_INVALID_FUNCTION (1)
*/
RexxMethod3(RexxObjectPtr, menu_removePopup, RexxObjectPtr, rxItemID, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
RexxMethodContext *c = context;
RexxObjectPtr result = TheZeroObj;
uint32_t wID = 0;
uint32_t positionID = 0;
HMENU hSubMenu = getSubMenuHandle(cMenu, rxItemID, byPosition, &wID, &positionID);
if ( hSubMenu == NULL )
{
goto done_out;
}
if ( RemoveMenu(cMenu->getHMenu(), (byPosition ? positionID : wID), byPositionFlag(byPosition)) == 0 )
{
oodSetSysErrCode(context->threadContext);
goto done_out;
}
// TODO Check if .PopupMenu object is already stored in the submenu user
// data and use if so just return it directly. Otherwise, create it and
// store it back in the menu user data so it doesn't need to be created
// again. ALSO if we are saving PopupMenu objects somewhere, need to save
// it after creating it.
RexxObjectPtr menuObj = NULL;
if ( ! menuData(context, hSubMenu, &menuObj) )
{
goto done_out;
}
if ( menuObj != NULL )
{
result = menuObj;
}
else
{
// TODO if this fails, we should re-insert the removed menu. But, will
// be hard to do if not byPosition. ?
result = newPopupFromHandle(context, hSubMenu, rxItemID, byPosition, wID, cMenu->getSelf());
// TODO if good result store it in dwMenuData. Not doing this yet.
/*
if ( result != TheZeroObj )
{
if ( ! menuData(context, hSubMenu, &result) )
{
result = TheZeroObj;
goto done_out;
}
}
*/
}
cMenu->maybeRedraw(false);
done_out:
return result;
}
/** Menu::deletePopup()
*
* Deletes the specified popup menu from the menu.
*
* When a popup menu (a submenu) is deleted, the operating system frees all
* resources used by the popup menu and any references to the popup are no
* longer valid. To be explicit, this means that any .PopupMenu objects that
* represent this submenu are no longer valid, which would also include any menu
* that has this submenu as one of its submenus.
*
* To remove a submenu from a menu and still use the submenu, use the
* removePopup() method.
*
* @param rxItemID The item id of the submenu to remove.
*
* @param byPosition [optional] Whether the popup menu to be deleted is found
* by ID or by position. The default is false, found by ID.
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode on error. If the specified menu item is not a
* popup menu, then the system error code is set to:
*
* ERROR_INVALID_FUNCTION (1)
*/
RexxMethod3(logical_t, menu_deletePopup, RexxObjectPtr, rxItemID, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return deleteMenuItem(cMenu, rxItemID, byPosition, 1, MF_POPUP);
}
/** Menu::getPopup()
*
* Gets the specified popup menu from the menu. The menu is unchanged.
*
* @param rxItemID The item id of the popup menu.
*
* @param byPosition [optional] Whether the popup menu is found by ID or by
* position. The default is false, found by ID.
*
* @return A .PopupMenu object on success, or 0 on failure.
*
* @note Sets .SystemErrorCode on failure. In addition to error codes set the
* OS, the following error codes may also be set.
*
* If the specified menu item is not a popup menu, then the system error
* code is set to:
*
* ERROR_INVALID_FUNCTION (1)
*
* If there is an internal error (getting the .PopupMenu object) the
* system error code is set to:
*
* OR_INVALID_OID (1911) The object specified was not found.
*
* @remarks Note below that, if the call to getSubMenuHandle() succeeds,
* rxItemID is valid. wID is the correct submenu id, if it was
* assigned, or the correct default value if it was not assigned.
*
* So, in all cases wID is the correct ID to use to create a new
* PopupMenu object, if needed. If byPosition, then of course
* rxItemID is not the menu's resource ID. If not byPosition, then
* rxItemID equals wID, but is already a Rexx object.
*/
RexxMethod3(RexxObjectPtr, menu_getPopup, RexxObjectPtr, rxItemID, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
RexxObjectPtr result = TheZeroObj;
uint32_t wID = 0;
HMENU hSubMenu = getSubMenuHandle(cMenu, rxItemID, byPosition, &wID, NULL);
if ( hSubMenu == NULL )
{
goto done_out;
}
// TODO We are not yet storing the Rexx object, so this will always come
// back NULL. ALSO if we are saving PopupMenu objects somewhere, need to
// save it after creating it.
RexxObjectPtr menuObj = NULL;
if ( ! menuData(context, hSubMenu, &menuObj) )
{
goto done_out;
}
if ( menuObj != NULL )
{
result = menuObj;
}
else
{
result = newPopupFromHandle(context, hSubMenu, rxItemID, byPosition, wID, cMenu->getSelf());
// TODO if good result store it in dwMenuData. Not doing this yet.
/*
if ( result != TheZeroObj )
{
if ( ! menuData(context, hSubMenu, &result) )
{
result = TheZeroObj;
}
}
*/
}
done_out:
return result;
}
/** Menu::getItemState()
*
* Returns a string of 0 or more keywords that indicate the current state of the
* specified menu item. The state for a separator will be the emtpy string.
*
* @param rxItemID The item ID to query. This can be a position ID or a
* resource ID, depending on the value of byPosition.
*
* @param byPosition [optional] If true, rxItemID is a positional ID,
* otherwise it is a resource ID. The default is false.
*
* @return The keyword string on success, and -1 on failure.
*
* @note Sets the .SystemErrorCode on failure.
*
* The set of possible keywords is:
*
* CHECKED UNCHECKED DISABLED GRAYED ENABLED DEFAULT HILITE UNHILITE
*
* @remarks Note to myself, if separators are allowed, the string comes back:
* UNCHECKED DISABLED GRAYED UNHILITE, which makes sense.
*/
RexxMethod3(RexxObjectPtr, menu_getItemState, RexxObjectPtr, rxItemID, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return itemFlags2String(cMenu, rxItemID, (BOOL)byPosition, 1, MIIM_STATE);
}
/** Menu::getType()
*
* Returns a string of 0 or more keywords that indicate the type of the
* specified menu item.
*
* @param rxItemID The item ID to query. This can be a position ID or a
* resource ID, depending on the value of byPosition.
*
* @param byPosition [optional] If true, rxItemID is a positional ID,
* otherwise it is a resource ID. The default is false.
*
* @return The keyword string on success, and -1 on failure.
*
* @note Sets the .SystemErrorCode on failure.
*
* The set of possible keywords is:
*
* SEPARATOR COMMAND SUBMENU MENUBARBREAK MENUBREAK OWNERDRAW RADIO
* RIGHTJUSTIFY RIGHTORDER BITMAP STRING
*
*/
RexxMethod3(RexxObjectPtr, menu_getItemType, RexxObjectPtr, rxItemID, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return itemFlags2String(cMenu, rxItemID, (BOOL)byPosition, 1, MIIM_FTYPE | MIIM_SUBMENU | MIIM_BITMAP | MIIM_STRING);
}
/** Menu::getID()
*
* Gets the resource ID of the specified menu item. This is always done by
* position, if the ID is already known, there is no use querying for it.
*
* @param pos The position of the menu item.
*
* @return The id of the menu item on success, which is always positive, -1 on
* failure.
*
* @note Sets .SystemErrorCode,
*
* Remember that when using by position you must use the menu that
* actually holds the menu item, the item can not be in a submenu of the
* menu.
*/
RexxMethod2(RexxObjectPtr, menu_getID, uint32_t, pos, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
oodResetSysErrCode(context->threadContext);
RexxObjectPtr result = TheNegativeOneObj;
MENUITEMINFO mii = {0};
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_ID;
if ( GetMenuItemInfo(cMenu->getHMenu(), pos, TRUE, &mii) == 0 )
{
oodSetSysErrCode(context->threadContext);
}
else
{
result = context->UnsignedInt32(mii.wID);
}
return result;
}
/** Menu::setID()
*
* Sets the resource ID of the specified menu item. This would usually be done
* by position, to maybe set the ID of an item that does not have an ID.
* However, the method could also be used to change the existing ID of an item.
* For this reason, by resource ID is supported.
*
* @param itemID Specifies the menu item whose resource ID is being set.
* @param newID The new resource ID.
* @param byPosition [optional] Whether itemID is a resource ID or a
* position ID. The default is true, a position ID, because
* this method would most often be used with a by position
* id.
*
* @return True on success, false on failure.
*
* @note Sets .SystemErrorCode.
*
* Remember that when using by position you must use the menu that
* actually holds the menu item, the item can not be in a submenu of the
* menu.
*/
RexxMethod4(logical_t, menu_setID, RexxObjectPtr, rxItemID, RexxObjectPtr, newID, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
oodResetSysErrCode(context->threadContext);
logical_t success = FALSE;
MENUITEMINFO mii = {0};
uint32_t itemID = resolveItemID(context, rxItemID, byPosition, 1);
if ( itemID == OOD_ID_EXCEPTION )
{
goto done_out;
}
mii.wID = oodGlobalID(context, newID, 2, true);
if ( mii.wID == OOD_ID_EXCEPTION )
{
goto done_out;
}
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_ID;
if ( SetMenuItemInfo(cMenu->getHMenu(), itemID, byPositionFlag(byPosition), &mii) == 0 )
{
oodSetSysErrCode(context->threadContext);
goto done_out;
}
success = TRUE;
done_out:
return success;
}
/** Menu::setHelpID()
*
* Sets the Help context identifier for the this menu, and optionally all
* submenus. Note that unlike most resource IDs, the help ID can be a full 32
* bits instead of 16 bits.
*
* @param id The ID to be set.
* @param recurse If true, set this menu and all submenus. The default is
* false.
*
* @return True on success, false on failure.
*
* @note Sets .SystemErrorCode on failure.
*
* @remarks We don't check for a null menu handle, the OS will check for us
* and set last error.
*/
RexxMethod3(logical_t, menu_setHelpID, RexxObjectPtr, id, OPTIONAL_logical_t, recurse, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
oodResetSysErrCode(context->threadContext);
logical_t result = FALSE;
DWORD helpID = oodGlobalID(context, id, 1, true);
if ( helpID == OOD_ID_EXCEPTION )
{
goto done_out;
}
uint32_t rc = menuHelpID(cMenu->getHMenu(), helpID, (BOOL)recurse, NULL);
if ( rc == 0 )
{
result = TRUE;
}
else
{
oodSetSysErrCode(context->threadContext, rc);
}
done_out:
return result;
}
/** Menu::getHelpID()
*
* Gets the Help context identifier for the menu.
*
* @return On success the help ID, or 0 if the help ID for the menu is not set.
* On failure, -1.
*
* @note Sets .SystemErrorCode on failure.
*
* @remarks We don't check for a null menu handle, the OS will check for us
* and set last error.
*/
RexxMethod1(RexxObjectPtr, menu_getHelpID, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
oodResetSysErrCode(context->threadContext);
RexxObjectPtr result = TheNegativeOneObj;
uint32_t helpID;
uint32_t rc = menuHelpID(cMenu->getHMenu(), 0, 0, &helpID);
if ( rc == 0 )
{
result = context->UnsignedInt32(helpID);
}
else
{
oodSetSysErrCode(context->threadContext, rc);
}
return result;
}
/** Menu::setMaxHeight()
*
* Sets the maximum height for this menu, and optionally all submenus.
*
* When a menu reaches the maximum height, scroll bars are automatically added.
* The default height is the height of the screen. To revert back to the
* defualt height use 0.
*
* @param height The maximum height, in pixels, for the menu.
* @param recurse If true, set the height for this menu and all submenus. The
* default is false.
*
* @return True on success, false on failure.
*
* @note Sets .SystemErrorCode on failure.
*/
RexxMethod3(logical_t, menu_setMaxHeight, uint32_t, height, OPTIONAL_logical_t, recurse, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return cMenu->setMaxHeight(height, recurse);
}
/** Menu::getMaxHeight()
*
* Gets the current maximum height for the menu in pixels. Note that 0,
* indicates the height of the screen.
*
* @return On success the maximum height for the menu. On failure, -1.
*
* @note Sets .SystemErrorCode on failure.
*/
RexxMethod1(int, menu_getMaxHeight, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return cMenu->getMaxHeight();
}
/** Menu::setText()
*
* Sets the text of the specified menu item. Separator menu items do not have
* text
*
* @param itemID Specifies the menu item whose text is being set.
* @param text The text for the item
* @param byPosition [optional] Whether itemID is a resource ID or a
* position ID. The default is false, a resource ID.
*
* @return True on success, false on failure.
*
* @note Sets .SystemErrorCode. If the specified menu item is a separator, the
* system error code is set to:
*
* ERROR_INVALID_FUNCTION (1) -> Incorrect function.
*/
RexxMethod4(logical_t, menu_setText, RexxObjectPtr, rxItemID, CSTRING, text, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
logical_t success = FALSE;
MENUITEMINFO mii;
uint32_t itemID;
if ( ! getMII(cMenu, rxItemID, (BOOL)byPosition, 1, &itemID, MIIM_FTYPE, &mii) )
{
goto done_out;
}
if ( _isSeparator(&mii) )
{
oodSetSysErrCode(context->threadContext, ERROR_INVALID_FUNCTION);
goto done_out;
}
ZeroMemory(&mii, sizeof(MENUITEMINFO));
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STRING;
mii.dwTypeData = (LPSTR)text;
if ( SetMenuItemInfo(cMenu->getHMenu(), itemID, (BOOL)byPosition, &mii) == 0 )
{
oodSetSysErrCode(context->threadContext);
goto done_out;
}
success = TRUE;
done_out:
return success;
}
/** Menu::getText()
*
* Gets the text of the specified menu item. Separator menu items do not have
* text.
*
* @param itemID Specifies the menu item whose text is being set.
* @param byPosition [optional] Whether itemID is a resource ID or a
* position ID. The default is false, a resource ID.
*
* @return The text of the specified menu item on success, the empty string on
* failure.
*
* @note Sets .SystemErrorCode on failure. If the specified menu item is a
* separator, the system error code is set to:
*
* ERROR_INVALID_FUNCTION (1) -> Incorrect function.
*/
RexxMethod3(RexxStringObject, menu_getText, RexxObjectPtr, rxItemID, OPTIONAL_logical_t, byPosition, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
char buf[256];
*buf = '\0';
MENUITEMINFO mii = {0};
uint32_t itemID;
if ( ! getMII(cMenu, rxItemID, (BOOL)byPosition, 1, &itemID, MIIM_FTYPE, &mii) )
{
goto done_out;
}
if ( _isSeparator(&mii) )
{
oodSetSysErrCode(context->threadContext, ERROR_INVALID_FUNCTION);
goto done_out;
}
ZeroMemory(&mii, sizeof(MENUITEMINFO));
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STRING;
mii.dwTypeData = (LPSTR)buf;
mii.cch = sizeof(buf);
if ( GetMenuItemInfo(cMenu->getHMenu(), itemID, (BOOL)byPosition, &mii) == 0 )
{
oodSetSysErrCode(context->threadContext);
}
done_out:
return context->CString(buf);
}
/** Menu::setAutoConnection()
*
* Turns auto connect on or off, or changes the way the method name to auto
* connect is determined. [do link to auto connection section]
*
* @param on If true, auto connection is turned on, if false it is
* turned off.
*
* @param methodName [optional] The method name to connect all menu items
* to. If this argument is omitted, each menu item is
* connected to a method whose name is constructed from the
* text of the item. If auto connection is off, this
* argument is ignored.
*
* @return This method does not return a value.
*/
RexxMethod3(RexxObjectPtr, menu_setAutoConnection, logical_t, on, OPTIONAL_CSTRING, methodName, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
if ( ! cMenu->setAutoConnection(on, methodName) )
{
outOfMemoryException(context->threadContext);
return TheFalseObj;
}
return TheTrueObj;
}
/** Menu::getAutoConnectStatus()
*
* Returns a Directory object containing the current stats of autoconnection.
*
* @return A Directory object with 2 indexes:
*
* autoConnect -> .true if autoconnection is on and .false if it is
* off.
* methodName -> .nil if not set, othewise the name of the
* autoconnection method.
*/
RexxMethod1(RexxObjectPtr, menu_getAutoConnectStatus, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return (RexxObjectPtr)cMenu->autoConnectionStatus();
}
/** Menu::itemTextToMethodName()
*
* Converts the text of a (presumed) menu command it to a valid Rexx method
* name. That is, it removes all space characters, the possible ampersand, any
* trailing '...' and upper-cases it.
*
* This would normally be done when connecting a menu command item to a method.
*
* @param text The text to convert.
*
* @return the string that is valid to use as a method name.
*/
RexxMethod2(RexxStringObject, menu_itemTextToMethodName, CSTRING, text, OSELF, self)
{
RexxStringObject result = NULLOBJECT;
if ( strlen(text) == 0 )
{
nullStringMethodException(context, 1);
return result;
}
char *name = strdup_2methodName(text);
if ( name != NULL )
{
result = context->String(name);
free(name);
}
else
{
outOfMemoryException(context->threadContext);
}
return result;
}
/** Menu::connectMenuEvent()
*
* Connects WM_XXX menu message events to a method in a dialog.
*
* @param methodName The method name of the method being connected.
*
* @param keyword A single keyword specifying which message event to
* connect.
*
* @param hFilter Window handle of an object to use for to filter the
* connected notification. The use of this filter is specific
* to the event being connectd. For the CONTEXTMENU event it
* can be a window handle, in which case only notifications
* for that window are generated. For the INITMENUPOPUP
* event it can be the menu handle of a submenu, in which
* case only notifications for that submenu are generated.
*
*
* @param dlg [optional] The dialog being connected. By default the
* dialog this menu is attached to is used. However, any
* dialog can be used. In most cases, it only makes sense to
* connect the window message to the dialog the menu is
* attached to.
*
* If omitted and there is no owner dialog, then a condition
* is raised.
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode on error.
*
* The system error code is set this way in addition to what the OS might
* set:
*
* ERROR_INVALID_FUNCTION (1) -> The dialog argument was omitted and the
* menu does not have an assigned dialog.
*
* ERROR_WINDOW_NOT_DIALOG (1420) -> The dialog argument was not
* ommitted, but the object is not a .PlainBaseDialog, (or subclass of
* course.)
*
* ERROR_NOT_ENOUGH_MEMORY (8) -> The dialog message table is full.
*/
RexxMethod5(logical_t, menu_connectMenuEvent, CSTRING, methodName, CSTRING, keyWord,
OPTIONAL_POINTERSTRING, hFilter, OPTIONAL_RexxObjectPtr, _dlg, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return cMenu->connectMenuMessage(methodName, keyWord, (HWND)hFilter, _dlg);
}
/** Menu::connectCommandEvent()
*
* Directly connects the menu command item event with a method in the specified
* dialog.
*
* @param id The resource ID of the menu item.
*
* @param methodName The method to connect the item select event to. This can
* not be the empty string.
*
* @param dlg [optional] The dlg to connect the menu item select event
* to. If omitted, then the menu's owning dialog is used. If
* omitted and there is no owning dialog, no connection is
* made and the system error code is set as mentioned below.
* (To connect a menu item select event, there must be a
* dialog to connect it to.)
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode on error.
*
* The system error code is set this way in addition to what the OS might
* set:
*
* ERROR_INVALID_FUNCTION (1) -> The dialog argument was omitted and the
* menu does not have an assigned dialog.
*
* ERROR_INVALID_PARAMETER (87) -> The methodName argument can not be the
* empty string.
*
* ERROR_WINDOW_NOT_DIALOG (1420) -> The dialog argument was not
* ommitted, but the object is not a .PlainBaseDialog, (or subclass of
* course.)
*
* ERROR_NOT_ENOUGH_MEMORY (8) -> The dialog message table is full.
*/
RexxMethod4(logical_t, menu_connectCommandEvent, RexxObjectPtr, rxID, CSTRING, methodName,
OPTIONAL_RexxObjectPtr, _dlg, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return cMenu->connectCommandEvent(rxID, methodName, _dlg);
}
/** Menu::connectAllCommandEvents()
*
* Connects all menu command items in this menu to a method.
*
* @param msg [optional] Connect all menu command items to the method by
* this name. The default is to connect all menu command items to
* a method name composed from the text of the command item.
*
* @param _dlg [optional] Connect the command items to the method(s) of this
* dialog object. The default is to connect the command items to
* the owner dialog of this menu.
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode.
*
* The system error code is set this way in addition to what the OS might
* set:
*
* ERROR_INVALID_FUNCTION (1) -> The dialog argument was omitted and the
* menu does not have an assigned dialog.
*
* ERROR_WINDOW_NOT_DIALOG (1420) -> The dialog argument was not
* ommitted, but the object is not a .PlainBaseDialog, (or subclass of
* course.)
*
* ERROR_NOT_ENOUGH_MEMORY (8) -> The dialog message table is full.
*/
RexxMethod3(logical_t, menu_connectAllCommandEvents, OPTIONAL_CSTRING, msg, OPTIONAL_RexxObjectPtr, _dlg, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return cMenu->connectAllCommandEvents(msg, _dlg);
}
/** Menu::connectSomeCommandEvents()
*
* Connects a collection of menu command items to the single specified method.
* @param rxItemIDs A collection of item IDs to connect. The IDs can be by
* position IDs or resource IDs, depending on the value of
* byPosition. However, they must be all the same type, all
* resource IDs or all by position IDs.
*
* @param msg [optional] Connect all menu command items to the method
* by this name. The default is to connect all menu command
* items to a method name composed from the text of the
* command item.
*
* If not omitted, method can not be the empty string.
*
* @param byPosition [optional] If true, rxItemIDs are positional IDs,
* otherwise the are resource IDs. The default is false,
* resource IDs.
*
* @param _dlg [optional] Connect the command items to the method(s) of
* this dialog object. The default is to connect the command
* items to the owner dialog of this menu.
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode.
*
* The system error code is set this way in addition to what the OS might
* set:
*
* ERROR_INVALID_FUNCTION (1) -> The dialog argument was omitted and the
* menu does not have an assigned dialog.
*
* ERROR_WINDOW_NOT_DIALOG (1420) -> The dialog argument was not
* ommitted, but the object is not a .PlainBaseDialog, (or subclass of
* course.)
*
* ERROR_NOT_ENOUGH_MEMORY (8) -> The dialog message table is full.
*
* ERROR_INVALID_PARAMETER (87) -> One or more of the specified item IDs
* is not a menu command item. Or the msg argument was used, but it is
* the empty string.
*
* The method quits when it encounters the first error, therefore menu
* items processed before the error will be connected and menu items that
* would be processed after the error will not be connected.
*/
RexxMethod5(logical_t, menu_connectSomeCommandEvents, RexxObjectPtr, rxItemIDs, OPTIONAL_CSTRING, msg,
OPTIONAL_logical_t, byPosition, OPTIONAL_RexxObjectPtr, _dlg, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return cMenu->connectSomeCommandEvents(rxItemIDs, msg, byPosition, _dlg);
}
/**
* Methods for the .MenuBar mixin class.
*/
#define MENUBAR_CLASS "MenuBar"
/** MenuBar::attachTo()
*
* Attaches this menu bar to the specified dialog window.
*
* A menu bar can only be attached to one dialog and a dialog can only have one
* menu bar attached to it. If either the menu bar is already attached to a
* dialog, or the dialog already has a menu bar attached to it, this method
* fails.
*
* If the menu bar is already attached to a dialog, first use the
* .MenuBar~detach() method to detach it.
*
* If the dialog already has a menu bar attached to it and you want to attach
* this menu bar to that dialog, get a reference to the dialog's current menu
* bar and use the replace() method.
*
* @param dlg The dialog to attach to.
*
* @param countRows [optional] The number of rows the menu has. If this
* number is greater than 0, the size of the dialog is
* automatically adjusted to account for the height of the
* menu.
*
* @return True on success, false on failure.
*
* @note Sets .SystemErrorCode on failure. In addition to error codes set by
* the operating system, the following error codes may be set by
* ooDialog:
*
* ERROR_INVALID_FUNCTION (1) this menu is already attached to a dlg
*
* ERROR_NOT_ENOUGH_MEMORY (8) some menu items were not connected
* because the message table is full.
*
* ERROR_INVALID_WINDOW_HANDLE (1400) dlg has no underlying Windows
* dialog
*
* ERROR_INVALID_MENU_HANDLE (1401) this menu has been destroyed
*
* ERROR_WINDOW_NOT_DIALOG (1420) dlg is not a .PlainBaseDialog
*
* ERROR_INVALID_WINDOW_STYLE (2002) dlg already attached to a menu
* bar
*
* When this method returns false, the menu is not attached to a dialog,
* except in one circumstance. If the .SystemErrorCode is
* ERROR_NOT_ENOUGH_MEMORY, then the menu is attached to the dialog, but
* some menu items were not connected.
*/
RexxMethod3(logical_t, menuBar_attachTo, RexxObjectPtr, dlg, OPTIONAL_uint32_t, countRows, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return cMenu->attachToDlg(dlg, countRows);
}
/** MenuBar::detach()
*
* Detaches this menu from its assigned dialog.
*
* @return True on success, false on failure.
*
* @note Sets .SystemErrorCode on failure. In addition to codes set by the
* operating system, the following error code indicates that this menu
* bar is not attached to a dialog:
*
* ERROR_INVALID_FUNCTION (1) -> Not attached to a dialog.
*/
RexxMethod1(logical_t, menuBar_detach, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return cMenu->detach(false);
}
/** MenuBar::isAttached()
*
* Determines if this menu bar is currently attached to a dialog.
*
* @return True if attached, false if not attached.
*/
RexxMethod1(logical_t, menuBar_isAttached, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
oodResetSysErrCode(context->threadContext);
return cMenu->isAttached();
}
/** MenuBar::redraw()
*
* Tells the dialog this menu bar is attached to, to redraw the menu.
*
* @return True on success, false on failure.
*
* @note Sets .SystemErrorCode on failure. In addition to codes set by the
* operating system, the following error code indicates that this menu
* bar is not attached to a dialog:
*
* ERROR_INVALID_FUNCTION (1) -> Not attached to a dialog.
*/
RexxMethod1(logical_t, menuBar_redraw, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
oodResetSysErrCode(context->threadContext);
return cMenu->maybeRedraw(true);
}
/** MenuBar::replace()
*
* If this menubar is attached to a dialog, the menubar for the dialog is
* replaced by the specified menubar.
*
* @param newMenu The new menu bar to attach to this menu bar's dialog.
*
* @return The existing menu bar, if there is one, otherwise .ni
*
* @note Sets .SystemErrorCode on failure. In addition to codes set by the
* operating system, the following error code indicates that this menu
* bar is not attached to a dialog:
*
* ERROR_INVALID_FUNCTION (1) -> Not attached to a dialog.
*/
RexxMethod2(RexxObjectPtr, menuBar_replace, RexxObjectPtr, newMenu, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return cMenu->replace(newMenu);
}
/**
* Methods for the .Menu mixin class.
*/
#define MENUTEMPLATE_CLASS "MenuTemplate"
/** MenuTemplate::addPopup()
*
* Adds a popup menu to the in memory template. This method is only valid after
* the .UserMenu has been created and before it is completed.
*
* @param id The resource ID for the popup menu.
*
* @param text The text label for the popup menu.
*
* @param opts [optional] A string of 0 or more, blank seperated, keywords
* indicating additional options for the popup menu. The
* keywords set the state and type of the of the popup menu, and
* specify when the popup menu is the last item at the current
* level in the menu.
*
* @param helpID [optional] The context help ID for the popup menu. The
* default is 0 indicating no help ID.
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode on error.
*
* The system error code is set this way in addition to what the OS might
* set:
*
* ERROR_INVALID_FUNCTION (1) -> The .UserMenu has already been
* completed.
*
* @note State keywords: DEFAULT DISABLED GRAYED HILITE. The keywords:
* ENABLED UNHILITE NOTDEFAULT, although valid keywords are simply
* ignored. By default the state will be ENABLED UNHILITE NOTDEFAULT
*
* Type keywords: MENUBARBREAK MENUBREAK RIGHTJUSTIFY RIGHTORDER
*
* Additional keyword: END This keyword is required to indicate the
* popup menu is the last item at the current level of the menu.
*
* @remarks Note to myself. I have tested this with DEFAULT, DISABLED, GRAYED,
* HILITE, MENUBARBREAK, MENUBREAK, RIGHTJUSTIFY, and RIGHTORDER. They
* all work.
*/
RexxMethod5(logical_t, menuTemplate_addPopup, RexxObjectPtr, rxID, CSTRING, text,
OPTIONAL_CSTRING, opts, OPTIONAL_RexxObjectPtr, rxHelpID, OSELF, self)
{
CppMenu *cMenu = menuToCSelf(context, self);
cMenu->setContext(context, TheFalseObj);
return cMenu->addTemplatePopup(rxID, text, opts, rxHelpID);
}
/** MenuTemplate::addItem()
*
* Adds a menu command item to the in memory template. This method is only
* valid after the .UserMenu has been created and before it is completed.
*
* @param id The resource ID for the menu command item.
*
* @param text The text label for the item.
*
* @param opts [optional] A string of 0 or more, blank seperated, keywords
* indicating additional options for the menu item. The keywords
* set the state and type of the of the item, and specify when
* the item is the last item at the current level in the menu.
*
* @param method [optional] A method name to connect the item to. The default
* is to not connect the menu command item. If this argument is
* used it can not be the empty string.
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode on error.
*
* The system error code is set this way in addition to what the OS might
* set:
*
* ERROR_INVALID_FUNCTION (1) -> The .UserMenu has already been
* completed.
*
* ERROR_INVALID_PARAMETER (87) -> Argument method can not be the empty
* string.
*
* @note State keywords: DEFAULT DISABLED GRAYED HILITE CHECKED. The keywords:
* ENABLED UNHILITE NOTDEFAULT UNCHECKED, although valid keywords are
* simply ignored. By default the state will be ENABLED UNHILITE
* NOTDEFAULT UNCHECKED.
*
* Type keywords: MENUBARBREAK MENUBREAK RIGHTJUSTIFY RADIO. By default
* no special type is set.
*
* Additional keyword: END This keyword is required to indicate the menu
* command item is the last item at the current level of the menu.
*
*/
RexxMethod5(logical_t, menuTemplate_addItem, RexxObjectPtr, rxID, CSTRING, text,
OPTIONAL_CSTRING, opts, OPTIONAL_CSTRING, method, OSELF, self)
{
CppMenu *cMenu = menuToCSelf(context, self);
cMenu->setContext(context, TheFalseObj);
return cMenu->addTemplateItem(rxID, text, opts, method);
}
/** MenuTemplate::addSeparator()
*
* Adds a separator item to the in memory template. This method is only valid
* after the .UserMenu has been created and before it is completed.
*
* @param id The resource ID for the separator.
*
* @param opts [optional] A string of 0 or more, blank seperated, keywords
* indicating additional options for the menu item. The keywords
* specify a few of the additional type settings that work with a
* separator and can indicate that the separator is the last item
* at the current level in the menu.
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode on error.
*
* The system error code is set this way in addition to what the OS might
* set:
*
* ERROR_INVALID_FUNCTION (1) -> The .UserMenu has already been
* completed.
*
* @note Type keywords: MENUBARBREAK MENUBREAK RIGHTJUSTIFY. By default no
* special type is set.
*
* Additional keyword: END This keyword is required to indicate the menu
* command item is the last item at the current level of the menu.
*
* @remarks Although MSDN says separators can not be used in a menu bar, on
* Windows 7 at least they can. Not sure if that is because of using
* the extended menu template, or a Windows 7 thing only
*
*/
RexxMethod3(logical_t, menuTemplate_addSeparator, RexxObjectPtr, rxID, OPTIONAL_CSTRING, opts, OSELF, self)
{
CppMenu *cMenu = menuToCSelf(context, self);
cMenu->setContext(context, TheFalseObj);
return cMenu->addTemplateSepartor(rxID, opts);
}
/** MenuTemplate::isComplete()
*
* Determines if the in memory template has been loaded into memory as a menu
* resource. Once this is done, no more menu items can be added to the menu,
* through the addItem(), addSeparator(), and addPopup() methods.
*
* Those items can still be added to the menu through the insertItem(),
* insertSeparator(), and insertPopup() methods.
*
* @return True if the memory template has been finished and loaded into
* memory, otherwise false.
*/
RexxMethod1(logical_t, menuTemplate_isComplete, OSELF, self)
{
CppMenu *cMenu = menuToCSelf(context, self);
cMenu->setContext(context, TheFalseObj);
return cMenu->templateIsComplete();
}
/**
* Methods for the .BinaryMenuBar class.
*/
#define BINARYMENUBAR_CLASS "Menu"
/** BinaryMenuBar::init()
*
* Initializes a BinaryMenuBar object.
*
* @param src [optional] The source to create the menu. Can be:
* .nil -> Create new empty menu
* .Pointer -> Must be a valid HMENU
* .ResDialog -> Load menu from the resource DLL
* .String -> File name of module to load menu from
* The default if omitted is to create a new empty menu.
*
* @param id [optional] The resource ID of the menu. The default
* is -1 indicating no ID. However, the ID is required if
* src is a .ResDialog or a module file name.
*
* @param helpID [optional] Context help ID for the menu. The default
* is 0 indicating no help ID.
*
* @param attachTo [optional] If specified, attach this menu to the
* dialog. If specified, attachTo has to be a
* .PlainBaseDialog or subclass. If not, an exception is
* raised.
*
* @param autoConnect [optional] Turn on auto connection if true. Default
* is false
*
* @param mName [optional] If autoConnect, set autoConnectionMethod to
* this method. If omitted autoConectionMethod is left
* alone.
*
* @return No return.
*
* @remarks Raises exceptions for all failures. If no exceptions, the menu is
* created successfully.
*
* Also sets .SystemErrorCode. It will be non-zero, only, if the
* help ID is set and there is a Windows API failure. It hardly
* seems possible that this could happen.
*/
RexxMethod7(RexxObjectPtr, binMenu_init, OPTIONAL_RexxObjectPtr, src, OPTIONAL_RexxObjectPtr, _id,
OPTIONAL_RexxObjectPtr, helpID, OPTIONAL_RexxObjectPtr, attachTo, OPTIONAL_logical_t, autoConnect,
OPTIONAL_CSTRING, mName, OSELF, self)
{
RexxMethodContext *c = context;
CppMenu *cMenu = new CppMenu(self, BinaryMenuBar, context);
RexxPointerObject cMenuPtr = context->NewPointer(cMenu);
context->SendMessage1(self, "MENUINIT", cMenuPtr);
if ( argumentExists(2) )
{
int32_t id = oodGlobalID(context, _id, 2, false);
if ( id == OOD_ID_EXCEPTION )
{
goto done_out;
}
cMenu->setMenuID(id);
}
DWORD dwHelpID = 0;
if ( argumentExists(3) )
{
int32_t tmp = oodGlobalID(context, helpID, 3, false);
if ( tmp == OOD_ID_EXCEPTION )
{
goto done_out;
}
dwHelpID = tmp;
}
// We check here, before we go any farther, if the attachTo argument is
// valid and attachToDlg() is not going fail later:
if ( argumentExists(4) )
{
if ( ! validAttachTo(context, attachTo, 4) )
{
goto done_out;
}
}
HMENU hMenu = NULL;
bool isResDialog = false;
bool isPointer = false;
if ( argumentOmitted(1) || src == TheNilObj )
{
hMenu = CreateMenu();
if ( hMenu == NULL )
{
systemServiceExceptionCode(context->threadContext, API_FAILED_MSG, "CreateMenu");
goto done_out;
}
}
else if ( context->IsPointer(src) )
{
isPointer = true; // Do not destroy this menu if we fail.
hMenu = (HMENU)context->PointerValue((RexxPointerObject)src);
if ( ! IsMenu(hMenu) )
{
invalidTypeException(context->threadContext, 1, INVALID_MENU_HANDLE_MSG);
goto done_out;
}
}
else if ( context->IsOfType(src, "ResDialog") )
{
isResDialog = true;
}
else if ( context->IsString(src) )
{
; // Purposively do nothing because src could be a module file name.
}
else
{
wrongArgValueException(context->threadContext, 1, "ResDialog, module file name, menu handle, or .nil", src);
goto done_out;
}
if ( hMenu == NULL )
{
// src has to be a ResDialog or a module file name.
HINSTANCE hinst = NULL;
if ( isResDialog )
{
pCPlainBaseDialog pcpbd = dlgToCSelf(context, src);
hinst = pcpbd->hInstance;
}
else
{
CSTRING fileName = c->ObjectToStringValue(src);
hinst = LoadLibrary(TEXT(fileName));
if ( hinst == NULL )
{
systemServiceExceptionCode(context->threadContext, NO_HMODULE_MSG, fileName);
goto done_out;
}
}
hMenu = LoadMenu(hinst, MAKEINTRESOURCE(cMenu->wID));
if ( hMenu == NULL )
{
systemServiceExceptionCode(context->threadContext, API_FAILED_MSG, "LoadMenu");
goto done_out;
}
if ( ! isResDialog )
{
FreeLibrary(hinst);
}
}
cMenu->setHMenu(hMenu);
if ( dwHelpID != 0 )
{
uint32_t rc = menuHelpID(hMenu, dwHelpID, TRUE, NULL);
if ( rc )
{
oodSetSysErrCode(context->threadContext, rc);
}
}
if ( autoConnect )
{
if ( ! cMenu->setAutoConnection(TRUE, mName) )
{
outOfMemoryException(c->threadContext);
goto done_out;
}
}
if ( argumentExists(4) )
{
cMenu->attachToDlg(attachTo, 0);
}
// TODO need to think about putting this Rexx object in the data word of the menu.
done_out:
return NULLOBJECT;
}
/**
* Methods for the .SystemMenu class.
*/
#define SYSTEMMENU_CLASS "SystemMenu"
/** SystemMenu::init()
*
* Initializes a .SystemMenu object. The underlying menu object is a copy of
* the system menu of the specified dialog. Once the copy is made, the system
* menu can be manipulated and modified just like other menu objects.
*
* It should be obvious that the dialog must have a system menu in order to
* instantiate a .SystemMenu object.
*
* @param dialog The dialog whose system menu is to be copied.
*
* @note Raises exceptions for all failures. If no exceptions, the menu is
* created successfully.
*/
RexxMethod2(RexxObjectPtr, sysMenu_init, RexxObjectPtr, dialog, OSELF, self)
{
CppMenu *cMenu = new CppMenu(self, SystemMenu, context);
RexxPointerObject cMenuPtr = context->NewPointer(cMenu);
context->SendMessage1(self, "MENUINIT", cMenuPtr);
if ( ! requiredClass(context->threadContext, dialog, "PLAINBASEDIALOG", 1) )
{
goto done_out;
}
cMenu->setUpSysMenu(dialog);
done_out:
return NULLOBJECT;
}
/** SystemMenu::revert()
*
* Reverts the system menu for the dialog back to the standard system menu.
*
* When a SystemMenu object is instantiated, it receives a copy of the system
* menu for the dialog. (The operating system maintains the standard system
* menu.) This method reverses that process. The operating system removes the
* copied system menu and replaces it with the standard system menu.
*
* This object will then no loger be valid. Note however that any of the
* pre-defined System Command menu items that were connected to methods, will
* remain connected. Currently in ooDialog there is no way to 'unconnect' a
* method connection once it is made.
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode on error.
*
* The operating system will only revert back to the standard system
* menu. A dialog that does not have minimize and maximize buttons is
* originally given a standard system menu, where the operating system
* has removed the menu items that are not applicable. Namely, the
* Restore, Size, Maximize and Minimize menu items.
*
* When the operating system reverts back to the standard system menu on
* these dialogs, it does not remove these menu items. There is nothing
* the programmer can do about this, because only the operating system
* has access to the standard system menu.
*/
RexxMethod1(logical_t, sysMenu_revert, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return cMenu->revertSysMenu();
}
/**
* Methods for the .PopupMenu class.
*/
#define POPUPMENU_CLASS "PopupMenu"
/** PopupMenu::connectContextMenu() [class]
*
* This class method connects WM_CONTEXTMENU Windows message event to a method
* in a dialog. The WM_CONTEXTMENU event is generated when the user right-mouse
* clicks on a window.
*
* @param dlg The dialog being connected.
*
* @param methodName The method name of the method being connected.
*
* @param hwnd [optional] A window handle to filter the right-clicks on.
* This can be the window handle of any control in the dialog
* being connnected, or even the dialog window handle itself.
* If used, only right-clicks on the specified window will be
* received. If omitted, all right-clicks on the dialog are
* received.
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode on error.
*
* The system error code is set this way in addition to what the OS might
* set:
*
* ERROR_WINDOW_NOT_DIALOG (1420) -> The dlg argument not a
* .PlainBaseDialog, (or subclass of course.)
*
* ERROR_NOT_ENOUGH_MEMORY (8) -> The dialog message table is full.
*/
RexxMethod3(logical_t, popMenu_connectContextMenu_cls, RexxObjectPtr, dlg, CSTRING, methodName, OPTIONAL_POINTERSTRING, hwnd)
{
BOOL success = FALSE;
pCEventNotification pcen = _getPCEN(context, dlg);
if ( pcen == NULL )
{
goto done_out;
}
uint32_t tag = TAG_DIALOG | TAG_CONTEXTMENU;
if ( hwnd != NULL )
{
success = addMiscMessage(pcen, context, WM_CONTEXTMENU, UINT32_MAX, (WPARAM)hwnd, UINTPTR_MAX, 0, 0, methodName, tag);
}
else
{
success = addMiscMessage(pcen, context, WM_CONTEXTMENU, UINT32_MAX, 0, 0, 0, 0, methodName, tag);
}
if ( ! success )
{
oodSetSysErrCode(context->threadContext, ERROR_NOT_ENOUGH_MEMORY);
}
done_out:
return success;
}
/** PopupMenu::init()
*
* Initializes a .PopupMenu object. The underlying menu object is either
* created as a new empty popup menu, or an existing popup menu handle is
* passed in.
*
* @param id [optional] The resource id of / for the menu. Can be
* -1 to indicate no ID. The default is -1.
*
* @param helpID [optional] Context help ID for the menu. The default
* is 0 indicating no help ID.
*
* @param handle [optional] If not null or omitted, this is the handle
* of an existing submenu. This is then set as the
* underlying menu of this .PopupMenu. When omitted or
* null, a new empty menu is created as the underlying
* menu.
*
* TODO - don't document this argument at this time. The
* user has no way of getting a menu handle, except
* through a menu object. If the user gets a submenu from
* a menu bar, or other menu, to get its handle, it is
* easier just to use the submenu object itself. So,
* there seems to be no use for this argument, at this
* time.
*
* @return No return.
*
* @remarks Raises exceptions for all failures. If no exceptions, the menu is
* created successfully.
*
* Also sets .SystemErrorCode. It will be non-zero, only, if the
* help ID is set and there is a Windows API failure. It hardly
* seems possible that this could happen.
*/
RexxMethod4(RexxObjectPtr, popMenu_init, OPTIONAL_RexxObjectPtr, _id, OPTIONAL_RexxObjectPtr, helpID,
OPTIONAL_POINTER, handle, OSELF, self)
{
CppMenu *cMenu = new CppMenu(self, PopupMenu, context);
RexxPointerObject cMenuPtr = context->NewPointer(cMenu);
context->SendMessage1(self, "MENUINIT", cMenuPtr);
if ( argumentExists(1) )
{
int32_t id = oodGlobalID(context, _id, 1, false);
if ( id == OOD_ID_EXCEPTION )
{
goto done_out;
}
else
{
cMenu->setMenuID(id);
}
}
DWORD dwHelpID = 0;
if ( argumentExists(2) )
{
int32_t tmp = oodGlobalID(context, helpID, 2, false);
if ( tmp == OOD_ID_EXCEPTION )
{
goto done_out;
}
dwHelpID = tmp;
}
HMENU hMenu = NULL;
if ( handle == NULL )
{
hMenu = CreatePopupMenu();
if ( hMenu == NULL )
{
systemServiceExceptionCode(context->threadContext, API_FAILED_MSG, "CreatePopupMenu");
goto done_out;
}
}
else
{
hMenu = (HMENU)handle;
if ( ! IsMenu(hMenu) )
{
invalidTypeException(context->threadContext, 4, INVALID_MENU_HANDLE_MSG);
goto done_out;
}
}
cMenu->setHMenu(hMenu);
if ( dwHelpID != 0 )
{
uint32_t rc = menuHelpID(hMenu, dwHelpID, TRUE, NULL);
if ( rc )
{
oodSetSysErrCode(context->threadContext, rc);
}
}
// TODO need to think about putting this Rexx object in the data word of the menu.
done_out:
return NULLOBJECT;
}
/** PopupMenu::connectContextMenu()
*
* Connects WM_CONTEXTMETHOD messages to a method in a dialog.
*
* @param methodName The method name of the method being connected.
*
* @param hwnd [optional] A window handle to filter the right-clicks on.
* This can be the window handle of any control in the dialog
* being connnected, or even the dialog window handle itself.
* If used, only right-clicks on the specified window will be
* received. If omitted, all right-clicks on the dialog are
* received.
*
* @param dlg [optional] The dialog being connected. By default the
* dialog this short cut menu is assigned to is used.
* However, any dialog can be used. This especially makes
* sense if the track() method is being used for the short
* cut menu.
*
* If omitted and there is no assigned dialog, then a
* condition is raised.
*
* @return True on success, false on error.
*
* @note Sets .SystemErrorCode on error.
*
* The system error code is set this way in addition to what the OS might
* set:
*
* ERROR_INVALID_FUNCTION (1) -> The dialog argument was omitted and the
* menu does not have an assigned dialog.
*
* ERROR_WINDOW_NOT_DIALOG (1420) -> The dialog argument was not
* ommitted, but the object is not a .PlainBaseDialog, (or subclass of
* course.)
*
* ERROR_NOT_ENOUGH_MEMORY (8) -> The dialog message table is full.
*/
RexxMethod4(logical_t, popMenu_connectContextMenu, CSTRING, methodName, OPTIONAL_POINTERSTRING, hwnd,
OPTIONAL_RexxObjectPtr, _dlg, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return cMenu->connectMenuMessage(methodName, "CONTEXTMENU", (HWND)hwnd, _dlg);
}
/** PopupMenu::isAssigned()
*
* Determines if this short cut menu is currently assigned to a dialog.
*
* @return True if attached, false if not attached.
*/
RexxMethod1(logical_t, popMenu_isAssigned, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
oodResetSysErrCode(context->threadContext);
return cMenu->isAssigned();
}
/** PopupMenu::assignTo()
*
* For short cut, also called context, menus only.
*
* Assigns this shortcut menu to a dialog. When a popup menu is used as a
* shortcut (context) menu it sends messages to its owner dialog when menu items
* are selected. Even if the short cut menu is only used with the track()
* method, (where selecting a menu item does not send a message to its owner
* dialog,) the short cut menu still requires an owner dialog.
*
* It is not neccessary to assign a short cut menu to a dialog, it just may be
* more convenient. If the shortcut menu does not have an assigned dialog, then
* the owner dialog must be specified each time the track() or show() methods
* are invoked.
*
* A short cut menu can only be assigned to one dialog, so if this menu is
* already assigned to a dialog, it is simply replaced.
*
* @param dlg The dialog to assign this short cut menu to.
* @param connect [optional] Turns on autoconnection.
* @param methodName [optional] Method name for autoconnection.
*
* @return True on success, false on failure.
*
* @note Sets .SystemErrorCode on failure. In addition to error codes set
* bythe operating system, the following error codes may be set:
*
* ERROR_INVALID_MENU_HANDLE (1401) this menu has been destroyed
*
* ERROR_WINDOW_NOT_DIALOG (1420) dlg is not a .PlainBaseDialog
*/
RexxMethod4(logical_t, popMenu_assignTo, RexxObjectPtr, dlg, OPTIONAL_logical_t, autoConnect,
OPTIONAL_CSTRING, methodName, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return cMenu->assignToDlg(dlg, autoConnect, methodName);
}
/** PopupMenu::track()
*
* Displays a contex menu and returns after the user has selected an item or
* canceled the menu. No notification (no WM_COMMAND message) is sent to the
* owner window, but rather the selected id is returned directly. 0 is
* returned if the user cancels the menu.
*
* @param location A Point object specifying the location of the shortcut
* menu, in screen co-ordinates.
*
* @param ownerDlg [optional]
*
* @param opts [optional] A string containing blank separated
* keywords specifying additional options for the shortcut
* menu.
*
* @param bothButtons [optional] If true, the user can select menu items
* with both the left and right mouse buttons. If false,
* the default, the user can select menu items with only
* the left mouse button.
*
* @param excludeRect [optional] A Rect object that specifies an area of the
* screen the shortcut menu should not overlap.
*
* @return A non-negative number on success, -1 on error. On success, the
* return is either 0, meaning the user canceled the menu, or the id
* of the menu item selected.
*
* @notes Sets .SystemErrorCode. The system error code is set this way:
*
* ERROR_INVALID_FUNCTION (1) -> The dialog argument was omitted and the
* menu does not have an assigned dialog.
*
* ERROR_WINDOW_NOT_DIALOG (1420) The dialog argument was specified, but
* the object is not a .PlainBaseDialog, (or subclass of course.)
*
* ERROR_INVALID_MENU_HANDLE (1401) This menu has been destroyed, or is
* no longer valid for some reason.
*
* ERROR_INVALID_WINDOW_HANDLE (1400) The window handle for the dialog
* could not be obtained.
*
*/
RexxMethod6(RexxObjectPtr, popMenu_track, RexxObjectPtr, location, OPTIONAL_RexxObjectPtr, _dlg,
OPTIONAL_CSTRING, opts, OPTIONAL_logical_t, bothButtons, OPTIONAL_RexxObjectPtr, excludeRect, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return cMenu->trackPopup(location, _dlg, opts, bothButtons, excludeRect, true);
}
/** PopupMenu::show()
*
* Displays a contex menu and returns after the user has selected an item or
* canceled the menu. When the user selects an item, a WM_COMMAND message with
* the id of the selection is generated. If the user cancels, nothing happens.
*
* @param location A Point object specifying the location of the shortcut
* menu, in screen co-ordinates.
*
* @param ownerDlg [optional]
*
* @param opts [optional] A string containing blank separated
* keywords specifying additional options for the shortcut
* menu.
*
* @param bothButtons [optional] If true, the user can select menu items
* with both the left and right mouse buttons. If false,
* the default, the user can select menu items with only
* the left mouse button.
*
* @param excludeRect [optional] A Rect object that specifies an area of the
* screen the shortcut menu should not overlap.
*
* @return True on success, othewise false.
*
* @notes Sets .SystemErrorCode. In addition to error codes set by the
* operating system, the system error code may be set this way:
*
* ERROR_INVALID_FUNCTION (1) -> The dialog argument was omitted and
* the menu does not have an assigned dialog.
*
* ERROR_WINDOW_NOT_DIALOG (1420) The dialog argument was specified,
* but the object is not a .PlainBaseDialog, (or subclass of course.)
*
* ERROR_INVALID_MENU_HANDLE (1401) This menu has been destroyed, or
* is no longer valid for some reason.
*
* ERROR_INVALID_WINDOW_HANDLE (1400) The window handle for the dialog
* could not be obtained.
*/
RexxMethod6(RexxObjectPtr, popMenu_show, RexxObjectPtr, location, OPTIONAL_RexxObjectPtr, _dlg,
OPTIONAL_CSTRING, opts, OPTIONAL_logical_t, bothButtons, OPTIONAL_RexxObjectPtr, excludeRect, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
return cMenu->trackPopup(location, _dlg, opts, bothButtons, excludeRect, false);
}
/**
* Methods for the .ScriptMenuBar class.
*/
#define SCRIPTMENUBAR_CLASS "ScriptMenuBar"
/** ScriptMenuBar::init()
*
* Initializes a .ScriptMenuBar object. The underlying menu object is created
* in memory by parsing a resource script file. The script is parsed and
* converted to a HMENU at once.
*
* @param rcFile [required] The file name of the resource script.
*
* @param id [optional] The resource id of the menu. If omitted,
* then the first menu found in the resource file is used.
*
* @param helpID [optional] Context help ID for the menu. The default
* is 0 indicating no help ID.
*
* @param count [optional] The count of menu items. This determines
* the size of memory allocated for the template. The
* default if omitted is 100.
*
* @param connect [optional] If true, each menu command item in the menu
* is connected to a method in a Rexx dialog. The name of
* the method is composed from the menu item text. This
* uses the connection requested method of connecting menu
* items. The default is false.
*
* @param attachTo [optional] If specified attach this menu to the
* dialog. If specified, attachTo has to be a
* .PlainBaseDialog or subclass. If not, an exception is
* raised.
*
* @return No return.
*
* @remarks Raises exceptions for all failures. If no exceptions, the menu is
* created successfully.
*
* Also sets .SystemErrorCode. It will be non-zero, only, if the
* help ID is set and there is a Windows API failure. It hardly
* seems possible that this could happen.
*
* Script menu bars pose some problems relating to the MENU
* definition ID in the resource script file. The menu id can be a
* simple string. Because of that, we can't raise an exception if
* the ID does not resolve, because it could be a legimate string
* name for the menu. We need to wait and have load() raise an
* exception if it can not locate the menu.
*/
RexxMethod7(RexxObjectPtr, scriptMenu_init, RexxStringObject, rcFile, OPTIONAL_RexxObjectPtr, _id,
OPTIONAL_RexxObjectPtr, helpID, OPTIONAL_uint32_t, count, OPTIONAL_logical_t, connect,
OPTIONAL_RexxObjectPtr, attachTo, OSELF, self)
{
CppMenu *cMenu = new CppMenu(self, ScriptMenuBar, context);
RexxPointerObject cMenuPtr = context->NewPointer(cMenu);
context->SendMessage1(self, "MENUINIT", cMenuPtr);
bool idOmitted = argumentOmitted(2) ? true : false;
if ( argumentExists(2) )
{
int32_t id = oodGlobalID(context, _id, 2, true);
if ( id == OOD_ID_EXCEPTION )
{
context->ClearCondition();
}
else
{
cMenu->setMenuID(id);
}
}
DWORD dwHelpID = 0;
if ( argumentExists(3) )
{
int32_t tmp = oodGlobalID(context, helpID, 3, false);
if ( tmp == OOD_ID_EXCEPTION )
{
goto done_out;
}
dwHelpID = tmp;
}
if ( argumentOmitted(4) || count == 0 )
{
count = DEFAULT_MENUITEM_COUNT;
}
if ( argumentExists(6) )
{
// We make sure here, that attachToDlg() later will not fail.
if ( ! validAttachTo(context, attachTo, 6) )
{
goto done_out;
}
}
if ( ! cMenu->initTemplate(count, dwHelpID) )
{
goto done_out;
}
// If wID == -1 and id was not ommitted, then id could be a string menu
// name. Or, it could be a bad symbolic ID. If it is a bad symbol, then
// load() will raise an exception, so that's ok.
RexxObjectPtr menuName = (cMenu->wID == -1 && ! idOmitted) ? _id : context->NullString();
RexxMethodContext *c = context;
RexxArrayObject args = context->ArrayOfFour(rcFile, c->Int32(cMenu->wID), context->Logical(connect),
context->UnsignedInt32(count));
context->ArrayAppend(args, idOmitted ? TheTrueObj : TheFalseObj);
context->ArrayAppend(args, menuName);
// Note well: the load() method makes repeated calls to addItem(),
// addPopup(), etc. Each call resets the internal CppMenu context. When we
// return, the internal cMenu context will no longer be this context. It
// *must* be reset.
context->SendMessage(self, "LOAD", args);
cMenu->setContext(context, TheNilObj);
if ( context->CheckCondition() )
{
cMenu->deleteTemplate();
cMenu->noTempHelpID();
goto done_out;
}
if ( ! cMenu->finishTemplate() )
{
goto done_out;
}
if ( argumentExists(6) )
{
cMenu->attachToDlg(attachTo, 0);
}
done_out:
return NULLOBJECT;
}
/**
* Methods for the .UserMenuBar class.
*/
#define USERMENUBAR_CLASS "UserMenuBar"
/** UserMenuBar::init()
*
* Initializes a .UserMenuBar object. The underlying menu object is created as
* a template in memory by the Rexx programmer using methods of the
* .MenuTemplate class. The menu is not valid until the programmer invokes the
* complete() method which tramsforms the in memory template to an actual menu.
*
*
* @param id [optional] The resource id of / for the menu. Can be
* -1 to indicate no ID. The default is -1.
*
* @param helpID [optional] Context help ID for the menu. The default
* is 0 indicating no help ID.
*
* @param count [optional] The count of menu items. This determines
* how much storage is allocated for the menu template.
* This is just a rough estimate, a generous amount of
* storage is allocated for each menu item. In almost all
* cases more menu items can be added than specified here.
* The default is 100. If more items are added than there
* is storage for, a condition is raised. If that
* happens, the count needs to be increased.
*
* @param autoConnect [optional] Turn on autoConnection if true. Default is
* false.
*
* @param mName [optional] If autoConnect, set autoConnectionMethod to
* this method. If omitted autoConectionMethod is left
* alone.
*
* @return No return.
*
* @note Raises exceptions for all detected problems. The menu is not
* actually created until complete() is invoked.
*
* To use symbolic IDs, the global .ConstDir must be enabled.
*
* @remarks Note that when using the MENUEX_TEMPLATE_HEADER you are supposed
* to be able to set the help ID for the menu, but this does not seem
* to work. So, for this class we save the help ID in CppMenu and
* then set it when the complete method is called.
*/
RexxMethod6(RexxObjectPtr, userMenu_init, OPTIONAL_RexxObjectPtr, _id, OPTIONAL_RexxObjectPtr, helpID,
OPTIONAL_uint32_t, count, OPTIONAL_logical_t, autoConnect, OPTIONAL_CSTRING, mName, OSELF, self)
{
CppMenu *cMenu = new CppMenu(self, UserMenuBar, context);
RexxPointerObject cMenuPtr = context->NewPointer(cMenu);
context->SendMessage1(self, "MENUINIT", cMenuPtr);
if ( argumentExists(1) )
{
int32_t id = oodGlobalID(context, _id, 1, false);
if ( id == OOD_ID_EXCEPTION )
{
goto done_out;
}
cMenu->setMenuID(id);
}
DWORD dwHelpID = 0;
if ( argumentExists(2) )
{
int32_t tmp = oodGlobalID(context, helpID, 2, false);
if ( tmp == OOD_ID_EXCEPTION )
{
goto done_out;
}
dwHelpID = tmp;
}
if ( argumentOmitted(3) || count == 0 )
{
count = DEFAULT_MENUITEM_COUNT;
}
if ( ! cMenu->initTemplate(count, dwHelpID) )
{
goto done_out;
}
if ( autoConnect )
{
if ( ! cMenu->setAutoConnection(TRUE, mName) )
{
outOfMemoryException(context->threadContext);
}
}
done_out:
return NULLOBJECT;
}
/** UserMenuBar::complete()
*
*
*/
RexxMethod1(logical_t, userMenu_complete, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
if ( ! cMenu->finishTemplate() )
{
return FALSE;
}
return TRUE;
}
/** Menu::test()
*
* Used as a convenient way to test code.
*
*/
RexxMethod1(logical_t, menu_test, CSELF, cMenuPtr)
{
CppMenu *cMenu = (CppMenu *)cMenuPtr;
cMenu->setContext(context, TheFalseObj);
CppMenu *tmpMenu = new CppMenu(cMenu->getSelf(), BinaryMenuBar, context);
cMenu->test(tmpMenu);
return 0;
}
void CppMenu::test(CppMenu *other)
{
printf("CppMenu::test() self=%p other=%p\n", this, other);
printf("Access protected field? isFinal? %d\n", other->isFinal);
}
static UINT checkCommonTypeOpts(const char *opts, UINT type)
{
if ( StrStrI(opts, "NOTMENUBARBREAK") != NULL )
{
type &= ~MFT_MENUBARBREAK;
}
else if ( StrStrI(opts, "MENUBARBREAK") != NULL )
{
type |= MFT_MENUBARBREAK;
}
if ( StrStrI(opts, "NOTMENUBREAK") != NULL )
{
type &= ~MFT_MENUBREAK;
}
else if ( StrStrI(opts, "MENUBREAK") != NULL )
{
type |= MFT_MENUBREAK;
}
if ( StrStrI(opts, "NOTRIGHTJUSTIFY") != NULL )
{
type &= ~MFT_RIGHTJUSTIFY;
}
else if ( StrStrI(opts, "RIGHTJUSTIFY") != NULL )
{
type |= MFT_RIGHTJUSTIFY;
}
return type;
}
static UINT checkCommonStateOpts(const char *opts, UINT state)
{
if ( StrStrI(opts, "NOTDEFAULT") != NULL )
{
state &= ~MFS_DEFAULT;
}
else if ( StrStrI(opts, "DEFAULT") != NULL )
{
state |= MFS_DEFAULT;
}
if ( StrStrI(opts, "DISABLED") != NULL )
{
state |= MFS_DISABLED;
}
if ( StrStrI(opts, "GRAYED") != NULL )
{
state |= MFS_GRAYED;
}
if ( StrStrI(opts, "ENABLED") != NULL )
{
state &= ~MFS_DISABLED;
}
if ( StrStrI(opts, "UNHILITE") != NULL )
{
state &= ~MFS_HILITE;
}
else if ( StrStrI(opts, "HILITE") != NULL )
{
state |= MFS_HILITE;
}
return state;
}
/**
* Parses an option string to determine a popup menu's type flags.
*
* @param opts Keywords signaling the different MFT_* flags. These are the
* valid keywords: MENUBARBREAK MENUBREAK RIGHTJUSTIFY RIGHTORDER
*
* To remove these types from an existing item, use NOT, i.e.
* NOTRIGHTORDER will remvoe the MFT_RIGHTORDER flag from a menu
* item.
*
* @return The combined MFT_* flags for a popup menu.
*/
static UINT getPopupTypeOpts(const char *opts, UINT type)
{
type = checkCommonTypeOpts(opts, type);
if ( StrStrI(opts, "NOTRIGHTORDER") != NULL )
{
type &= ~MFT_RIGHTORDER;
}
else if ( StrStrI(opts, "RIGHTORDER") != NULL )
{
type |= MFT_RIGHTORDER;
}
return type;
}
/**
* Parses an option string to determine a popup menu's state flags.
*
* @param opts Keywords signaling the different MFS_* flags. These are the
* valid keyworkds: DEFAULT NOTDEFAULT DISABLED GRAYED ENABLED
* HILITE UNHILITE
*
* @return The combined MFS_* flags for a popup menu.
*
* Note that with extended menus disabled and grared are the same thing.
*/
static UINT getPopupStateOpts(const char *opts, UINT state)
{
state = checkCommonStateOpts(opts, state);
return state;
}
/**
* Parses an option string to determine a menu item's type flags.
*
* @param opts Keywords signaling the different MFT_* flags. These are the
* valid keywords: MENUBARBREAK MENUBREAK RIGHTJUSTIFY RADIO
*
* To remove these types from an existing item, use NOT, i.e.
* NOTRADIO will remvoe the MFT_RADIOCHECK flag from a menu item.
*
* @return The combined MFT_* flags for a menu item.
*
* Note that RIGHTJUSTIFY is only valid in a menu bar. Normally menu bars only
* contain submenus, but menu items are perfectly valid in a menu bar. If the
* right justify flag is used in a submenu, it has no effect.
*/
static UINT getItemTypeOpts(const char *opts, UINT type)
{
type = checkCommonTypeOpts(opts, type);
if ( StrStrI(opts, "NOTRADIO") != NULL )
{
type &= ~MFT_RADIOCHECK;
}
else if ( StrStrI(opts, "RADIO") != NULL )
{
type |= MFT_RADIOCHECK;
}
return type;
}
/**
* Parses an option string to determine a separtor's type flags.
*
* @param opts Keywords signaling the different MFT_* flags. These are the
* valid keywords: MENUBARBREAK MENUBREAK RIGHTJUSTIFY
*
* To remove these types from an existing separator, use NOT, i.e.
* NOTMENUBARBREAK will remove the MFT_MENUBARBREAK flag from a menu
* separator.
*
* @return The combined MFT_* flags for a menu separtor.
*/
static UINT getSeparatorTypeOpts(const char *opts, UINT type)
{
if ( StrStrI(opts, "NOTMENUBARBREAK") != NULL )
{
type &= ~MFT_MENUBARBREAK;
}
else if ( StrStrI(opts, "MENUBARBREAK") != NULL )
{
type |= MFT_MENUBARBREAK;
}
if ( StrStrI(opts, "NOTMENUBREAK") != NULL )
{
type &= ~MFT_MENUBREAK;
}
else if ( StrStrI(opts, "MENUBREAK") != NULL )
{
type |= MFT_MENUBREAK;
}
if ( StrStrI(opts, "NOTRIGHTJUSTIFY") != NULL )
{
type &= ~MFT_RIGHTJUSTIFY;
}
else if ( StrStrI(opts, "RIGHTJUSTIFY") != NULL )
{
type |= MFT_RIGHTJUSTIFY;
}
return type;
}
/**
* Parses an option string to determine a menu item's state flags.
*
* @param opts The valid keywords are DEFAULT NOTDEFAULT DISABLED GRAYED ENABLED
* UNCHECKED CHECKED HILITE UNHILITE.
* @param state The parsed state from the options is combined with this state,
* pesumably the current state. Use 0 to get the exact state
* specified by the opts string.
*
* @return UINT
*
* Note that with extended menus grayed and disabled are the same thing.
*/
static UINT getItemStateOpts(const char *opts, UINT state)
{
state = checkCommonStateOpts(opts, state);
if ( StrStrI(opts, "UNCHECKED") != NULL )
{
state &= ~MFS_CHECKED;
}
else if ( StrStrI(opts, "CHECKED") != NULL )
{
state |= MFS_CHECKED;
}
return state;
}
static UINT getTrackFlags(const char *opt)
{
uint32_t flag = 0;
if ( StrStrI(opt, "LEFT") != NULL )
{
flag = TPM_LEFTALIGN;
}
else if ( StrStrI(opt, "HCENTER") != NULL )
{
flag = TPM_CENTERALIGN;
}
else
{
flag = TPM_RIGHTALIGN;
}
if ( StrStrI(opt, "TOP") != NULL )
{
flag |= TPM_TOPALIGN;
}
else if ( StrStrI(opt, "VCENTER") != NULL )
{
flag |= TPM_VCENTERALIGN;
}
else
{
flag |= TPM_BOTTOMALIGN;
}
if ( StrStrI(opt, "HORNEGANIMATION") != NULL )
{
flag |= TPM_HORNEGANIMATION;
}
if ( StrStrI(opt, "HORPOSANIMATION") != NULL )
{
flag |= TPM_HORPOSANIMATION;
}
if ( StrStrI(opt, "NOANIMATION") != NULL )
{
flag |= TPM_NOANIMATION;
}
if ( StrStrI(opt, "VERNEGANIMATION") != NULL )
{
flag |= TPM_VERNEGANIMATION;
}
if ( StrStrI(opt, "VERPOSANIMATION") != NULL )
{
flag |= TPM_VERPOSANIMATION;
}
if ( StrStrI(opt, "HORIZONTAL") != NULL )
{
flag |= TPM_HORIZONTAL;
}
if ( StrStrI(opt, "VERTICAL") != NULL )
{
flag |= TPM_VERTICAL;
}
if ( StrStrI(opt, "RECURSE") != NULL )
{
flag |= TPM_RECURSE;
}
if ( ComCtl32Version >= COMCTL32_6_0 )
{
if ( StrStrI(opt, "LAYOUTRTL") != NULL )
{
flag |= TPM_LAYOUTRTL;
}
}
return flag;
}