[r8780]: ooDialog / trunk / ooDialog / ooDialog.cpp Maximize Restore History

Download this file

ooDialog.cpp    5292 lines (4761 with data), 170.0 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
/*----------------------------------------------------------------------------*/
/* */
/* 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. */
/* */
/*----------------------------------------------------------------------------*/
/**
* ooDialog.cpp
*
* The base module for the ooDialog package. Contains the method implmentations
* for the WindowBase and PlainBaseDialog classes.
*/
#include "ooDialog.hpp" // Must be first, includes windows.h, commctrl.h, and oorexxapi.h
#include <mmsystem.h>
#include <stdio.h>
#include <dlgs.h>
#include <shlwapi.h>
#include "APICommon.hpp"
#include "oodCommon.hpp"
#include "oodControl.hpp"
#include "oodMessaging.hpp"
#include "oodData.hpp"
#include "oodDeviceGraphics.hpp"
#include "oodResizableDialog.hpp"
#include "oodResourceIDs.hpp"
inline bool isValidOwner(pCPlainBaseDialog pcpbd)
{
if ( pcpbd->isPropSheetDlg || pcpbd->isPageDlg || pcpbd->isControlDlg )
{
return false;
}
return true;
}
/**
* Loads and returns the handle to an icon for the specified ID, of the
* specified size.
*
* The icons can come from the user resource DLL, a user defined dialog, the
* OODialog DLL, the System. IDs for the icons bound to the OODialog.dll are
* reserved.
*
* @param pcpbd Pointer to the CSelf struct for the dialog
* @param id Numerical resource ID.
* @param iconSrc Flag indicating the source of the icon.
* @param cx The desired width of the icon.
* @param cy The desired height of the icon.
*
* @return The handle to the loaded icon on success, or null on failure.
*/
static HICON getIconForID(pCPlainBaseDialog pcpbd, UINT id, UINT iconSrc, int cx, int cy)
{
HINSTANCE hInst = NULL;
LPCTSTR pName = NULL;
UINT loadFlags = 0;
if ( iconSrc & ICON_FILE )
{
// Load the icon from a file, file name should be in the icon table.
size_t i;
for ( i = 0; i < pcpbd->IT_nextIndex; i++ )
{
if ( pcpbd->IconTab[i].iconID == id )
{
pName = pcpbd->IconTab[i].fileName;
break;
}
}
if ( ! pName )
{
return NULL;
}
loadFlags = LR_LOADFROMFILE;
}
else
{
// Load the icon from the resources in oodialog.dll or the user's resource DLL.
hInst = (iconSrc & ICON_OODIALOG) ? MyInstance : pcpbd->hInstance;
pName = MAKEINTRESOURCE(id);
loadFlags = LR_SHARED;
}
return (HICON)LoadImage(hInst, pName, IMAGE_ICON, cx, cy, loadFlags);
}
static void deleteMessageTables(pCEventNotification pcen)
{
size_t i;
for ( i = 0; i < pcen->cmNextIndex; i++ )
{
safeLocalFree(pcen->commandMsgs[i].rexxMethod);
}
LocalFree(pcen->commandMsgs);
pcen->commandMsgs = NULL;
pcen->cmSize = 0;
pcen->cmNextIndex = 0;
if ( pcen->notifyMsgs != NULL )
{
for ( i = 0; i < pcen->nmNextIndex; i++ )
{
safeLocalFree(pcen->notifyMsgs[i].rexxMethod);
}
LocalFree(pcen->notifyMsgs);
pcen->nmNextIndex = 0;
pcen->nmSize = 0;
pcen->notifyMsgs = NULL;
}
if ( pcen->miscMsgs != NULL )
{
for ( i = 0; i < pcen->mmNextIndex; i++ )
{
safeLocalFree(pcen->miscMsgs[i].rexxMethod);
}
LocalFree(pcen->miscMsgs);
pcen->mmNextIndex = 0;
pcen->mmSize = 0;
pcen->miscMsgs = NULL;
}
}
HBRUSH searchForBrush(pCPlainBaseDialog pcpbd, size_t *index, uint32_t id)
{
HBRUSH hBrush = NULL;
size_t i = 0;
if ( pcpbd != NULL && pcpbd->ColorTab != NULL )
{
while ( i < pcpbd->CT_nextIndex && pcpbd->ColorTab[i].itemID != id )
{
i++;
}
if ( i < pcpbd->CT_nextIndex )
{
hBrush = pcpbd->ColorTab[i].ColorBrush;
*index = i;
}
}
return hBrush;
}
bool loadResourceDLL(pCPlainBaseDialog pcpbd, CSTRING library)
{
pcpbd->hInstance = LoadLibrary(library);
if ( ! pcpbd->hInstance )
{
CHAR msg[256];
sprintf(msg,
"Failed to load Dynamic Link Library (resource DLL.)\n"
" Windows System Error Code:\t%d\n"
" File name:\t\t%s\n", GetLastError(), library);
MessageBox(0, msg, "ooDialog DLL Load Error", MB_OK | MB_ICONHAND | MB_SYSTEMMODAL);
return false;
}
return true;
}
/**
* Do some common set up when creating the underlying Windows dialog for any
* ooDialog dialog. This involves setting the 'TopDlg' and the hInstance
* fields of the CSelf struct for the dialog.
*
* If this is a ResDialog then the resource DLL is loaded, otherwise the
* hInstance field is the ooDialog.dll instance.
*
* @param pcpbd Pointer to the CSelf struct for the dialog
* @param library The library to load the dialog from, if a ResDialog, othewise
* null.
*
* @return True on success, false only if this is for a ResDialog and the
* loading of the resource DLL failed.
*/
bool installNecessaryStuff(pCPlainBaseDialog pcpbd, CSTRING library)
{
if ( pcpbd->previous )
{
((pCPlainBaseDialog)pcpbd->previous)->onTheTop = false;
}
TopDlg = pcpbd;
if ( library != NULL )
{
return loadResourceDLL(pcpbd, library);
}
else
{
pcpbd->hInstance = MyInstance;
}
return true;
}
inline bool dlgInDlgTable(pCPlainBaseDialog dlg)
{
register size_t i;
for ( i = 0; i < CountDialogs; i++ )
{
if ( DialogTable[i] == dlg )
{
return true;
}
}
return false;
}
/**
* Makes sure the finished attribute in the Rexx dialog is set to true. This
* causes the Rexx dialog's run method to complete and things to unwind.
*
* @param pcpbd CSelf struct for the dialog.
* @param c Rexx thread context we are operating in. It is possible that
* this is null.
*
* @remarks
*/
void ensureFinished(pCPlainBaseDialog pcpbd, RexxThreadContext *c, RexxObjectPtr abnormal)
{
if ( c != NULL )
{
c->SendMessage1(pcpbd->rexxSelf, "ENSUREFINISHED", abnormal);
}
else
{
RexxThreadContext *context;
if ( pcpbd->interpreter->AttachThread(&context) )
{
context->SendMessage1(pcpbd->rexxSelf, "ENSUREFINISHED", abnormal);
context->DetachThread();
}
}
}
void delPageDialog(pCPropertySheetPage pcpsp)
{
if ( pcpsp->pageTitle != NULL )
{
LocalFree(pcpsp->pageTitle);
pcpsp->pageTitle = NULL;
}
if ( pcpsp->headerTitle != NULL )
{
LocalFree(pcpsp->headerTitle);
pcpsp->headerTitle = NULL;
}
if ( pcpsp->headerTitleAero != NULL )
{
LocalFree(pcpsp->headerTitleAero);
pcpsp->headerTitleAero = NULL;
}
if ( pcpsp->headerSubTitle != NULL )
{
LocalFree(pcpsp->headerSubTitle);
pcpsp->headerSubTitle = NULL;
}
if ( ! pcpsp->inRemovePage && pcpsp->hPropSheetPage != NULL )
{
DestroyPropertySheetPage(pcpsp->hPropSheetPage);
pcpsp->hPropSheetPage = NULL;
safeLocalFree(pcpsp->psp);
pcpsp->psp = NULL;
}
}
void delPropSheetDialog(pCPropertySheetDialog pcpsd)
{
if ( pcpsd->cppPages != NULL )
{
LocalFree(pcpsd->cppPages);
pcpsd->cppPages = NULL;
}
if ( pcpsd->rexxPages != NULL )
{
LocalFree(pcpsd->rexxPages);
pcpsd->rexxPages = NULL;
}
if ( pcpsd->caption != NULL )
{
LocalFree(pcpsd->caption);
pcpsd->caption = NULL;
}
pcpsd->pageCount = 0;
}
/**
* Ends a running dialog and cleans up some (most) of the CSelf struct.
*
* Note that this function is at times called when the underlying Windows dialog
* was not created, and therefore there is no dialog handle.
*
* @param pcpbd The CSelf pointer for the PlainBaseDialog whose underlying
* dialog is being ended, (or whose CSelf is being cleaned up
* if the dialog never got started.)
*
* @param c A valid thread context, or null if the thread context is not
* known. This is only used when it is thought to be an abnormal
* termination, in which case it is use to invoke ensureFinished()
* int the Rexx dialog object.
*
* @return It doesn't appeat that the return code was ever used anywhere in
* ooDialog. So, it may be better to just eliminate the return. For
* now, 1 is returned if the admin block has already been through
* delDialog(), which should nver happen. 2 is returned if
* abnormalHal() is still set. Otherwise 1 is returned.
*
* @remarks We should never enter this function with dlgAllocated set to
* false. The flag is only set to false in this function, and it is
* protected by the critical section. Nevertheless, if we do get
* here, we just leave.
*
* @remarks If abnormalHalt set to true, then we entered delDialog() under some
* very unusual error path.
*
* In which case, it is likely that the PlainBaseDialog::run() method
* is still waiting (guard on) on the finished attribute and we will
* hang.
*
* In all normal cases, the finished attribute is set through the OK
* or Cancel mechanism and delDialog() is running *after* finished is
* already set. So, if abnormalHalt is set, we take an extra step to
* try and be sure waitForDialog() ends. So far, this cleans up all
* the hangs I was able to produce, but this could still be a problem
* area.
*
* @remarks There was an old ooDialog comment right before the admin block was
* removed from the DialogTable, which read: "The dialog adminstration
* block entry must be removed before the WM_QUIT message is posted."
*
* I believe that comment was due to worries about acessing the
* pointer after things had started to be freed. The
* 'dialogInAdminTable' check was used a lot. Now the dlgAllocated
* flag replaces that check, and the flag is set ahead of the WM_QUIT
* being posted.
*
* @remarks The small and big icons: If not shared, the icon(s) were loaded
* from a file and need to be freed, otherwise the OS handles the
* free. The title bar icon is tricky. At this point the dialog may
* still be visible. If the small icon in the class is set to 0, the
* application will hang. Same thing happens if the icon is freed.
* So, don't set a zero into the class bytes, and, if the icon is to
* be freed, do so after leaving the critical section.
*/
int32_t delDialog(pCPlainBaseDialog pcpbd, RexxThreadContext *c)
{
size_t i;
HICON hIconBig = NULL;
HICON hIconSmall = NULL;
EnterCriticalSection(&crit_sec);
#if 0
printf("In delDialog() hDlg=%p tabIdx=%d allocated=%d isActive=%d onTop=%d\n prev=%p abnormalHalt=%d\n",
pcpbd->hDlg, pcpbd->tableIndex, pcpbd->dlgAllocated, pcpbd->isActive, pcpbd->onTheTop, pcpbd->previous,
pcpbd->abnormalHalt);
#endif
if ( ! pcpbd->dlgAllocated )
{
printf("delDialog() already ran for this dialog! pcpbd=%p\n", pcpbd);
return -1;
}
pcpbd->dlgAllocated = false;
int32_t ret = 1;
bool wasFGW = (pcpbd->hDlg == GetForegroundWindow());
if ( pcpbd->abnormalHalt )
{
ensureFinished(pcpbd, c, TheTrueObj);
ret = 2;
}
pcpbd->abnormalHalt = false;
if ( !( pcpbd->isControlDlg || pcpbd->isPageDlg) )
{
// Remove the dialog from the dialog table
if ( pcpbd->tableIndex == CountDialogs - 1 )
{
// The dialog being ended is the last entry in the table, just set it to
// null.
DialogTable[pcpbd->tableIndex] = NULL;
}
else
{
// The dialog being ended is not the last entry. Move the last entry to
// the one being deleted and then delete the last entry.
DialogTable[pcpbd->tableIndex] = DialogTable[CountDialogs-1];
DialogTable[pcpbd->tableIndex]->tableIndex = pcpbd->tableIndex;
DialogTable[CountDialogs-1] = NULL;
}
CountDialogs--;
}
if ( pcpbd->hDlg && ! pcpbd->isPageDlg )
{
if ( ! pcpbd->isControlDlg )
{
PostMessage(pcpbd->hDlg, WM_QUIT, 0, 0);
}
DestroyWindow(pcpbd->hDlg);
}
pcpbd->isActive = false;
if ( pcpbd->mouseCSelf != NULL )
{
pCMouse pcm = (pCMouse)pcpbd->mouseCSelf;
pcm->dlgCSelf = NULL;
pcpbd->rexxMouse = NULLOBJECT;
pcpbd->mouseCSelf = NULL;
}
// Swap back the saved icons, if needed. See the remarks in the function
// header.
if ( pcpbd->hDlg && pcpbd->didChangeIcon )
{
hIconBig = (HICON)setClassPtr(pcpbd->hDlg, GCLP_HICON, (LONG_PTR)pcpbd->sysMenuIcon);
if ( pcpbd->titleBarIcon )
{
hIconSmall = (HICON)setClassPtr(pcpbd->hDlg, GCLP_HICONSM, (LONG_PTR)pcpbd->titleBarIcon);
}
if ( ! pcpbd->sharedIcon )
{
DestroyIcon(hIconBig);
if ( ! hIconSmall )
{
hIconSmall = (HICON)getClassPtr(pcpbd->hDlg, GCLP_HICONSM);
}
}
else
{
hIconSmall = NULL;
}
}
if ( pcpbd->hInstance != NULL && pcpbd->hInstance != MyInstance )
{
FreeLibrary(pcpbd->hInstance);
}
pcpbd->hDlg = NULL;
if ( pcpbd->wndBase->rexxHwnd != TheZeroObj && c != NULL ) // TODO fix it so that c can not be null.
{
c->ReleaseGlobalReference(pcpbd->wndBase->rexxHwnd);
pcpbd->wndBase->rexxHwnd = TheZeroObj;
}
safeLocalFree(pcpbd->bkgBitmap);
safeDeleteObject(pcpbd->bkgBrush);
pcpbd->bkgBitmap = NULL;
pcpbd->bkgBrush = NULL;
// Delete the message tables of the dialog.
deleteMessageTables(pcpbd->enCSelf);
// Delete the data table.
safeLocalFree(pcpbd->DataTab);
pcpbd->DataTab = NULL;
pcpbd->DT_nextIndex = 0;
pcpbd->DT_size = 0;
// Delete the color brushes.
if (pcpbd->ColorTab)
{
for ( i = 0; i < pcpbd->CT_nextIndex; i++ )
{
safeDeleteObject(pcpbd->ColorTab[i].ColorBrush);
}
LocalFree(pcpbd->ColorTab);
pcpbd->ColorTab = NULL;
pcpbd->CT_nextIndex = 0;
pcpbd->CT_size = 0;
}
// Delete the bitmaps and bitmap table.
if (pcpbd->BmpTab)
{
for ( i = 0; i < pcpbd->BT_nextIndex; i++ )
{
if ( (pcpbd->BmpTab[i].loaded & 0x1011) == 1 )
{
/* otherwise stretched bitmap files are not freed */
safeLocalFree((void *)pcpbd->BmpTab[i].bitmapID);
safeLocalFree((void *)pcpbd->BmpTab[i].bmpFocusID);
safeLocalFree((void *)pcpbd->BmpTab[i].bmpSelectID);
safeLocalFree((void *)pcpbd->BmpTab[i].bmpDisableID);
}
else if ( pcpbd->BmpTab[i].loaded == 0 )
{
safeDeleteObject((HBITMAP)pcpbd->BmpTab[i].bitmapID);
safeDeleteObject((HBITMAP)pcpbd->BmpTab[i].bmpFocusID);
safeDeleteObject((HBITMAP)pcpbd->BmpTab[i].bmpSelectID);
safeDeleteObject((HBITMAP)pcpbd->BmpTab[i].bmpDisableID);
}
}
LocalFree(pcpbd->BmpTab);
safeDeleteObject(pcpbd->colorPalette);
pcpbd->BT_nextIndex = 0;
pcpbd->BT_size = 0;
}
// Delete the icon resource table.
if (pcpbd->IconTab)
{
for ( i = 0; i < pcpbd->IT_nextIndex; i++ )
{
safeLocalFree(pcpbd->IconTab[i].fileName);
}
LocalFree(pcpbd->IconTab);
pcpbd->IconTab = NULL;
pcpbd->IT_nextIndex = 0;
pcpbd->IT_size = 0;
}
// Unhook a hook if it is installed.
if ( pcpbd->enCSelf->hHook )
{
removeKBHook(pcpbd->enCSelf);
}
// For property sheet and property sheet page dialogs, it is unlikely, but
// posible that dlgPrivate is not yet set. (Happens if there is an error in
// init().
if ( pcpbd->isPageDlg && pcpbd->dlgPrivate != NULL )
{
delPageDialog((pCPropertySheetPage)pcpbd->dlgPrivate);
pcpbd->dlgPrivate = NULL;
}
if ( pcpbd->isResizableDlg && pcpbd->resizeInfo != NULL )
{
safeLocalFree(pcpbd->resizeInfo->riCtrls);
safeLocalFree(pcpbd->resizeInfo->sizeEndedMeth);
safeLocalFree(pcpbd->resizeInfo);
pcpbd->resizeInfo = NULL;
}
if ( pcpbd->isPropSheetDlg && pcpbd->dlgPrivate != NULL )
{
delPropSheetDialog((pCPropertySheetDialog)pcpbd->dlgPrivate);
pcpbd->dlgPrivate = NULL;
}
if ( ! (pcpbd->isControlDlg || pcpbd->isPageDlg) )
{
// Not sure this whole TopDlg thing is correctly coded.
if ( CountDialogs == 0 )
{
TopDlg = NULL;
}
else
{
// It seems possible that pcpbd->previous may have been deleted already.
pCPlainBaseDialog prev = (pCPlainBaseDialog)pcpbd->previous;
if ( prev != NULL && dlgInDlgTable(prev) )
{
TopDlg = prev;
if ( ! IsWindowEnabled(TopDlg->hDlg) )
{
EnableWindow(TopDlg->hDlg, TRUE);
}
if ( wasFGW )
{
SetForegroundWindow(TopDlg->hDlg);
TopDlg->onTheTop = true;
}
}
}
}
LeaveCriticalSection(&crit_sec);
if ( hIconSmall )
{
DestroyIcon(hIconSmall);
}
return ret;
}
/**
* Loads and returns the handles to the regular size and small size icons for
* the dialog. These icons are used in the title bar of the dialog, on the task
* bar, and for the alt-tab display.
*
* The icons can come from the user resource DLL, a user defined dialog, or the
* OODialog DLL. IDs for the icons bound to the OODialog.dll are reserved.
*
* This function attempts to always succeed. If an icon is not attained, the
* default icon from the resources in the OODialog DLL is used. This icon
* should always be present, it is bound to the DLL when ooRexx is built.
*
* @param pcpbd Pointer to the CSelf struct for the dialog
* @param id Numerical resource ID.
* @param iconSrc Flag indicating whether the icon is located in a DLL or to
* be loaded from a file.
* @param phBig In/Out Pointer to an icon handle. If the function succeeds,
* on return will contain the handle to a regular size icon.
* @param phSmall In/Out Pointer to an icon handle. On success will contain
* a handle to a small size icon.
*
* @return True if the icons were loaded and the returned handles are valid,
* otherwise false.
*/
BOOL getDialogIcons(pCPlainBaseDialog pcpbd, INT id, UINT iconSrc, PHANDLE phBig, PHANDLE phSmall)
{
int cx, cy;
if ( phBig == NULL || phSmall == NULL )
{
return FALSE;
}
if ( id < 1 )
{
id = IDI_DLG_DEFAULT;
}
/* If one of the reserved IDs, iconSrc has to be ooDialog. */
if ( id >= IDI_DLG_MIN_ID && id <= IDI_DLG_MAX_ID )
{
iconSrc = ICON_OODIALOG;
}
cx = GetSystemMetrics(SM_CXICON);
cy = GetSystemMetrics(SM_CYICON);
*phBig = getIconForID(pcpbd, id, iconSrc, cx, cy);
/* If that didn't get the big icon, try to get the default icon. */
if ( ! *phBig && id != IDI_DLG_DEFAULT )
{
id = IDI_DLG_DEFAULT;
iconSrc = ICON_OODIALOG;
*phBig = getIconForID(pcpbd, id, iconSrc, cx, cy);
}
/* If still no big icon, don't bother trying for the small icon. */
if ( *phBig )
{
cx = GetSystemMetrics(SM_CXSMICON);
cy = GetSystemMetrics(SM_CYSMICON);
*phSmall = getIconForID(pcpbd, id, iconSrc, cx, cy);
/* Very unlikely that the big icon was obtained and failed to get the
* small icon. But, if so, fail completely. If the big icon came from
* a DLL it was loaded as shared and the system handles freeing it. If
* it was loaded from a file, free it here.
*/
if ( ! *phSmall )
{
if ( iconSrc & ICON_FILE )
{
DestroyIcon((HICON)*phBig);
}
*phBig = NULL;
}
}
if ( ! *phBig )
{
return FALSE;
}
pcpbd->sharedIcon = iconSrc != ICON_FILE;
return TRUE;
}
/**
* Methods for the .WindowBase mixin class.
*/
#define WINDOWBASE_CLASS "WindowBase"
#define DISPLAY_METHOD_OPTIONS "'NORMAL', 'NORMAL FAST', 'DEFAULT', 'DEFAULT FAST', 'HIDE', 'HIDE FAST', or 'INACTIVE'"
static inline pCWindowBase validateWbCSelf(RexxMethodContext *c, void *pCSelf)
{
pCWindowBase pcwb = (pCWindowBase)pCSelf;
if ( pcwb == NULL )
{
baseClassInitializationException(c);
}
return pcwb;
}
static inline HWND getWBWindow(RexxMethodContext *c, void *pCSelf)
{
pCWindowBase pcwb = validateWbCSelf(c, pCSelf);
return pcwb == NULL ? NULL : pcwb->hwnd;
}
static HWND wbSetUp(RexxMethodContext *c, void *pCSelf)
{
oodResetSysErrCode(c->threadContext);
HWND hwnd = getWBWindow(c, pCSelf);
if ( hwnd == NULL )
{
noWindowsDialogException(c, ((pCWindowBase)pCSelf)->rexxSelf);
}
return hwnd;
}
#define CWP_KEYWORDS "SKIPDISABLED, SKIPINVISIBLE, SKIPTRANSPARENT, or ALL"
uint32_t flags2cwp(CSTRING flags)
{
uint32_t opts = 0xFFFFFFFF;
if ( StrStrI(flags, "ALL") )
{
opts = CWP_ALL;
}
else
{
opts = 0;
if ( StrStrI(flags, "SKIPDISABLED" ) ) opts |= CWP_SKIPDISABLED;
if ( StrStrI(flags, "SKIPINVISIBLE" ) ) opts |= CWP_SKIPINVISIBLE;
if ( StrStrI(flags, "SKIPTRANSPARENT") ) opts |= CWP_SKIPTRANSPARENT;
}
return opts;
}
/**
* Interface to the Windows API: SendMessage().
*
* @param context
* @param wm_msg
* @param wParam
* @param lParam
* @param _hwnd
* @param pcwb
*
* @return LRESULT
*
* @remarks This function is used for most of the internally generated send
* message functions. The assumption is that internally the code is
* correct in calling the function, but the programmer may be calling
* a method incorrectly.
*
* Easier to describe by example: Many of the dialog methods are
* only valid after the underlying dialog has been created, because a
* valid window handle is needed. But, the programmer may invoke the
* method at the wrong time, say in the defineDialog(). Therefore,
* this function will raise a syntax condition if the window handle,
* for any reason is not valid. Contrast this with
* sendWinMsgGeneric().
*/
static LRESULT sendWinMsg(RexxMethodContext *context, CSTRING wm_msg, WPARAM wParam, LPARAM lParam,
HWND _hwnd, pCWindowBase pcwb)
{
oodResetSysErrCode(context->threadContext);
uint32_t msgID;
if ( ! rxStr2Number32(context, wm_msg, &msgID, 2) )
{
return 0;
}
HWND hwnd = (argumentOmitted(4) ? pcwb->hwnd : (HWND)_hwnd);
if ( ! IsWindow(hwnd) )
{
invalidWindowException(context, pcwb->rexxSelf);
return 0;
}
LRESULT result = SendMessage(hwnd, msgID, wParam, lParam);
oodSetSysErrCode(context->threadContext);
return result;
}
/**
* Generic interface to the Windows API: SendMessage().
*
* @param c
* @param hwnd
* @param wm_msg
* @param _wParam
* @param _lParam
* @param argPos
* @param doIntReturn
*
* @return RexxObjectPtr
*
* @remarks This function is used mostly for the implementation of previously
* documented ooDialog methods, such as
* DialogControl::processMessage(), or
* CategoryDialog::sendMessageToCategoryItem(). These functions did
* not raise syntax conditions, so, in an effort to retain backwards
* compatibility, an exception is not raised for an invalid window
* handle. Rather, the .SystemErrorCode is set. Contrast this to
* sendWinMessage().
*/
RexxObjectPtr sendWinMsgGeneric(RexxMethodContext *c, HWND hwnd, CSTRING wm_msg, RexxObjectPtr _wParam,
RexxObjectPtr _lParam, size_t argPos, bool doIntReturn)
{
oodResetSysErrCode(c->threadContext);
uint32_t msgID;
if ( ! rxStr2Number32(c, wm_msg, &msgID, argPos) )
{
return TheZeroObj;
}
argPos++;
WPARAM wParam;
if ( ! oodGetWParam(c, _wParam, &wParam, argPos, true) )
{
return TheZeroObj;
}
argPos++;
LPARAM lParam;
if ( ! oodGetLParam(c, _lParam, &lParam, argPos, true) )
{
return TheZeroObj;
}
LRESULT lr = SendMessage(hwnd, msgID, wParam, lParam);
oodSetSysErrCode(c->threadContext);
if ( doIntReturn )
{
return c->Intptr((intptr_t)lr);
}
else
{
return pointer2string(c, (void *)lr);
}
}
/**
* Common code to call ShowWindow() from a native C++ API method.
*
* @param hwnd Window handle of window to show.
* @param type Single character indicating which SW_ flag to use.
*
* @return True if the window was previously visible. Return false if the
* window was previously hidden.
*/
logical_t showWindow(HWND hwnd, char type)
{
int flag;
switch ( type )
{
case 'D' :
case 'N' :
flag = SW_NORMAL;
break;
case 'H' :
flag = SW_HIDE;
break;
case 'I' :
flag = SW_SHOWNA;
break;
case 'M' :
flag = SW_SHOWMINIMIZED;
break;
case 'R' :
flag = SW_RESTORE;
break;
case 'X' :
flag = SW_SHOWMAXIMIZED;
break;
case 'S' :
default :
flag = SW_SHOW;
break;
}
return ShowWindow(hwnd, flag);
}
uint32_t showFast(HWND hwnd, char type)
{
uint32_t style = GetWindowLong(hwnd, GWL_STYLE);
if ( style )
{
if ( type == 'H' )
{
style ^= WS_VISIBLE;
}
else
{
style |= WS_VISIBLE;
}
SetWindowLong(hwnd, GWL_STYLE, style);
return 0;
}
return 1;
}
/**
* Parses a string for all the show options possible in the setWindowPos() API.
*
* @param options The keyword string. This is a case-insensitive check. More
* than one keyword, or no keyword, is acceptable.
*
* @return The show window postion flag corresponding to the options string.
*/
static uint32_t parseAllShowOptions(CSTRING options)
{
uint32_t opts = 0;
if ( options != NULL )
{
if ( StrStrI(options, "ASYNCWINDOWPOS") ) opts |= SWP_ASYNCWINDOWPOS;
if ( StrStrI(options, "DEFERERASE" ) ) opts |= SWP_DEFERERASE;
if ( StrStrI(options, "DRAWFRAME" ) ) opts |= SWP_DRAWFRAME;
if ( StrStrI(options, "FRAMECHANGED" ) ) opts |= SWP_FRAMECHANGED;
if ( StrStrI(options, "HIDEWINDOW" ) ) opts |= SWP_HIDEWINDOW;
if ( StrStrI(options, "NOACTIVATE" ) ) opts |= SWP_NOACTIVATE;
if ( StrStrI(options, "NOCOPYBITS" ) ) opts |= SWP_NOCOPYBITS;
if ( StrStrI(options, "NOMOVE" ) ) opts |= SWP_NOMOVE;
if ( StrStrI(options, "NOOWNERZORDER" ) ) opts |= SWP_NOOWNERZORDER;
if ( StrStrI(options, "NOREDRAW" ) ) opts |= SWP_NOREDRAW;
if ( StrStrI(options, "NOREPOSITION" ) ) opts |= SWP_NOREPOSITION;
if ( StrStrI(options, "NOSENDCHANGING") ) opts |= SWP_NOSENDCHANGING;
if ( StrStrI(options, "NOSIZE" ) ) opts |= SWP_NOSIZE;
if ( StrStrI(options, "NOZORDER" ) ) opts |= SWP_NOZORDER;
if ( StrStrI(options, "SHOWWINDOW" ) ) opts |= SWP_SHOWWINDOW;
}
return opts;
}
static bool getHwndBehind(RexxMethodContext *c, RexxObjectPtr _hwndBehind, HWND *hwnd)
{
if ( c->IsPointer(_hwndBehind) )
{
*hwnd = (HWND)c->PointerValue((RexxPointerObject)_hwndBehind);
}
else
{
CSTRING str = c->ObjectToStringValue(_hwndBehind);
if ( stricmp(str, "BOTTOM" ) == 0 ) *hwnd = HWND_BOTTOM;
else if ( stricmp(str, "NOTTOPMOST") == 0 ) *hwnd = HWND_NOTOPMOST;
else if ( stricmp(str, "TOP" ) == 0 ) *hwnd = HWND_TOP;
else if ( stricmp(str, "TOPMOST" ) == 0 ) *hwnd = HWND_TOPMOST;
else
{
size_t len = strlen(str);
if ( (len == 0 || len == 2) || (len == 1 && *str != '0') || (len > 2 && toupper(str[1]) != 'X') )
{
wrongArgValueException(c->threadContext, 1, "BOTTOM, NOTTOPMOST, TOP, TOPMOST, or a valid window handle", str);
return false;
}
*hwnd = (HWND)string2pointer(str);
}
}
return true;
}
/**
* Performs the initialization of the WindowBase mixin class.
*
* This is done by creating the cself struct for that class and then sending
* that struct to the init_windowBase() method. That method will raise an
* exception if its arg is not a RexxBufferObject. This implies that the
* WindowBase mixin class can only be initialized through the native API.
*
* The plain base dialog, dialog control, and window classes in ooDialog inherit
* WindowBase.
*
* @param c Method context we are operating in.
*
* @param hwndObj Window handle of the underlying object. This can be null and
* for a dialog object, it is always null. (Because for a
* dialog object the underlying dialog has not been created at
* this point.)
*
* @param self The Rexx object that inherited WindowBase.
*
* @return True on success, otherwise false. If false an exception has been
* raised.
*
* @remarks This method calculates the factor X and Y values using the old,
* incorrect, ooDialog method. When the hwnd is unknown, that is the
* best that can be done. But, when the hwnd is known, it would be
* better to calculate it correctly. Even when the hwnd is unknown,
* we could calculate it correctly using the font of the dialog.
*
* Note that in the original ooDialog code, factorX and factorY were
* formatted to only 1 decimal place.
*
* Note that in the original ooDialog, if the object was a dialog,
* (i.e. the hwnd is unknown,) then sizeX and sizeY simply remain at
* 0.
*/
bool initWindowBase(RexxMethodContext *c, HWND hwndObj, RexxObjectPtr self, pCWindowBase *ppCWB)
{
RexxBufferObject obj = c->NewBuffer(sizeof(CWindowBase));
if ( obj == NULLOBJECT )
{
return false;
}
pCWindowBase pcwb = (pCWindowBase)c->BufferData(obj);
memset(pcwb, 0, sizeof(CWindowBase));
ULONG bu = GetDialogBaseUnits();
pcwb->factorX = LOWORD(bu) / 4;
pcwb->factorY = HIWORD(bu) / 8;
pcwb->rexxSelf = self;
if ( hwndObj != NULL )
{
RECT r = {0};
if ( GetWindowRect(hwndObj, &r) == 0 )
{
systemServiceExceptionCode(c->threadContext, API_FAILED_MSG, "GetWindowRect");
return false;
}
RexxStringObject h = pointer2string(c, hwndObj);
pcwb->hwnd = hwndObj;
pcwb->rexxHwnd = c->RequestGlobalReference(h);
pcwb->sizeX = (uint32_t)((r.right - r.left) / pcwb->factorX);
pcwb->sizeY = (uint32_t)((r.bottom - r.top) / pcwb->factorY);
}
else
{
pcwb->rexxHwnd = TheZeroObj;
}
RexxObjectPtr result = c->SendMessage1(self, "INIT_WINDOWBASE", obj);
if ( result == TheFalseObj )
{
pcwb->initCode = 1;
}
if ( ppCWB != NULL )
{
*ppCWB = pcwb;
}
return true;
}
/** WindowBase::init_windowBase()
*
*
*/
RexxMethod1(RexxObjectPtr, wb_init_windowBase, RexxObjectPtr, cSelf)
{
RexxMethodContext *c = context;
if ( ! context->IsBuffer(cSelf) )
{
wrongClassException(context->threadContext, 1, "Buffer");
return TheFalseObj;
}
context->SetObjectVariable("CSELF", cSelf);
return TheTrueObj;
}
/** WindowBase::initCode [attribute]
*/
RexxMethod1(wholenumber_t, wb_getInitCode, CSELF, pCSelf)
{
pCWindowBase pcwb = validateWbCSelf(context, pCSelf);
if ( pcwb != NULL )
{
return pcwb->initCode;
}
return 0;
}
RexxMethod2(RexxObjectPtr, wb_setInitCode, wholenumber_t, code, CSELF, pCSelf)
{
pCWindowBase pcwb = validateWbCSelf(context, pCSelf);
if ( pcwb != NULL )
{
pcwb->initCode = code;
}
return NULLOBJECT;
}
/** WindowBase::hwnd [attribute get]
*
* We use a lazy init for the Rexx hwnd object.
*/
RexxMethod1(RexxObjectPtr, wb_getHwnd, CSELF, pCSelf)
{
pCWindowBase pcwb = validateWbCSelf(context, pCSelf);
if ( pcwb == NULL )
{
return TheZeroObj;
}
if ( pcwb->rexxHwnd == TheZeroObj && pcwb->hwnd != NULL )
{
pcwb->rexxHwnd = context->RequestGlobalReference(pointer2string(context, pcwb->hwnd));
}
return pcwb->rexxHwnd;
}
/** WindowBase::factorX [attribute]
*/
RexxMethod1(double, wb_getFactorX, CSELF, pCSelf) { return ((pCWindowBase)pCSelf)->factorX; }
RexxMethod2(RexxObjectPtr, wb_setFactorX, float, xFactor, CSELF, pCSelf) { ((pCWindowBase)pCSelf)->factorX = xFactor; return NULLOBJECT; }
/** WindowBase::factorY [attribute]
*/
RexxMethod1(double, wb_getFactorY, CSELF, pCSelf) { return ((pCWindowBase)pCSelf)->factorY; }
RexxMethod2(RexxObjectPtr, wb_setFactorY, float, yFactor, CSELF, pCSelf) { ((pCWindowBase)pCSelf)->factorY = yFactor; return NULLOBJECT; }
/** WindowBase::sizeX [attribute]
*/
RexxMethod1(uint32_t, wb_getSizeX, CSELF, pCSelf) { return ((pCWindowBase)pCSelf)->sizeX; }
RexxMethod2(RexxObjectPtr, wb_setSizeX, uint32_t, xSize, CSELF, pCSelf) { ((pCWindowBase)pCSelf)->sizeX = xSize; return NULLOBJECT; }
/** WindowBase::sizeY [attribute]
*/
RexxMethod1(uint32_t, wb_getSizeY, CSELF, pCSelf) { return ((pCWindowBase)pCSelf)->sizeY; }
RexxMethod2(RexxObjectPtr, wb_setSizeY, uint32_t, ySize, CSELF, pCSelf) { ((pCWindowBase)pCSelf)->sizeY = ySize; return NULLOBJECT; }
/** WindowBase::pixelCX [attribute]
*
* Returns the width of the window in pixels. This is a 'get' only attribute.
*/
RexxMethod1(uint32_t, wb_getPixelCX, CSELF, pCSelf)
{
pCWindowBase pcs = (pCWindowBase)pCSelf;
if ( pcs->hwnd == NULL )
{
return 0;
}
RECT r = {0};
GetWindowRect(pcs->hwnd, &r);
return r.right - r.left;
}
/** WindowBase::pixelY [attribute]
*
* Returns the height of the window in pixels. This is a 'get' only attribute.
*/
RexxMethod1(uint32_t, wb_getPixelCY, CSELF, pCSelf)
{
pCWindowBase pcs = (pCWindowBase)pCSelf;
if ( pcs->hwnd == NULL )
{
return 0;
}
RECT r = {0};
GetWindowRect(pcs->hwnd, &r);
return r.bottom - r.top;
}
/** WindowBase::sendMessage()
* WindowBase::sendMessageHandle()
*
* Sends a window message to the underlying window of this object.
*
* @param wm_msg The Windows window message ID. This can be specified in
* either "0xFFFF" or numeric format.
*
* @param wParam The WPARAM value for the message.
* @param lParam The LPARAM value for the message.
*
* @return The result of sending the message, as returned by the operating
* system. For sendMessage() the result is returned as a whole number.
* For sendMessageHandle() the result is returned as an operating
* system handle.
*
* @note Sets the .SystemErrorCode.
*
* The wParam and lParam arguments can be in a number of formats. An
* attempt is made to convert the Rexx object from a .Pointer, pointer
* string, uintptr_t number, or intptr_t number. If they all fail, an
* exception is raised.
*
* These methods will not work for window messages that take a string as
* an argument or return a string as a result.
*
* @remarks This function is used for the documented DialogControl
* processMessage() method, and therefore needs to remain generic.
* Internally, most of the time, it would make more sense to use one
* of the argument type specific methods like sendWinIntMsg().
*/
RexxMethod5(RexxObjectPtr, wb_sendMessage, CSTRING, wm_msg, RexxObjectPtr, _wParam, RexxObjectPtr, _lParam,
NAME, method, CSELF, pCSelf)
{
HWND hwnd = getWBWindow(context, pCSelf);
bool doIntReturn = (strlen(method) == 11 ? true : false);
return sendWinMsgGeneric(context, hwnd, wm_msg, _wParam, _lParam, 1, doIntReturn);
}
/** WindowBase::sendWinIntMsg()
* WindowBase::sendWinIntMsgH()
*
* Sends a message to a Windows window where WPARAM and LPARAM are both numbers
* and the return is a number or a handle. I.e., neither param is a handle and
* the return is not a string.
*
* @param wm_msg The Windows window message ID. This can be specified in
* "0xFFFF" format or numeric format.
*
* @param wParam The WPARAM value for the message.
* @param lParam The LPARAM value for the message.
*
* @param _hwnd [OPTIONAL] The handle of the window the message is sent to.
* If omitted, the window handle of this object is used.
*
* @return The result of sending the message, as returned by the operating
* system.
*
* @remarks Sets the .SystemErrorCode.
*
* This method is not meant to be documented for the user, it is
* intended to be used internally only.
*
* In addition, wParam should really be uintptr_t. However, some,
* many?, control messages use / accept negative nubmers for wParam.
* If we were just casting the number here, that would work. But,
* the interpreter checks the range before invoking and negative
* numbers cause a condition to be raised. So, we use intptr_t for
* wParam here. sendWinUintMsg() has been added for the case where
* WPARAM and LPARAM need an unsigned range.
*/
RexxMethod6(RexxObjectPtr, wb_sendWinIntMsg, CSTRING, wm_msg, intptr_t, wParam, intptr_t, lParam,
OPTIONAL_POINTERSTRING, _hwnd, NAME, method, CSELF, pCSelf)
{
LRESULT lr = sendWinMsg(context, wm_msg, (WPARAM)wParam, (LPARAM)lParam, (HWND)_hwnd, (pCWindowBase)pCSelf);
if ( method[13] == '\0' )
{
return context->Intptr((intptr_t)lr);
}
else
{
return pointer2string(context, (void *)lr);
}
}
/** WindowBase::sendWinUintMsg()
*
* Sends a message to a Windows window where WPARAM and LPARAM are both
* unsigned numbers and the return is also unsigned. I.e., neither param is a
* handle and the return is not a string or a handle.
*
* @param wm_msg The Windows window message ID. This can be specified in
* "0xFFFF" format or numeric format.
*
* @param wParam The WPARAM value for the message.
* @param lParam The LPARAM value for the message.
*
* @param _hwnd [OPTIONAL] The handle of the window the message is sent to.
* If omitted, the window handle of this object is used.
*
* @return The result of sending the message, as returned by the operating
* system.
*
* @remarks Sets the .SystemErrorCode.
*
* This method is not meant to be documented for the user, it is
* intended to be used internally only. Currently, all uses of this
* function have a return of a number. If a need comes up to return
* a handle, then add sendWinUintMsgH().
*/
RexxMethod5(uintptr_t, wb_sendWinUintMsg, CSTRING, wm_msg, uintptr_t, wParam, uintptr_t, lParam,
OPTIONAL_POINTERSTRING, _hwnd, CSELF, pCSelf)
{
return (uintptr_t)sendWinMsg(context, wm_msg, (WPARAM)wParam, (LPARAM)lParam, (HWND)_hwnd, (pCWindowBase)pCSelf);
}
/** WindowBase::sendWinHandleMsg()
* WindowBase::sendWinHandleMsgH()
*
* Sends a message to a Windows window where WPARAM is a handle and LPARAM is a
* number. The result is returned as a number or as a handle, depending on the
* invoking method.
*
* @param wm_msg The Windows window message ID. This can be specified as a
* decimal number, or in "0xFFFF" format.
*
* @param wParam The WPARAM value for the message. The argument must be in
* pointer or handle format.
* @param lParam The LPARAM value for the message.
*
* @param _hwnd [OPTIONAL] The handle of the window the message is sent to.
* If omitted, the window handle of this object is used.
*
* @return The result of sending the message, as returned by the operating
* system.
*
* @note Sets the .SystemErrorCode.
*
* @remarks This method is not meant to be documented to the user, it is
* intended to be used internally only.
*/
RexxMethod6(RexxObjectPtr, wb_sendWinHandleMsg, CSTRING, wm_msg, POINTERSTRING, wParam, intptr_t, lParam,
OPTIONAL_POINTERSTRING, _hwnd, NAME, method, CSELF, pCSelf)
{
LRESULT lr = sendWinMsg(context, wm_msg, (WPARAM)wParam, (LPARAM)lParam, (HWND)_hwnd, (pCWindowBase)pCSelf);
if ( method[16] == '\0' )
{
return context->Intptr((intptr_t)lr);
}
else
{
return pointer2string(context, (void *)lr);
}
}
/** WindowBase::sendWinHandle2Msg()
* WindowBase::sendWinHandle2MsgH()
*
* Sends a message to a Windows window where WPARAM is a number and LPARAM is a
* handle. The result is returned as a number or as a handle, depending on the
* invoking method.
*
* @param wm_msg The Windows window message ID. This can be specified as a
* decimal number, or in "0xFFFF" format.
*
* @param wParam The WPARAM value for the message.
* @param lParam The LPARAM value for the message. The argument must be in
* pointer or handle format.
*
* @param _hwnd [OPTIONAL] The handle of the window the message is sent to.
* If omitted, the window handle of this object is used.
*
* @return The result of sending the message, as returned by the operating
* system.
*
* @note Sets the .SystemErrorCode.
*
* @remarks This method is not meant to be documented to the user, it is
* intended to be used internally only.
*/
RexxMethod6(RexxObjectPtr, wb_sendWinHandle2Msg, CSTRING, wm_msg, intptr_t, wParam, RexxObjectPtr, lParam,
OPTIONAL_POINTERSTRING, _hwnd, NAME, method, CSELF, pCSelf)
{
void *handle;
if ( ! oodObj2handle(context, lParam, &handle, 3) )
{
return NULLOBJECT;
}
LRESULT lr = sendWinMsg(context, wm_msg, (WPARAM)wParam, (LPARAM)handle, (HWND)_hwnd, (pCWindowBase)pCSelf);
if ( strlen(method) == 17 )
{
return context->Intptr((intptr_t)lr);
}
else
{
return pointer2string(context, (void *)lr);
}
}
/** WindowBase::enable() / WindowBase::disable()
*
* Enables or disables the window. This function is mapped to both methods of
* WindowBase.
*
* @return True if the window was previously disabled, returns false if the
* window was not previously disabled. Note that this is not succes
* or failure. It always succeeds.
*
* @remarks The return was not previously documented.
*/
RexxMethod1(logical_t, wb_enable, CSELF, pCSelf)
{
BOOL enable = TRUE;
if ( msgAbbrev(context) == 'D' )
{
enable = FALSE;
}
return EnableWindow(getWBWindow(context, pCSelf), enable);
}
RexxMethod1(logical_t, wb_isEnabled, CSELF, pCSelf)
{
return IsWindowEnabled(getWBWindow(context, pCSelf));
}
RexxMethod1(logical_t, wb_isVisible, CSELF, pCSelf)
{
return IsWindowVisible(getWBWindow(context, pCSelf));
}
/** WindowBase::show() / WindowBase::hide()
*
* Hides or shows the window. This function is mapped to both methods of
* WindowBase. The return for these methods was not previously documented.
*
* @return True if the window was previously visible. Return false if the
* window was previously hidden.
*
* @remarks Note that early versions of ooDialog use SW_SHOWNORMAL for the
* flag, not SW_SHOW. We need to preserve that because of the
* differences in SW_SHOW and SW_SHOWNORMAL when the window is
* maximized or minimized.
*/
RexxMethod2(logical_t, wb_show, NAME, method, CSELF, pCSelf)
{
return showWindow(getWBWindow(context, pCSelf), (*method == 'S' ? 'N' : 'H'));
}
/** WindowBase::showFast() / WindowBase::hideFast()
*
* Hides or shows the window 'fast'. What this means is the visible flag is
* set, but the window is not forced to update.
*
* This function is mapped to both methods of WindowBase. The return for these
* methods was not previously documented.
*
* @return 0 for no error, 1 for error. An error is highly unlikely.
*/
RexxMethod1(uint32_t, wb_showFast, CSELF, pCSelf)
{
return showFast(getWBWindow(context, pCSelf), msgAbbrev(context));
}
/** WindowBase::display()
*
*
* @return 0 for success, 1 for error. An error is highly unlikely.
*
* @notes Sets the .SystemErrorCode. The underlying dialog must have been
* created or a synatx exceptions is raised.
*
* @remarks display() is a method that was originally in WindowExtentions,
* making it a method of both a dialog and a dialog object. It is one
* of those methods that makes little sense for a dialog control
* because the SW_SHOWxxx flags used have no effect on dialog
* controls, other than to make them visible or invisible.
*
* If the options keyword was omitted or wrong, then SW_SHOW was used
* as the flag, (really by accident.) This is changed in 4.1.0 to
* cause a syntax condition.
*/
RexxMethod2(uint32_t, wb_display, OPTIONAL_CSTRING, opts, CSELF, pCSelf)
{
char type;
uint32_t ret = 0;
bool doFast = false;
HWND hwnd = wbSetUp(context, pCSelf);
if ( hwnd == NULL )
{
return 1;
}
if ( opts != NULL && StrStrI(opts, "FAST") != NULL )
{
doFast = true;
}
if ( opts == NULL ) {type = 'N';}
else if ( StrStrI(opts, "NORMAL" ) != NULL ) {type = 'N';}
else if ( StrStrI(opts, "DEFAULT" ) != NULL ) {type = 'N';}
else if ( StrStrI(opts, "HIDE" ) != NULL ) {type = 'H';}
else if ( StrStrI(opts, "INACTIVE") != NULL )
{
if ( doFast )
{
userDefinedMsgException(context->threadContext, 1, "The keyword FAST can not be used with INACTIVE");
goto done_out;
}
type = 'I';
}
else
{
wrongArgValueException(context->threadContext, 1, DISPLAY_METHOD_OPTIONS, opts);
return 1;
}
if ( doFast )
{
// showFast() needs S or H
type = (type == 'N' ? 'S' : type);
ret = showFast(hwnd, type);
}
else
{
showWindow(hwnd, type);
}
done_out:
return ret;
}
/** WindowsBase::draw()
* WindowsBase::redrawClient()
* WindowsBase::update()
*
* Invalidates the entire client area of the the window. draw() and
* redrawClient() then forces the window to repaint.
*
* This method maps to the draw(), update() and the redrawClient() methods.
* The implementation preserves existing behavior prior to ooRexx 4.0.1. That
* is:
*
* The draw() method takes no argument and always uses false for the erase
* background arg.
*
* The update() method takes no argument and always uses true for the erase
* background arg. This method invalidates the client area only, does not call
* UpdateWindow(). The Rexx method name of 'update' was poorly choosen,
* because it does not do an update, only an invalidate.
*
* The redrawClient() method takes an argument to set the erase background arg.
* The argument can be either .true / .false (1 or 0), or yes / no, or ja /
* nein. Note however, the redrawClient() has always been documented as taking
* 1 or Y to erase the background and implemented so that if the arg was
* omitted it would be .false.
*
* @param erase [optional] Whether the redrawClient operation should erase
* the window background. Can be true / false or yes / no. The
* default is false.
*
* @return 0 for success, 1 for error.
*
* @note Sets the .SystemErrorCode.
*/
RexxMethod2(RexxObjectPtr, wb_redrawClient, OPTIONAL_CSTRING, erase, CSELF, pCSelf)
{
HWND hwnd = getWBWindow(context, pCSelf);
char flag = msgAbbrev(context);
bool doErase;
bool doUpdate = true;
if ( flag == 'D' )
{
doErase = false;
}
else if ( flag == 'U' )
{
doErase = true;
doUpdate = false;
}
else
{
doErase = isYes(erase);
}
return redrawRect(context, hwnd, NULL, doErase, doUpdate);
}
/** WindowsBase::redraw()
*
* Causes the entire window, including frame, to be redrawn.
*
* @return 0 for success, 1 for error.
*
* @note Sets the .SystemErrorCode.
*/
RexxMethod1(RexxObjectPtr, wb_redraw, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
if ( RedrawWindow(getWBWindow(context, pCSelf), NULL, NULL,
RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN) == 0 )
{
oodSetSysErrCode(context->threadContext);
return TheOneObj;
}
return TheZeroObj;
}
/** WindowBase::title / WindowBase::getText()
*
* Gets the window text.
*
* For a window with a frame, this is the window title. But for a dialog
* control, this is the text for the control. This of course varies depending
* on the type of control. For a button, it is the button label, for an edit
* control it is the edit text, etc..
*
* @return On success, the window text, which could be the empty string. On
* failure, the empty string.
*
* @note Sets the .SystemErrorCode.
*/
RexxMethod1(RexxStringObject, wb_getText, CSELF, pCSelf)
{
RexxStringObject result = context->NullString();
HWND hwnd = getWBWindow(context, pCSelf);
// Whether this fails or succeeds doesn't matter, we just return result.
rxGetWindowText(context, hwnd, &result);
return result;
}
/** WindowBase::setText() / WindowBase::setTitle() / WindowBase::title=
*
* Sets the window text to the value specified.
*
* @param text The text to be set as the window text
*
* @return 0 for success, 1 for error.
*
* @note Sets the .SystemErrorCode.
*
* @remarks Unfortunately, in 3.2.0, setText for an edit control was
* documented as returning the negated system error code and in 4.0.0
* setText for a static control was documented as returning the
* system error code (which is positive of course.) The mapping here
* to the various versions of 'getText' is cleaner, but we may need
* to special case the return to match the previous documentation.
*/
RexxMethod2(wholenumber_t, wb_setText, CSTRING, text, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
if ( SetWindowText(getWBWindow(context, pCSelf), text) == 0 )
{
oodSetSysErrCode(context->threadContext);
return 1;
}
return 0;
}
/** WindowBase::getTextSizePx()
*
* Gets the size, (width and height,) in pixels, needed to display a string.
*
* @param text The string to calculate the size of.
*
* @return A .Size object containg the width and height for the text in
* pixels.
*/
RexxMethod2(RexxObjectPtr, wb_getTextSizePx, CSTRING, text, CSELF, pCSelf)
{
SIZE size = {0};
HWND hwnd = wbSetUp(context, pCSelf);
if ( hwnd == NULL )
{
goto error_out;
}
if ( ! textSizeFromWindow(context, text, &size, hwnd) )
{
goto error_out;
}
return rxNewSize(context, size.cx, size.cy);
error_out:
return NULLOBJECT;
}
/** WindowBase::getTextSizeScreen()
*
* Gets the size, width and height, in pixels, needed to display a string in a
* specific font.
*
* @param text The text to calculate the size of. If this is the only
* argument then the font of this object is used for the
* calculation.
*
* @param type Optional. If the text arg is not the only argument, then
* type is required. It signals what fontSrc is. The allowed
* types are:
*
* Indirect -> fontSrc is a font name and fontSize is the size
* of the font. The calculation is done indirectly by
* temporarily obtaining a logical font.
*
* DC -> fontSrc is a handle to a device context. The correct
* font for the calculation must already be selected into this
* device context. fontSize is ignored.
*
* Font -> fontSrc is a handle to a font. fontSize is
* ignored.
*
* Only the first letter of type is needed and case is not
* significant.
*
* @param fontSrc Optional. An object to use for calculating the size of
* text. The type argument determines how this object is
* interpreted.
*
* @param fontSize Optional. The size of the font. This argument is always
* ignored unless the type argument is Indirect. If type is
* Indirect and this argument is omitted then the defualt font
* size is used. (Currently the default size is 8.)
*
* @return A .Size object containg the width and height for the text in
* pixels.
*
* @remarks This method is needed to provide backward compatibility for the
* deprecated getTextSize(). That is why the arguments are so
* convoluted. Users are advised to use getTextSizePx()
*/
RexxMethod5(RexxObjectPtr, wb_getTextSizeScreen, CSTRING, text, OPTIONAL_CSTRING, type,
OPTIONAL_CSTRING, fontSrc, OPTIONAL_uint32_t, fontSize, CSELF, pCSelf)
{
SIZE size = {0};
HWND hwnd = wbSetUp(context, pCSelf);
if ( hwnd == NULL )
{
goto error_out;
}
if ( rxArgCount(context) == 1 )
{
if ( ! textSizeFromWindow(context, text, &size, hwnd) )
{
goto error_out;
}
}
else if ( argumentOmitted(2) )
{
missingArgException(context->threadContext, 2);
goto error_out;
}
else
{
if ( argumentOmitted(3) )
{
missingArgException(context->threadContext, 3);
goto error_out;
}
char m = toupper(*type);
if ( m == 'I' )
{
if ( argumentOmitted(4) )
{
fontSize = DEFAULT_FONTSIZE;
}
if ( ! textSizeIndirect(context, text, fontSrc, fontSize, &size, hwnd) )
{
goto error_out;
}
}
else if ( m == 'D' )
{
HDC hdc = (HDC)string2pointer(fontSrc);
if ( hdc == NULL )
{
invalidTypeException(context->threadContext, 3, "handle to a device context");
goto error_out;
}
GetTextExtentPoint32(hdc, text, (int)strlen(text), &size);
}
else if ( m == 'F' )
{
HFONT hFont = (HFONT)string2pointer(fontSrc);
if ( hFont == NULL )
{
invalidTypeException(context->threadContext, 3, " handle to a font");
goto error_out;
}
HDC hdc = GetDC(hwnd);
if ( hdc == NULL )
{
systemServiceExceptionCode(context->threadContext, API_FAILED_MSG, "GetDC");
goto error_out;
}
bool success = true;
if ( ! getTextExtent(hFont, hdc, text, &size) )
{
systemServiceExceptionCode(context->threadContext, API_FAILED_MSG, "GetTextExtentPoint32");
success = false;
}
ReleaseDC(hwnd, hdc);
if ( ! success )
{
goto error_out;
}
}
else
{
context->RaiseException2(Rexx_Error_Incorrect_method_option, context->String("I, D, F"),
context->String(type));
goto error_out;
}
}
return rxNewSize(context, size.cx, size.cy);
error_out:
return NULLOBJECT;
}
/** WindowBase::windowRect()
*
* Retrieves the dimensions of the bounding rectangle of this window. The
* dimensions are in pixels and the coordinates are relative to the upper-left
* corner of the screen.
*
* @param hwnd [OPTIONAL] By default, the coordinates are for this window.
* However, the optional hwnd argument can be used to specify
* getting the coordinates for some other window. See remarks.
*
* @return The bounding rectangle of the window as .Rect object.
*
* @note Sets the .SystemErrorCode.
*
* @remarks The windowRect() method supplies an alternative to both the
* getRect() and getWindowRect(hwnd) methods, to allow returning a
* .Rect object rather than a string of blank separated values.
*
* Pre 4.0.1, getRect() was in WindowExtensions and getWindowRect()
* was in DialogExtensions. The need to provide backward
* compatibility, use meaningful method names, maintain symmetry with
* the getClientRect(hwnd) method is what drove the decision to allow
* the optional hwnd argument to this method.
*/
RexxMethod2(RexxObjectPtr, wb_windowRect, OPTIONAL_POINTERSTRING, _hwnd, CSELF, pCSelf)
{
HWND hwnd = (argumentOmitted(1) ? getWBWindow(context, pCSelf) : (HWND)_hwnd);
return oodGetWindowRect(context, hwnd);
}
/** WindowBse::childWindowFromPoint()
*
*
*/
RexxMethod3(RexxStringObject, wb_childWindowFromPoint, RexxObjectPtr, pt, OPTIONAL_CSTRING, _flags, CSELF, pCSelf)
{
HWND hwnd = wbSetUp(context, pCSelf);
if ( hwnd == NULL )
{
goto err_out;
}
PPOINT p = rxGetPoint(context, pt, 1);
if ( p == NULL )
{
goto err_out;
}
uint32_t flags = CWP_SKIPINVISIBLE | CWP_SKIPDISABLED | CWP_SKIPTRANSPARENT;
if ( argumentExists(2) )
{
flags = flags2cwp(_flags);
if ( flags == 0xFFFFFFFF )
{
wrongArgKeywordsException(context->threadContext, 2, CWP_KEYWORDS, _flags);
goto err_out;
}
}
return pointer2string(context, ChildWindowFromPointEx(hwnd, *p, flags));
err_out:
return NULLOBJECT;
}
/** WindowBase::clientRect()
*
* Retrieves the coordinates of a window's client area. The coordinates are in
* pixels.
*
* The client coordinates specify the upper-left and lower-right corners of the
* client area. Because client coordinates are relative to the upper-left
* corner of a window's client area, the coordinates of the upper-left corner
* are always (0,0).
*
* @param hwnd [OPTIONAL] By default, the coordinates are for this window.
* However, the optional hwnd argument can be used to specify
* getting the coordinates for some other window. See remarks.
*
* @return The coordinates of the client area of the window as a .Rect object.
*
* @note Sets the .SystemErrorCode.
*
* @remarks The clientRect() method supplies an alternative to the
* getClientRect(hwnd) method, to allow returning a .Rect object
* rather than a string of blank separated values.
*
* Pre 4.0.1, getClientRect() was in WindowExtensions. The need to
* provide backward compatibility, use meaningful method names, and
* maintain symmetry with the getRect() and getWindowRect(hwnd)
* methods is what drove the decision to move this method to
* WidnowBase and allow the optional hwnd argument to this method.
*/
RexxMethod2(RexxObjectPtr, wb_clientRect, OPTIONAL_POINTERSTRING, _hwnd, CSELF, pCSelf)
{
HWND hwnd = (argumentOmitted(1) ? getWBWindow(context, pCSelf) : (HWND)_hwnd);
RECT r = {0};
oodGetClientRect(context, (HWND)hwnd, &r);
return rxNewRect(context, &r);
}
/** WindowBase::setRect()
*
* Changes the size, and position of a child, pop-up, or top-level window.
*
* Provides a simplified interface to the Windows API, SetWindowPos(). There
* is no provision for the hwndInsertAfter arg, it does not recognize all the
* allowable flags, and it always uses SWP_NOZORDER.
*
* By specifying either NOSIZE or NOMOVE options the programmer can only move
* or only resize the window.
*
* @param coordinates The coordinates of a point / size rectangle, given in
* pixels
*
* Form 1: A .Rect object.
* Form 2: A .Point object and a .Size object.
* Form 3: x1, y1, cx, cy
*
* @param flags [OPTIONAL] Keywords specifying the behavior of the method.
*
* @return True for success, false on error.
*
* @note Sets the .SystemErrorCode.
*
* @remarks Microsoft says: If the SWP_SHOWWINDOW or SWP_HIDEWINDOW flag is
* set, the window cannot be moved or sized. But, that does not
* appear to be true.
*
* The processing of the flags argument is exactly the same as what
* the original ooDialog code did. I.e., the flags start with
* SWP_NOZORDER and then the string is checked for each possible
* keyword, if found, that flag is added. If the user had both
* NOMOVE and NOSIZE, both flags ared added. If the user had both
* SHOW and HIDE, then both flags are added, etc..
*/
RexxMethod2(RexxObjectPtr, wb_setRect, ARGLIST, args, CSELF, pCSelf)
{
HWND hwnd = wbSetUp(context, pCSelf);
if ( hwnd == NULL )
{
return NULLOBJECT;
}
// A RECT is used to return the values, even though the semantics are not
// quite correct. (right will really be cx and bottom will be cy.)
size_t countArgs;
size_t argsUsed;
RECT rect;
if ( ! getRectFromArglist(context, args, &rect, false, 1, 5, &countArgs, &argsUsed) )
{
return NULLOBJECT;
}
RexxObjectPtr obj;
CSTRING options = "";
if ( argsUsed == 1 )
{
if ( countArgs > 2 )
{
return tooManyArgsException(context->threadContext, 2);
}
if ( countArgs == 2 )
{
obj = context->ArrayAt(args, 2);
options = context->ObjectToStringValue(obj);
}
}
else if ( argsUsed == 2 )
{
if ( countArgs > 3 )
{
return tooManyArgsException(context->threadContext, 3);
}
if ( countArgs == 3 )
{
obj = context->ArrayAt(args, 3);
options = context->ObjectToStringValue(obj);
}
}
else
{
if ( countArgs == 5 )
{
obj = context->ArrayAt(args, 5);
options = context->ObjectToStringValue(obj);
}
}
uint32_t opts = parseShowOptions(options);
if ( SetWindowPos(hwnd, NULL, rect.left, rect.top, rect.right, rect.bottom, opts) != 0 )
{
return TheTrueObj;
}
oodSetSysErrCode(context->threadContext);
return TheFalseObj;
}
/** WindowBase::resizeTo()
* WindowBase::moveTo()
*
* Resize to, changes the size of this window. The new size is specified in
* pixels.
*
* Move to, changes the position of this window. The new position is specified
* as the coordinates of the upper left corner of the window, in pixels.
*
* @param coordinates The new position (x, y) or new size (cx, cy) in pixels.
*
* resizeTo()
* Form 1: A .Size object.
* Form 2: cx, cy
*
* moveTo()
* Form 1: A .Point object.
* Form 2: x, y
*
* @param flags [OPTIONAL] Keywords that control the behavior of the method.
*
* @return 0 for success, 1 on error.
*
* @note Sets the .SystemErrorCode.
*
* @remarks No effort is made to ensure that only a .Size object is used for
* resizeTo() and only a .Point object for moveTo().
*
* The processing of the flags argument is exactly the same as what
* the original ooDialog code did. I.e., the flags start with
* SWP_NOZORDER and then the string is checked for each possible
* keyword, if found, that flag is added. For resize and move then,
* if the user did have NOMOVE or NOSIZE, the flag is added. If the
* user had both SHOW and HIDE, then both flags are added, etc..
*/
RexxMethod3(RexxObjectPtr, wb_resizeMove, ARGLIST, args, NAME, method, CSELF, pCSelf)
{
HWND hwnd = wbSetUp(context, pCSelf);
if ( hwnd == NULL )
{
return NULLOBJECT;
}
// POINT and SIZE structs are binary compatible. A POINT is used to return
// the values, even though the semantics are not quite correct for
// resizeTo(). (x will really be cx and y will be cy.)
size_t countArgs;
size_t argsUsed;
POINT point;
if ( ! getPointFromArglist(context, args, &point, 1, 3, &countArgs, &argsUsed) )
{
return NULLOBJECT;
}
RexxObjectPtr obj;
CSTRING options = "";
if ( argsUsed == 1 )
{
if ( countArgs > 2 )
{
return tooManyArgsException(context->threadContext, 2);
}
if ( countArgs == 2 )
{
// The object at index 2 has to exist, otherwise countArgs would
// equal 1.
obj = context->ArrayAt(args, 2);
options = context->ObjectToStringValue(obj);
}
}
else if ( argsUsed == 2 )
{
if ( countArgs == 3 )
{
// The object at index 3 has to exist, otherwise countArgs would
// equal 2.
obj = context->ArrayAt(args, 3);
options = context->ObjectToStringValue(obj);
}
}
uint32_t opts = parseShowOptions(options);
RECT r = {0};
if ( *method == 'R' )
{
opts = (opts & ~SWP_NOSIZE) | SWP_NOMOVE;
r.right = point.x;
r.bottom = point.y;
}
else
{
opts = (opts & ~SWP_NOMOVE) | SWP_NOSIZE;
r.left = point.x;
r.top = point.y;
}
if ( SetWindowPos(hwnd, NULL, r.left, r.top, r.right, r.bottom, opts) == 0 )
{
oodSetSysErrCode(context->threadContext);
return TheOneObj;
}
return TheZeroObj;
}
/** WindowBase::getRealSize()
* WindowBase::getRealPos()
*
* Retrieves the size, or the position, in pixels, of this window
*
* @return The size as a .Size object, or the position as a .Point object.
*
* @note Sets the .SystemErrorCode.
*/
RexxMethod2(RexxObjectPtr, wb_getSizePos, NAME, method, CSELF, pCSelf)
{
HWND hwnd = wbSetUp(context, pCSelf);
if ( hwnd == NULL )
{
return NULLOBJECT;
}
RECT r = {0};
if ( GetWindowRect(getWBWindow(context, pCSelf), &r) == 0 )
{
oodSetSysErrCode(context->threadContext);
}
if ( method[7] == 'S' )
{
return rxNewSize(context, (r.right - r.left), (r.bottom - r.top));
}
return rxNewPoint(context, r.left, r.top);
}
/** WindowBase::setWindowPos()
*
* Changes the size and position of the specified window. Provides a complete
* interface to the SetWindowPos() Windows API, as contrasted to the setRect()
* method.
*
* By specifying either NOSIZE or NOMOVE options the programmer can only move
* or only resize the window. However, the programmer can also use the
* convenience methods moveWindow() and sizeWindow().
*
* @param hwndBehind This window is inserted after hwndBehind. This is the
* hwndInsertAfter arg in SetWindowPos().
* @param coordinates The coordinates of a point / size rectangle, given in
* pixels
*
* Form 1: A .Rect object.
* Form 2: A .Point object and a .Size object.
* Form 3: x1, y1, cx, cy
*
* @param flags [OPTIONAL] Keywords specifying the behavior of the method.
*
* @return True for success, false on error.
*
* @note Sets the .SystemErrorCode.
*
* @remarks Microsoft says: If the SWP_SHOWWINDOW or SWP_HIDEWINDOW flag is
* set, the window cannot be moved or sized. But, that does not
* appear to be true.
*
* Th WindowBase::setRect() should be considered a convenience method
* for setWindowPos(). It leaves out the hwndBehind arg and only a
* recognizes a subset of the show options.
*/
RexxMethod3(RexxObjectPtr, wb_setWindowPos, RexxObjectPtr, _hwndBehind, ARGLIST, args, CSELF, pCSelf)
{
HWND hwnd = wbSetUp(context, pCSelf);
if ( hwnd == NULL )
{
goto done_out;
}
HWND hwndBehind;
if ( ! getHwndBehind(context, _hwndBehind, &hwndBehind) )
{
goto done_out;
}
size_t countArgs;
size_t argsUsed;
RECT rect;
if ( ! getRectFromArglist(context, args, &rect, false, 2, 6, &countArgs, &argsUsed) )
{
goto done_out;
}
RexxObjectPtr obj;
CSTRING options = "";
if ( argsUsed == 1 )
{
if ( countArgs > 3 )
{
return tooManyArgsException(context->threadContext, 3);
}
if ( countArgs == 3 )
{
obj = context->ArrayAt(args, 3);
options = context->ObjectToStringValue(obj);
}
}
else if ( argsUsed == 2 )
{
if ( countArgs > 4 )
{
return tooManyArgsException(context->threadContext, 4);
}
if ( countArgs == 4 )
{
obj = context->ArrayAt(args, 4);
options = context->ObjectToStringValue(obj);
}
}
else
{
if ( countArgs == 6 )
{
obj = context->ArrayAt(args, 6);
options = context->ObjectToStringValue(obj);
}
}
uint32_t opts = parseAllShowOptions(options);
if ( SetWindowPos(hwnd, hwndBehind, rect.left, rect.top, rect.right, rect.bottom, opts) != 0 )
{
return TheTrueObj;
}
oodSetSysErrCode(context->threadContext);
done_out:
return TheFalseObj;
}
/** WindowBase::moveWindow()
* WindowBase::sizeWindow()
*
* Size window, changes the size of this window. The new size is specified in
* pixels.
*
* Move window, changes the position of this window. The new position is
* specified as the coordinates of the upper left corner of the window, in
* pixels.
*
* @param hwndBehind If the z-order is changed, then this window is inserted
* into the z-order after hwndBehind. TOP BOTTOM TOPMOST
* and NOTTOPMOST keywords are also accepted.
*
* @param coordinates The new position (x, y) or new size (cx, cy) in pixels.
*
* sizeWindow()
* Form 1: A .Size object.
* Form 2: cx, cy
*
* moveWindow()
* Form 1: A .Point object.
* Form 2: x, y
*
* @param flags [OPTIONAL] Keywords that control the behavior of the method.
*
* @return True for success, false on error.
*
* @note Sets the .SystemErrorCode.
*
* moveTo() and resizeTo() are convenience methods that are somewhat
* less complicated to use. Those methods eliminate the hwndBehind
* argument and use a simple subset of the allowable flags.
*
* @remarks No effort is made to ensure that only a .Size object is used for
* sizeWindow() and only a .Point object for moveWindow().
*/
RexxMethod4(RexxObjectPtr, wb_moveSizeWindow, RexxObjectPtr, _hwndBehind, ARGLIST, args, NAME, method, CSELF, pCSelf)
{
RECT r = {0};
HWND hwnd = wbSetUp(context, pCSelf);
if ( hwnd == NULL )
{
goto done_out;
}
HWND hwndBehind;
if ( ! getHwndBehind(context, _hwndBehind, &hwndBehind) )
{
goto done_out;
}
// POINT and SIZE structs are binary compatible. A POINT is used to return
// the values, even though the semantics are not quite correct for
// resizeTo(). (x will really be cx and y will be cy.)
size_t countArgs;
size_t argsUsed;
POINT point;
if ( ! getPointFromArglist(context, args, &point, 2, 4, &countArgs, &argsUsed) )
{
goto done_out;
}
RexxObjectPtr obj;
CSTRING options = "";
if ( argsUsed == 1 )
{
if ( countArgs > 3 )
{
return tooManyArgsException(context->threadContext, 3);
}
if ( countArgs == 3 )
{
// The object at index 3 has to exist, otherwise countArgs would
// equal 2.
obj = context->ArrayAt(args, 3);
options = context->ObjectToStringValue(obj);
}
}
else if ( argsUsed == 2 )
{
if ( countArgs == 4 )
{
// The object at index 4 has to exist, otherwise countArgs would
// equal 3.
obj = context->ArrayAt(args, 4);
options = context->ObjectToStringValue(obj);
}
}
uint32_t opts = parseAllShowOptions(options);
if ( *method == 'S' )
{
opts = (opts &= ~SWP_NOSIZE) | SWP_NOMOVE;
;
r.right = point.x;
r.bottom = point.y;
}
else
{
opts = (opts & ~SWP_NOMOVE) | SWP_NOSIZE;
r.left = point.x;
r.top = point.y;
}
if ( SetWindowPos(hwnd, hwndBehind, r.left, r.top, r.right, r.bottom, opts) != 0 )
{
return TheTrueObj;
}
oodSetSysErrCode(context->threadContext);
done_out:
return TheFalseObj;
}
/** WindowBase::clear()
*
* 'Clears' the dialog's client area by painting the entire area with the
* system color COLOR_BTNFACE brush. This is the same color as the default
* dialog background color so it has the effect of erasing everything on the
* client area, or 'clearing' it.
*
* @return 0 on success, 1 for error.
*
* @note Sets the .SystemErrorCode.
*
* @remarks Prior to 4.0.1, this method was in both the DialogExtensions and
* Dialog class. However, each method simply uses the object's window
* handle so it makes more sense to be a WindowBase method.
*
* Note this also: both methods were broken. They used the window
* rect of the window, not the client rect. In addition,
* GetWindowDC() was used instead of GetDC(). This has the effect of
* painting in the nonclient area of the window, which normally is
* not done. Since the methods were broken and the documentation was
* vague, it is not possible to tell what the original intent was.
*
* Since clearing the window rect of the dialog erases the title bar,
* and there is no way for the ooDialog programmer to redraw the
* title bar or title bar buttons, the assumption is that the methods
* were intended to clear the client area.
*/
RexxMethod1(RexxObjectPtr, wb_clear, CSELF, pCSelf)
{
HWND hwnd = getWBWindow(context, pCSelf);
RECT r = {0};
if ( oodGetClientRect(context, hwnd, &r) == TheOneObj )
{
return TheOneObj;
}
return clearRect(context, hwnd, &r);
}
/** WindowBase::foreGroundWindow()
*
* Returns the handle of the window in the foreground. The foreground window
* can be NULL in certain circumstances, such as when a window is losing
* activation.
*
* @note Sets the .SystemErrorCode, but it is unlikely that the operating
* system sets last error during the execution of this method.
*/
RexxMethod0(POINTERSTRING, wb_foreGroundWindow)
{
oodResetSysErrCode(context->threadContext);
HWND hwnd = GetForegroundWindow();
oodSetSysErrCode(context->threadContext);
return hwnd;
}
/** WindowBase::screen2client()
* WindowBase::client2screen()
*
* screen2client() converts the screen coordinates of the specified point on
* the screen to client-area coordinates of this window.
*
* This method uses the screen coordinates given in the .Point object to
* compute client-area coordinates. It then replaces the screen coordinates
* with the client coordinates. The new coordinates are relative to the
* upper-left corner of this window's client area.
*
*
* client2screen() converts the client-area coordinates of the specified point
* to screen coordinates.
*
* This method uses the client-area coordinates given in the .Point object to
* compute screen coordinates. It then replaces the client-area coordinates
* with the screen coordinates. The new coordinates are relative to the
* upper-left corner of the screen.
*
* @param pt [in/out] On entry, the coordinates to be converted, on exit the
* converted coordinates.
*
* @return True on success, false on failure. The .SystemErrorCode should
* contain the reason for failure.
*
* @note Sets the .SystemErrorCode.
*
*/
RexxMethod4(logical_t, wb_screenClient, RexxObjectPtr, pt, NAME, method, OSELF, self, CSELF, pCSelf)
{
RexxMethodContext *c = context;
oodResetSysErrCode(context->threadContext);
BOOL success = FALSE;
HWND hwnd = getWBWindow(context, pCSelf);
if ( hwnd == NULL )
{
noWindowsDialogException(context, self);
goto done_out;
}
if ( c->IsOfType(pt, "POINT") )
{
POINT *p = rxGetPoint(context, pt, 1);
if ( p != NULL )
{
if ( *method == 'S' )
{
success = ScreenToClient(hwnd, p);
}
else
{
success = ClientToScreen(hwnd, p);
}
if ( ! success )
{
oodSetSysErrCode(context->threadContext);
}
}
}
else if ( c->IsOfType(pt, "RECT") )
{
RECT *r = rxGetRect(context, pt, 1);
if ( r != NULL )
{
if ( *method == 'S' )
{
if ( ScreenToClient(hwnd, (POINT *)r) )
{
success = ScreenToClient(hwnd, ((POINT *)r) + 1);
}
}
else
{
if ( ClientToScreen(hwnd, (POINT *)r) )
{
success = ClientToScreen(hwnd, ((POINT *)r) + 1);
}
}
if ( ! success )
{
oodSetSysErrCode(context->threadContext);
}
}
}
else
{
wrongArgValueException(context->threadContext, 1, "Point or Rect", pt);
}
done_out:
return success;
}
/** WindowBase:: mapWindowPoints()
*
*
*/
RexxMethod3(logical_t, wb_mapWindowPoints, POINTERSTRING, hwndTo, RexxObjectPtr, points, CSELF, pCSelf)
{
BOOL result = FALSE;
HWND hwndFrom = wbSetUp(context, pCSelf);
if ( hwndFrom != NULL )
{
PPOINT pts;
uint32_t count = 1;
RexxMethodContext *c = context;
if ( c->IsOfType(points, "POINT") )
{
pts = rxGetPoint(context, points, 1);
if ( pts == NULL )
{
goto done_out;
}
}
else if ( c->IsOfType(points, "RECT") )
{
RECT *r = rxGetRect(context, points, 1);
if ( r == NULL )
{
goto done_out;
}
pts = (LPPOINT)r;
count = 2;
}
else
{
wrongArgValueException(context->threadContext, 1, "Point or Rect", points);
}
SetLastError(0);
uint32_t rc = 0;
MapWindowPoints(hwndFrom, (HWND)hwndTo, pts, count);
rc = GetLastError();
if ( rc == 0 )
{
result = TRUE;
}
else
{
oodSetSysErrCode(context->threadContext, rc);
}
}
done_out:
return result;
}
/** WindowBase::getWindowLong() [private]
*
* Retrieves information about this window. Specifically, the information
* available through the GetWindowLong(). Internally this used to get the
* GWL_ID, GWL_STYLE, and GWL_EXSTYLE values.
*
* @param flag The index for the information to be retrieved.
*
* @return The unsigned 32-bit information for the specified index.
*
* @remarks The other indexes, besides the 3 mentioned above are all pointer
* or handle values. Because of this, this method should not be
* documented. The implementation may change.
*/
RexxMethod2(uint32_t, wb_getWindowLong_pvt, int32_t, flag, CSELF, pCSelf)
{
return GetWindowLong(getWBWindow(context, pCSelf), flag);
}
/**
* Methods for the .PlainBaseDialog class.
*/
#define PLAINBASEDIALOG_CLASS "PlainBaseDialog"
#define CONTROLBAG_ATTRIBUTE "PlainBaseDialogControlBag"
static inline HWND getPBDWindow(RexxMethodContext *c, void *pCSelf)
{
if ( pCSelf == NULL )
{
return (HWND)baseClassInitializationException(c);
}
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( pcpbd->hDlg == NULL )
{
noWindowsDialogException(c, pcpbd->rexxSelf);
}
return pcpbd->hDlg;
}
HWND getPBDControlWindow(RexxMethodContext *c, pCPlainBaseDialog pcpbd, RexxObjectPtr rxID)
{
if ( pcpbd == NULL )
{
return (HWND)baseClassInitializationException(c);
}
HWND hCtrl = NULL;
oodResetSysErrCode(c->threadContext);
int32_t id;
if ( ! oodSafeResolveID(&id, c, pcpbd->rexxSelf, rxID, -1, 1, true) )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_WINDOW_HANDLE);
}
else
{
hCtrl = GetDlgItem(pcpbd->hDlg, id);
if ( hCtrl == NULL )
{
oodSetSysErrCode(c->threadContext);
}
}
return hCtrl;
}
/**
* Used to end the Windows dialog and clean up the CSelf struct for the Rexx
* dialog.
*
* Can also be used to clean up the CSelf struct when an error happens during
* the creation of the underlying Windows dialog.
*
* @param pcpbd Pointer to the PlainBaseDialog CSelf struct.
* @param c Thread context we are operating in.
*
* @return -1 if the CSelf struct has already been cleaned up. Otherwise, 1 for
* a normal termination, or 2 for an abnormal termination. The return
* is not really used anywhere.
*
* @remarks Prior to the conversion to the C++ APIs, this function was passed
* the dialog window handle and did a seekDlgAdm using that handle.
* It was also possible that it would be called when the creation of
* the underlying dialog failed, passing in a null handle. In that
* case, it erroneously deleted the 'TopDlg.'
*
* @remarks It turns out it is relatively easy for this function to be called
* twice for the same dialog (hence the old seekDlgAdm.) We first
* test dlgAllocated to bypass calling EnterCriticalSection() when
* it is not needed. But, then we need to test the flag again after
* gaining the critical section, because it is not unusual for
* delDialog() to be running at the time this function is entered.
*/
int32_t stopDialog(pCPlainBaseDialog pcpbd, RexxThreadContext *c)
{
int32_t result = -1;
if ( pcpbd->dlgAllocated )
{
EnterCriticalSection(&crit_sec);
if ( pcpbd->dlgAllocated )
{
result = delDialog(pcpbd, c);
}
LeaveCriticalSection(&crit_sec);
}
return result;
}
/**
* This function is only called after the underlying dialog has been
* successfully created. It then sets the dialog handle into the various CSelf
* structs that need it.
*
* @param pcpbd CSelf pointer of the dialog
*
* @remarks Originally we created the Rexx hwnd object here and requested a
* global reference for it. We now skip that and instead do a lazy
* init of the Rexx object in the hwnd attribute get.
*/
void setDlgHandle(pCPlainBaseDialog pcpbd)
{
if ( ! pcpbd->isDlgHwndSet )
{
HWND hDlg = pcpbd->hDlg;
pcpbd->enCSelf->hDlg = hDlg;
pcpbd->weCSelf->hwnd = hDlg;
pcpbd->wndBase->hwnd = hDlg;
pcpbd->isDlgHwndSet = true;
}
}
/**
* Gets the window handle of the dialog control that has the focus. The call to
* GetFocus() needs to run in the window thread of the dialog to ensure that the
* correct handle is obtained. However, we could executing on that thread.
*
* @param c Method context we are operating in.
* @param hDlg Handle to the dialog of interest.
* @param isDlgProcThread Is this the dialog message processing thread?
*
* @return The window handle of the dialog control with the focus, or 0 on
* failure.
*/
RexxObjectPtr oodGetFocus(RexxMethodContext *c, HWND hDlg, bool isDlgProcThread)
{
HWND hwndFocus;
if ( isDlgProcThread )
{
hwndFocus = GetFocus();
}
else
{
hwndFocus = (HWND)SendMessage(hDlg, WM_USER_GETFOCUS, 0, 0);
}
return pointer2string(c, hwndFocus);
}
/**
* Brings the specified window to the foreground and returns the previous
* foreground window.
*
* @param c
* @param hwnd
*
* @return The previous window handle as a Rexx object, or 0 on error.
*
* @remarks SetForegroundWindow() is not documented as setting last error. So,
* if it fails, last error is checked. If it is set, it is used. If
* it is not set, we arbitrarily use ERROR_NOTSUPPORTED. On XP at
* least, last error is set to 5, access denied.
*/
RexxObjectPtr oodSetForegroundWindow(RexxMethodContext *c, HWND hwnd)
{
oodResetSysErrCode(c->threadContext);
if ( hwnd == NULL || ! IsWindow(hwnd) )
{
oodSetSysErrCode(c->threadContext, ERROR_INVALID_WINDOW_HANDLE);
return TheZeroObj;
}
HWND hwndPrevious = GetForegroundWindow();
if ( hwndPrevious != hwnd )
{
SetLastError(0);
if ( SetForegroundWindow(hwnd) == 0 )
{
uint32_t rc = GetLastError();
if ( rc == 0 )
{
rc = ERROR_NOT_SUPPORTED;
}
oodSetSysErrCode(c->threadContext, rc);
return TheZeroObj;
}
}
return pointer2string(c, hwndPrevious);
}
/**
* Convenience function, called from PlainBaseDialog::init().
*
* @param c
* @param self
* @param pcpbd
* @param ownerData
*
* @return bool
*/
static bool checkDlgType(RexxMethodContext *c, RexxObjectPtr self, pCPlainBaseDialog pcpbd, RexxObjectPtr ownerData)
{
bool arg5Exists = (c->arguments[5].flags & ARGUMENT_EXISTS) != 0;
if ( c->IsOfType(self, "CATEGORYDIALOG") )
{
pcpbd->isCategoryDlg = true;
}
else if ( c->IsOfType(self, "CONTROLDIALOG") )
{
if ( arg5Exists )
{
if ( c->IsOfType(ownerData, "PLAINBASEDIALOG") )
{
pCPlainBaseDialog ownerPcpbd = requiredDlgCSelf(c, ownerData, oodPlainBaseDialog, 5, NULL);
if ( ownerPcpbd == NULL )
{
goto err_out;
}
pcpbd->isOwnedDlg = true;
pcpbd->rexxOwner = ownerData;
pcpbd->hOwnerDlg = ownerPcpbd->hDlg;
pcpbd->initPrivate = TheNilObj;
}
else if( c->IsOfType(ownerData, "CONTROLDLGINFO") )
{
pcpbd->initPrivate = ownerData;
pCControlDialogInfo pccid = (pCControlDialogInfo)c->ObjectToCSelf(ownerData);
// For a control dialog used with a tab owner dialog, it is not
// likely that the owner will be set yet.
if ( pccid->owner != NULLOBJECT )
{
pCPlainBaseDialog ownerPcpbd = dlgToCSelf(c, pccid->owner);
pcpbd->isOwnedDlg = true;
pcpbd->rexxOwner = pccid->owner;
pcpbd->hOwnerDlg = ownerPcpbd->hDlg;
}
}
else
{
wrongArgValueException(c->threadContext, 5, "a PlainBaseDialog or a ControlDialogInfo object", ownerData);
goto err_out;
}
}
pcpbd->isControlDlg = true;
}
else if ( c->IsOfType(self, "TABOWNERDIALOG") )
{
if ( arg5Exists )
{
if ( ! c->IsOfType(ownerData, "TABOWNERDLGINFO") )
{
wrongClassException(c->threadContext, 5, "TabOwnerDlgInfo");
goto err_out;
}
pcpbd->initPrivate = ownerData;
}
else
{
pcpbd->initPrivate = TheNilObj;
}
pcpbd->isTabOwnerDlg = true;
}
else if ( c->IsOfType(self, "PROPERTYSHEETDIALOG") )
{
pcpbd->isPropSheetDlg = true;
}
else if ( c->IsOfType(self, "PROPERTYSHEETPAGE") )
{
pcpbd->isPageDlg = true;
}
if ( c->IsOfType(self, "CUSTOMDRAW") )
{
pcpbd->isCustomDrawDlg = true;
pcpbd->idsNotChecked = true;
}
if ( c->IsOfType(self, "RESIZINGADMIN") )
{
pcpbd->isResizableDlg = true;
}
return true;
err_out:
return false;
}
RexxMethod1(RexxObjectPtr, pbdlg_init_cls, OSELF, self)
{
if ( isOfClassType(context, self, PLAINBASEDIALOG_CLASS) )
{
ThePlainBaseDialogClass = (RexxClassObject)self;
context->RequestGlobalReference(ThePlainBaseDialogClass);
RexxBufferObject buf = context->NewBuffer(sizeof(CPlainBaseDialogClass));
if ( buf != NULLOBJECT )
{
pCPlainBaseDialogClass pcpbdc = (pCPlainBaseDialogClass)context->BufferData(buf);
strcpy(pcpbdc->fontName, DEFAULT_FONTNAME);
pcpbdc->fontSize = DEFAULT_FONTSIZE;
context->SetObjectVariable("CSELF", buf);
}
}
return NULLOBJECT;
}
RexxMethod2(RexxObjectPtr, pbdlg_setDefaultFont_cls, CSTRING, fontName, uint32_t, fontSize)
{
pCPlainBaseDialogClass pcpbdc = dlgToClassCSelf(context);
if ( strlen(fontName) > (MAX_DEFAULT_FONTNAME - 1) )
{
stringTooLongException(context->threadContext, 1, MAX_DEFAULT_FONTNAME, strlen(fontName));
}
else
{
strcpy(pcpbdc->fontName, fontName);
pcpbdc->fontSize = fontSize;
}
return NULLOBJECT;
}
RexxMethod1(CSTRING, pbdlg_getFontName_cls, CSELF, pCSelf)
{
pCPlainBaseDialogClass pcpbdc = dlgToClassCSelf(context);
return pcpbdc->fontName;
}
RexxMethod1(uint32_t, pbdlg_getFontSize_cls, CSELF, pCSelf)
{
pCPlainBaseDialogClass pcpbdc = dlgToClassCSelf(context);
return pcpbdc->fontSize;
}
/** PlainBaseDialog::new()
*
* The new() method is implemented to provide a clean way to prevent more than
* MAXDIALOGS dialog objects from being instantiated.
*
* If we try to enforce this in PlaingBaseDialog::init() we run into the
* problem of having to either:
*
* Raise an error condition and have the other dialog threads pretty much hang.
*
* Raise an error condition and issue an interpreter halt, pretty much shutting
* everything down.
*
* Here we intercept the too many dialogs condition and return a proxy object
* that has only 1 method, the initCode. For the proxy object, initCode always
* returns 1. If the programmer checks the init code, they will know the
* dialog is not vaild. If they try to use it, it won't work.
*
*/
RexxMethod2(RexxObjectPtr, pbdlg_new_cls, ARGLIST, args, SUPER, superClass)
{
RexxObjectPtr dlgObj = TheNilObj;
if ( CountDialogs >= MAXDIALOGS )
{
char buf[128];
_snprintf(buf, sizeof(buf),
"The number of active dialogs has\n"
"reached the maximum (%d) allowed\n\n"
"No more dialogs can be instantiated", MAXDIALOGS);
MessageBox(NULL, buf, "ooDialog Error", MB_OK | MB_ICONHAND | MB_SYSTEMMODAL);
RexxClassObject proxyClass = rxGetContextClass(context, "DIALOGPROXY");
if ( proxyClass != NULLOBJECT )
{
dlgObj = context->SendMessage0(proxyClass, "NEW");
}
goto done_out;
}
dlgObj = context->ForwardMessage(NULLOBJECT, NULL, superClass, NULL);
done_out:
return dlgObj;
}
/** PlainBaseDialog::init()
*
* The initialization of the base dialog.
*
* @params library DLL or .rc file for ResDialog or RcDialog dialogs.
* @params resource Resource ID for ResDialog or RcDialog dialogs.
* @params dlgDataStem Data stem.
* @params hFile Header file.
*
* @params initData Init data can be any object used to initialize a
* specific concrete dialog class. Around ooDialog 4.2.0
* it was decided that rather than continually adding
* optional init parameters to new dialog classes, we
* would simply use a single init object that is passed
* on to the concrete class. Which in turn knows how to
* use that init object.
*
* @remarks Prior to 4.0.1, if something failed here, the 'init code' was set
* to non-zero. One problem with this is that it relies on the user
* checking the init code and *not* using the dialog object if it is
* an error code. Since we can not rely on that, in order to prevent
* a crash, the internal code would need to constantly check that the
* CSELF pointer was not null.
*
* Rather than do that, the code now raises an error condition if
* something fails. (This seems to be the right thing to do anyway.)
* That works fine if there is only one dialog running. But, if more
* than one dialog is running, the other threads just hang. Not real
* clean for the user. So, in addition, we use the interpreter
* instance to do a Halt(), which pretty much shuts everything down.
*
* As ooDialog was being converted to the C++ APIs, the initCode
* attribute came to have less and less meaningingful. With this
* change, it is mostly not needed. The one exception is when the
* maximum number of active dialogs has been reached. (See
* PlainBaseDialog::new().)
*/
RexxMethod6(RexxObjectPtr, pbdlg_init, CSTRING, library, RexxObjectPtr, resource,
OPTIONAL_RexxObjectPtr, dlgDataStem, OPTIONAL_RexxObjectPtr, hFile,
OPTIONAL_RexxObjectPtr, ownerData, OSELF, self)
{
// This is an error return, but see remarks.
RexxObjectPtr result = TheOneObj;
// Before processing the arguments, do everything that might raise an error
// condition.
// Get a buffer for the PlainBaseDialog CSelf.
RexxBufferObject cselfBuffer = context->NewBuffer(sizeof(CPlainBaseDialog));
if ( cselfBuffer == NULLOBJECT )
{
goto terminate_out;
}
context->SetObjectVariable("CSELF", cselfBuffer);
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)context->BufferData(cselfBuffer);
memset(pcpbd, 0, sizeof(CPlainBaseDialog));
// Initialize the window base.
pCWindowBase pWB;
if ( ! initWindowBase(context, NULL, self, &pWB) )
{
goto terminate_out;
}
pcpbd->wndBase = pWB;
if ( ! initWindowExtensions(context, self, NULL, pcpbd->wndBase, pcpbd) )
{
goto terminate_out;
}
// We want to set the dialog type before initializing the event notification
// class.
if ( ! checkDlgType(context, self, pcpbd, ownerData) )
{
goto terminate_out;
}
// Initialize the event notification mixin class. The only thing that could
// fail is getting a buffer from the interpreter kernel.
pCEventNotification pEN = NULL;
if ( ! initEventNotification(context, pcpbd, self, &pEN) )
{
goto terminate_out;
}
pcpbd->enCSelf = pEN;
size_t len = strlen(library);
if ( len >= MAX_LIBRARYNAME )
{
stringTooLongException(context->threadContext, 1, MAX_LIBRARYNAME, len);
goto terminate_out;
}
strcpy(pcpbd->library, library);
pcpbd->resourceID = resource;
pcpbd->interpreter = context->threadContext->instance;
pcpbd->autoDetect = (pcpbd->isPropSheetDlg ? FALSE : TRUE);
pcpbd->rexxSelf = self;
// Set our default font to the PlainBaseDialog class default font.
pCPlainBaseDialogClass pcpbdc = dlgToClassCSelf(context);
strcpy(pcpbd->fontName, pcpbdc->fontName);
pcpbd->fontSize = pcpbdc->fontSize;
if ( ! (pcpbd->isControlDlg || pcpbd->isPageDlg) )
{
pcpbd->previous = TopDlg;
pcpbd->tableIndex = CountDialogs;
CountDialogs++;
DialogTable[pcpbd->tableIndex] = pcpbd;
}
pcpbd->dlgAllocated = true;
// Now process the arguments and do the rest of the initialization.
result = TheZeroObj;
if ( argumentExists(3) )
{
context->SetObjectVariable("DLGDATA.", dlgDataStem);
context->SetObjectVariable("USESTEM", TheTrueObj);
}
else
{
context->SetObjectVariable("DLGDATA.", TheNilObj);
context->SetObjectVariable("USESTEM", TheFalseObj);
}
context->SetObjectVariable("FINISHED", TheFalseObj);
context->SetObjectVariable("PROCESSINGLOAD", TheFalseObj);
context->SendMessage1(self, "CHILDDIALOGS=", rxNewList(context)); // self~childDialogs = .list~new
context->SendMessage1(self, "DATACONNECTION=", context->NewArray(50)); // self~dataConnection = .array~new(50)
context->SendMessage1(self, "AUTOMATICMETHODS=", rxNewQueue(context)); // self~autoMaticMethods = .queue~new
context->SendMessage1(self, "MENUBAR=", TheNilObj);
context->SendMessage1(self, "ISLINKED=", TheFalseObj);
context->SendMessage0(self, "INITAUTODETECTION"); // self~initAutoDetection
if ( TheConstDirUsage == globalOnly )
{
context->SendMessage1(self, "CONSTDIR=", TheConstDir); // self~constDir = .constDir (global)
}
else
{
RexxDirectoryObject constDir = context->NewDirectory();
context->SendMessage1(self, "CONSTDIR=", constDir); // self~constDir = .directory~new
putDefaultSymbols(context, constDir);
}
if ( argumentExists(4) )
{
context->SendMessage1(self, "PARSEINCLUDEFILE", hFile);
}
if ( pcpbd->isResizableDlg )
{
if ( ! allocateResizeInfo(context, pcpbd, cselfBuffer) )
{
result = TheOneObj;
goto done_out;
}
pcpbd->resizeInfo->inDefineSizing = true;
RexxObjectPtr reply = context->SendMessage0(self, "DEFINESIZING");
if ( ! isInt(0, reply, context->threadContext) )
{
result = TheOneObj;
}
pcpbd->resizeInfo->inDefineSizing = false;
}
goto done_out;
terminate_out:
context->threadContext->instance->Halt();
return result;
done_out:
pWB->initCode = (result == TheZeroObj ? 0 : 1);
return result;
}
RexxMethod1(RexxObjectPtr, pbdlg_unInit, CSELF, pCSelf)
{
if ( pCSelf != NULLOBJECT )
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
#if 0
printf("PlainBaseDialog::uninit() hDlg=%p isAllocated=%d Dialog is a ", pcpbd->hDlg, pcpbd->dlgAllocated);
dbgPrintClassID(context, pcpbd->rexxSelf);
#endif
EnterCriticalSection(&crit_sec);
if ( pcpbd->dlgAllocated )
{
delDialog(pcpbd, context->threadContext);
}
LeaveCriticalSection(&crit_sec);
// If we are terminating the interpreter from PlainBaseDialog::init on
// an error condition, it possible for pcwb to be NULL.
pCWindowBase pcwb = pcpbd->wndBase;
if ( pcwb != NULL && pcwb->rexxHwnd != TheZeroObj )
{
context->ReleaseGlobalReference(pcwb->rexxHwnd);
pcwb->rexxHwnd = TheZeroObj;
}
// It is tempting to think dlgProcContext should be checked here, and,
// if not null do a DetachThread(). However, the DetachThread() is, and
// should be, done from the message loop thread, not here. The only
// time dlgProcContext is not null is if the interpreter is being
// abruptly terminated (Ctrl-C, syntax condition, etc..) And in this
// case the DetachThread() is not needed.
}
return TheZeroObj;
}
/** PlainBaseDialog::library [attribute get]
*/
RexxMethod1(CSTRING, pbdlg_getLibrary, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( pcpbd == NULL )
{
return (CSTRING)baseClassInitializationException(context);
}
return pcpbd->library;
}
/** PlainBaseDialog::resourceID [attribute get]
*/
RexxMethod1(RexxObjectPtr, pbdlg_getResourceID, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( pcpbd == NULL )
{
return (RexxObjectPtr)baseClassInitializationException(context);
}
return pcpbd->resourceID;
}
/** PlainBaseDialog::dlgHandle [attribute get] / PlainBaseDialog::getSelf()
*
* We use a lazy init for rexxHwnd.
*/
RexxMethod1(RexxObjectPtr, pbdlg_getDlgHandle, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( pcpbd == NULL )
{
return (RexxObjectPtr)baseClassInitializationException(context);
}
if ( pcpbd->wndBase->rexxHwnd == TheZeroObj && pcpbd->wndBase->hwnd != NULL )
{
pcpbd->wndBase->rexxHwnd = context->RequestGlobalReference(pointer2string(context, pcpbd->wndBase->hwnd));
}
return pcpbd->wndBase->rexxHwnd;
}
/** PlainBaseDialog::autoDetect [attribute get]
*/
RexxMethod1(RexxObjectPtr, pbdlg_getAutoDetect, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( pcpbd == NULL )
{
return (RexxObjectPtr)baseClassInitializationException(context);
}
return pcpbd->autoDetect ? TheTrueObj : TheFalseObj;
}
/** PlainBaseDialog::autoDetect [attribute set]
*/
RexxMethod2(RexxObjectPtr, pbdlg_setAutoDetect, logical_t, on, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( pcpbd == NULL )
{
return (RexxObjectPtr)baseClassInitializationException(context);
}
pcpbd->autoDetect = on;
return NULLOBJECT;
}
/** PlainBaseDialog::parentDlg [attribute get private]
*/
RexxMethod1(RexxObjectPtr, pbdlg_getParentDlg_pvt, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( pcpbd == NULL )
{
return (RexxObjectPtr)baseClassInitializationException(context);
}
return pcpbd->rexxParent == NULLOBJECT ? TheNilObj : pcpbd->rexxParent;
}
/** PlainBaseDialog::parentDlg [attribute set private]
*/
RexxMethod2(RexxObjectPtr, pbdlg_setParentDlg_pvt, RexxObjectPtr, parent, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( pcpbd == NULL )
{
return (RexxObjectPtr)baseClassInitializationException(context);
}
if ( requiredClass(context->threadContext, parent, "PLAINBASEDIALOG", 1) )
{
pcpbd->rexxParent = parent;
}
return NULLOBJECT;
}
/** PlainBaseDialog::ownerDialog [attribute get]
*
* Returns the value of the owner dialog attribute, which is .nil if there is
* no owner dialog.
*
* @remarks Read the remarks for the ownerDialog [attribute set] below.
*/
RexxMethod1(RexxObjectPtr, pbdlg_getOwnerDialog, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( pcpbd == NULL )
{
return (RexxObjectPtr)baseClassInitializationException(context);
}
return pcpbd->rexxOwner == NULLOBJECT ? TheNilObj : pcpbd->rexxOwner;
}
/** PlainBaseDialog::ownerDialog [attribute set]
*
* Sets an owner dialog of this dialog.
*
* @note There are restraints on setting an owner dialog. The owner argument
* must be a Rexx dialog object, but can not be a PropertySheetDialog,
* PropertySheetPage, or ControlDialog. Once set, the owner dialog can
* not be changed or removed. The owner dialog can not be set once the
* underlying dialog for this dialog has been created and when the owned
* dialog is executed, the underlying owner dialog must have already
* been created.
*
* Raises error conditions if the constraints are not met.
*
* @remarks The ownerDialog attribute is used for both regular dialogs and
* ControlDialogs. A control dialog must have the owner dialog
* attribute set or it will not execute. A regular dialog does not
* need the owner dialog attribute set, and in almost all cases it
* will not be set. However, once it is set, the regular dialog
* becomes an 'owned' dialog, and from that point on the dialog
* remains an owned dialog.
*
* Although hOwnerDlg gets set here, it very well could still be
* null. When the owned dialog is executed, that is the underlying
* dialog is about to be created, there is a check that the
* underlying owner dialog has already been created.
*/
RexxMethod2(RexxObjectPtr, pbdlg_setOwnerDialog, RexxObjectPtr, owner, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( pcpbd == NULL )
{
return (RexxObjectPtr)baseClassInitializationException(context);
}
if ( pcpbd->isOwnedDlg )
{
userDefinedMsgException(context, "Once set, the owner dialog attribute can not be changed");
return NULLOBJECT;
}
if ( pcpbd->hDlg != NULL )
{
userDefinedMsgException(context, "The owner dialog attribute can not be set after the underlying dialog is created");
return NULLOBJECT;
}
pCPlainBaseDialog ownerPcpbd = requiredDlgCSelf(context, owner, oodPlainBaseDialog, 1, NULL);
if ( ownerPcpbd != NULL )
{
if ( ! isValidOwner(ownerPcpbd) )
{
userDefinedMsgException(context, "The owner dialog can not be a PropertySheetDialog or a child dialog");
}
else
{
pcpbd->isOwnedDlg = true;
pcpbd->rexxOwner = owner;
pcpbd->hOwnerDlg = ownerPcpbd->hDlg;
}
}
return NULLOBJECT;
}
/** PlainBaseDialog::finished [attribute get]
*/
RexxMethod1(RexxObjectPtr, pbdlg_getFinished, CSELF, pCSelf)
{
return context->GetObjectVariable("FINISHED");
}
/** PlainBaseDialog::finished [attribute set]
*/
RexxMethod2(RexxObjectPtr, pbdlg_setFinished, logical_t, val, CSELF, pCSelf)
{
((pCPlainBaseDialog)pCSelf)->isFinished = val ? true : false;
context->SetObjectVariable("FINISHED", val ? TheTrueObj : TheFalseObj);
return NULLOBJECT;
}
/** PlainBaseDialog::fontName [attribute get]
* PlainBaseDialog::fontSize [attribute get]
*/
RexxMethod2(RexxObjectPtr, pbdlg_getFontNameSize, NAME, method, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( pcpbd == NULL )
{
return (RexxObjectPtr)baseClassInitializationException(context);
}
RexxObjectPtr result;
if ( *(method + 4) == 'N' )
{
result = context->String(pcpbd->fontName);
}
else
{
result = context->UnsignedInt32(pcpbd->fontSize);
}
return result;
}
/** PlainBaseDialog::fontName [attribute set private]
*/
RexxMethod2(RexxObjectPtr, pbdlg_setFontName_pvt, CSTRING, name, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( pcpbd == NULL )
{
return (RexxObjectPtr)baseClassInitializationException(context);
}
if ( strlen(name) > (MAX_DEFAULT_FONTNAME - 1) )
{
stringTooLongException(context->threadContext, 1, MAX_DEFAULT_FONTNAME, strlen(name));
}
else
{
strcpy(pcpbd->fontName, name);
}
return NULLOBJECT;
}
/** PlainBaseDialog::fontSize [attribute set private]
*/
RexxMethod2(RexxObjectPtr, pbdlg_setFontSize_pvt, uint32_t, size, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( pcpbd == NULL )
{
return (RexxObjectPtr)baseClassInitializationException(context);
}
pcpbd->fontSize = size;
return NULLOBJECT;
}
/** PlaingBaseDialog::setDlgFont()
*
* Sets the font that will be used for the font of the underlying Windows
* dialog, when it is created. This is primarily of use in a UserDialog or a
* subclasses of a UserDialog.
*
* In a ResDialog, the font of the compiled binary resource will be used and
* the font set by this method has no bearing. In a RcDialog, if the resource
* script file specifies the font, that font will be used.
*
* Likewise, in a UserDialog, if the programmer specifies a font in the create
* method call (or createCenter() method call) the specified font over-rides
* what is set by this method.
*
* However, setting the font through the setDlgFont() method allows the true
* dialog unit values to be correctly calculated. That is the primary use for
* this method. A typical sequence might be:
*
* dlg = .MyDialog~new
* dlg~setFont("Tahoma", 12)
* ...
* ::method defineDialog
* ...
*
* @param fontName The font name, such as Tahoma. The name must be less than
* 256 characters in length.
* @param fontSize [optional] The point size of the font, for instance 10.
* The default if this argument is omitted is 8.
*
* @return 0, always.
*/
RexxMethod3(RexxObjectPtr, pbdlg_setDlgFont, CSTRING, fontName, OPTIONAL_uint32_t, fontSize, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( pcpbd == NULL )
{
return (RexxObjectPtr)baseClassInitializationException(context);
}
if ( strlen(fontName) > (MAX_DEFAULT_FONTNAME - 1) )
{
stringTooLongException(context->threadContext, 1, MAX_DEFAULT_FONTNAME, strlen(fontName));
}
else
{
if ( argumentOmitted(2) )
{
fontSize = DEFAULT_FONTSIZE;
}
strcpy(pcpbd->fontName, fontName);
pcpbd->fontSize = fontSize;
// TODO at this point calculate the true dialog base units from the font
// and set them into CPlainBaseDialog.
}
return TheZeroObj;
}
/** PlainBaseDialog::sendMessageToControl()
* PlainBaseDialog::sendMessageToControlH()
*
* Sends a window message to the specified dialog control.
*
* @param rxID The resource ID of the control, may be numeric or symbolic.
*
* @param wm_msg The Windows window message ID. This can be specified in
* either "0xFFFF" or numeric format.
*
* @param _wParam The WPARAM value for the message.
* @param _lParam The LPARAM value for the message.
*
* @return The result of sending the message, as returned by the operating
* system. sendMessageToControl() returns the result as a number.
* sendMessageToControlH() returns the result as an operating system
* handle.
*
* @note Sets the .SystemErrorCode.
*
* @remarks sendMessageToItem(), which forwards to this method, a method of
* DialogExtensions, but was moved back into PlainBaseDialog after
* the 4.0.0 release. Therefore, sendMessageToControl() can not
* raise an exception for a bad resource ID, sendMessageToControlH()
* can.
*/
RexxMethod6(RexxObjectPtr, pbdlg_sendMessageToControl, RexxObjectPtr, rxID, CSTRING, wm_msg,
RexxObjectPtr, _wParam, RexxObjectPtr, _lParam, NAME, method, CSELF, pCSelf)
{
bool doIntReturn = (strlen(method) == 20 ? true : false);
HWND hCtrl = getPBDControlWindow(context, (pCPlainBaseDialog)pCSelf, rxID);
if ( hCtrl == NULL )
{
if ( doIntReturn )
{
return TheNegativeOneObj;
}
else
{
return invalidTypeException(context->threadContext, 1, "resource ID, there is no matching dialog control");
}
}
return sendWinMsgGeneric(context, hCtrl, wm_msg, _wParam, _lParam, 2, doIntReturn);
}
/** PlainBaseDialog::sendMessageToWindow()
* PlainBaseDialog::sendMessageToWindowH()
*
* Sends a window message to the specified window.
*
* @param _hwnd The handle of the window the message is sent to.
* @param wm_msg The Windows window message ID. This can be specified in
* either "0xFFFF" or numeric format.
*
* @param _wParam The WPARAM value for the message.
* @param _lParam The LPARAM value for the message.
*
* @return The result of sending the message, as returned by the operating
* system. sendMessageToWindow() returns the result as a number and
* sendMessageToWindowH() returns the the result as an operating systme
* handle.
*
* @note Sets the .SystemErrorCode.
*/
RexxMethod6(RexxObjectPtr, pbdlg_sendMessageToWindow, CSTRING, _hwnd, CSTRING, wm_msg,
RexxObjectPtr, _wParam, RexxObjectPtr, _lParam, NAME, method, CSELF, pCSelf)
{
HWND hwnd = (HWND)string2pointer(_hwnd);
bool doIntReturn = (strlen(method) == 19 ? true : false);
return sendWinMsgGeneric(context, hwnd, wm_msg, _wParam, _lParam, 2, doIntReturn);
}
/** PlainBaseDialog::get()
*
* Returns the handle of the "top" dialog.
*
* @return The handle of the top dialog, or the null handle if there is no
* top dialog.
*
* @remarks This is a documented method from the original ooDialog
* implementation. The original documentaion said: "The Get method
* returns the handle of the current Windows dialog." The
* implementation has always been to get the handle of the TopDlg. I
* have never understood what the point of this method is, since the
* TopDlg, usually, just reflects the last dialog created.
*/
RexxMethod0(RexxObjectPtr, pbdlg_get)
{
if (TopDlg && TopDlg->hDlg)
{
return pointer2string(context, TopDlg->hDlg);
}
else
{
return TheZeroObj;
}
}
/** PlainBaseDialog::getWindowText()
*
* Gets the text of the specified window.
*
* For a window with a frame, this is the window title. But for a dialog
* control, this is the text for the control. This of course varies depending
* on the type of control. For a button, it is the button label, for an edit
* control it is the edit text, etc..
*
* @param hwnd The handle of the window.
*
* @return On success, the window text, which could be the empty string. On
* failure, the empty string.
*
* @note Sets the .SystemErrorCode.
*/
RexxMethod1(RexxStringObject, pbdlg_getWindowText, POINTERSTRING, hwnd)
{
RexxStringObject result = context->NullString();
rxGetWindowText(context, (HWND)hwnd, &result);
return result;
}
/** PlainBaseDialog::getTextSizeDu()
*
* Gets the size (width and height) in dialog units for any given string.
*
* @param text The string whose size is needed.
*
* @return The size needed for the string in a .Size object.
*/
RexxMethod2(RexxObjectPtr, pbdlg_getTextSizeDu, CSTRING, text, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
SIZE textSize = {0};
if ( pcpbd->hDlg == NULL )
{
if ( ! getTextSizeDuInactiveDlg(context, pcpbd, text, &textSize) )
{
goto error_out;
}
}
else
{
if ( ! getTextSizeDuActiveDlg(context, pcpbd, text, &textSize) )
{
goto error_out;
}
}
return rxNewSize(context, textSize.cx, textSize.cy);
error_out:
return NULLOBJECT;
}
/** PlainBaseDialog::getTextSizeDlg()
*
* Gets the size (width and height) in dialog units for any given string.
*
* Since dialog units only have meaning for a specific dialog, normally the
* dialog units are calculated using the font of the dialog. Optionally, this
* method will calculate the dialog units using a specified font.
*
* @param text The string whose size is needed.
*
* @param fontName Optional. If specified, use this font to calculate the
* size.
*
* @param fontSize Optional. If specified, use this font size with
* fontName to calculate the size. The default if omitted
* is 8. This arg is ignored if fontName is omitted.
*
* @param hwndFontSrc Optional. Use this window's font to calculate the size.
* This arg is always ignored if fontName is specified.
*
* @note The normal useage for this method would be, before the underlying
* dialog is created:
*
* dlg~setDlgFont("fontName", fontSize)
* dlg~getTextSizeDlg("some text")
*
* or, after the underlying dialog is created, just:
*
* dlg~getTextSizeDlg("some text")
*
* The convoluted use of the optional arguments are needed to maintain
* backwards compatibility with the pre 4.0.0 ooDialog, the Rexx
* programmer should be strongly discouraged from using them.
*
* In addition, a version of this method is mapped to the DialogControl
* class. This also is done only for backwards compatibility. There is
* no logical reason for this to be a method of a dialog control.
*/
RexxMethod5(RexxObjectPtr, pbdlg_getTextSizeDlg, CSTRING, text, OPTIONAL_CSTRING, fontName,
OPTIONAL_uint32_t, fontSize, OPTIONAL_POINTERSTRING, hwndFontSrc, OSELF, self)
{
HWND hwndSrc = NULL;
if ( argumentExists(2) )
{
if ( argumentOmitted(3) )
{
fontSize = DEFAULT_FONTSIZE;
}
}
else if ( argumentExists(4) )
{
if ( hwndFontSrc == NULL )
{
nullObjectException(context->threadContext, "window handle", 4);
return NULLOBJECT;
}
hwndSrc = (HWND)hwndFontSrc;
}
SIZE textSize = {0};
if ( getTextSize(context, text, fontName, fontSize, hwndSrc, self, &textSize) )
{
return rxNewSize(context, textSize.cx, textSize.cy);
}
return NULLOBJECT;
}
/** PlainBaseDialog::getTextSizeTitleBar()
*
* Gets the size, width and height, of a string used in the caption bar for the
* title.
*
* @param text [required] The text to get the dimensions for.
*
* @return A .Size object that reflects the width and height of the string if
* it were used in the caption bar.
*
* @notes This method can be invoked before the underlying dialog is created,
* and will return the dimensions as it does after the dialog is
* created.
*
* @remarks For GetWindowDC(), if the window handle passed to it is NULL, it
* returns a DC for the screen. This works fine for our needs.
* Testing shows the same dimensions are returned with a NULL window
* handle as with the actual dialog's window handle.
*/
RexxMethod2(RexxObjectPtr, pbdlg_getTextSizeTitleBar, CSTRING, text, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
uint32_t errCode = 0;
SIZE size = {0};
NONCLIENTMETRICS ncm = { 0 };
ncm.cbSize = sizeof(NONCLIENTMETRICS );
pCPlainBaseDialog pcpbd = getPBDCSelf(context, pCSelf);
if ( pcpbd == NULL )
{
goto done_out;
}
// First get the LOGFONT for the caption.
if ( ! SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS ), &ncm, 0) )
{
errCode = GetLastError();
goto done_out;
}
HDC hDC = GetWindowDC(pcpbd->hDlg);
if ( hDC == NULL )
{
errCode = GetLastError();
goto done_out;
}
HFONT hFont = CreateFontIndirect(&ncm.lfCaptionFont);
if ( hFont == NULL )
{
errCode = GetLastError();
goto done_out;
}
// This could fail, in which case the next steps are exactly the same, we
// release the DC and set the system error code. So we don't check for an
// error.
getTextExtent(hFont, hDC, text, &size);
DeleteObject(hFont);
ReleaseDC(pcpbd->hDlg, hDC);
done_out:
oodSetSysErrCode(context->threadContext, errCode);
return rxNewSize(context, size.cx, size.cy);
}
/** PlainBaseDialog::show()
*
* Shows the dialog in the manner specified by the keyword option. The dialog
* can be hidden, minimized, made visible, brought to the foreground, etc.
*
* @param keyword A single keyword that controls how the dialog is shown.
* Case is not significant.
*
* @return True if the dialog was previously visible. Return false if the
* window was previously hidden. Note that this is not a success or
* failure return, rather it is what the Windows API returns.
*
* @note The DEFAULT and NORMAL keywords are both equivalent to SW_SHOWNORMAL.
*
* Key words are NORMAL DEFAULT SHOWTOP RESTORE MIN MAX HIDE INACTIVE
*
* @remarks Note! This method over-rides the WindowBase::show() method. The
* WindowBase::show() method, does a show normal only. This method
* takes a number of keyword options, whereas WindowBase::show()
* method takes no options.
*
* Therefore, all dialog objects have this show method. All dialog
* control objects have the no-option show() method.
*
* The WindowBase::display() method is similar to this show(), but
* with fewer, and somewhat different, keywords.
*
* PlainBaseDialog::restore() also maps to this function. restore()
* takes no options.
*
* Older ooDialog did this: SHOWTOP used the SW_SHOW flag after
* bringing the dialog to the foreground. If there was a keyword,
* but no keyword match, then SW_SHOW was used. If the keyword was
* omitted, then SW_SHOWNORMAL was used. This bevavior is preserved.
*/
RexxMethod3(logical_t, pbdlg_show, OPTIONAL_CSTRING, options, NAME, method, CSELF, pCSelf)
{
HWND hwnd = getPBDWindow(context, pCSelf);
if ( hwnd == NULL )
{
return FALSE;
}
char flag = (*method == 'R' ? 'R' : 'N') ;
if ( options != NULL && *options != '\0' && flag != 'R' )
{
switch ( toupper(*options) )
{
case 'S' :
SetForegroundWindow(hwnd);
flag = 'S';
break;
case 'M' :
flag = (StrCmpNI("MIN", options, 3) == 0 ? 'M' : 'X');
break;
case 'H' :
flag = 'H';
break;
case 'I' :
flag = 'I';
break;
case 'R' :
flag = 'R';
break;
case 'D' :
flag = 'D';
break;
case 'N' :
flag = 'N';
break;
default :
flag = 'S';
break;
}
}
return showWindow(hwnd, flag);
}
/** PlainBaseDialog::showWindow() / PlainBaseDialog::hideWindow()
* PlainBaseDialog::showWindowFast() / PlainBaseDialog::hideWindowFast()
*
* Hides or shows the specified window, normally, or 'fast'. "Fast" means
* the visible flag is set, but the window is not forced to update.
*
* @param hwnd The handle of the window to be shown.
*
* @return 1 if the window was previously visible. Return 0 if the
* window was previously hidden. The return for these methods was not
* previously documented, but this matches what was returned.
*
* @note Sets the .SystemErrorCode.
*/
RexxMethod3(RexxObjectPtr, pbdlg_showWindow, POINTERSTRING, hwnd, NAME, method, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
if ( *method == 'S' )
{
((pCPlainBaseDialog)pCSelf)->activeChild = (HWND)hwnd;
}
logical_t rc;
if ( strstr("FAST", method) != NULL )
{
rc = showFast((HWND)hwnd, *method);
}
else
{
rc = showWindow((HWND)hwnd, *method);
}
return (rc ? TheOneObj : TheZeroObj);
}
/** PlainBaseDialog::showControl() / PlainBaseDialog::hideControl()
* PlainBaseDialog::showControlFast() / PlainBaseDialog::hideControlFast()
*
* Hides or shows the dialog control window, normally, or 'fast'. "Fast" means
* the visible flag is set, but the window is not forced to update.
*
* @param rxID The resource ID of the dialog control, may be numeric or
* symbolic.
*
* @return 1 if the window was previously visible. Return 0 if the
* window was previously hidden. Return -1 if the resource ID was no
* good. The return for these methods was not previously documented,
* but this matches what was returned.
*
* @note Sets the .SystemErrorCode.
*/
RexxMethod3(RexxObjectPtr, pbdlg_showControl, RexxObjectPtr, rxID, NAME, method, CSELF, pCSelf)
{
HWND hCtrl = getPBDControlWindow(context, (pCPlainBaseDialog)pCSelf, rxID);
if ( hCtrl == NULL )
{
return TheNegativeOneObj;
}
logical_t rc;
if ( strstr("FAST", method) != NULL )
{
rc = showFast(hCtrl, *method);
}
else
{
rc = showWindow(hCtrl, *method);
}
return (rc ? TheOneObj : TheZeroObj);
}
/** PlainBaseDialog::center()
*
* Moves the dialog to the center of screen.
*
* The dialog can be centered in the physical screen, or optionally centered in
* the screen work area. The work area is the portion of the screen not
* obscured by the system taskbar or by application desktop toolbars.
*
* @param options [OPTIONAL] A string of zero or more blank separated
* keywords. The key words control the behavior when the dialog
* is moved.
* @param workArea [OPTIONAL] If true, the dialog is centered in the work area
* of the screen. The default, false, centers the dialog in
* the physical screen area.
*
* @return True on success, otherwise false.
*
* @note Sets the .SystemErrorCode.
*/
RexxMethod3(RexxObjectPtr, pbdlg_center, OPTIONAL_CSTRING, options, OPTIONAL_logical_t, workArea, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
HWND hwnd = getPBDWindow(context, pCSelf);
if ( hwnd == NULL )
{
return TheFalseObj;
}
RECT r;
if ( GetWindowRect(hwnd, &r) == 0 )
{
oodSetSysErrCode(context->threadContext);
return TheFalseObj;
}
if ( workArea )
{
RECT wa;
if ( SystemParametersInfo(SPI_GETWORKAREA, 0, &wa, 0) == 0 )
{
oodSetSysErrCode(context->threadContext);
return TheFalseObj;
}
r.left = wa.left + (((wa.right - wa.left) - (r.right - r.left)) / 2);
r.top = wa.top + (((wa.bottom - wa.top) - (r.bottom - r.top)) / 2);
}
else
{
uint32_t cxScr = GetSystemMetrics(SM_CXSCREEN);
uint32_t cyScr = GetSystemMetrics(SM_CYSCREEN);
r.left = (cxScr - (r.right - r.left)) / 2;
r.top = (cyScr - (r.bottom - r.top)) / 2;
}
uint32_t opts = parseShowOptions(options);
opts = (opts | SWP_NOSIZE) & ~SWP_NOMOVE;
if ( SetWindowPos(hwnd, NULL, r.left, r.top, r.right, r.bottom, opts) == 0 )
{
oodSetSysErrCode(context->threadContext);
return TheFalseObj;
}
return TheTrueObj;
}
/** PlainBaseDialog::setWindowText()
*
* Sets the text for the specified window.
*
* @param hwnd The handle of the window.
* @param text The text to be set.
*
* @return 0 for success, 1 for error.
*
* @note Sets the .SystemErrorCode.
*/
RexxMethod2(wholenumber_t, pbdlg_setWindowText, POINTERSTRING, hwnd, CSTRING, text)
{
oodResetSysErrCode(context->threadContext);
if ( SetWindowText((HWND)hwnd, text) == 0 )
{
oodSetSysErrCode(context->threadContext);
return 1;
}
return 0;
}
/** PlainBaseDialog::toTheTop()
*
* Brings this dialog to the foreground.
*
* @return The handle of the window that previously was the foreground on
* success, 0 on failure.
*
* @note Sets the .SystemErrorCode. In very rare cases, there might not be a
* previous foreground window and 0 would be returned. In this case,
* the .SystemErrorCode will be 0, otherwise the .SystemErrorCode will
* not be 0.
*
* @note Windows no longer allows a program to arbitrarily change the
* foreground window.
*
* The system restricts which processes can set the foreground window. A
* process can set the foreground window only if one of the following
* conditions is true:
*
* The process is the foreground process.
* The process was started by the foreground process.
* The process received the last input event.
* There is no foreground process.
* No menus are active.
*
* With this change, an application cannot force a window to the
* foreground while the user is working with another window.
*/
RexxMethod1(RexxObjectPtr, pbdlg_toTheTop, CSELF, pCSelf)
{
HWND hwnd = getPBDWindow(context, pCSelf);
if ( hwnd == NULL )
{
return TheZeroObj;
}
return oodSetForegroundWindow(context, hwnd);
}
/** PlainBaseDialog::getFocus()
*
* Retrieves the window handle of the dialog control with the focus.
*
* @return The window handle on success, 0 on failure.
*/
RexxMethod1(RexxObjectPtr, pbdlg_getFocus, CSELF, pCSelf)
{
HWND hwnd = getPBDWindow(context, pCSelf);
if ( hwnd == NULL )
{
return TheZeroObj;
}
return oodGetFocus(context, hwnd, isDlgThread((pCPlainBaseDialog)pCSelf));
}
/** PlainBaseDialog::setFocus()
*
* Sets the focus to the dialog control specified.
*
* @param hwnd The window handle of the dialog control to recieve the focus.
*
* PlainBaseDialog::setFocusToWindow()
*
* Sets the focus to the dialog or other top-level window specified.
*
* @param hwnd The window handle of the dialog or other top-level window that
* will be brought to the foreground.
*
* @return On success, the window handle of the dialog control that previously
* had the focus. Otherwise, 0, if the focus was changed, but the
* previous focus could not be determined, and -1 on error.
*
* @note Sets the .SystemErrorCode.
*/
RexxMethod3(RexxObjectPtr, pbdlg_setFocus, RexxStringObject, hwnd, NAME, method, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
HWND hDlg = getPBDWindow(context, pCSelf);
if ( hDlg == NULL )
{
return TheNegativeOneObj;
}
HWND focusNext = (HWND)string2pointer(context, hwnd);
if ( ! IsWindow(focusNext) )
{
oodSetSysErrCode(context->threadContext, ERROR_INVALID_WINDOW_HANDLE);
return TheNegativeOneObj;
}
RexxObjectPtr previousFocus = oodGetFocus(context, hDlg, isDlgThread((pCPlainBaseDialog)pCSelf));
if ( strlen(method) > 7 )
{
if ( oodSetForegroundWindow(context, focusNext) == TheZeroObj )
{
return TheNegativeOneObj;
}
}
else
{
SendMessage(hDlg, WM_NEXTDLGCTL, (WPARAM)focusNext, TRUE);
}
return previousFocus;
}
/** PlainBaseDialog::TabToNext()
*
* Sets the focus to the next tab stop dialog control in the dialog and returns
* the window handle of the dialog control that currently has the focus.
*
* PlainBaseDialog::TabToPrevious()
*
* Sets the focus to the previous tab stop dialog control in the dialog and
* returns the window handle of the dialog control that currently has the
* focus.
*
* @return On success, the window handle of the dialog control that previously
* had the focus. Otherwise, 0, if the focus was changed, but the
* previous focus could not be determined, and -1 on error.
*
* @note Sets the .SystemErrorCode, but there is nothing that would change it
* from 0.
*/
RexxMethod2(RexxObjectPtr, pbdlg_tabTo, NAME, method, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
HWND hDlg = getPBDWindow(context, pCSelf);
if ( hDlg == NULL )
{
return TheNegativeOneObj;
}
RexxObjectPtr previousFocus = oodGetFocus(context, hDlg, isDlgThread((pCPlainBaseDialog)pCSelf));
if ( method[5] == 'N' )
{
SendMessage(hDlg, WM_NEXTDLGCTL, 0, FALSE);
}
else
{
SendMessage(hDlg, WM_NEXTDLGCTL, 1, FALSE);
}
return previousFocus;
}
/** PlainBaseDialog::backgroundBitmap()
*
* Uses the specified bitmap for the background of the dialog.
*
* The bitmap is stretched or shrunk to fit the size of the dialog and the
* bitmap is drawn internally by ooDialog. Contrast this with
* tiledBackgroundBitmap().
*
* @param bitmapFileName The name of a bitmap file to use as the dilaog
* background.
*
* @return True on success, false for some error.
*
* @note Sets the .SystemErrorCode.
*
* The .SystemErrorCode is set to: 2 ERROR_FILE_NOT_FOUND The system
* cannot find the file specified, if there is a problem with the bitmap
* file. This might be because the file could not be found. However,
* this code is used for other problems, such as the file was not a
* valid bitmap file.
*
* If the dialog already had a custom background set, it is changed to
* the bitmap. However, if an error ocurrs, then the existing custom
* background is not changed.
*
* @remarks In 4.0.1 and prior, this method was a DialogExtension method and
* it did not return a value. When it was moved to PlainBaseDialog
* after 4.0.1, the return was added.
*/
RexxMethod3(RexxObjectPtr, pbdlg_backgroundBitmap, CSTRING, bitmapFileName, OPTIONAL_CSTRING, opts, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
uint32_t errCode = 0;
HBITMAP hBitmap = (HBITMAP)loadDIB(bitmapFileName, &errCode);
if ( hBitmap == NULL )
{
oodSetSysErrCode(context->threadContext, errCode);
return TheFalseObj;
}
maybeSetColorPalette(context, hBitmap, opts, pcpbd);
if ( pcpbd->bkgBitmap != NULL )
{
DeleteObject(pcpbd->bkgBitmap);
}
pcpbd->bkgBitmap = hBitmap;
return TheTrueObj;
}
/** PlainBaseDialog::tiledBackgroundBitmap()
*
* Sets a bitmap to be used as a custom dialog background.
*
* An operating system 'brush' is created from the bitmap and used to paint the
* dialog background. If the bitmap size is less than the size of the dialog,
* this results in the background having a 'tiled' effect. The painting is
* done entirely by the operating system. Contrast this to the
* backgroundBitmap() method.
*
* @param bitmapFileName The name of a bitmap file to use as the dilaog
* background.
*
* @return True on success, false for some error.
*
* @note Sets the .SystemErrorCode.
*
* The .SystemErrorCode is set to: 2 ERROR_FILE_NOT_FOUND The system
* cannot find the file specified, if there is a problem with the bitmap
* file. This might be because the file could not be found. However,
* this code is used for other problems, such as the file was not a
* valid bitmap file.
*
* If the dialog already had a custom background set, it is changed to
* the bitmap. However, if an error ocurrs, then the existing custom
* background is not changed.
*
* @remarks In 4.0.1 and prior, this method was a DialogExtension method and
* it did not return a value. When it was moved to PlainBaseDialog
* after 4.0.1, the return was added.
*/
RexxMethod2(RexxObjectPtr, pbdlg_tiledBackgroundBitmap, CSTRING, bitmapFileName, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
uint32_t errCode = 0;
HBITMAP hBitmap = (HBITMAP)loadDIB(bitmapFileName, &errCode);
if ( hBitmap == NULL )
{
oodSetSysErrCode(context->threadContext, errCode);
return TheFalseObj;
}
LOGBRUSH logicalBrush;
logicalBrush.lbStyle = BS_DIBPATTERNPT;
logicalBrush.lbColor = DIB_RGB_COLORS;
logicalBrush.lbHatch = (ULONG_PTR)hBitmap;
HBRUSH hBrush = CreateBrushIndirect(&logicalBrush);
errCode = GetLastError();
LocalFree((void *)hBitmap);
if ( hBrush == NULL )
{
oodSetSysErrCode(context->threadContext, errCode);
return TheFalseObj;
}
if ( pcpbd->bkgBrush != NULL )
{
DeleteObject(pcpbd->bkgBrush);
}
pcpbd->bkgBrush = hBrush;
return TheTrueObj;
}
/** PlainBaseDialog::backgroundColor()
* PlainBaseDialog::backgroundSysColor()
*
* Sets a custom background color for the dialog.
*
* In Windows, background colors are painted using a "brush." This method
* creates a new brush for the specified color and this brush is then used
* whenever the background of the dialog needs to be repainted.
*
* @param colorIndex The color index.
*
* @param isClr [optional] For backgroundColor() only. If isClr is true
* colorIndex refers to a COLORREF color, if false colorIndex is
* a palette index. The default is fase.
*
* @return True on success, false for some error.
*
* @note Sets the .SystemErrorCode.
*
* If the dialog already had a custom background color set, it is
* changed to the new color. However, if an error ocurrs creating the
* new color brush then the custom color is not changed.
*
* @remarks In 4.0.1 and prior, this method was a DialogExtension method and
* it did not return a value. When it was moved to PlainBaseDialog
* after 4.0.1, the return was added.
*/
RexxMethod4(RexxObjectPtr, pbdlg_backgroundColor, RexxObjectPtr, _colorIndex, OPTIONAL_logical_t, isClr,
NAME, methName, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
uint32_t colorIndex;
HBRUSH hBrush = NULL;
bool isSys = (methName[10] == 'S');
if ( isSys )
{
if ( argumentExists(2) )
{
tooManyArgsException(context->threadContext, 1);
return TheFalseObj;
}
if ( ! getSystemColor(context, _colorIndex, &colorIndex, 1) )
{
return TheFalseObj;
}
hBrush = GetSysColorBrush(colorIndex);
}
else
{
if ( ! context->UnsignedInt32(_colorIndex, &colorIndex) )
{
wrongRangeException(context->threadContext, 1, (uint32_t)0, UINT32_MAX, _colorIndex);
return TheFalseObj;
}
if ( isClr )
{
hBrush = CreateSolidBrush(colorIndex);
}
else
{
hBrush = CreateSolidBrush(PALETTEINDEX(colorIndex));
}
}
if ( hBrush == NULL )
{
oodSetSysErrCode(context->threadContext);
return TheFalseObj;
}
if ( pcpbd->bkgBrush != NULL && ! pcpbd->bkgBrushIsSystem )
{
DeleteObject(pcpbd->bkgBrush);
}
pcpbd->bkgBrushIsSystem = isSys;
pcpbd->bkgBrush = hBrush;
return TheTrueObj;
}
/** PlainBaseDialog::pixel2dlgUnit()
*
* Takes a dimension expressed in pixels and tranforms it to a dimension
* expressed in dialog units of this dialog.
*
* @param pixels [IN / OUT ] The object to transform, can be either a
* .Point, .Size, or .Rect. On input, the unit of measurement
* is assumed to be pixels and on return the pixels will have
* been converted to dialog units.
*
* @return True on success, false on error.
*
* @remarks A point and a size are binary compatible, so they can be treated
* the same by using a cast for a size.
*/
RexxMethod2(logical_t, pbdlg_pixel2dlgUnit, RexxObjectPtr, du, OSELF, self)
{
if ( context->IsOfType(du, "POINT") || context->IsOfType(du, "SIZE") )
{
POINT *p = (PPOINT)context->ObjectToCSelf(du);
return mapPixelToDu(context, self, p, 1) ? TRUE : FALSE;
}
else if ( context->IsOfType(du, "RECT") )
{
RECT *r = (PRECT)context->ObjectToCSelf(du);
return mapPixelToDu(context, self, (PPOINT)r, 2) ? TRUE : FALSE;
}
wrongArgValueException(context->threadContext, 1, "Point, Size, or Rect", du);
return FALSE;
}
/** PlainBaseDialog::dlgUnit2pixel()
*
* Takes a dimension expressed in dialog units of this dialog and tranforms it
* to a dimension expressed in pixels.
*
* @param du [IN / OUT ] The object to transform, can be either a .Rect,
* .Point, or .Size. On input, the unit of measurement is assumed
* to be dialog units of this dialog and on return the dialog units
* will have been converted to pixels.
*
* @return True on success, false on error.
*
* @remarks A point and a size are binary compatible, so they can be treated
* the same by using a cast for a size.
*/
RexxMethod2(logical_t, pbdlg_dlgUnit2pixel, RexxObjectPtr, pixels, OSELF, self)
{
if ( context->IsOfType(pixels, "RECT") )
{
RECT *r = (PRECT)context->ObjectToCSelf(pixels);
return mapDuToPixel(context, self, r) ? TRUE : FALSE;
}
else if ( context->IsOfType(pixels, "POINT") || context->IsOfType(pixels, "SIZE") )
{
RECT r = {0};
POINT *p = (PPOINT)context->ObjectToCSelf(pixels);
r.right = p->x;
r.bottom = p->y;
if ( mapDuToPixel(context, self, &r) )
{
p->x = r.right;
p->y = r.bottom;
return TRUE;
}
return FALSE;
}
wrongArgValueException(context->threadContext, 1, "Point, Size, or Rect", pixels);
return FALSE;
}
/** PlainBaseDialog::getControlText()
*
* Gets the text of the specified control.
*
* @param rxID The resource ID of the control, may be numeric or symbolic.
*
* @return On success, the window text, which could be the empty string. On
* failure, the empty string.
*
* @note Sets the .SystemErrorCode.
*/
RexxMethod2(RexxStringObject, pbdlg_getControlText, RexxObjectPtr, rxID, CSELF, pCSelf)
{
RexxStringObject result = context->NullString();
HWND hCtrl = getPBDControlWindow(context, (pCPlainBaseDialog)pCSelf, rxID);
if ( hCtrl != NULL )
{
rxGetWindowText(context, hCtrl, &result);
}
else
{
result = context->String("-1");
}
return result;
}
/** PlainBaseDialog::setControlText()
*
* Sets the text for the specified control.
*
* @param rxID The resource ID of the control, may be numeric or symbolic.
* @param text The text to be set.
*
* @return 0 for success, -1 for an incorrect resource ID, 1 for other errors.
*
* @note Sets the .SystemErrorCode.
*/
RexxMethod3(RexxObjectPtr, pbdlg_setControlText, RexxObjectPtr, rxID, CSTRING, text, CSELF, pCSelf)
{
RexxObjectPtr result = TheOneObj;
HWND hCtrl = getPBDControlWindow(context, (pCPlainBaseDialog)pCSelf, rxID);
if ( hCtrl != NULL )
{
if ( SetWindowText(hCtrl, text) == 0 )
{
oodSetSysErrCode(context->threadContext);
}
else
{
result = TheZeroObj;
}
}
else
{
result = TheNegativeOneObj;
}
return result;
}
/** PlainBaseDialog::focusControl
*
* Sets the focus to the specified control in this dialog.
*
* @param rxID The resource ID of the control, may be numeric or symbolic.
*
* @return 0 on success, -1 if there is a problem identifying the dialog
* control.
*
* @note Sets the .SystemErrorCode.
*/
RexxMethod2(RexxObjectPtr, pbdlg_focusControl, RexxObjectPtr, rxID, CSELF, pCSelf)
{
HWND hCtrl = getPBDControlWindow(context, (pCPlainBaseDialog)pCSelf, rxID);
if ( hCtrl != NULL )
{
SendMessage(((pCPlainBaseDialog)pCSelf)->hDlg, WM_NEXTDLGCTL, (WPARAM)hCtrl, TRUE);
return TheZeroObj;
}
else
{
return TheNegativeOneObj;
}
}
/** PlainBaseDialog::enableControl()
* PlainBaseDialog::disableControl()
*
* Disables or enables the specified control
*
* @param rxID The resource ID of the control, may be numeric or symbolic.
*
* @return 1 (true) if the window was previously disabled, returns 0 (false)
* if the window was not previously disabled. Note that this is not
* succes or failure.
*
* @note Sets the .SystemErrorCode.
*
* @remarks The return was not previously documented.
*/
RexxMethod2(RexxObjectPtr, pbdlg_enableDisableControl, RexxObjectPtr, rxID, CSELF, pCSelf)
{
RexxObjectPtr result = TheNegativeOneObj;
HWND hCtrl = getPBDControlWindow(context, (pCPlainBaseDialog)pCSelf, rxID);
if ( hCtrl != NULL )
{
BOOL enable = TRUE;
if ( msgAbbrev(context) == 'D' )
{
enable = FALSE;
}
result = EnableWindow(hCtrl, enable) == 0 ? TheZeroObj : TheOneObj;
}
return result;
}
/** PlainBaseDialog::getControlHandle()
*
* Gets the window handle of a dialog control.
*
* @param rxID The resource ID of the control, which may be numeric or
* symbolic.
* @param _hDlg [optional] The window handle of the dialog the control
* belongs to. If omitted, the handle of this dialog is used.
*
* @return The window handle of the specified dialog control on success,
* otherwise 0.
*
* @note Sets the .SystemErrorCode.
*
* @remarks For pre 4.0.1 compatibility, this method needs to return 0 if the
* symbolic ID does not resolve, rather than the normal -1.
*/
RexxMethod3(RexxObjectPtr, pbdlg_getControlHandle, RexxObjectPtr, rxID, OPTIONAL_RexxStringObject, _hDlg, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
int32_t id;
if ( ! oodSafeResolveID(&id, context, pcpbd->rexxSelf, rxID, -1, 1, true) )
{
oodSetSysErrCode(context->threadContext, ERROR_INVALID_WINDOW_HANDLE);
return TheZeroObj;
}
HWND hDlg;
if ( argumentOmitted(2) )
{
hDlg = pcpbd->hDlg;
}
else
{
hDlg = (HWND)string2pointer(context, _hDlg);
}
HWND hCtrl = GetDlgItem(hDlg, id);
if ( hCtrl == NULL )
{
oodSetSysErrCode(context->threadContext);
return TheZeroObj;
}
return pointer2string(context, hCtrl);
}
RexxMethod1(int32_t, pbdlg_getControlID, CSTRING, hwnd)
{
HWND hCtrl = (HWND)string2pointer(hwnd);
int32_t id = -1;
if ( IsWindow(hCtrl) )
{
SetLastError(0);
id = GetDlgCtrlID(hCtrl);
if ( id == 0 )
{
id = -(int32_t)GetLastError();
}
}
return id == 0 ? -1 : id;
}
/** PlainBaseDialog::maximize()
* PlainBaseDialog::minimize()
* PlainBaseDialog::isMaximized()
* PlainBaseDialog::isMinimized()
*
*/
RexxMethod2(RexxObjectPtr, pbdlg_doMinMax, NAME, method, CSELF, pCSelf)
{
HWND hDlg = getPBDWindow(context, pCSelf);
if ( hDlg == NULL )
{
return TheFalseObj;
}
if ( *method == 'M' )
{
uint32_t flag = (method[1] == 'I' ? SW_SHOWMINIMIZED : SW_SHOWMAXIMIZED);
return (ShowWindow(hDlg, flag) ? TheZeroObj : TheOneObj);
}
if ( method[3] == 'A' )
{
// Zoomed is Maximized.
return (IsZoomed(hDlg) ? TheTrueObj : TheFalseObj);
}
// Iconic is Minimized.
return (IsIconic(hDlg) ? TheTrueObj : TheFalseObj);
}
/** PlainBaseDialog::setTabstop()
* PlainBaseDialog::setGroup()
*/
RexxMethod4(RexxObjectPtr, pbdlg_setTabGroup, RexxObjectPtr, rxID, OPTIONAL_logical_t, addStyle, NAME, method, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( pcpbd->hDlg == NULL )
{
noWindowsDialogException(context, pcpbd->rexxSelf);
return TheFalseObj;
}
int32_t id;
if ( ! oodSafeResolveID(&id, context, pcpbd->rexxSelf, rxID, -1, 1, true) )
{
return TheNegativeOneObj;
}
if ( argumentOmitted(2) )
{
addStyle = TRUE;
}
HWND hCtrl = GetDlgItem(pcpbd->hDlg, id);
uint32_t style = GetWindowLong(hCtrl, GWL_STYLE);
if ( method[3] == 'T' )
{
style = (addStyle ? (style | WS_TABSTOP) : (style & ~WS_TABSTOP));
}
else
{
style = (addStyle ? (style | WS_GROUP) : (style & ~WS_GROUP));
}
return setWindowStyle(context, hCtrl, style);
}
/** PlainBaseDialog::isDialogActive()
*
* Tests if the Windows dialog is still active.
*
* @return True if the underlying Windows dialog is active, otherwise false.
*/
RexxMethod1(RexxObjectPtr, pbdlg_isDialogActive, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = getPBDCSelf(context, pCSelf);
if ( pcpbd != NULL )
{
if ( ! pcpbd->isFinished && pcpbd->hDlg != NULL && pcpbd->isActive && IsWindow(pcpbd->hDlg) )
{
return TheTrueObj;
}
}
return TheFalseObj;
}
/** PlainBaseDialog::connect<ControlName>()
*
* Connects a windows dialog control with a 'data' attribute of the Rexx dialog
* object. The attribute is added to the Rexx object and an entry is made in
* the data table using the control's resource ID.
*
* @param rxID The resource ID of the control, can be numeric or
* symbolic.
* @param attributeName [optional] The name of the attribute to be added.
* If omitted, the addAttribute() method will design a
* name from the information available.
* @param opts [optional] Not used, but must be present for
* backwards compatibility. Was only used in
* connectComboBox() to distinguish between types of
* combo boxes. That functionality has been moved to
* the native code.
*
* @remarks The control type is determined by the invoking Rexx method name.
*/
RexxMethod6(RexxObjectPtr, pbdlg_connect_ControName, RexxObjectPtr, rxID, OPTIONAL_RexxObjectPtr, attributeName,
OPTIONAL_CSTRING, opts, NAME, msgName, OSELF, self, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = getPBDCSelf(context, pCSelf);
if ( pcpbd == NULL )
{
return NULLOBJECT;
}
oodControl_t type = oodName2controlType(msgName + 7);
if ( type == winNotAControl )
{
return TheNegativeOneObj;
}
// result will be the resolved resource ID, which may be -1 on error.
RexxObjectPtr result = context->ForwardMessage(NULLOBJECT, "ADDATTRIBUTE", NULLOBJECT, NULLOBJECT);
// If the user is using the global constDir and has mismatched case in the
// use of symbolic IDs, we could have a condition raised.
if ( checkForCondition(context->threadContext, true) )
{
return TheNegativeOneObj;
}
int id;
if ( ! context->Int32(result, &id) || id == -1 )
{
return TheNegativeOneObj;
}
uint32_t category = getCategoryNumber(context, self);
return ( addToDataTable(context->threadContext, pcpbd, id, type, category) == OOD_NO_ERROR ? TheZeroObj : TheOneObj );
}
RexxMethod2(uint32_t, pbdlg_setDlgDataFromStem_pvt, RexxStemObject, internDlgData, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = getPBDCSelf(context, pCSelf);
if ( pcpbd == NULL )
{
return 0;
}
if ( pcpbd->hDlg == NULL )
{
noWindowsDialogException(context, pcpbd->rexxSelf);
return 0;
}
return setDlgDataFromStem(context, pcpbd, internDlgData);
}
RexxMethod2(uint32_t, pbdlg_putDlgDataInStem_pvt, RexxStemObject, internDlgData, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = getPBDCSelf(context, pCSelf);
if ( pcpbd == NULL )
{
return 0;
}
if ( pcpbd->hDlg == NULL )
{
noWindowsDialogException(context, pcpbd->rexxSelf);
return 0;
}
return putDlgDataInStem(context, pcpbd, internDlgData);
}
/** PlainBaseDialog::getControlData()
*
* Gets the 'data' from a single dialog control.
*
* The original ooDialog implementation seemed to use the abstraction that the
* state of a dialog control was its 'data' and this abstraction influenced the
* naming of many of the instance methods. I.e., getData() setData().
*
* The method getControlData() is, in the Rexx code, a general purpose method
* that replaces getValue() after 4.0.0. getValue() forwards to
* getControlData(). The old doc:
*
* "The getValue method gets the value of a dialog item, regardless of its
* type. The item must have been connected before."
*
* @param rxID The resource ID of control.
*
* @return The 'data' value of the dialog control. This of course varies
* depending on the type of the dialog control.
*
* @remarks The control type is determined by the invoking method name. When
* the general purpose GETCONTROLDATA + 3 name is passed to
* oodName2controlType() it won't resolve and winUnknown will be
* returned. This is the value that signals getControlData() to do a
* data table look up by resource ID.
*/
RexxMethod3(RexxObjectPtr, pbdlg_getControlData, RexxObjectPtr, rxID, NAME, msgName, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( pcpbd->hDlg == NULL )
{
noWindowsDialogException(context, pcpbd->rexxSelf);
return TheNegativeOneObj;
}
int32_t id;
if ( ! oodSafeResolveID(&id, context, pcpbd->rexxSelf, rxID, -1, 1, true) )
{
return TheNegativeOneObj;
}
oodControl_t ctrlType = oodName2controlType(msgName + 3);
return getControlData(context, pcpbd, id, pcpbd->hDlg, ctrlType);
}
/** PlainBaseDialog::setControlData()
*
* Sets the 'data' for a single dialog control.
*
* The original ooDialog implementation seemed to use the abstraction that the
* state of a dialog control was its 'data' and this abstraction influenced the
* naming of many of the instance methods. I.e., getData() setData().
*
* The method setControlData() is, in the Rexx code, a general purpose method
* that replaces setValue() after 4.0.0. setValue() forwards to
* setControlData(). The old doc:
*
* "The setValue() method sets the value of a dialog item. You do not have to
* know what kind of item it is. The dialog item must have been connected
* before."
*
* @param rxID The resource ID of control.
* @param data The 'data' to set the control with.
*
* @return 0 for success, 1 for error, -1 for bad resource ID.
*
* @remarks The control type is determined by the invoking method name. When
* the general purpose setControlDate name (msgName + 3 is
* ControlData) is passed to oodName2controlType() it won't resolve
* and winUnknown will be returned. This is the value that signals
* setControlData() to do a data table look up by resource ID.
*/
RexxMethod4(int32_t, pbdlg_setControlData, RexxObjectPtr, rxID, CSTRING, data, NAME, msgName, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( pcpbd->hDlg == NULL )
{
noWindowsDialogException(context, pcpbd->rexxSelf);
return -1;
}
int32_t id;
if ( ! oodSafeResolveID(&id, context, pcpbd->rexxSelf, rxID, -1, 1, true) )
{
return -1;
}
oodControl_t ctrlType = oodName2controlType(msgName + 3);
return setControlData(context, pcpbd, id, data, pcpbd->hDlg, ctrlType);
}
/** PlainBaseDialog::stopIt()
*
*
* @remarks Normally, this method is inovked to stop a running dialog, and
* internally clean up the CSelf struct. However, it is sometimes
* invoked when a dialog fails to be created. The old ooDialog code
* checked if hDlg was null and if so didn't call stopDialog(). That
* was okay, sort of, the dialog admin block got cleaned up in the
* uninit() method. stopDialog() is now called even if hDlg == null
* to clean up the CSelf struct here instead of in uninit().
*
* @remarks PlainBaseDialog::leaving() does nothing. It is intended to be
* over-ridden by the Rexx programer to do whatever she would want.
* It is invoked here, right before stopDialog(). However, it is
* only invoked if the underlying dialog was created.
*/
RexxMethod2(int32_t, pbdlg_stopIt, OPTIONAL_RexxObjectPtr, caller, CSELF, pCSelf)
{
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
RexxObjectPtr finished = context->GetObjectVariable("FINISHED");
pcpbd->abnormalHalt = (finished == TheFalseObj ? true : false);
if ( pcpbd->hDlg != NULL && ! pcpbd->abnormalHalt )
{
context->SendMessage0(pcpbd->rexxSelf, "LEAVING");
}
int32_t result = stopDialog(pcpbd, context->threadContext);
if ( argumentOmitted(1) )
{
context->SendMessage0(pcpbd->rexxSelf, "FINALSTOPIT");
}
else
{
context->SendMessage1(pcpbd->rexxSelf, "FINALSTOPIT", caller);
}
return result;
}
/** PlainBaseDialog::new<DialogControl>()
*
* Instantiates a dialog control object for the specified Windows control. All
* dialog control objects are instantiated through one of the PlainBaseDialog
* new<DialogControl>() methods. In turn each of those methods filter through
* this function. newEdit(), newPushButton(), newListView(), etc..
*
* @param rxID The resource ID of the control.
*
* @param categoryPageID [optional] If the dialog is a category dialog, this
* indicates which page of the dialog the control is on.
*
* @returns The properly instantiated dialog control object on success, or the
* nil object on failure.
*
* @remarks Either returns the control object asked for, or .nil.
*
* The first time a Rexx object is instantiated for a specific Windows
* control, the Rexx object is stored in the window words of the
* control. Before a Rexx object is instantiated, the window words are
* checked to see if there is already an instantiated object. If so,
* that object is returned rather than instantiating a new object.
*
* It goes without saying that the intent here is to exactly preserve
* pre 4.0.0 behavior. With category dialogs, it is somewhat hard to
* be sure the behavior is preserved. Prior to 4.0.0, getControl(id,
* catPage) would assign the parent dialog as the oDlg (owner dialog)
* of dialog controls on any of the category pages. This seems
* technically wrong, but the same thing is done here. Need to
* investigate whether this ever makes a difference? CategoryDialog is
* deprecated and no further work will be donwe with it.
*/
RexxMethod5(RexxObjectPtr, pbdlg_newControl, RexxObjectPtr, rxID, OPTIONAL_uint32_t, categoryPageID,
NAME, msgName, OSELF, self, CSELF, pCSelf)
{
RexxMethodContext *c = context;
RexxObjectPtr result = TheNilObj;
bool isCategoryDlg = false;
HWND hDlg = ((pCPlainBaseDialog)pCSelf)->hDlg;
// If the underlying dialog is not created yet, just return.
if ( hDlg == NULL )
{
return result;
}
if ( c->IsOfType(self, "CATEGORYDIALOG") )
{
isCategoryDlg = true;
// If the category page is not omitted and equal to 0, then we already
// have the dialog handle. It is the handle of the parent Rexx dialog.
// Otherwise, we need to resolve the handle, which is the handle of one
// of the child dialogs used for the pages of the parent dialog.
//
// In addition, the original Rexx code would check if the category page
// ID was greater than 9000 and if so treat things as though the control
// were part of the parent dialog, not one of the child dialog's
// controls. That is done here. The CategoryDialog is deprecated, and
// this is just maintained for backwards compatibility. The intent is
// to not fix any bugs in deprecated classes or methods.
if ( ! (argumentExists(2) && (categoryPageID == 0 || categoryPageID > 9000)) )
{
if ( ! getCategoryHDlg(context, self, &categoryPageID, &hDlg, 2) )
{
context->ClearCondition();
goto out;
}
}
}
int32_t id;
if ( ! oodSafeResolveID(&id, c, self, rxID, -1, 1, true) )
{
goto out;
}
HWND hControl = GetDlgItem(hDlg, (int)id);
if ( isCategoryDlg && hControl == NULL )
{
// It could be that this is a control in the parent dialog of the
// category dialog. So, try once more. If this still fails, then we
// give up.
hDlg = ((pCPlainBaseDialog)pCSelf)->hDlg;
hControl = GetDlgItem(((pCPlainBaseDialog)pCSelf)->hDlg, (int)id);
}
if ( hControl == NULL )
{
goto out;
}
// Check that the underlying Windows control is the control type requested
// by the programmer. Return .nil if this is not true.
oodControl_t controlType = oodName2controlType(msgName + 3);
if ( ! isControlMatch(hControl, controlType) )
{
goto out;
}
RexxClassObject controlCls = oodClass4controlType(context, controlType);
if ( controlCls == NULLOBJECT )
{
goto out;
}
result = createRexxControl(context->threadContext, hControl, hDlg, id, controlType, self, controlCls, isCategoryDlg, true);
out:
return result;
}
/** PlainBaseDialog::getNewControl()
*
* Returns an instantiated dialog control object from the specified resoure ID.
*
* @param Dialog control resource ID, may be symbolic or numeric.
*
* @return The Rexx dialog control object, or .nil on error. However, a
* condition is raised for *all* errors.
*
* @remarks The method is written for use by the ooDialog framework in certain
* special circumstances. Currently the only special circumstance is
* to provide backward compatibility for deprecated methods. It may,
* or may not, be documented for the user. Not decided yet.
*/
RexxMethod3(RexxObjectPtr, pbdlg_getNewControl, RexxObjectPtr, rxID, OSELF, self, CSELF, pCSelf)
{
RexxMethodContext *c = context;
RexxObjectPtr result = TheNilObj;
HWND hDlg = getPBDWindow(context, pCSelf);
if ( hDlg == NULL )
{
goto out;
}
int32_t id = oodResolveSymbolicID(context, self, rxID, -1, 1, true);
if ( id == OOD_ID_EXCEPTION )
{
goto out;
}
HWND hControl = GetDlgItem(hDlg, (int)id);
if ( hControl == NULL )
{
noSuchControlException(context, id, self, 1);
goto out;
}
oodControl_t controlType = control2controlType(hControl);
if ( controlType == winUnknown )
{
controlNotSupportedException(context, rxID, self, 1, controlWindow2rexxString(context, hControl));
goto out;
}
RexxClassObject controlCls = oodClass4controlType(controlType, context);
if ( controlCls == NULLOBJECT )
{
goto out;
}
result = createRexxControl(context->threadContext, hControl, hDlg, id, controlType, self, controlCls, false, true);
out:
return result;
}
RexxMethod2(RexxObjectPtr, pbdlg_putControl, RexxObjectPtr, control, OSELF, self)
{
RexxObjectPtr bag = context->GetObjectVariable(CONTROLBAG_ATTRIBUTE);
if ( bag == NULLOBJECT )
{
bag = rxNewBag(context);
context->SetObjectVariable(CONTROLBAG_ATTRIBUTE, bag);
}
if ( bag != NULLOBJECT )
{
context->SendMessage2(bag, "PUT", control, control);
}
return TheNilObj;
}
void dumpMsgTable(MESSAGETABLEENTRY *msgTable, size_t count, CSTRING title)
{
printf(" %s\n", title);
printf("msg filter wParam filter lParam filter tag method\n");
printf("=====================================================================================================\n");
if ( msgTable == NULL )
{
printf(" table is empty\n\n");
return;
}
for ( size_t i = 0; i < count; i++)
{
printf("0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x %s\n",
msgTable[i].msg, msgTable[i].msgFilter,
msgTable[i].wParam, msgTable[i].wpFilter,
msgTable[i].lParam, msgTable[i].lpFilter,
msgTable[i].tag, msgTable[i].rexxMethod);
}
printf("\n");
}
RexxMethod2(RexxObjectPtr, pbdlg_dumpMessageTable, OPTIONAL_CSTRING, table, CSELF, pCSelf)
{
RexxMethodContext *c = context;
pCPlainBaseDialog pcpbd = (pCPlainBaseDialog)pCSelf;
if ( argumentOmitted(1) )
{
dumpMsgTable(pcpbd->enCSelf->notifyMsgs, pcpbd->enCSelf->nmNextIndex, "Notify Message Table:");
dumpMsgTable(pcpbd->enCSelf->commandMsgs, pcpbd->enCSelf->cmNextIndex, "Command Message Table:");
dumpMsgTable(pcpbd->enCSelf->miscMsgs, pcpbd->enCSelf->mmNextIndex, "Miscellaneous Message Table:");
}
else if( !strcmpi(table, "notify") )
{
dumpMsgTable(pcpbd->enCSelf->notifyMsgs, pcpbd->enCSelf->nmNextIndex, "Notify Message Table:");
}
else if( !strcmpi(table, "command") )
{
dumpMsgTable(pcpbd->enCSelf->notifyMsgs, pcpbd->enCSelf->nmNextIndex, "Command Message Table:");
}
else if( !strcmpi(table, "misc") )
{
dumpMsgTable(pcpbd->enCSelf->notifyMsgs, pcpbd->enCSelf->mmNextIndex, "Miscellaneous Message Table:");
}
else
{
printf("Wrong table option: notify, command, misc, or omit the argument\n");
}
return NULLOBJECT;
}