[60e7f8]: win32 / SciTEWin.cxx Maximize Restore History

Download this file

SciTEWin.cxx    3937 lines (3404 with data), 112.6 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
// SciTE - Scintilla based Text Editor
/** @file SciTEWin.cxx
** Main code for the Windows version of the editor.
**/
// Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#include <time.h>
#include "SciTEWin.h"
#if defined(DTBG_CLIPRECT) && !defined(DISABLE_THEMES)
#define THEME_AVAILABLE
#endif
// Since Vsstyle.h and Vssym32.h are not available from all compilers just define the used symbols
#define CBS_NORMAL 1
#define CBS_HOT 2
#define CBS_PUSHED 3
#define WP_SMALLCLOSEBUTTON 19
#define TS_NORMAL 1
#define TS_HOT 2
#define TS_PRESSED 3
#define TS_CHECKED 5
#define TS_HOTCHECKED 6
#define TP_BUTTON 1
#ifndef DFCS_HOT
#define DFCS_HOT 1000
#endif
#ifndef WM_UPDATEUISTATE
#define WM_UPDATEUISTATE 0x0128
#endif
#ifndef UISF_HIDEACCEL
#define UISF_HIDEACCEL 2
#define UISF_HIDEFOCUS 1
#define UIS_CLEAR 2
#define UIS_SET 1
#endif
#ifndef NO_EXTENSIONS
#include "MultiplexExtension.h"
#ifndef NO_FILER
#include "DirectorExtension.h"
#endif
#ifndef NO_LUA
#include "LuaExtension.h"
#endif
#endif
#ifdef STATIC_BUILD
const GUI::gui_char appName[] = GUI_TEXT("Sc1");
#else
const GUI::gui_char appName[] = GUI_TEXT("SciTE");
#endif
static GUI::gui_string GetErrorMessage(DWORD nRet) {
LPWSTR lpMsgBuf = NULL;
if (::FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
nRet,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
reinterpret_cast<LPWSTR>(&lpMsgBuf),
0,
NULL
) != 0) {
GUI::gui_string s= lpMsgBuf;
::LocalFree(lpMsgBuf);
return s;
} else {
return TEXT("");
}
}
long SciTEKeys::ParseKeyCode(const char *mnemonic) {
int modsInKey = 0;
int keyval = -1;
if (mnemonic && *mnemonic) {
SString sKey = mnemonic;
if (sKey.contains("Ctrl+")) {
modsInKey |= SCMOD_CTRL;
sKey.remove("Ctrl+");
}
if (sKey.contains("Shift+")) {
modsInKey |= SCMOD_SHIFT;
sKey.remove("Shift+");
}
if (sKey.contains("Alt+")) {
modsInKey |= SCMOD_ALT;
sKey.remove("Alt+");
}
if (sKey.length() == 1) {
keyval = VkKeyScan(sKey[0]) & 0xFF;
} else if (sKey.length() > 1) {
if ((sKey[0] == 'F') && (isdigit(sKey[1]))) {
sKey.remove("F");
int fkeyNum = sKey.value();
if (fkeyNum >= 1 && fkeyNum <= 12)
keyval = fkeyNum - 1 + VK_F1;
} else if ((sKey[0] == 'V') && (isdigit(sKey[1]))) {
sKey.remove("V");
int vkey = sKey.value();
if (vkey > 0 && vkey <= 0x7FFF)
keyval = vkey;
} else if (sKey.search("Keypad") == 0) {
sKey.remove("Keypad");
if (isdigit(sKey[0])) {
int keyNum = sKey.value();
if (keyNum >= 0 && keyNum <= 9)
keyval = keyNum + VK_NUMPAD0;
} else if (sKey == "Plus") {
keyval = VK_ADD;
} else if (sKey == "Minus") {
keyval = VK_SUBTRACT;
} else if (sKey == "Decimal") {
keyval = VK_DECIMAL;
} else if (sKey == "Divide") {
keyval = VK_DIVIDE;
} else if (sKey == "Multiply") {
keyval = VK_MULTIPLY;
}
} else if (sKey == "Left") {
keyval = VK_LEFT;
} else if (sKey == "Right") {
keyval = VK_RIGHT;
} else if (sKey == "Up") {
keyval = VK_UP;
} else if (sKey == "Down") {
keyval = VK_DOWN;
} else if (sKey == "Insert") {
keyval = VK_INSERT;
} else if (sKey == "End") {
keyval = VK_END;
} else if (sKey == "Home") {
keyval = VK_HOME;
} else if (sKey == "Enter") {
keyval = VK_RETURN;
} else if (sKey == "Space") {
keyval = VK_SPACE;
} else if (sKey == "Tab") {
keyval = VK_TAB;
} else if (sKey == "Escape") {
keyval = VK_ESCAPE;
} else if (sKey == "Delete") {
keyval = VK_DELETE;
} else if (sKey == "PageUp") {
keyval = VK_PRIOR;
} else if (sKey == "PageDown") {
keyval = VK_NEXT;
} else if (sKey == "Win") {
keyval = VK_LWIN;
} else if (sKey == "Menu") {
keyval = VK_APPS;
}
}
}
return (keyval > 0) ? (keyval | (modsInKey<<16)) : 0;
}
bool SciTEKeys::MatchKeyCode(long parsedKeyCode, int keyval, int modifiers) {
return parsedKeyCode && !(0xFFFF0000 & (keyval | modifiers)) && (parsedKeyCode == (keyval | (modifiers<<16)));
}
HINSTANCE SciTEWin::hInstance = 0;
const TCHAR *SciTEWin::className = NULL;
const TCHAR *SciTEWin::classNameInternal = NULL;
SciTEWin *SciTEWin::app = NULL;
SciTEWin::SciTEWin(Extension *ext) : SciTEBase(ext) {
app = this;
contents.SetSciTE(this);
contents.SetLocalizer(&localiser);
backgroundStrip.SetLocalizer(&localiser);
searchStrip.SetLocalizer(&localiser);
searchStrip.SetSearcher(this);
findStrip.SetLocalizer(&localiser);
findStrip.SetSearcher(this);
replaceStrip.SetLocalizer(&localiser);
replaceStrip.SetSearcher(this);
cmdShow = 0;
heightBar = 7;
fontTabs = 0;
wFocus = 0;
memset(&winPlace, 0, sizeof(winPlace));
winPlace.length = 0;
memset(&rcWorkArea, 0, sizeof(rcWorkArea));
openWhat[0] = '\0';
tooltipText[0] = '\0';
modalParameters = false;
filterDefault = 1;
staticBuild = false;
menuSource = 0;
hWriteSubProcess = NULL;
subProcessGroupId = 0;
// Read properties resource into propsEmbed
// The embedded properties file is to allow distributions to be sure
// that they have a sensible default configuration even if the properties
// files are missing. Also allows a one file distribution of Sc1.EXE.
propsEmbed.Clear();
// System type properties are also stored in the embedded properties.
propsEmbed.Set("PLAT_WIN", "1");
propsEmbed.Set("PLAT_WINNT", "1");
HRSRC handProps = ::FindResource(hInstance, TEXT("Embedded"), TEXT("Properties"));
if (handProps) {
DWORD size = ::SizeofResource(hInstance, handProps);
HGLOBAL hmem = ::LoadResource(hInstance, handProps);
if (hmem) {
const void *pv = ::LockResource(hmem);
if (pv) {
propsEmbed.ReadFromMemory(
reinterpret_cast<const char *>(pv), size, FilePath(), filter);
}
}
::FreeResource(handProps);
}
pathAbbreviations = GetAbbrevPropertiesFileName();
ReadGlobalPropFile();
/// Need to copy properties to variables before setting up window
SetPropertiesInitial();
ReadAbbrevPropFile();
hDevMode = 0;
hDevNames = 0;
::ZeroMemory(&pagesetupMargin, sizeof(pagesetupMargin));
hHH = 0;
hMM = 0;
uniqueInstance.Init(this);
hAccTable = ::LoadAccelerators(hInstance, TEXT("ACCELS")); // md
cmdWorker.pSciTE = this;
}
SciTEWin::~SciTEWin() {
if (hDevMode)
::GlobalFree(hDevMode);
if (hDevNames)
::GlobalFree(hDevNames);
if (hHH)
::FreeLibrary(hHH);
if (hMM)
::FreeLibrary(hMM);
if (fontTabs)
::DeleteObject(fontTabs);
}
uptr_t SciTEWin::GetInstance() {
return reinterpret_cast<uptr_t>(hInstance);
}
void SciTEWin::Register(HINSTANCE hInstance_) {
const TCHAR resourceName[] = TEXT("SciTE");
hInstance = hInstance_;
WNDCLASS wndclass;
// Register the frame window
className = TEXT("SciTEWindow");
wndclass.style = 0;
wndclass.lpfnWndProc = SciTEWin::TWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = sizeof(SciTEWin*);
wndclass.hInstance = hInstance;
wndclass.hIcon = ::LoadIcon(hInstance, resourceName);
wndclass.hCursor = NULL;
wndclass.hbrBackground = NULL;
wndclass.lpszMenuName = resourceName;
wndclass.lpszClassName = className;
if (!::RegisterClass(&wndclass))
exit(FALSE);
// Register the window that holds the two Scintilla edit windows and the separator
classNameInternal = TEXT("SciTEWindowContent");
wndclass.lpfnWndProc = BaseWin::StWndProc;
wndclass.lpszMenuName = 0;
wndclass.lpszClassName = classNameInternal;
if (!::RegisterClass(&wndclass))
exit(FALSE);
}
static int CodePageFromName(const SString &encodingName) {
struct Encoding {
const char *name;
int codePage;
} knownEncodings[] = {
{ "ascii", CP_UTF8 },
{ "utf-8", CP_UTF8 },
{ "latin1", 1252 },
{ "latin2", 28592 },
{ "big5", 950 },
{ "gbk", 936 },
{ "shift_jis", 932 },
{ "euc-kr", 949 },
{ "cyrillic", 1251 },
{ "iso-8859-5", 28595 },
{ "iso8859-11", 874 },
{ "1250", 1250 },
{ "windows-1251", 1251 },
{ 0, 0 },
};
for (Encoding *enc=knownEncodings; enc->name; enc++) {
if (encodingName == enc->name) {
return enc->codePage;
}
}
return CP_UTF8;
}
// Convert to UTF-8
static std::string ConvertEncoding(const char *original, int codePage) {
if (codePage == CP_UTF8) {
return original;
} else {
int cchWide = ::MultiByteToWideChar(codePage, 0, original, -1, NULL, 0);
wchar_t *pszWide = new wchar_t[cchWide + 1];
::MultiByteToWideChar(codePage, 0, original, -1, pszWide, cchWide + 1);
GUI::gui_string sWide(pszWide);
std::string ret = GUI::UTF8FromString(sWide);
delete []pszWide;
return ret;
}
}
void SciTEWin::ReadLocalization() {
SciTEBase::ReadLocalization();
SString encoding = localiser.Get("translation.encoding");
encoding.lowercase();
if (encoding.length()) {
int codePage = CodePageFromName(encoding);
const char *key = NULL;
const char *val = NULL;
// Get encoding
bool more = localiser.GetFirst(key, val);
while (more) {
std::string converted = ConvertEncoding(val, codePage);
if (converted != "") {
localiser.Set(key, converted.c_str());
}
more = localiser.GetNext(key, val);
}
}
}
void SciTEWin::GetWindowPosition(int *left, int *top, int *width, int *height, int *maximize) {
winPlace.length = sizeof(winPlace);
::GetWindowPlacement(MainHWND(), &winPlace);
*left = winPlace.rcNormalPosition.left;
*top = winPlace.rcNormalPosition.top;
*width = winPlace.rcNormalPosition.right - winPlace.rcNormalPosition.left;
*height = winPlace.rcNormalPosition.bottom - winPlace.rcNormalPosition.top;
*maximize = (winPlace.showCmd == SW_MAXIMIZE) ? 1 : 0;
}
// Allow UTF-8 file names and command lines to be used in calls to io.open and io.popen in Lua scripts.
// The scite_lua_win.h header redirects fopen and _popen to these functions.
extern "C" {
FILE *scite_lua_fopen(const char *filename, const char *mode) {
GUI::gui_string sFilename = GUI::StringFromUTF8(filename);
GUI::gui_string sMode = GUI::StringFromUTF8(mode);
FILE *f = _wfopen(sFilename.c_str(), sMode.c_str());
if (f == NULL)
// Fallback on narrow string in case already in CP_ACP
f = fopen(filename, mode);
return f;
}
FILE *scite_lua_popen(const char *filename, const char *mode) {
GUI::gui_string sFilename = GUI::StringFromUTF8(filename);
GUI::gui_string sMode = GUI::StringFromUTF8(mode);
FILE *f = _wpopen(sFilename.c_str(), sMode.c_str());
if (f == NULL)
// Fallback on narrow string in case already in CP_ACP
f = _popen(filename, mode);
return f;
}
}
void SciTEWin::ReadProperties() {
SciTEBase::ReadProperties();
}
static FilePath GetSciTEPath(FilePath home) {
if (home.IsSet()) {
return FilePath(home);
} else {
GUI::gui_char path[MAX_PATH];
if (::GetModuleFileNameW(0, path, ELEMENTS(path)) == 0)
return FilePath();
// Remove the SciTE.exe
GUI::gui_char *lastSlash = wcsrchr(path, pathSepChar);
if (lastSlash)
*lastSlash = '\0';
return FilePath(path);
}
}
FilePath SciTEWin::GetDefaultDirectory() {
GUI::gui_char *home = _wgetenv(GUI_TEXT("SciTE_HOME"));
return GetSciTEPath(home);
}
FilePath SciTEWin::GetSciteDefaultHome() {
GUI::gui_char *home = _wgetenv(GUI_TEXT("SciTE_HOME"));
return GetSciTEPath(home);
}
FilePath SciTEWin::GetSciteUserHome() {
GUI::gui_char *home = _wgetenv(GUI_TEXT("SciTE_HOME"));
if (!home)
home = _wgetenv(GUI_TEXT("USERPROFILE"));
return GetSciTEPath(home);
}
// Help command lines contain topic!path
void SciTEWin::ExecuteOtherHelp(const char *cmd) {
GUI::gui_string s = GUI::StringFromUTF8(cmd);
size_t pos = s.find_first_of('!');
if (pos != GUI::gui_string::npos) {
GUI::gui_string topic = s.substr(0, pos);
GUI::gui_string path = s.substr(pos+1);
::WinHelpW(MainHWND(),
path.c_str(),
HELP_KEY,
reinterpret_cast<ULONG_PTR>(topic.c_str()));
}
}
// HH_AKLINK not in mingw headers
struct XHH_AKLINK {
long cbStruct;
BOOL fReserved;
const wchar_t *pszKeywords;
wchar_t *pszUrl;
wchar_t *pszMsgText;
wchar_t *pszMsgTitle;
wchar_t *pszWindow;
BOOL fIndexOnFail;
};
// Help command lines contain topic!path
void SciTEWin::ExecuteHelp(const char *cmd) {
if (!hHH)
hHH = ::LoadLibrary(TEXT("HHCTRL.OCX"));
if (hHH) {
GUI::gui_string s = GUI::StringFromUTF8(cmd);
size_t pos = s.find_first_of('!');
if (pos != GUI::gui_string::npos) {
GUI::gui_string topic = s.substr(0, pos);
GUI::gui_string path = s.substr(pos + 1);
typedef HWND (WINAPI *HelpFn) (HWND, const wchar_t *, UINT, DWORD_PTR);
HelpFn fnHHW = (HelpFn)::GetProcAddress(hHH, "HtmlHelpW");
if (fnHHW) {
XHH_AKLINK ak;
ak.cbStruct = sizeof(ak);
ak.fReserved = FALSE;
ak.pszKeywords = topic.c_str();
ak.pszUrl = NULL;
ak.pszMsgText = NULL;
ak.pszMsgTitle = NULL;
ak.pszWindow = NULL;
ak.fIndexOnFail = TRUE;
fnHHW(NULL,
path.c_str(),
0x000d, // HH_KEYWORD_LOOKUP
reinterpret_cast<DWORD_PTR>(&ak)
);
}
}
}
}
void SciTEWin::CopyAsRTF() {
Sci_CharacterRange cr = GetSelection();
char *fileNameTemp = _tempnam(NULL, "scite-tmp-");
if (fileNameTemp) {
SaveToRTF(GUI::StringFromUTF8(fileNameTemp), cr.cpMin, cr.cpMax);
FILE *fp = fopen(fileNameTemp, "rb");
if (fp) {
fseek(fp, 0, SEEK_END);
int len = ftell(fp);
fseek(fp, 0, SEEK_SET);
HGLOBAL hand = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, len + 1);
if (hand) {
::OpenClipboard(MainHWND());
::EmptyClipboard();
char *ptr = static_cast<char *>(::GlobalLock(hand));
if (ptr) {
fread(ptr, 1, len, fp);
ptr[len] = '\0';
}
::GlobalUnlock(hand);
::SetClipboardData(::RegisterClipboardFormat(CF_RTF), hand);
::CloseClipboard();
}
fclose(fp);
}
unlink(fileNameTemp);
free(fileNameTemp);
}
}
void SciTEWin::CopyPath() {
if (filePath.IsUntitled())
return;
GUI::gui_string clipText(filePath.AsInternal());
size_t blobSize = sizeof(GUI::gui_char)*(clipText.length()+1);
HGLOBAL hand = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, blobSize);
if (hand && ::OpenClipboard(MainHWND())) {
::EmptyClipboard();
GUI::gui_char *ptr = static_cast<GUI::gui_char*>(::GlobalLock(hand));
if (ptr)
memcpy(ptr, clipText.c_str(), blobSize);
::GlobalUnlock(hand);
::SetClipboardData(CF_UNICODETEXT, hand);
::CloseClipboard();
}
}
void SciTEWin::FullScreenToggle() {
HWND wTaskBar = FindWindow(TEXT("Shell_TrayWnd"), TEXT(""));
HWND wStartButton = FindWindow(TEXT("Button"), NULL);
fullScreen = !fullScreen;
if (fullScreen) {
::SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0);
::SystemParametersInfo(SPI_SETWORKAREA, 0, 0, SPIF_SENDCHANGE);
if (wStartButton != NULL)
::ShowWindow(wStartButton, SW_HIDE);
::ShowWindow(wTaskBar, SW_HIDE);
winPlace.length = sizeof(winPlace);
::GetWindowPlacement(MainHWND(), &winPlace);
int topStuff = ::GetSystemMetrics(SM_CYSIZEFRAME) + ::GetSystemMetrics(SM_CYCAPTION);
if (props.GetInt("full.screen.hides.menu"))
topStuff += ::GetSystemMetrics(SM_CYMENU);
::SetWindowLongPtr(HwndOf(wContent),
GWL_EXSTYLE, 0);
::SetWindowPos(MainHWND(), HWND_TOP,
-::GetSystemMetrics(SM_CXSIZEFRAME),
-topStuff,
::GetSystemMetrics(SM_CXSCREEN) + 2 * ::GetSystemMetrics(SM_CXSIZEFRAME),
::GetSystemMetrics(SM_CYSCREEN) + topStuff + ::GetSystemMetrics(SM_CYSIZEFRAME),
0);
} else {
::ShowWindow(wTaskBar, SW_SHOW);
if (wStartButton != NULL)
::ShowWindow(wStartButton, SW_SHOW);
::SetWindowLongPtr(HwndOf(wContent),
GWL_EXSTYLE, WS_EX_CLIENTEDGE);
if (winPlace.length) {
::SystemParametersInfo(SPI_SETWORKAREA, 0, &rcWorkArea, 0);
if (winPlace.showCmd == SW_SHOWMAXIMIZED) {
::ShowWindow(MainHWND(), SW_RESTORE);
::ShowWindow(MainHWND(), SW_SHOWMAXIMIZED);
} else {
::SetWindowPlacement(MainHWND(), &winPlace);
}
}
}
::SetForegroundWindow(MainHWND());
CheckMenus();
}
HWND SciTEWin::MainHWND() {
return HwndOf(wSciTE);
}
void SciTEWin::Command(WPARAM wParam, LPARAM lParam) {
int cmdID = ControlIDOfWParam(wParam);
if (wParam & 0x10000) {
// From accelerator -> goes to focused pane.
menuSource = 0;
}
if (reinterpret_cast<HWND>(lParam) == wToolBar.GetID()) {
// From toolbar -> goes to focused pane.
menuSource = 0;
}
if (!menuSource) {
if (!wEditor.HasFocus() && !wOutput.HasFocus()) {
HWND wWithFocus = ::GetFocus();
enum { capSize = 2000 };
GUI::gui_char className[capSize];
::GetClassName(wWithFocus, className, capSize);
if (wcscmp(className, TEXT("Edit")) == 0) {
switch (cmdID) {
case IDM_UNDO:
::SendMessage(wWithFocus, EM_UNDO, 0, 0);
return;
case IDM_CUT:
::SendMessage(wWithFocus, WM_CUT, 0, 0);
return;
case IDM_COPY:
::SendMessage(wWithFocus, WM_COPY, 0, 0);
return;
}
}
}
}
switch (cmdID) {
case IDM_SRCWIN:
case IDM_RUNWIN:
if (HIWORD(wParam) == SCEN_SETFOCUS) {
wFocus = reinterpret_cast<HWND>(lParam);
CheckMenus();
}
if (HIWORD(wParam) == SCEN_KILLFOCUS) {
CheckMenus();
}
break;
case IDM_ACTIVATE:
Activate(lParam);
break;
case IDM_FINISHEDEXECUTE: {
jobQueue.SetExecuting(false);
if (needReadProperties)
ReadProperties();
CheckMenus();
jobQueue.ClearJobs();
CheckReload();
}
break;
case IDM_ONTOP:
topMost = (topMost ? false : true);
::SetWindowPos(MainHWND(), (topMost ? HWND_TOPMOST : HWND_NOTOPMOST ), 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE);
CheckAMenuItem(IDM_ONTOP, topMost);
break;
case IDM_OPENFILESHERE:
uniqueInstance.ToggleOpenFilesHere();
break;
case IDM_FULLSCREEN:
FullScreenToggle();
break;
case IDC_TABCLOSE:
CloseTab((int)lParam);
break;
case IDC_SHIFTTAB:
ShiftTab(LOWORD(lParam), HIWORD(lParam));
break;
default:
SciTEBase::MenuCommand(cmdID, menuSource);
}
}
// from ScintillaWin.cxx
static UINT CodePageFromCharSet(DWORD characterSet, UINT documentCodePage) {
CHARSETINFO ci = { 0, 0, { { 0, 0, 0, 0 }, { 0, 0 } } };
BOOL bci = ::TranslateCharsetInfo(reinterpret_cast<DWORD*>(static_cast<uptr_t>(characterSet)),
&ci, TCI_SRCCHARSET);
UINT cp;
if (bci)
cp = ci.ciACP;
else
cp = documentCodePage;
CPINFO cpi;
if (!::IsValidCodePage(cp) && !::GetCPInfo(cp, &cpi))
cp = CP_ACP;
return cp;
}
void SciTEWin::OutputAppendEncodedStringSynchronised(GUI::gui_string s, int codePage) {
int cchMulti = ::WideCharToMultiByte(codePage, 0, s.c_str(), static_cast<int>(s.size()), NULL, 0, NULL, NULL);
char *pszMulti = new char[cchMulti + 1];
::WideCharToMultiByte(codePage, 0, s.c_str(), static_cast<int>(s.size()), pszMulti, cchMulti + 1, NULL, NULL);
pszMulti[cchMulti] = 0;
OutputAppendStringSynchronised(pszMulti);
delete []pszMulti;
}
CommandWorker::CommandWorker() : pSciTE(NULL) {
Initialise(true);
}
void CommandWorker::Initialise(bool resetToStart) {
if (resetToStart)
icmd = 0;
originalEnd = 0;
exitStatus = 0;
flags = 0;
seenOutput = false;
outputScroll = 1;
}
void CommandWorker::Execute() {
pSciTE->ProcessExecute();
}
void SciTEWin::ResetExecution() {
cmdWorker.Initialise(true);
jobQueue.SetExecuting(false);
if (needReadProperties)
ReadProperties();
CheckReload();
CheckMenus();
jobQueue.ClearJobs();
::SendMessage(MainHWND(), WM_COMMAND, IDM_FINISHEDEXECUTE, 0);
}
void SciTEWin::ExecuteNext() {
cmdWorker.icmd++;
if (cmdWorker.icmd < jobQueue.commandCurrent && cmdWorker.icmd < jobQueue.commandMax && cmdWorker.exitStatus == 0) {
Execute();
} else {
ResetExecution();
}
}
/**
* Run a command with redirected input and output streams
* so the output can be put in a window.
* It is based upon several usenet posts and a knowledge base article.
* This is running in a separate thread to the user interface so should always
* use ScintillaWindow::Send rather than a one of the direct function calls.
*/
DWORD SciTEWin::ExecuteOne(const Job &jobToRun) {
DWORD exitcode = 0;
if (jobToRun.jobType == jobShell) {
ShellExec(jobToRun.command, jobToRun.directory.AsUTF8().c_str());
return exitcode;
}
if (jobToRun.jobType == jobHelp) {
ExecuteHelp(jobToRun.command.c_str());
return exitcode;
}
if (jobToRun.jobType == jobOtherHelp) {
ExecuteOtherHelp(jobToRun.command.c_str());
return exitcode;
}
if (jobToRun.jobType == jobGrep) {
// jobToRun.command is "(w|~)(c|~)(d|~)(b|~)\0files\0text"
const char *grepCmd = jobToRun.command.c_str();
if (*grepCmd) {
GrepFlags gf = grepNone;
if (*grepCmd == 'w')
gf = static_cast<GrepFlags>(gf | grepWholeWord);
grepCmd++;
if (*grepCmd == 'c')
gf = static_cast<GrepFlags>(gf | grepMatchCase);
grepCmd++;
if (*grepCmd == 'd')
gf = static_cast<GrepFlags>(gf | grepDot);
grepCmd++;
if (*grepCmd == 'b')
gf = static_cast<GrepFlags>(gf | grepBinary);
const char *findFiles = grepCmd + 2;
const char *findWhat = findFiles + strlen(findFiles) + 1;
if (cmdWorker.outputScroll == 1)
gf = static_cast<GrepFlags>(gf | grepScroll);
sptr_t positionEnd = wOutput.Send(SCI_GETCURRENTPOS);
InternalGrep(gf, jobToRun.directory.AsInternal(), GUI::StringFromUTF8(findFiles).c_str(), findWhat, positionEnd);
if ((gf & grepScroll) && returnOutputToCommand)
wOutput.Send(SCI_GOTOPOS, positionEnd, 0);
}
return exitcode;
}
UINT codePage = static_cast<UINT>(wOutput.Send(SCI_GETCODEPAGE));
if (codePage != SC_CP_UTF8) {
codePage = CodePageFromCharSet(characterSet, codePage);
}
SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), 0, 0};
OutputAppendStringSynchronised(">");
OutputAppendEncodedStringSynchronised(GUI::StringFromUTF8(jobToRun.command.c_str()), codePage);
OutputAppendStringSynchronised("\n");
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
SECURITY_DESCRIPTOR sd;
// Make a real security thing to allow inheriting handles
::InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
::SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = &sd;
HANDLE hPipeWrite = NULL;
HANDLE hPipeRead = NULL;
// Create pipe for output redirection
// read handle, write handle, security attributes, number of bytes reserved for pipe - 0 default
::CreatePipe(&hPipeRead, &hPipeWrite, &sa, 0);
// Create pipe for input redirection. In this code, you do not
// redirect the output of the child process, but you need a handle
// to set the hStdInput field in the STARTUP_INFO struct. For safety,
// you should not set the handles to an invalid handle.
hWriteSubProcess = NULL;
subProcessGroupId = 0;
HANDLE hRead2 = NULL;
// read handle, write handle, security attributes, number of bytes reserved for pipe - 0 default
::CreatePipe(&hRead2, &hWriteSubProcess, &sa, 0);
::SetHandleInformation(hPipeRead, HANDLE_FLAG_INHERIT, 0);
::SetHandleInformation(hWriteSubProcess, HANDLE_FLAG_INHERIT, 0);
// Make child process use hPipeWrite as standard out, and make
// sure it does not show on screen.
STARTUPINFOW si = {
sizeof(STARTUPINFO), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
if (jobToRun.jobType == jobCLI)
si.wShowWindow = SW_HIDE;
else
si.wShowWindow = SW_SHOW;
si.hStdInput = hRead2;
si.hStdOutput = hPipeWrite;
si.hStdError = hPipeWrite;
FilePath startDirectory = jobToRun.directory.AbsolutePath();
PROCESS_INFORMATION pi = {0, 0, 0, 0};
bool running = ::CreateProcessW(
NULL,
const_cast<wchar_t *>(GUI::StringFromUTF8(jobToRun.command.c_str()).c_str()),
NULL, NULL,
TRUE, CREATE_NEW_PROCESS_GROUP,
NULL,
startDirectory.IsSet() ?
startDirectory.AsInternal() : NULL,
&si, &pi);
// if jobCLI "System cant find" - try calling with command processor
if ((!running) && (jobToRun.jobType == jobCLI) && (::GetLastError() == ERROR_FILE_NOT_FOUND)) {
SString runComLine = "cmd.exe /c ";
runComLine = runComLine.append(jobToRun.command.c_str());
running = ::CreateProcessW(
NULL,
const_cast<wchar_t*>(GUI::StringFromUTF8(runComLine.c_str()).c_str()),
NULL, NULL,
TRUE, CREATE_NEW_PROCESS_GROUP,
NULL,
startDirectory.IsSet() ?
startDirectory.AsInternal() : NULL,
&si, &pi);
}
if (running) {
subProcessGroupId = pi.dwProcessId;
bool cancelled = false;
SString repSelBuf;
size_t totalBytesToWrite = 0;
if (jobToRun.flags & jobHasInput) {
totalBytesToWrite = jobToRun.input.length();
}
if (totalBytesToWrite > 0 && !(jobToRun.flags & jobQuiet)) {
SString input = jobToRun.input;
input.substitute("\n", "\n>> ");
OutputAppendStringSynchronised(">> ");
OutputAppendStringSynchronised(input.c_str());
OutputAppendStringSynchronised("\n");
}
unsigned writingPosition = 0;
int countPeeks = 0;
while (running) {
if (writingPosition >= totalBytesToWrite) {
if (countPeeks > 10)
::Sleep(100L);
else if (countPeeks > 2)
::Sleep(10L);
countPeeks++;
}
DWORD bytesRead = 0;
DWORD bytesAvail = 0;
char buffer[16384];
if (!::PeekNamedPipe(hPipeRead, buffer,
sizeof(buffer), &bytesRead, &bytesAvail, NULL)) {
bytesAvail = 0;
}
if ((bytesAvail < 1000) && (hWriteSubProcess != INVALID_HANDLE_VALUE) && (writingPosition < totalBytesToWrite)) {
// There is input to transmit to the process. Do it in small blocks, interleaved
// with reads, so that our hRead buffer will not be overrun with results.
size_t bytesToWrite;
int eol_pos = jobToRun.input.search("\n", writingPosition);
if (eol_pos == -1) {
bytesToWrite = totalBytesToWrite - writingPosition;
} else {
bytesToWrite = eol_pos + 1 - writingPosition;
}
if (bytesToWrite > 250) {
bytesToWrite = 250;
}
DWORD bytesWrote = 0;
int bTest = ::WriteFile(hWriteSubProcess,
const_cast<char *>(jobToRun.input.c_str() + writingPosition),
static_cast<DWORD>(bytesToWrite), &bytesWrote, NULL);
if (bTest) {
if ((writingPosition + bytesToWrite) / 1024 > writingPosition / 1024) {
// sleep occasionally, even when writing
::Sleep(100L);
}
writingPosition += bytesWrote;
if (writingPosition >= totalBytesToWrite) {
::CloseHandle(hWriteSubProcess);
hWriteSubProcess = INVALID_HANDLE_VALUE;
}
} else {
// Is this the right thing to do when writing to the pipe fails?
::CloseHandle(hWriteSubProcess);
hWriteSubProcess = INVALID_HANDLE_VALUE;
OutputAppendStringSynchronised("\n>Input pipe closed due to write failure.\n");
}
} else if (bytesAvail > 0) {
int bTest = ::ReadFile(hPipeRead, buffer,
sizeof(buffer), &bytesRead, NULL);
if (bTest && bytesRead) {
if (jobToRun.flags & jobRepSelMask) {
repSelBuf.append(buffer, bytesRead);
}
if (!(jobToRun.flags & jobQuiet)) {
if (!cmdWorker.seenOutput) {
MakeOutputVisible();
cmdWorker.seenOutput = true;
}
// Display the data
OutputAppendStringSynchronised(buffer, bytesRead);
}
::UpdateWindow(MainHWND());
} else {
running = false;
}
} else {
if (::GetExitCodeProcess(pi.hProcess, &exitcode)) {
if (STILL_ACTIVE != exitcode) {
// Already dead
running = false;
}
}
}
if (jobQueue.SetCancelFlag(0)) {
if (WAIT_OBJECT_0 != ::WaitForSingleObject(pi.hProcess, 500)) {
// We should use it only if the GUI process is stuck and
// don't answer to a normal termination command.
// This function is dangerous: dependant DLLs don't know the process
// is terminated, and memory isn't released.
OutputAppendStringSynchronised("\n>Process failed to respond; forcing abrupt termination...\n");
::TerminateProcess(pi.hProcess, 1);
}
running = false;
cancelled = true;
}
}
if (WAIT_OBJECT_0 != ::WaitForSingleObject(pi.hProcess, 1000)) {
OutputAppendStringSynchronised("\n>Process failed to respond; forcing abrupt termination...");
::TerminateProcess(pi.hProcess, 2);
}
::GetExitCodeProcess(pi.hProcess, &exitcode);
SString sExitMessage(static_cast<int>(exitcode));
sExitMessage.insert(0, ">Exit code: ");
if (jobQueue.TimeCommands()) {
sExitMessage += " Time: ";
sExitMessage += SString(cmdWorker.commandTime.Duration(), 3);
}
sExitMessage += "\n";
OutputAppendStringSynchronised(sExitMessage.c_str());
::CloseHandle(pi.hProcess);
::CloseHandle(pi.hThread);
if (!cancelled) {
bool doRepSel = false;
if (jobToRun.flags & jobRepSelYes)
doRepSel = true;
else if (jobToRun.flags & jobRepSelAuto)
doRepSel = (0 == exitcode);
if (doRepSel) {
int cpMin = static_cast<int>(wEditor.Send(SCI_GETSELECTIONSTART, 0, 0));
wEditor.Send(SCI_REPLACESEL,0,reinterpret_cast<sptr_t>(repSelBuf.c_str()));
wEditor.Send(SCI_SETSEL, cpMin, cpMin+repSelBuf.length());
}
}
WarnUser(warnExecuteOK);
} else {
DWORD nRet = ::GetLastError();
OutputAppendStringSynchronised(">");
OutputAppendEncodedStringSynchronised(GetErrorMessage(nRet), codePage);
WarnUser(warnExecuteKO);
}
::CloseHandle(hPipeRead);
::CloseHandle(hPipeWrite);
::CloseHandle(hRead2);
::CloseHandle(hWriteSubProcess);
hWriteSubProcess = NULL;
subProcessGroupId = 0;
return exitcode;
}
/**
* Run a command in the job queue, stopping if one fails.
* This is running in a separate thread to the user interface so must be
* careful when reading and writing shared state.
*/
void SciTEWin::ProcessExecute() {
if (scrollOutput)
wOutput.Send(SCI_GOTOPOS, wOutput.Send(SCI_GETTEXTLENGTH));
cmdWorker.exitStatus = ExecuteOne(jobQueue.jobQueue[cmdWorker.icmd]);
if (jobQueue.isBuilding) {
// The build command is first command in a sequence so it is only built if
// that command succeeds not if a second returns after document is modified.
jobQueue.isBuilding = false;
if (cmdWorker.exitStatus == 0)
jobQueue.isBuilt = true;
}
// Move selection back to beginning of this run so that F4 will go
// to first error of this run.
// scroll and return only if output.scroll equals
// one in the properties file
if ((cmdWorker.outputScroll == 1) && returnOutputToCommand)
wOutput.Send(SCI_GOTOPOS, cmdWorker.originalEnd, 0);
returnOutputToCommand = true;
PostOnMainThread(WORK_EXECUTE, &cmdWorker);
}
void SciTEWin::ShellExec(const SString &cmd, const char *dir) {
char *mycmd;
// guess if cmd is an executable, if this succeeds it can
// contain spaces without enclosing it with "
SString cmdLower = cmd;
cmdLower.lowercase();
char *mycmdcopy = StringDup(cmdLower.c_str());
char *mycmd_end = NULL;
char *myparams = NULL;
char *s = strstr(mycmdcopy, ".exe");
if (s == NULL)
s = strstr(mycmdcopy, ".cmd");
if (s == NULL)
s = strstr(mycmdcopy, ".bat");
if (s == NULL)
s = strstr(mycmdcopy, ".com");
if ((s != NULL) && ((*(s + 4) == '\0') || (*(s + 4) == ' '))) {
ptrdiff_t len_mycmd = s - mycmdcopy + 4;
delete []mycmdcopy;
mycmdcopy = StringDup(cmd.c_str());
mycmd = mycmdcopy;
mycmd_end = mycmdcopy + len_mycmd;
} else {
delete []mycmdcopy;
mycmdcopy = StringDup(cmd.c_str());
if (*mycmdcopy != '"') {
// get next space to separate cmd and parameters
mycmd_end = strchr(mycmdcopy, ' ');
mycmd = mycmdcopy;
} else {
// the cmd is surrounded by ", so it can contain spaces, but we must
// strip the " for ShellExec
mycmd = mycmdcopy + 1;
char *sm = strchr(mycmdcopy + 1, '"');
if (sm != NULL) {
*sm = '\0';
mycmd_end = sm + 1;
}
}
}
if ((mycmd_end != NULL) && (*mycmd_end != '\0')) {
*mycmd_end = '\0';
// test for remaining params after cmd, they may be surrounded by " but
// we give them as-is to ShellExec
++mycmd_end;
while (*mycmd_end == ' ')
++mycmd_end;
if (*mycmd_end != '\0')
myparams = mycmd_end;
}
GUI::gui_string sMycmd = GUI::StringFromUTF8(mycmd);
GUI::gui_string sMyparams = GUI::StringFromUTF8(myparams);
GUI::gui_string sDir = GUI::StringFromUTF8(dir);
SHELLEXECUTEINFO exec= { sizeof (exec), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
exec.fMask= SEE_MASK_FLAG_NO_UI; // own msg box on return
exec.hwnd= MainHWND();
exec.lpVerb= L"open"; // better for executables to use "open" instead of NULL
exec.lpFile= sMycmd.c_str(); // file to open
exec.lpParameters= sMyparams.c_str(); // parameters
exec.lpDirectory= sDir.c_str(); // launch directory
exec.nShow= SW_SHOWNORMAL; //default show cmd
if (::ShellExecuteEx(&exec)) {
// it worked!
delete []mycmdcopy;
return;
}
DWORD rc = GetLastError();
SString errormsg("Error while launching:\n\"");
errormsg += mycmdcopy;
if (myparams != NULL) {
errormsg += "\" with Params:\n\"";
errormsg += myparams;
}
errormsg += "\"\n";
GUI::gui_string sErrorMsg = GUI::StringFromUTF8(errormsg.c_str()) + GetErrorMessage(rc);
WindowMessageBox(wSciTE, sErrorMsg, MB_OK);
delete []mycmdcopy;
}
void SciTEWin::Execute() {
if (buffers.SavingInBackground())
// May be saving file that should be used by command so wait until all saved
return;
SciTEBase::Execute();
if (!jobQueue.HasCommandToRun())
// No commands to execute - possibly cancelled in SciTEBase::Execute
return;
cmdWorker.Initialise(false);
cmdWorker.outputScroll = props.GetInt("output.scroll", 1);
cmdWorker.originalEnd = wOutput.Call(SCI_GETTEXTLENGTH);
cmdWorker.commandTime.Duration(true);
cmdWorker.flags = jobQueue.jobQueue[cmdWorker.icmd].flags;
if (scrollOutput)
wOutput.Send(SCI_GOTOPOS, wOutput.Send(SCI_GETTEXTLENGTH));
if (jobQueue.jobQueue[cmdWorker.icmd].jobType == jobExtension) {
// Execute extensions synchronously
if (jobQueue.jobQueue[cmdWorker.icmd].flags & jobGroupUndo)
wEditor.Send(SCI_BEGINUNDOACTION);
if (extender)
extender->OnExecute(jobQueue.jobQueue[cmdWorker.icmd].command.c_str());
if (jobQueue.jobQueue[cmdWorker.icmd].flags & jobGroupUndo)
wEditor.Send(SCI_ENDUNDOACTION);
Redraw();
// A Redraw "might" be needed, since Lua and Director
// provide enough low-level capabilities to corrupt the
// display.
ExecuteNext();
} else {
// Execute other jobs asynchronously on a new thread
PerformOnNewThread(&cmdWorker);
}
}
void SciTEWin::StopExecute() {
if (hWriteSubProcess && (hWriteSubProcess != INVALID_HANDLE_VALUE)) {
char stop[] = "\032";
DWORD bytesWrote = 0;
::WriteFile(hWriteSubProcess, stop, static_cast<DWORD>(strlen(stop)), &bytesWrote, NULL);
Sleep(500L);
}
#ifdef USE_CONSOLE_EVENT
if (subProcessGroupId) {
// this also doesn't work
OutputAppendStringSynchronised("\n>Attempting to cancel process...");
if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, subProcessGroupId)) {
LONG errCode = GetLastError();
OutputAppendStringSynchronised("\n>BREAK Failed ");
OutputAppendStringSynchronised(SString(errCode).c_str());
OutputAppendStringSynchronised("\n");
}
Sleep(100L);
}
#endif
jobQueue.SetCancelFlag(1);
}
void SciTEWin::AddCommand(const SString &cmd, const SString &dir, JobSubsystem jobType, const SString &input, int flags) {
if (cmd.length()) {
if ((jobType == jobShell) && ((flags & jobForceQueue) == 0)) {
SString pCmd = cmd;
parameterisedCommand = "";
if (pCmd[0] == '*') {
pCmd.remove(0, 1);
parameterisedCommand = pCmd;
if (!ParametersDialog(true)) {
return;
}
} else {
ParamGrab();
}
pCmd = props.Expand(pCmd.c_str());
ShellExec(pCmd, dir.c_str());
} else {
SciTEBase::AddCommand(cmd, dir, jobType, input, flags);
}
}
}
static void WorkerThread(void *ptr) {
Worker *pWorker = static_cast<Worker *>(ptr);
pWorker->Execute();
}
bool SciTEWin::PerformOnNewThread(Worker *pWorker) {
uintptr_t result = _beginthread(WorkerThread, 1024 * 1024, reinterpret_cast<void *>(pWorker));
return result != static_cast<uintptr_t>(-1);
}
void SciTEWin::PostOnMainThread(int cmd, Worker *pWorker) {
::PostMessage(reinterpret_cast<HWND>(wSciTE.GetID()), SCITE_WORKER, cmd, reinterpret_cast<LPARAM>(pWorker));
}
void SciTEWin::WorkerCommand(int cmd, Worker *pWorker) {
if (cmd < WORK_PLATFORM) {
SciTEBase::WorkerCommand(cmd, pWorker);
} else {
if (cmd == WORK_EXECUTE) {
// Move to next command
ExecuteNext();
}
}
}
void SciTEWin::QuitProgram() {
quitting = false;
if (SaveIfUnsureAll() != IDCANCEL) {
if (fullScreen) // Ensure tray visible on exit
FullScreenToggle();
quitting = true;
// If ongoing saves, wait for them to complete.
if (!buffers.SavingInBackground()) {
::PostQuitMessage(0);
wSciTE.Destroy();
}
}
}
void SciTEWin::RestorePosition() {
int left = propsSession.GetInt("position.left", CW_USEDEFAULT);
int top = propsSession.GetInt("position.top", CW_USEDEFAULT);
int width = propsSession.GetInt("position.width", CW_USEDEFAULT);
int height = propsSession.GetInt("position.height", CW_USEDEFAULT);
cmdShow = propsSession.GetInt("position.maximize", 0) ? SW_MAXIMIZE : 0;
if (left != static_cast<int>(CW_USEDEFAULT) &&
top != static_cast<int>(CW_USEDEFAULT) &&
width != static_cast<int>(CW_USEDEFAULT) &&
height != static_cast<int>(CW_USEDEFAULT)) {
winPlace.length = sizeof(winPlace);
winPlace.rcNormalPosition.left = left;
winPlace.rcNormalPosition.right = left + width;
winPlace.rcNormalPosition.top = top;
winPlace.rcNormalPosition.bottom = top + height;
::SetWindowPlacement(MainHWND(), &winPlace);
}
}
void SciTEWin::CreateUI() {
CreateBuffers();
int left = props.GetInt("position.left", CW_USEDEFAULT);
int top = props.GetInt("position.top", CW_USEDEFAULT);
int width = props.GetInt("position.width", CW_USEDEFAULT);
int height = props.GetInt("position.height", CW_USEDEFAULT);
cmdShow = props.GetInt("position.maximize", 0) ? SW_MAXIMIZE : 0;
if (width == -1 || height == -1) {
cmdShow = SW_MAXIMIZE;
width = CW_USEDEFAULT;
height = CW_USEDEFAULT;
}
if (props.GetInt("position.tile") && ::FindWindow(TEXT("SciTEWindow"), NULL) &&
(left != static_cast<int>(CW_USEDEFAULT))) {
left += width;
}
// Pass 'this' pointer in lpParam of CreateWindow().
wSciTE = ::CreateWindowEx(
0,
className,
windowName.c_str(),
WS_CAPTION | WS_SYSMENU | WS_THICKFRAME |
WS_MINIMIZEBOX | WS_MAXIMIZEBOX |
WS_CLIPCHILDREN,
left, top, width, height,
NULL,
NULL,
hInstance,
reinterpret_cast<LPSTR>(this));
if (!wSciTE.Created())
exit(FALSE);
if (props.GetInt("save.position"))
RestorePosition();
LocaliseMenus();
SString pageSetup = props.Get("print.margins");
char val[32];
char *ps = StringDup(pageSetup.c_str());
const char *next = GetNextPropItem(ps, val, 32);
pagesetupMargin.left = atol(val);
next = GetNextPropItem(next, val, 32);
pagesetupMargin.right = atol(val);
next = GetNextPropItem(next, val, 32);
pagesetupMargin.top = atol(val);
GetNextPropItem(next, val, 32);
pagesetupMargin.bottom = atol(val);
delete []ps;
UIAvailable();
}
static bool IsASpace(int ch) {
return (ch == ' ') || (ch == '\t');
}
/**
* Break up the command line into individual arguments and strip double quotes
* from each argument.
* @return A string with each argument separated by '\n'.
*/
GUI::gui_string SciTEWin::ProcessArgs(const GUI::gui_char *cmdLine) {
GUI::gui_string args;
const GUI::gui_char *startArg = cmdLine;
while (*startArg) {
while (IsASpace(*startArg)) {
startArg++;
}
const GUI::gui_char *endArg = startArg;
if (*startArg == '"') { // Opening double-quote
startArg++;
endArg = startArg;
while (*endArg && *endArg != '\"') {
endArg++;
}
} else { // No double-quote, end of argument on first space
while (*endArg && !IsASpace(*endArg)) {
endArg++;
}
}
GUI::gui_string arg(startArg, 0, endArg - startArg);
if (args.size() > 0)
args += GUI_TEXT("\n");
args += arg;
startArg = endArg; // On a space or a double-quote, or on the end of the command line
if (*startArg) {
startArg++;
}
}
return args;
}
/**
* Process the command line, check for other instance wanting to open files,
* create the SciTE window, perform batch processing (print) or transmit command line
* to other instance and exit or just show the window and open files.
*/
void SciTEWin::Run(const GUI::gui_char *cmdLine) {
// Load the default session file
if (props.GetInt("save.session") || props.GetInt("save.position") || props.GetInt("save.recent")) {
LoadSessionFile(GUI_TEXT(""));
}
// Break up the command line into individual arguments
GUI::gui_string args = ProcessArgs(cmdLine);
// Read the command line parameters:
// In case the check.if.already.open property has been set or reset on the command line,
// we still get a last chance to force checking or to open a separate instance;
// Check if the user just want to print the file(s).
// Don't process files yet.
bool bBatchProcessing = ProcessCommandLine(args, 0);
// No need to check for other instances when doing a batch job:
// perform some tasks and exit immediately.
if (!bBatchProcessing && props.GetInt("check.if.already.open") != 0) {
uniqueInstance.CheckOtherInstance();
}
// We create the window, so it can be found by EnumWindows below,
// and the Scintilla control is thus created, allowing to print the file(s).
// We don't show it yet, so if it is destroyed (duplicate instance), it will
// not flash on the taskbar or on the display.
CreateUI();
if (bBatchProcessing) {
// Reprocess the command line and read the files
ProcessCommandLine(args, 1);
Print(false); // Don't ask user for print parameters
// Done, we exit the program
::PostQuitMessage(0);
wSciTE.Destroy();
return;
}
if (props.GetInt("check.if.already.open") != 0 && uniqueInstance.FindOtherInstance()) {
uniqueInstance.SendCommands(GUI::UTF8FromString(cmdLine).c_str());
// Kill itself, leaving room to the previous instance
::PostQuitMessage(0);
wSciTE.Destroy();
return; // Don't do anything else
}
// OK, the instance will be displayed
SizeSubWindows();
wSciTE.Show();
if (cmdShow) { // assume SW_MAXIMIZE only
::ShowWindow(MainHWND(), cmdShow);
}
// Open all files given on command line.
// The filenames containing spaces must be enquoted.
// In case of not using buffers they get closed immediately except
// the last one, but they move to the MRU file list
ProcessCommandLine(args, 1);
Redraw();
}
/**
* Draw the split bar.
*/
void ContentWin::Paint(HDC hDC, GUI::Rectangle) {
GUI::Rectangle rcInternal = GetClientPosition();
int heightClient = rcInternal.Height();
int widthClient = rcInternal.Width();
int heightEditor = heightClient - pSciTEWin->heightOutput - pSciTEWin->heightBar;
int yBorder = heightEditor;
int xBorder = widthClient - pSciTEWin->heightOutput - pSciTEWin->heightBar;
for (int i = 0; i < pSciTEWin->heightBar; i++) {
HPEN pen;
if (i == 1)
pen = ::CreatePen(0,1,::GetSysColor(COLOR_3DHIGHLIGHT));
else if (i == pSciTEWin->heightBar - 2)
pen = ::CreatePen(0,1,::GetSysColor(COLOR_3DSHADOW));
else if (i == pSciTEWin->heightBar - 1)
pen = ::CreatePen(0,1,::GetSysColor(COLOR_3DDKSHADOW));
else
pen = ::CreatePen(0,1,::GetSysColor(COLOR_3DFACE));
HPEN penOld = static_cast<HPEN>(::SelectObject(hDC, pen));
if (pSciTEWin->splitVertical) {
::MoveToEx(hDC, xBorder + i, 0, 0);
::LineTo(hDC, xBorder + i, heightClient);
} else {
::MoveToEx(hDC, 0, yBorder + i, 0);
::LineTo(hDC, widthClient, yBorder + i);
}
::SelectObject(hDC, penOld);
::DeleteObject(pen);
}
}
void SciTEWin::AboutDialog() {
#ifdef STATIC_BUILD
AboutDialogWithBuild(1);
#else
AboutDialogWithBuild(0);
#endif
}
/**
* Open files dropped on the SciTE window.
*/
void SciTEWin::DropFiles(HDROP hdrop) {
// If drag'n'drop inside the SciTE window but outside
// Scintilla, hdrop is null, and an exception is generated!
if (hdrop) {
bool tempFilesSyncLoad = props.GetInt("temp.files.sync.load") != 0;
GUI::gui_char tempDir[MAX_PATH];
DWORD tempDirLen = ::GetTempPath(MAX_PATH, tempDir);
bool isTempFile = false;
int filesDropped = ::DragQueryFile(hdrop, 0xffffffff, NULL, 0);
// Append paths to dropFilesQueue, to finish drag operation soon
for (int i = 0; i < filesDropped; ++i) {
GUI::gui_char pathDropped[MAX_PATH];
::DragQueryFileW(hdrop, i, pathDropped, ELEMENTS(pathDropped));
// Only do this for the first file in the drop op
// as all are coming from the same drag location
if (i == 0 && tempFilesSyncLoad) {
// check if file's parent dir is temp
if (::wcsncmp(tempDir, pathDropped, tempDirLen) == 0) {
isTempFile = true;
}
}
if (isTempFile) {
if (!Open(pathDropped, ofSynchronous)) {
break;
}
} else {
dropFilesQueue.push_back(pathDropped);
}
}
::DragFinish(hdrop);
// Put SciTE to forefront
// May not work for Win2k, but OK for lower versions
// Note: how to drop a file to an iconic window?
// Actually, it is the Send To command that generates a drop.
if (::IsIconic(MainHWND())) {
::ShowWindow(MainHWND(), SW_RESTORE);
}
::SetForegroundWindow(MainHWND());
// Post message to ourself for opening the files so we can finish the drop message and
// the drop source will respond when open operation takes long time (opening big files...)
if (!dropFilesQueue.empty()) {
::PostMessage(MainHWND(), SCITE_DROP, 0, 0);
}
}
}
/**
* Handle simple wild-card file patterns and directory requests.
*/
bool SciTEWin::PreOpenCheck(const GUI::gui_char *arg) {
bool isHandled = false;
HANDLE hFFile;
WIN32_FIND_DATA ffile;
DWORD fileattributes = ::GetFileAttributes(arg);
GUI::gui_char filename[MAX_PATH] = L"";
int nbuffers = props.GetInt("buffers");
if (fileattributes != (DWORD) -1) { // arg is an existing directory or filename
// if the command line argument is a directory, use OpenDialog()
if (fileattributes & FILE_ATTRIBUTE_DIRECTORY) {
OpenDialog(FilePath(arg), GUI::StringFromUTF8(props.GetExpanded("open.filter").c_str()).c_str());
isHandled = true;
}
} else if (nbuffers > 1 && (hFFile = ::FindFirstFile(arg, &ffile)) != INVALID_HANDLE_VALUE) {
// If several buffers is accepted and the arg is a filename pattern matching at least an existing file
isHandled = true;
wcscpy(filename, arg);
GUI::gui_char *lastslash;
if (NULL == (lastslash = wcsrchr(filename, GUI_TEXT('\\'))))
lastslash = filename; // No path
else
lastslash++;
// Open files matching the given pattern until no more files or all available buffers are exhausted
do {
if (!(ffile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { // Skip directories
wcscpy(lastslash, ffile.cFileName);
Open(filename);
--nbuffers;
}
} while (nbuffers > 0 && ::FindNextFile(hFFile, &ffile));
::FindClose(hFFile);
} else {
const GUI::gui_char *lastslash = wcsrchr(arg, '\\');
const GUI::gui_char *lastdot = wcsrchr(arg, '.');
// if the filename is only an extension, open the dialog box with it as the extension filter
if ((lastslash && lastdot && lastslash == lastdot - 1) || (!lastslash && lastdot == arg)) {
isHandled = true;
GUI::gui_char dir[MAX_PATH] = L"";
if (lastslash) { // the arg contains a path, so copy that part to dirName
wcsncpy(dir, arg, lastslash - arg + 1);
dir[lastslash - arg + 1] = '\0';
} else {
wcscpy(dir, GUI_TEXT(".\\"));
}
wcscpy(filename, GUI_TEXT("*"));
wcscat(filename, lastdot);
wcscat(filename, GUI_TEXT("|"));
wcscat(filename, GUI_TEXT("*"));
wcscat(filename, lastdot);
OpenDialog(FilePath(dir), filename);
} else if (!lastdot || (lastslash && lastdot < lastslash)) {
// if the filename has no extension, try to match a file with list of standard extensions
SString extensions = props.GetExpanded("source.default.extensions");
if (extensions.length()) {
wcscpy(filename, arg);
GUI::gui_char *endfilename = filename + wcslen(filename);
extensions.substitute('|', '\0');
size_t start = 0;
while (start < extensions.length()) {
GUI::gui_string filterName = GUI::StringFromUTF8(extensions.c_str() + start);
wcscpy(endfilename, filterName.c_str());
if (::GetFileAttributes(filename) != (DWORD) -1) {
isHandled = true;
Open(filename);
break; // Found!
} else {
// Next extension
start += strlen(extensions.c_str() + start) + 1;
}
}
}
}
}
return isHandled;
}
/* return true if stdin is blocked:
- stdin is the console (isatty() == 1)
- a valid handle for stdin cannot be generated
- the handle appears to be the console - this may be a duplicate of using isatty() == 1
- the pipe cannot be peeked, which appears to be from command lines such as "scite <file.txt"
otherwise it is unblocked
*/
bool SciTEWin::IsStdinBlocked() {
DWORD unread_messages;
INPUT_RECORD irec[1];
char bytebuffer;
HANDLE hStdIn = ::GetStdHandle(STD_INPUT_HANDLE);
if (hStdIn == INVALID_HANDLE_VALUE) {
/* an invalid handle, assume that stdin is blocked by falling to bottomn */;
} else if (::PeekConsoleInput(hStdIn, irec, 1, &unread_messages) != 0) {
/* it is the console, assume that stdin is blocked by falling to bottomn */;
} else if (::GetLastError() == ERROR_INVALID_HANDLE) {
for (int n = 0; n < 4; n++) {
/* if this fails, it is either
- a busy pipe "scite \*.,cxx /s /b | s -@",
- another type of pipe "scite - <file", or
- a blocked pipe "findstrin nothing | scite -"
in any case case, retry in a short bit
*/
if (::PeekNamedPipe(hStdIn, &bytebuffer, sizeof(bytebuffer), NULL,NULL, &unread_messages) != 0) {
if (unread_messages != 0) {
return false; /* is a pipe and it is not blocked */
}
}
::Sleep(2500);
}
}
return true;
}
void SciTEWin::MinimizeToTray() {
TCHAR n[64] = TEXT("SciTE");
NOTIFYICONDATA nid;
memset(&nid, 0, sizeof(nid));
nid.cbSize = sizeof(nid);
nid.hWnd = MainHWND();
nid.uID = 1;
nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
nid.uCallbackMessage = SCITE_TRAY;
nid.hIcon = static_cast<HICON>(
::LoadImage(hInstance, TEXT("SCITE"), IMAGE_ICON, 16, 16, LR_DEFAULTSIZE));
StringCopy(nid.szTip, n);
::ShowWindow(MainHWND(), SW_MINIMIZE);
if (::Shell_NotifyIcon(NIM_ADD, &nid)) {
::ShowWindow(MainHWND(), SW_HIDE);
}
}
void SciTEWin::RestoreFromTray() {
NOTIFYICONDATA nid;
memset(&nid, 0, sizeof(nid));
nid.cbSize = sizeof(nid);
nid.hWnd = MainHWND();
nid.uID = 1;
::ShowWindow(MainHWND(), SW_SHOW);
::Sleep(100);
::Shell_NotifyIcon(NIM_DELETE, &nid);
}
#ifndef VK_OEM_2
static const int VK_OEM_2=0xbf;
static const int VK_OEM_3=0xc0;
static const int VK_OEM_4=0xdb;
static const int VK_OEM_5=0xdc;
static const int VK_OEM_6=0xdd;
#endif
#ifndef VK_OEM_PLUS
static const int VK_OEM_PLUS=0xbb;
#endif
inline bool KeyMatch(const SString &sKey, int keyval, int modifiers) {
return SciTEKeys::MatchKeyCode(
SciTEKeys::ParseKeyCode(sKey.c_str()), keyval, modifiers);
}
LRESULT SciTEWin::KeyDown(WPARAM wParam) {
// Look through lexer menu
int modifiers =
(IsKeyDown(VK_SHIFT) ? SCMOD_SHIFT : 0) |
(IsKeyDown(VK_CONTROL) ? SCMOD_CTRL : 0) |
(IsKeyDown(VK_MENU) ? SCMOD_ALT : 0);
if (extender && extender->OnKey(static_cast<int>(wParam), modifiers))
return 1l;
for (int j = 0; j < languageItems; j++) {
if (KeyMatch(languageMenu[j].menuKey, static_cast<int>(wParam), modifiers)) {
SciTEBase::MenuCommand(IDM_LANGUAGE + j);
return 1l;
}
}
// loop through the Tools menu's active commands.
HMENU hMenu = ::GetMenu(MainHWND());
HMENU hToolsMenu = ::GetSubMenu(hMenu, menuTools);
for (int tool_i = 0; tool_i < toolMax; ++tool_i) {
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_DATA;
if (::GetMenuItemInfo(hToolsMenu, IDM_TOOLS+tool_i, FALSE, &mii) && mii.dwItemData) {
if (SciTEKeys::MatchKeyCode(static_cast<long>(mii.dwItemData), static_cast<int>(wParam), modifiers)) {
SciTEBase::MenuCommand(IDM_TOOLS+tool_i);
return 1l;
}
}
}
// loop through the keyboard short cuts defined by user.. if found
// exec it the command defined
for (size_t cut_i = 0; cut_i < shortCutItemList.size(); cut_i++) {
if (KeyMatch(shortCutItemList[cut_i].menuKey, static_cast<int>(wParam), modifiers)) {
int commandNum = SciTEBase::GetMenuCommandAsInt(shortCutItemList[cut_i].menuCommand);
if (commandNum != -1) {
// its possible that the command is for scintilla directly
// all scintilla commands are larger then 2000
if (commandNum < 2000) {
SciTEBase::MenuCommand(commandNum);
} else {
SciTEBase::CallFocused(commandNum);
}
return 1l;
}
}
}
return 0l;
}
LRESULT SciTEWin::KeyUp(WPARAM wParam) {
if (wParam == VK_CONTROL) {
EndStackedTabbing();
}
return 0l;
}
void SciTEWin::AddToPopUp(const char *label, int cmd, bool enabled) {
GUI::gui_string localised = localiser.Text(label);
HMENU menu = reinterpret_cast<HMENU>(popup.GetID());
if (0 == localised.length())
::AppendMenu(menu, MF_SEPARATOR, 0, TEXT(""));
else if (enabled)
::AppendMenu(menu, MF_STRING, cmd, localised.c_str());
else
::AppendMenu(menu, MF_STRING | MF_DISABLED | MF_GRAYED, cmd, localised.c_str());
}
LRESULT SciTEWin::ContextMenuMessage(UINT iMessage, WPARAM wParam, LPARAM lParam) {
GUI::ScintillaWindow *w = &wEditor;
GUI::Point pt = PointFromLong(lParam);
if ((pt.x == -1) && (pt.y == -1)) {
// Caused by keyboard so display menu near caret
if (wOutput.HasFocus())
w = &wOutput;
int position = w->Call(SCI_GETCURRENTPOS);
pt.x = w->Call(SCI_POINTXFROMPOSITION, 0, position);
pt.y = w->Call(SCI_POINTYFROMPOSITION, 0, position);
POINT spt = {pt.x, pt.y};
::ClientToScreen(static_cast<HWND>(w->GetID()), &spt);
pt = GUI::Point(spt.x, spt.y);
} else {
GUI::Rectangle rcEditor = wEditor.GetPosition();
if (!rcEditor.Contains(pt)) {
GUI::Rectangle rcOutput = wOutput.GetPosition();
if (rcOutput.Contains(pt)) {
w = &wOutput;
} else { // In frame so use default.
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
}
}
}
menuSource = ::GetDlgCtrlID(HwndOf(*w));
ContextMenu(*w, pt, wSciTE);
return 0;
}
LRESULT SciTEWin::WndProc(UINT iMessage, WPARAM wParam, LPARAM lParam) {
int statusFailure = 0;
static int boxesVisible = 0;
try {
LRESULT uim = uniqueInstance.CheckMessage(iMessage, wParam, lParam);
if (uim != 0) {
return uim;
}
switch (iMessage) {
case WM_CREATE:
Creation();
break;
case WM_COMMAND:
Command(wParam, lParam);
break;
case WM_CONTEXTMENU:
return ContextMenuMessage(iMessage, wParam, lParam);
case WM_ENTERMENULOOP:
if (!wParam)
menuSource = 0;
break;
case WM_SYSCOMMAND:
if ((wParam == SC_MINIMIZE) && props.GetInt("minimize.to.tray")) {
MinimizeToTray();
return 0;
}
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
case SCITE_TRAY:
if (lParam == WM_LBUTTONDOWN) {
RestoreFromTray();
::ShowWindow(MainHWND(), SW_RESTORE);
::FlashWindow(MainHWND(), FALSE);
}
break;
case SCITE_DROP:
// Open the files
while (!dropFilesQueue.empty()) {
FilePath file(dropFilesQueue.front());
dropFilesQueue.pop_front();
if (file.Exists()) {
Open(file.AsInternal());
} else {
GUI::gui_string msg = LocaliseMessage("Could not open file '^0'.", file.AsInternal());
WindowMessageBox(wSciTE, msg, MB_OK | MB_ICONWARNING);
}
}
break;
case SCITE_WORKER:
WorkerCommand(static_cast<int>(wParam), reinterpret_cast<Worker *>(lParam));
break;
case WM_NOTIFY:
Notify(reinterpret_cast<SCNotification *>(lParam));
break;
case WM_KEYDOWN:
return KeyDown(wParam);
case WM_KEYUP:
return KeyUp(wParam);
case WM_SIZE:
if (wParam != 1)
SizeSubWindows();
break;
case WM_MOVE:
wEditor.Call(SCI_CALLTIPCANCEL);
break;
case WM_GETMINMAXINFO: {
MINMAXINFO *pmmi = reinterpret_cast<MINMAXINFO *>(lParam);
if (fullScreen) {
pmmi->ptMaxSize.x = ::GetSystemMetrics(SM_CXSCREEN) +
2 * ::GetSystemMetrics(SM_CXSIZEFRAME);
pmmi->ptMaxSize.y = ::GetSystemMetrics(SM_CYSCREEN) +
::GetSystemMetrics(SM_CYCAPTION) +
::GetSystemMetrics(SM_CYMENU) +
2 * ::GetSystemMetrics(SM_CYSIZEFRAME);
pmmi->ptMaxTrackSize.x = pmmi->ptMaxSize.x;
pmmi->ptMaxTrackSize.y = pmmi->ptMaxSize.y;
return 0;
} else {
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
}
}
case WM_INITMENU:
CheckMenus();
break;
case WM_CLOSE:
QuitProgram();
return 0;
case WM_QUERYENDSESSION:
QuitProgram();
return 1;
case WM_DESTROY:
break;
case WM_SETTINGCHANGE:
wEditor.Call(WM_SETTINGCHANGE, wParam, lParam);
wOutput.Call(WM_SETTINGCHANGE, wParam, lParam);
break;
case WM_SYSCOLORCHANGE:
wEditor.Call(WM_SYSCOLORCHANGE, wParam, lParam);
wOutput.Call(WM_SYSCOLORCHANGE, wParam, lParam);
break;
case WM_ACTIVATEAPP:
wEditor.Call(SCI_HIDESELECTION, !wParam);
// Do not want to display dialog yet as may be in middle of system mouse capture
::PostMessage(MainHWND(), WM_COMMAND, IDM_ACTIVATE, wParam);
break;
case WM_ACTIVATE:
if (wParam != WA_INACTIVE) {
if (searchStrip.visible)
searchStrip.Focus();
else if (findStrip.visible)
findStrip.Focus();
else if (replaceStrip.visible)
replaceStrip.Focus();
else if (userStrip.visible)
userStrip.Focus();
else
::SetFocus(wFocus);
}
break;
case WM_TIMER:
OnTimer();
break;
case WM_DROPFILES:
DropFiles(reinterpret_cast<HDROP>(wParam));
break;
case WM_COPYDATA:
return uniqueInstance.CopyData(reinterpret_cast<COPYDATASTRUCT *>(lParam));
default:
return ::DefWindowProcW(MainHWND(), iMessage, wParam, lParam);
}
} catch (GUI::ScintillaFailure &sf) {
statusFailure = static_cast<int>(sf.status);
}
if ((statusFailure > 0) && (boxesVisible == 0)) {
boxesVisible++;
char buff[200];
if (statusFailure == SC_STATUS_BADALLOC) {
strcpy(buff, "Memory exhausted.");
} else {
sprintf(buff, "Scintilla failed with status %d.", statusFailure);
}
strcat(buff, " SciTE will now close.");
GUI::gui_string sMessage = GUI::StringFromUTF8(buff);
::MessageBox(MainHWND(), sMessage.c_str(), TEXT("Failure in Scintilla"), MB_OK | MB_ICONERROR | MB_APPLMODAL);
exit(FALSE);
}
return 0l;
}
// Take care of 32/64 bit pointers
#ifdef GetWindowLongPtr
static void *PointerFromWindow(HWND hWnd) {
return reinterpret_cast<void *>(::GetWindowLongPtr(hWnd, 0));
}
static void SetWindowPointer(HWND hWnd, void *ptr) {
::SetWindowLongPtr(hWnd, 0, reinterpret_cast<LONG_PTR>(ptr));
}
#else
static void *PointerFromWindow(HWND hWnd) {
return reinterpret_cast<void *>(::GetWindowLong(hWnd, 0));
}
static void SetWindowPointer(HWND hWnd, void *ptr) {
::SetWindowLong(hWnd, 0, reinterpret_cast<LONG>(ptr));
}
#endif
LRESULT PASCAL SciTEWin::TWndProc(
HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) {
// Find C++ object associated with window.
SciTEWin *scite = reinterpret_cast<SciTEWin *>(PointerFromWindow(hWnd));
// scite will be zero if WM_CREATE not seen yet
if (scite == 0) {
if (iMessage == WM_CREATE) {
LPCREATESTRUCT cs = reinterpret_cast<LPCREATESTRUCT>(lParam);
scite = reinterpret_cast<SciTEWin *>(cs->lpCreateParams);
scite->wSciTE = hWnd;
SetWindowPointer(hWnd, scite);
return scite->WndProc(iMessage, wParam, lParam);
} else
return ::DefWindowProcW(hWnd, iMessage, wParam, lParam);
} else
return scite->WndProc(iMessage, wParam, lParam);
}
LRESULT ContentWin::WndProc(UINT iMessage, WPARAM wParam, LPARAM lParam) {
try {
switch (iMessage) {
case WM_CREATE:
pSciTEWin->wContent = GetID();
return ::DefWindowProc(Hwnd(), iMessage, wParam, lParam);
case WM_COMMAND:
case WM_NOTIFY:
return pSciTEWin->WndProc(iMessage, wParam, lParam);
case WM_PAINT: {
PAINTSTRUCT ps;
::BeginPaint(Hwnd(), &ps);
GUI::Rectangle rcPaint(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom);
Paint(ps.hdc, rcPaint);
::EndPaint(Hwnd(), &ps);
return 0;
}
case WM_ERASEBKGND: {
RECT rc = {0, 0, 2000, 2000};
HBRUSH hbrFace = CreateSolidBrush(::GetSysColor(COLOR_3DFACE));
::FillRect(reinterpret_cast<HDC>(wParam), &rc, hbrFace);
::DeleteObject(hbrFace);
return 0;
}
case WM_LBUTTONDOWN:
pSciTEWin->ptStartDrag = PointFromLong(lParam);
capturedMouse = true;
pSciTEWin->heightOutputStartDrag = pSciTEWin->heightOutput;
::SetCapture(Hwnd());
break;
case WM_MOUSEMOVE:
if (capturedMouse) {
pSciTEWin->MoveSplit(PointFromLong(lParam));
}
break;
case WM_LBUTTONUP:
if (capturedMouse) {
pSciTEWin->MoveSplit(PointFromLong(lParam));
capturedMouse = false;
::ReleaseCapture();
}
break;
case WM_CAPTURECHANGED:
capturedMouse = false;
break;
case WM_SETCURSOR:
if (ControlIDOfCommand(static_cast<unsigned long>(lParam)) == HTCLIENT) {
GUI::Point ptCursor;
::GetCursorPos(reinterpret_cast<POINT *>(&ptCursor));
GUI::Point ptClient = ptCursor;
::ScreenToClient(pSciTEWin->MainHWND(), reinterpret_cast<POINT *>(&ptClient));
GUI::Rectangle rcScintilla = pSciTEWin->wEditor.GetPosition();
GUI::Rectangle rcOutput = pSciTEWin->wOutput.GetPosition();
if (!rcScintilla.Contains(ptCursor) && !rcOutput.Contains(ptCursor)) {
::SetCursor(::LoadCursor(NULL, pSciTEWin->splitVertical ? IDC_SIZEWE : IDC_SIZENS));
return TRUE;
}
}
return ::DefWindowProc(Hwnd(), iMessage, wParam, lParam);
default:
return ::DefWindowProc(Hwnd(), iMessage, wParam, lParam);
}
} catch (...) {
}
return 0l;
}
static void SetFontHandle(GUI::Window &w, HFONT hfont) {
::SendMessage(HwndOf(w),
WM_SETFONT, reinterpret_cast<WPARAM>(hfont),
0); // redraw option
}
static int WidthText(HFONT hfont, const GUI::gui_char *text) {
HDC hdcMeasure = ::CreateCompatibleDC(NULL);
HFONT hfontOriginal = static_cast<HFONT>(::SelectObject(hdcMeasure, hfont));
RECT rcText = {0,0, 2000, 2000};
::DrawText(hdcMeasure, const_cast<LPWSTR>(text), -1, &rcText, DT_CALCRECT);
int width = rcText.right - rcText.left;
::SelectObject(hdcMeasure, hfontOriginal);
::DeleteDC(hdcMeasure);
return width;
}
static int WidthControl(GUI::Window &w) {
GUI::Rectangle rc = w.GetPosition();
return rc.Width();
}
static GUI::gui_string ControlGText(GUI::Window w) {
HWND wT = HwndOf(w);
int len = ::GetWindowTextLengthW(wT) + 1;
std::vector<GUI::gui_char> itemText(len);
GUI::gui_string gsText;
if (::GetWindowTextW(wT, &itemText[0], len)) {
gsText = GUI::gui_string(&itemText[0]);
}
return gsText;
}
static SString ControlText(GUI::Window w) {
HWND wT = HwndOf(w);
int len = ::GetWindowTextLengthW(wT) + 1;
std::vector<GUI::gui_char> itemText(len);
GUI::gui_string gsFind;
if (::GetWindowText(wT, &itemText[0], len)) {
gsFind = GUI::gui_string(&itemText[0]);
}
return GUI::UTF8FromString(gsFind.c_str()).c_str();
}
static const char *textFindPrompt = "Fi&nd:";
static const char *textReplacePrompt = "Rep&lace:";
static const char *textFindNext = "&Find Next";
static const char *textMarkAll = "&Mark All";
static const char *textReplace = "&Replace";
static const char *textReplaceAll = "Replace &All";
static const char *textInSelection = "In &Selection";
static SearchOption toggles[] = {
{"Match &whole word only", IDM_WHOLEWORD, IDWHOLEWORD},
{"Case sensiti&ve", IDM_MATCHCASE, IDMATCHCASE},
{"Regular &expression", IDM_REGEXP, IDREGEXP},
{"Transform &backslash expressions", IDM_UNSLASH, IDUNSLASH},
{"Wrap ar&ound", IDM_WRAPAROUND, IDWRAP},
{"&Up", IDM_DIRECTIONUP, IDDIRECTIONUP},
{0, 0, 0},
};
GUI::Window Strip::CreateText(const char *text) {
GUI::gui_string localised = localiser->Text(text);
int width = WidthText(fontText, localised.c_str()) + 4;
GUI::Window w;
w.SetID(::CreateWindowEx(0, TEXT("Static"), localised.c_str(),
WS_CHILD | WS_CLIPSIBLINGS | SS_RIGHT,
2, 2, width, 21,
Hwnd(), reinterpret_cast<HMENU>(0), ::GetModuleHandle(NULL), 0));
SetFontHandle(w, fontText);
w.Show();
return w;
}
#define PACKVERSION(major,minor) MAKELONG(minor,major)
static DWORD GetVersion(LPCTSTR lpszDllName) {
DWORD dwVersion = 0;
HINSTANCE hinstDll = ::LoadLibrary(lpszDllName);
if (hinstDll) {
DLLGETVERSIONPROC pDllGetVersion = (DLLGETVERSIONPROC)::GetProcAddress(hinstDll, "DllGetVersion");
if (pDllGetVersion) {
DLLVERSIONINFO dvi;
::ZeroMemory(&dvi, sizeof(dvi));
dvi.cbSize = sizeof(dvi);
HRESULT hr = (*pDllGetVersion)(&dvi);
if (SUCCEEDED(hr)) {
dwVersion = PACKVERSION(dvi.dwMajorVersion, dvi.dwMinorVersion);
}
}
::FreeLibrary(hinstDll);
}
return dwVersion;
}
GUI::Window Strip::CreateButton(const char *text, int ident, bool check) {
GUI::gui_string localised = localiser->Text(text);
int width = WidthText(fontText, localised.c_str());
int height = 19 + 2 * ::GetSystemMetrics(SM_CYEDGE);
if (check) {
width += 6;
int checkSize = ::GetSystemMetrics(SM_CXMENUCHECK);
width += checkSize;
} else {
width += 2 * ::GetSystemMetrics(SM_CXEDGE); // Allow for 3D borders
width += 2 * WidthText(fontText, TEXT(" ")); // Allow a bit of space
}
if (check) {
height = 16 + 3 * 2;
width = 16 + 3 * 2;
}
GUI::Window w;
w.SetID(::CreateWindowEx(0, TEXT("Button"), localised.c_str(),
WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS |
(check ? (BS_AUTOCHECKBOX | BS_PUSHLIKE | BS_BITMAP) : BS_PUSHBUTTON),
2, 2, width, height,
Hwnd(), reinterpret_cast<HMENU>(ident), ::GetModuleHandle(NULL), 0));
if (check) {
int resNum = IDBM_WORD;
switch (ident) {
case IDWHOLEWORD: resNum = IDBM_WORD; break;
case IDMATCHCASE: resNum = IDBM_CASE; break;
case IDREGEXP: resNum = IDBM_REGEX; break;
case IDUNSLASH: resNum = IDBM_BACKSLASH; break;
case IDWRAP: resNum = IDBM_AROUND; break;
case IDDIRECTIONUP: resNum = IDBM_UP; break;
}
UINT flags = (GetVersion(TEXT("COMCTL32")) >= PACKVERSION(6,0)) ?
(LR_DEFAULTSIZE) : (LR_DEFAULTSIZE|LR_LOADMAP3DCOLORS);
HBITMAP bm = static_cast<HBITMAP>(::LoadImage(
::GetModuleHandle(NULL), MAKEINTRESOURCE(resNum), IMAGE_BITMAP,
16, 16, flags));
::SendMessage(reinterpret_cast<HWND>(w.GetID()),
BM_SETIMAGE, IMAGE_BITMAP, reinterpret_cast<LPARAM>(bm));
}
SetFontHandle(w, fontText);
w.Show();
#ifdef BCM_GETIDEALSIZE
if (!check) {
// Push buttons can be measured with BCM_GETIDEALSIZE
SIZE sz = {0, 0};
::SendMessage(reinterpret_cast<HWND>(w.GetID()),
BCM_GETIDEALSIZE, 0, reinterpret_cast<LPARAM>(&sz));
if (sz.cx > 0) {
GUI::Rectangle rc(0,0, sz.cx + 2 * WidthText(fontText, TEXT(" ")), sz.cy);
w.SetPosition(rc);
}
}
#endif
TOOLINFO toolInfo;
memset(&toolInfo, 0, sizeof(toolInfo));
toolInfo.cbSize = sizeof(toolInfo);
toolInfo.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
toolInfo.hinst = ::GetModuleHandle(NULL);
toolInfo.hwnd = Hwnd();
toolInfo.uId = (UINT_PTR)w.GetID();
toolInfo.lpszText = LPSTR_TEXTCALLBACK;
::GetClientRect(Hwnd(), &toolInfo.rect);
::SendMessageW(static_cast<HWND>(wToolTip.GetID()), TTM_ADDTOOLW,
0, (LPARAM) &toolInfo);
::SendMessage(static_cast<HWND>(wToolTip.GetID()), TTM_ACTIVATE, TRUE, 0);
return w;
}
void Strip::Tab(bool forwards) {
HWND wToFocus = ::GetNextDlgTabItem(Hwnd(), ::GetFocus(), !forwards);
if (wToFocus)
::SetFocus(wToFocus);
}
void Strip::Creation() {
// Use the message box font for the strip's font
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(ncm);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, FALSE);
fontText = ::CreateFontIndirect(&ncm.lfMessageFont);
wToolTip = ::CreateWindowEx(0,
TOOLTIPS_CLASSW, NULL,
WS_POPUP | TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
Hwnd(), NULL, ::GetModuleHandle(NULL), NULL);
SetTheme();
}
void Strip::Destruction() {
if (fontText)
::DeleteObject(fontText);
fontText = 0;
#ifdef THEME_AVAILABLE
if (hTheme)
::CloseThemeData(hTheme);
#endif
hTheme = 0;
}
void Strip::Close() {
visible = false;
}
bool Strip::KeyDown(WPARAM key) {
if (!visible)
return false;
switch (key) {
case VK_MENU:
::SendMessage(Hwnd(), WM_UPDATEUISTATE, (UISF_HIDEACCEL|UISF_HIDEFOCUS) << 16 | UIS_CLEAR, 0);
return false;
case VK_TAB:
if (IsChild(Hwnd(), ::GetFocus())) {
::SendMessage(Hwnd(), WM_UPDATEUISTATE, (UISF_HIDEACCEL|UISF_HIDEFOCUS) << 16 | UIS_CLEAR, 0);
Tab((::GetKeyState(VK_SHIFT) & 0x80000000) == 0);
return true;
} else {
return false;
}
case VK_ESCAPE:
Close();
return true;
default:
if ((::GetKeyState(VK_MENU) & 0x80000000) != 0) {
HWND wChild = ::GetWindow(Hwnd(), GW_CHILD);
while (wChild) {
enum { capSize = 2000 };
GUI::gui_char className[capSize];
::GetClassName(wChild, className, capSize);
if ((wcscmp(className, TEXT("Button")) == 0) ||
(wcscmp(className, TEXT("Static")) == 0)) {
GUI::gui_char caption[capSize];
::GetWindowText(wChild, caption, capSize);
for (int i=0; caption[i]; i++) {
if ((caption[i] == L'&') && (toupper(caption[i+1]) == static_cast<int>(key))) {
if (wcscmp(className, TEXT("Button")) == 0) {
::SendMessage(wChild, BM_CLICK, 0, 0);
} else { // Static caption
wChild = ::GetWindow(wChild, GW_HWNDNEXT);
::SetFocus(wChild);
}
return true;
}
}
}
wChild = ::GetWindow(wChild, GW_HWNDNEXT);
};
}
}
return false;
}
bool Strip::Command(WPARAM) {
return false;
}
void Strip::Size() {
}
void Strip::Paint(HDC hDC) {
GUI::Rectangle rcStrip = GetClientPosition();
RECT rc = {rcStrip.left, rcStrip.top, rcStrip.right, rcStrip.bottom};
HBRUSH hbrFace = CreateSolidBrush(::GetSysColor(COLOR_3DFACE));
::FillRect(hDC, &rc, hbrFace);
::DeleteObject(hbrFace);
if (HasClose()){
// Draw close box
GUI::Rectangle rcClose = CloseArea();
if (hTheme) {
#ifdef THEME_AVAILABLE
int closeAppearence = CBS_NORMAL;
if (closeState == csOver) {
closeAppearence = CBS_HOT;
} else if (closeState == csClickedOver) {
closeAppearence = CBS_PUSHED;
}
//DrawThemeBackground(htheme, hDC, WP_CLOSEBUTTON, closeAppearence,
// reinterpret_cast<RECT *>(&rcClose), reinterpret_cast<RECT *>(&rcClose));
::DrawThemeBackground(hTheme, hDC, WP_SMALLCLOSEBUTTON, closeAppearence,
reinterpret_cast<RECT *>(&rcClose), NULL);
//::DrawThemeBackground(hTheme, hDC, WP_MDICLOSEBUTTON, closeAppearence,
// reinterpret_cast<RECT *>(&rcClose), NULL);
#endif
} else {
int closeAppearence = 0;
if (closeState == csOver) {
closeAppearence = DFCS_HOT;
} else if (closeState == csClickedOver) {
closeAppearence = DFCS_PUSHED;
}
DrawFrameControl(hDC, reinterpret_cast<RECT *>(&rcClose), DFC_CAPTION,
DFCS_CAPTIONCLOSE | closeAppearence);
}
}
}
bool Strip::HasClose() const {
return true;
}
GUI::Rectangle Strip::CloseArea() {
if (HasClose()) {
GUI::Rectangle rcClose = GetClientPosition();
rcClose.right -= 2;
rcClose.left = rcClose.right - closeSize.cx;
rcClose.top += 2;
rcClose.bottom = rcClose.top + closeSize.cy;
return rcClose;
} else {
return GUI::Rectangle(-1,-1,-1,-1);
}
}
void Strip::InvalidateClose() {
GUI::Rectangle rcClose = CloseArea();
RECT rc = {
rcClose.left,
rcClose.top,
rcClose.right,
rcClose.bottom};
::InvalidateRect(Hwnd(), &rc, TRUE);
}
bool Strip::MouseInClose(GUI::Point pt) {
GUI::Rectangle rcClose = CloseArea();
return rcClose.Contains(pt);
}
void Strip::TrackMouse(GUI::Point pt) {
stripCloseState closeStateStart = closeState;
if (MouseInClose(pt)) {
if (closeState == csNone)
closeState = csOver;
if (closeState == csClicked)
closeState = csClickedOver;
} else {
if (closeState == csOver)
closeState = csNone;
if (closeState == csClickedOver)
closeState = csClicked;
}
if ((closeState != csNone) && !capturedMouse) {
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = Hwnd();
TrackMouseEvent(&tme);
}
if (closeStateStart != closeState)
InvalidateClose();
}
void Strip::SetTheme() {
#ifdef THEME_AVAILABLE
if (hTheme)
::CloseThemeData(hTheme);
hTheme = ::OpenThemeData(Hwnd(), TEXT("Window"));
if (hTheme) {
HRESULT hr = ::GetThemePartSize(hTheme, NULL, WP_SMALLCLOSEBUTTON, CBS_NORMAL,
NULL, TS_TRUE, &closeSize);
//HRESULT hr = ::GetThemePartSize(hTheme, NULL, WP_MDICLOSEBUTTON, CBS_NORMAL,
// NULL, TS_TRUE, &closeSize);
if (!SUCCEEDED(hr)) {
closeSize.cx = 11;
closeSize.cy = 11;
}
}
#endif
}
static bool HideKeyboardCues() {
BOOL b=FALSE;
if (::SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &b, 0) == 0)
return FALSE;
return !b;
}
LRESULT Strip::CustomDraw(NMHDR *pnmh) {
int btnStyle = ::GetWindowLong(pnmh->hwndFrom, GWL_STYLE);
if ((btnStyle & BS_AUTOCHECKBOX) != BS_AUTOCHECKBOX) {
return CDRF_DODEFAULT;
}
#ifdef THEME_AVAILABLE
LPNMCUSTOMDRAW pcd = reinterpret_cast<LPNMCUSTOMDRAW>(pnmh);
if (pcd->dwDrawStage == CDDS_PREERASE) {
::DrawThemeParentBackground(pnmh->hwndFrom, pcd->hdc, &pcd->rc);
}
if ((pcd->dwDrawStage == CDDS_PREERASE) || (pcd->dwDrawStage == CDDS_PREPAINT)) {
HTHEME hThemeButton = ::OpenThemeData(pnmh->hwndFrom, TEXT("Toolbar"));
if (!hThemeButton) {
return CDRF_DODEFAULT;
}
bool checked = ::SendMessage(pnmh->hwndFrom, BM_GETCHECK, 0, 0) == BST_CHECKED;
int buttonAppearence = checked ? TS_CHECKED : TS_NORMAL;
if (pcd->uItemState & CDIS_SELECTED)
buttonAppearence = TS_PRESSED;
else if (pcd->uItemState & CDIS_HOT)
buttonAppearence = checked ? TS_HOTCHECKED : TS_HOT;
HBRUSH hbrFace = CreateSolidBrush(::GetSysColor(COLOR_3DFACE));
::FillRect(pcd->hdc, &pcd->rc, hbrFace);
::DeleteObject(hbrFace);
::DrawThemeBackground(hThemeButton, pcd->hdc, TP_BUTTON, buttonAppearence,
&pcd->rc, NULL);
RECT rcButton = pcd->rc;
rcButton.bottom--;
HRESULT hr = ::GetThemeBackgroundContentRect(hThemeButton, pcd->hdc, TP_BUTTON,
buttonAppearence, &pcd->rc, &rcButton);
if (!SUCCEEDED(hr)) {
return CDRF_DODEFAULT;
}
HBITMAP hBitmap = reinterpret_cast<HBITMAP>(::SendMessage(
pnmh->hwndFrom, BM_GETIMAGE, IMAGE_BITMAP, 0));
// Retrieve the bitmap dimensions
BITMAPINFO rbmi;
memset(&rbmi, 0, sizeof (BITMAPINFO));
rbmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
::GetDIBits(pcd->hdc, hBitmap, 0, 0, NULL, &rbmi, DIB_RGB_COLORS);
DWORD colourTransparent = RGB(0xC0,0xC0,0xC0);
// Offset from button edge to contents.
int xOffset = ((rcButton.right - rcButton.left) - rbmi.bmiHeader.biWidth) / 2 + 1;
int yOffset = ((rcButton.bottom - rcButton.top) - rbmi.bmiHeader.biHeight) / 2;
HDC hdcBM = ::CreateCompatibleDC(NULL);
HBITMAP hbmOriginal = static_cast<HBITMAP>(::SelectObject(hdcBM, hBitmap));
::TransparentBlt(reinterpret_cast<HDC>(pcd->hdc), xOffset, yOffset,
rbmi.bmiHeader.biWidth, rbmi.bmiHeader.biHeight,
hdcBM, 0, 0, rbmi.bmiHeader.biWidth, rbmi.bmiHeader.biHeight, colourTransparent);
::SelectObject(hdcBM, hbmOriginal);
::DeleteDC(hdcBM);
if (pcd->uItemState & CDIS_FOCUS) {
// Draw focus rectangle
rcButton.left += 2;
rcButton.top += 3;
rcButton.right -= 2;
rcButton.bottom -= 3;
::DrawFocusRect(pcd->hdc, &rcButton);
}
::CloseThemeData(hThemeButton);
return CDRF_SKIPDEFAULT;
}
#endif
return CDRF_DODEFAULT;
}
LRESULT Strip::WndProc(UINT iMessage, WPARAM wParam, LPARAM lParam) {
switch (iMessage) {
case WM_CREATE:
Creation();
return ::DefWindowProc(Hwnd(), iMessage, wParam, lParam);
case WM_DESTROY:
Destruction();
return ::DefWindowProc(Hwnd(), iMessage, wParam, lParam);
case WM_COMMAND:
if (Command(wParam))
return 0;
else
return ::DefWindowProc(Hwnd(), iMessage, wParam, lParam);
case WM_SETCURSOR:
::SetCursor(::LoadCursor(NULL, IDC_ARROW));
break;
case WM_SIZE:
Size();
break;
case WM_WINDOWPOSCHANGED:
if ((reinterpret_cast<WINDOWPOS *>(lParam)->flags & SWP_SHOWWINDOW) && HideKeyboardCues())
::SendMessage(Hwnd(), WM_UPDATEUISTATE, (UISF_HIDEACCEL|UISF_HIDEFOCUS) << 16 | UIS_SET, 0);
return ::DefWindowProc(Hwnd(), iMessage, wParam, lParam);
case WM_PAINT: {
PAINTSTRUCT ps;
::BeginPaint(Hwnd(), &ps);
Paint(ps.hdc);
::EndPaint(Hwnd(), &ps);
return 0;
}
#ifdef THEME_AVAILABLE
case WM_THEMECHANGED:
SetTheme();
break;
#endif
case WM_LBUTTONDOWN:
if (MouseInClose(PointFromLong(lParam))) {
closeState = csClickedOver;
InvalidateClose();
capturedMouse = true;
::SetCapture(Hwnd());
}
break;
case WM_MOUSEMOVE:
TrackMouse(PointFromLong(lParam));
break;
case WM_LBUTTONUP:
if (capturedMouse) {
if (MouseInClose(PointFromLong(lParam))) {
Close();
}
capturedMouse = false;
closeState = csNone;
InvalidateClose();
::ReleaseCapture();
}
break;
case WM_MOUSELEAVE:
if (!capturedMouse) {
closeState = csNone;
InvalidateClose();
}
break;
case WM_NOTIFY: {
NMHDR *pnmh = reinterpret_cast<LPNMHDR>(lParam);
if (pnmh->code == static_cast<unsigned int>(NM_CUSTOMDRAW)) {
return CustomDraw(pnmh);
} else if (pnmh->code == static_cast<unsigned int>(TTN_GETDISPINFO)) {
NMTTDISPINFOW *pnmtdi = (LPNMTTDISPINFO) lParam;
int idButton = static_cast<int>(
(pnmtdi->uFlags & TTF_IDISHWND) ?
::GetDlgCtrlID(reinterpret_cast<HWND>(pnmtdi->hdr.idFrom)) : pnmtdi->hdr.idFrom);
for (size_t i=0; toggles[i].label; i++) {
if (toggles[i].id == idButton) {
GUI::gui_string localised = localiser->Text(toggles[i].label);
StringCopy(pnmtdi->szText, localised.c_str());
}
}
return 0;
} else {
return ::DefWindowProc(Hwnd(), iMessage, wParam, lParam);
}
}
default:
return ::DefWindowProc(Hwnd(), iMessage, wParam, lParam);
}
return 0l;
}
void BackgroundStrip::Creation() {
Strip::Creation();
wExplanation = ::CreateWindowEx(0, TEXT("Static"), TEXT(""),
WS_CHILD | WS_CLIPSIBLINGS,
2, 2, 100, 21,
Hwnd(), reinterpret_cast<HMENU>(0), ::GetModuleHandle(NULL), 0);
wExplanation.Show();
SetFontHandle(wExplanation, fontText);
wProgress = ::CreateWindowEx(0, PROGRESS_CLASS, TEXT(""),
WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
2, 2, 100, 21,
Hwnd(), reinterpret_cast<HMENU>(0), ::GetModuleHandle(NULL), 0);
}
void BackgroundStrip::Destruction() {
Strip::Destruction();
}
void BackgroundStrip::Close() {
entered++;
::SetWindowText(HwndOf(wExplanation), TEXT(""));
entered--;
Strip::Close();
}
void BackgroundStrip::Size() {
if (!visible)
return;
Strip::Size();
GUI::Rectangle rcArea = GetPosition();
rcArea.bottom -= rcArea.top;
rcArea.right -= rcArea.left;
rcArea.left = 2;
rcArea.top = 2;
rcArea.right -= 2;
rcArea.bottom -= 2;
rcArea.right -= closeSize.cx + 2; // Allow for close box and gap
const int progWidth = 200;
GUI::Rectangle rcProgress = rcArea;
rcProgress.right = rcProgress.left + progWidth;
wProgress.SetPosition(rcProgress);
GUI::Rectangle rcExplanation = rcArea;
rcExplanation.left += progWidth + 8;
rcExplanation.top -= 1;
rcExplanation.bottom += 1;
wExplanation.SetPosition(rcExplanation);
::InvalidateRect(Hwnd(), NULL, TRUE);
}
bool BackgroundStrip::HasClose() const {
return false;
}
void BackgroundStrip::Focus() {
::SetFocus(HwndOf(wExplanation));
}
bool BackgroundStrip::KeyDown(WPARAM key) {
if (!visible)
return false;
if (Strip::KeyDown(key))
return true;
return false;
}
bool BackgroundStrip::Command(WPARAM /* wParam */) {
return false;
}
LRESULT BackgroundStrip::WndProc(UINT iMessage, WPARAM wParam, LPARAM lParam) {
try {
return Strip::WndProc(iMessage, wParam, lParam);
} catch (...) {
}
return 0l;
}
void BackgroundStrip::SetProgress(const GUI::gui_string &explanation, int size, int progress) {
if (explanation != ControlGText(wExplanation)) {
::SetWindowTextW(HwndOf(wExplanation), explanation.c_str());
}
::SendMessage(HwndOf(wProgress), PBM_SETRANGE32, 0, size);
::SendMessage(HwndOf(wProgress), PBM_SETPOS, progress, 0);
}
void SearchStrip::Creation() {
Strip::Creation();
wStaticFind = CreateText(textFindPrompt);
wText = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("Edit"), TEXT(""),
WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
50, 2, 300, 21,
Hwnd(), reinterpret_cast<HMENU>(IDC_INCFINDTEXT), ::GetModuleHandle(NULL), 0);
wText.Show();
SetFontHandle(wText, fontText);
wButton = CreateButton(textFindNext, IDC_INCFINDBTNOK);
GUI::Rectangle rcButton = wButton.GetPosition();
lineHeight = rcButton.Height() + 3;
}
void SearchStrip::Destruction() {
Strip::Destruction();
}
void SearchStrip::SetSearcher(Searcher *pSearcher_) {
pSearcher = pSearcher_;
}
void SearchStrip::Close() {
entered++;
::SetWindowText(HwndOf(wText), TEXT(""));
entered--;
Strip::Close();
pSearcher->UIClosed();
}
void SearchStrip::Size() {
if (!visible)
return;
Strip::Size();
GUI::Rectangle rcArea = GetPosition();
rcArea.bottom -= rcArea.top;
rcArea.right -= rcArea.left;
rcArea.left = 2;
rcArea.top = 2;
rcArea.right -= 2;
rcArea.bottom -= 2;
rcArea.right -= closeSize.cx + 2; // Allow for close box and gap
GUI::Rectangle rcButton = rcArea;
rcButton.top -= 1;
rcButton.bottom += 1;
rcButton.left = rcButton.right - WidthControl(wButton);
wButton.SetPosition(rcButton);
GUI::Rectangle rcText = rcArea;
rcText.left = WidthControl(wStaticFind) + 8;
rcText.right = rcButton.left - 4;
wText.SetPosition(rcText);
rcText.right = rcText.left - 4;
rcText.left = 4;
rcText.top = rcArea.top + 3;
wStaticFind.SetPosition(rcText);
::InvalidateRect(Hwnd(), NULL, TRUE);
}
void SearchStrip::Paint(HDC hDC) {
Strip::Paint(hDC);
}
void SearchStrip::Focus() {
::SetFocus(HwndOf(wText));
}
bool SearchStrip::KeyDown(WPARAM key) {
if (!visible)
return false;
if (Strip::KeyDown(key))
return true;
if (key == VK_RETURN) {
if (IsChild(Hwnd(), ::GetFocus())) {
Next(false);
return true;
}
}
return false;
}
void SearchStrip::Next(bool select) {
SString ffLastWhat = pSearcher->findWhat;
pSearcher->findWhat = ControlText(wText);
if (select) {
if (ffLastWhat.length()) {
pSearcher->MoveBack(static_cast<int>(ffLastWhat.length()));
}
}
pSearcher->wholeWord = false;
if (pSearcher->FindHasText())
pSearcher->FindNext(false, false);
if ((!pSearcher->havefound) &&
strncmp(pSearcher->findWhat.c_str(), ffLastWhat.c_str(), ffLastWhat.length()) == 0) {
// Could not find string with added character so revert to previous value.
pSearcher->findWhat = ffLastWhat;
entered++;
GUI::gui_string gsPrevious = GUI::StringFromUTF8(ffLastWhat.c_str());
::SetWindowText(HwndOf(wText), gsPrevious.c_str());
::SendMessage(HwndOf(wText), EM_SETSEL, gsPrevious.length(), gsPrevious.length());
entered--;
}
}
bool SearchStrip::Command(WPARAM wParam) {
if (entered)
return false;
int control = ControlIDOfWParam(wParam);
int subCommand = static_cast<int>(wParam >> 16);
if (((control == IDC_INCFINDTEXT) && (subCommand == EN_CHANGE)) ||
(control == IDC_INCFINDBTNOK)) {
Next(control != IDC_INCFINDBTNOK);
return true;
}
return false;
}
LRESULT SearchStrip::WndProc(UINT iMessage, WPARAM wParam, LPARAM lParam) {
try {
return Strip::WndProc(iMessage, wParam, lParam);
/*
switch (iMessage) {
default:
}
*/
} catch (...) {
}
return 0l;
}
void FindStrip::Creation() {
Strip::Creation();
wStaticFind = CreateText(textFindPrompt);
wText = CreateWindowEx(0, TEXT("ComboBox"), TEXT(""),
WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | CBS_DROPDOWN | CBS_AUTOHSCROLL,
50, 2, 300, 80,
Hwnd(), reinterpret_cast<HMENU>(IDFINDWHAT), ::GetModuleHandle(NULL), 0);
SetFontHandle(wText, fontText);
wText.Show();
GUI::Rectangle rcCombo = wText.GetPosition();
lineHeight = rcCombo.Height() + 3;
wButton = CreateButton(textFindNext, IDOK);
wButtonMarkAll = CreateButton(textMarkAll, IDMARKALL);
wCheckWord = CreateButton(toggles[SearchOption::tWord].label, toggles[SearchOption::tWord].id, true);
wCheckCase = CreateButton(toggles[SearchOption::tCase].label, toggles[SearchOption::tCase].id, true);
wCheckRE = CreateButton(toggles[SearchOption::tRegExp].label, toggles[SearchOption::tRegExp].id, true);
wCheckBE = CreateButton(toggles[SearchOption::tBackslash].label, toggles[SearchOption::tBackslash].id, true);
wCheckWrap = CreateButton(toggles[SearchOption::tWrap].label, toggles[SearchOption::tWrap].id, true);
wCheckUp = CreateButton(toggles[SearchOption::tUp].label, toggles[SearchOption::tUp].id, true);
}
void FindStrip::Destruction() {
Strip::Destruction();
}
void FindStrip::SetSearcher(Searcher *pSearcher_) {
pSearcher = pSearcher_;
}
void FindStrip::Size() {
if (!visible)
return;
Strip::Size();
GUI::Rectangle rcArea = GetPosition();
rcArea.bottom -= rcArea.top;
rcArea.right -= rcArea.left;
rcArea.left = 2;
rcArea.top = 2;
rcArea.right -= 2;
rcArea.bottom -= 2;
rcArea.right -= closeSize.cx + 2; // Allow for close box and gap
GUI::Rectangle rcButton = rcArea;
rcButton.top -= 1;
rcButton.bottom += 1;
int checkWidth = rcButton.Height() - 2; // Using height to make square
rcButton.left = rcButton.right - checkWidth;
wCheckUp.SetPosition(rcButton);
rcButton.right = rcButton.left - 4;
rcButton.left = rcButton.right - checkWidth;
wCheckWrap.SetPosition(rcButton);
rcButton.right = rcButton.left - 4;
rcButton.left = rcButton.right - checkWidth;
wCheckBE.SetPosition(rcButton);
rcButton.right = rcButton.left - 4;
rcButton.left = rcButton.right - checkWidth;
wCheckRE.SetPosition(rcButton);
rcButton.right = rcButton.left - 4;
rcButton.left = rcButton.right - checkWidth;
wCheckCase.SetPosition(rcButton);
rcButton.right = rcButton.left - 4;
rcButton.left = rcButton.right - checkWidth;
wCheckWord.SetPosition(rcButton);
rcButton.right = rcButton.left - 4;
rcButton.left = rcButton.right - WidthControl(wButtonMarkAll);
wButtonMarkAll.SetPosition(rcButton);
rcButton.right = rcButton.left - 4;
rcButton.left = rcButton.right - WidthControl(wButton);
wButton.SetPosition(rcButton);
GUI::Rectangle rcText = rcArea;
rcText.bottom += 60;
rcText.left = WidthControl(wStaticFind) + 8;
rcText.right = rcButton.left - 4;
wText.SetPosition(rcText);
wText.Show();
rcText.right = rcText.left - 4;
rcText.left = 4;
rcText.top = rcArea.top + 3;
wStaticFind.SetPosition(rcText);
::InvalidateRect(Hwnd(), NULL, TRUE);
}
void FindStrip::Paint(HDC hDC) {
Strip::Paint(hDC);
}
void FindStrip::Focus() {
::SetFocus(HwndOf(wText));
}
void FindStrip::Close() {
Strip::Close();
pSearcher->UIClosed();
}
bool FindStrip::KeyDown(WPARAM key) {
if (!visible)
return false;
if (Strip::KeyDown(key))
return true;
switch (key) {
case VK_RETURN:
if (IsChild(Hwnd(), ::GetFocus())) {
Next(false, IsKeyDown(VK_SHIFT));
return true;
}
}
return false;
}
void FindStrip::Next(bool markAll, bool invertDirection) {
pSearcher->SetFind(ControlText(wText).c_str());
if (markAll){
pSearcher->MarkAll();
}
pSearcher->FindNext(pSearcher->reverseFind ^ invertDirection);
if (pSearcher->closeFind) {
visible = false;
pSearcher->UIClosed();
}
}
void FindStrip::AddToPopUp(GUI::Menu &popup, const char *label, int cmd, bool checked) {
GUI::gui_string localised = localiser->Text(label);
HMENU menu = reinterpret_cast<HMENU>(popup.GetID());
if (0 == localised.length())
::AppendMenu(menu, MF_SEPARATOR, 0, TEXT(""));
else
::AppendMenu(menu, MF_STRING | (checked ? MF_CHECKED : 0), cmd, localised.c_str());
}
void FindStrip::ShowPopup() {
GUI::Menu popup;
popup.CreatePopUp();
for (int i=SearchOption::tWord; i<=SearchOption::tUp; i++) {
AddToPopUp(popup, toggles[i].label, toggles[i].cmd, pSearcher->FlagFromCmd(toggles[i].cmd));
}
GUI::Rectangle rcButton = wButton.GetPosition();
GUI::Point pt(rcButton.left, rcButton.bottom);
popup.Show(pt, *this);
}
bool FindStrip::Command(WPARAM wParam) {
if (entered)
return false;
int control = ControlIDOfWParam(wParam);
if ((control == IDOK) || (control == IDMARKALL)) {
Next(control == IDMARKALL, false);
return true;
} else {
pSearcher->FlagFromCmd(control) = !pSearcher->FlagFromCmd(control);
}
return false;
}
LRESULT FindStrip::WndProc(UINT iMessage, WPARAM wParam, LPARAM lParam) {
try {
switch (iMessage) {
case WM_CONTEXTMENU:
ShowPopup();
return 0;
default:
return Strip::WndProc(iMessage, wParam, lParam);
}
} catch (...) {
}
return 0l;
}
void FindStrip::CheckButtons() {
entered++;
::SendMessage(reinterpret_cast<HWND>(wCheckWord.GetID()),
BM_SETCHECK, pSearcher->wholeWord ? BST_CHECKED : BST_UNCHECKED, 0);
::SendMessage(reinterpret_cast<HWND>(wCheckCase.GetID()),
BM_SETCHECK, pSearcher->matchCase ? BST_CHECKED : BST_UNCHECKED, 0);
::SendMessage(reinterpret_cast<HWND>(wCheckRE.GetID()),
BM_SETCHECK, pSearcher->regExp ? BST_CHECKED : BST_UNCHECKED, 0);
::SendMessage(reinterpret_cast<HWND>(wCheckWrap.GetID()),
BM_SETCHECK, pSearcher->wrapFind ? BST_CHECKED : BST_UNCHECKED, 0);
::SendMessage(reinterpret_cast<HWND>(wCheckBE.GetID()),
BM_SETCHECK, pSearcher->unSlash ? BST_CHECKED : BST_UNCHECKED, 0);
entered--;
}
void FindStrip::Show() {
Focus();
HWND combo = GetDlgItem(Hwnd(), IDFINDWHAT);
::SendMessage(combo, CB_RESETCONTENT, 0, 0);
for (int i = 0; i < pSearcher->memFinds.Length(); i++) {
GUI::gui_string gs = GUI::StringFromUTF8(pSearcher->memFinds.At(i).c_str());
::SendMessageW(combo, CB_ADDSTRING, 0,
reinterpret_cast<LPARAM>(gs.c_str()));
}
//::SendMessage(combo, CB_SETCURSEL, 0, 0);
::SetWindowText(HwndOf(wText), GUI::StringFromUTF8(pSearcher->findWhat.c_str()).c_str());
::SendMessage(HwndOf(wText), CB_SETEDITSEL, 0, MAKELPARAM(0, -1));
CheckButtons();
pSearcher->ScrollEditorIfNeeded();
}
void ReplaceStrip::Creation() {
Strip::Creation();
lineHeight = 23;
wStaticFind = CreateText(textFindPrompt);
wText = CreateWindowEx(0, TEXT("ComboBox"), TEXT(""),
WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | CBS_DROPDOWN | CBS_AUTOHSCROLL,
50, 2, 300, 80,
Hwnd(), reinterpret_cast<HMENU>(IDFINDWHAT), ::GetModuleHandle(NULL), 0);
SetFontHandle(wText, fontText);
wText.Show();
GUI::Rectangle rcCombo = wText.GetPosition();
lineHeight = rcCombo.Height() + 3;
wStaticReplace = CreateText(textReplacePrompt);
wReplace = CreateWindowEx(0, TEXT("ComboBox"), TEXT(""),
WS_CHILD | WS_TABSTOP | CBS_DROPDOWN | CBS_AUTOHSCROLL,
50, 2, 300, 80,
Hwnd(), reinterpret_cast<HMENU>(IDREPLACEWITH), ::GetModuleHandle(NULL), 0);
SetFontHandle(wReplace, fontText);
wReplace.Show();
wButtonFind = CreateButton(textFindNext, IDOK);
wButtonReplace = CreateButton(textReplace, IDREPLACE);
wButtonReplaceAll = CreateButton(textReplaceAll, IDREPLACEALL);
wButtonReplaceInSelection = CreateButton(textInSelection, IDREPLACEINSEL);
wCheckWord = CreateButton(toggles[SearchOption::tWord].label, toggles[SearchOption::tWord].id, true);
wCheckRE = CreateButton(toggles[SearchOption::tRegExp].label, toggles[SearchOption::tRegExp].id, true);
wCheckCase = CreateButton(toggles[SearchOption::tCase].label, toggles[SearchOption::tCase].id, true);
wCheckBE = CreateButton(toggles[SearchOption::tBackslash].label, toggles[SearchOption::tBackslash].id, true);
wCheckWrap = CreateButton(toggles[SearchOption::tWrap].label, toggles[SearchOption::tWrap].id, true);
}
void ReplaceStrip::Destruction() {
Strip::Destruction();
}
void ReplaceStrip::SetSearcher(Searcher *pSearcher_) {
pSearcher = pSearcher_;
}
void ReplaceStrip::Size() {
if (!visible)
return;
Strip::Size();
GUI::Rectangle rcArea = GetPosition();
int widthCaption = Maximum(WidthControl(wStaticFind), WidthControl(wStaticReplace));
rcArea.bottom -= rcArea.top;
rcArea.right -= rcArea.left;
rcArea.left = 2;
rcArea.top = 2;
rcArea.right -= 2;
rcArea.bottom -= 4;
rcArea.right -= closeSize.cx + 2; // Allow for close box and gap
GUI::Rectangle rcLine = rcArea;
rcLine.bottom = rcLine.top + lineHeight - 2;
int widthButtons = Maximum(WidthControl(wButtonFind), WidthControl(wButtonReplace));
int widthLastButtons = Maximum(WidthControl(wButtonReplaceAll), WidthControl(wButtonReplaceInSelection));
GUI::Rectangle rcButton = rcLine;
rcButton.top -= 1;
int checkWidth = rcButton.Height() - 2; // Using height to make square
// Allow empty slot to match wrap button on next line
rcButton.right = rcButton.right - (checkWidth + 4);
rcButton.left = rcButton.right - checkWidth;
wCheckCase.SetPosition(rcButton);
rcButton.right = rcButton.left - 4;
rcButton.left = rcButton.right - checkWidth;
wCheckWord.SetPosition(rcButton);
rcButton.right = rcButton.left - 4;
rcButton.left = rcButton.right - widthLastButtons;
wButtonReplaceAll.SetPosition(rcButton);
rcButton.right = rcButton.left - 4;
rcButton.left = rcButton.right - widthButtons;
wButtonFind.SetPosition(rcButton);
GUI::Rectangle rcText = rcLine;
rcText.bottom += 60;
rcText.left = widthCaption + 8;
rcText.right = rcButton.left - 4;
wText.SetPosition(rcText);
GUI::Rectangle rcStatic = rcLine;
rcStatic.right = rcText.left - 4;
rcStatic.left = 4;
rcStatic.top = rcLine.top + 3;
wStaticFind.SetPosition(rcStatic);
rcLine.top = rcLine.top + lineHeight;
rcLine.bottom = rcLine.bottom + lineHeight;
rcButton = rcLine;
rcButton.top -= 1;
rcButton.left = rcButton.right - checkWidth;
wCheckWrap.SetPosition(rcButton);
rcButton.right = rcButton.left - 4;
rcButton.left = rcButton.right - checkWidth;
wCheckBE.SetPosition(rcButton);
rcButton.right = rcButton.left - 4;
rcButton.left = rcButton.right - checkWidth;
wCheckRE.SetPosition(rcButton);
rcButton.right = rcButton.left - 4;
rcButton.left = rcButton.right - widthLastButtons;
wButtonReplaceInSelection.SetPosition(rcButton);
rcButton.right = rcButton.left - 4;
rcButton.left = rcButton.right - widthButtons;
wButtonReplace.SetPosition(rcButton);
GUI::Rectangle rcReplace = rcLine;
rcReplace.bottom += 60;
rcReplace.left = rcText.left;
rcReplace.right = rcText.right;
wReplace.SetPosition(rcReplace);
rcStatic = rcLine;
rcStatic.right = rcReplace.left - 4;
rcStatic.left = 4;
rcStatic.top = rcLine.top + 3;
wStaticReplace.SetPosition(rcStatic);
::InvalidateRect(Hwnd(), NULL, TRUE);
}
void ReplaceStrip::Paint(HDC hDC) {
Strip::Paint(hDC);
}
void ReplaceStrip::Focus() {
::SetFocus(HwndOf(wText));
}
void ReplaceStrip::Close() {
Strip::Close();
pSearcher->UIClosed();
}
static bool IsSameOrChild(GUI::Window &wParent, HWND wChild) {
HWND hwnd = reinterpret_cast<HWND>(wParent.GetID());
return (wChild == hwnd) || IsChild(hwnd, wChild);
}
bool ReplaceStrip::KeyDown(WPARAM key) {
if (!visible)
return false;
if (Strip::KeyDown(key))
return true;
switch (key) {
case VK_RETURN:
if (IsChild(Hwnd(), ::GetFocus())) {
if (IsSameOrChild(wButtonFind, ::GetFocus()))
HandleReplaceCommand(IDOK, IsKeyDown(VK_SHIFT));
else if (IsSameOrChild(wReplace, ::GetFocus()))
HandleReplaceCommand(IDOK, IsKeyDown(VK_SHIFT));
else if (IsSameOrChild(wButtonReplace, ::GetFocus()))
HandleReplaceCommand(IDREPLACE);
else if (IsSameOrChild(wButtonReplaceAll, ::GetFocus()))
HandleReplaceCommand(IDREPLACEALL);
else if (IsSameOrChild(wButtonReplaceInSelection, ::GetFocus()))
HandleReplaceCommand(IDREPLACEINSEL);
else
HandleReplaceCommand(IDOK, IsKeyDown(VK_SHIFT));
return true;
}
}
return false;
}
void ReplaceStrip::AddToPopUp(GUI::Menu &popup, const char *label, int cmd, bool checked) {
GUI::gui_string localised = localiser->Text(label);
HMENU menu = reinterpret_cast<HMENU>(popup.GetID());
if (0 == localised.length())
::AppendMenu(menu, MF_SEPARATOR, 0, TEXT(""));
else
::AppendMenu(menu, MF_STRING | (checked ? MF_CHECKED : 0), cmd, localised.c_str());
}
void ReplaceStrip::ShowPopup() {
GUI::Menu popup;
popup.CreatePopUp();
for (int i=SearchOption::tWord; i<=SearchOption::tWrap; i++) {
AddToPopUp(popup, toggles[i].label, toggles[i].cmd, pSearcher->FlagFromCmd(toggles[i].cmd));
}
GUI::Rectangle rcButton = wCheckWord.GetPosition();
GUI::Point pt(rcButton.left, rcButton.bottom);
popup.Show(pt, *this);
}
void ReplaceStrip::HandleReplaceCommand(int cmd, bool reverseFind) {
pSearcher->SetFind(ControlText(wText).c_str());
if (cmd != IDOK) {
pSearcher->SetReplace(ControlText(wReplace).c_str());
}
//int replacements = 0;
if (cmd == IDOK) {
if (pSearcher->FindHasText()) {
pSearcher->FindNext(reverseFind);
}
} else if (cmd == IDREPLACE) {
pSearcher->ReplaceOnce();
} else if ((cmd == IDREPLACEALL) || (cmd == IDREPLACEINSEL)) {
//~ replacements = pSciTEWin->ReplaceAll(cmd == IDREPLACEINSEL);
pSearcher->ReplaceAll(cmd == IDREPLACEINSEL);
}
//GUI::gui_string replDone = GUI::StringFromInteger(replacements);
//dlg.SetItemText(IDREPLDONE, replDone.c_str());
}
bool ReplaceStrip::Command(WPARAM wParam) {
if (entered)
return false;
int control = ControlIDOfWParam(wParam);
switch (control) {
case IDFINDWHAT:
switch (HIWORD(wParam)) {
case CBN_SETFOCUS:
case CBN_KILLFOCUS:
case CBN_SELENDCANCEL:
return false;
default:
return false;
}
case IDOK:
case IDREPLACEALL:
case IDREPLACE:
case IDREPLACEINSEL:
HandleReplaceCommand(control);
return true;
default:
pSearcher->FlagFromCmd(control) = !pSearcher->FlagFromCmd(control);
break;
}
CheckButtons();
return false;
}
LRESULT ReplaceStrip::WndProc(UINT iMessage, WPARAM wParam, LPARAM lParam) {
try {
switch (iMessage) {
case WM_CONTEXTMENU:
ShowPopup();
return 0;
default:
return Strip::WndProc(iMessage, wParam, lParam);
}
} catch (...) {
}
return 0l;
}
void ReplaceStrip::CheckButtons() {
entered++;
::SendMessage(reinterpret_cast<HWND>(wCheckWord.GetID()),
BM_SETCHECK, pSearcher->wholeWord ? BST_CHECKED : BST_UNCHECKED, 0);
::SendMessage(reinterpret_cast<HWND>(wCheckCase.GetID()),
BM_SETCHECK, pSearcher->matchCase ? BST_CHECKED : BST_UNCHECKED, 0);
::SendMessage(reinterpret_cast<HWND>(wCheckRE.GetID()),
BM_SETCHECK, pSearcher->regExp ? BST_CHECKED : BST_UNCHECKED, 0);
::SendMessage(reinterpret_cast<HWND>(wCheckWrap.GetID()),
BM_SETCHECK, pSearcher->wrapFind ? BST_CHECKED : BST_UNCHECKED, 0);
::SendMessage(reinterpret_cast<HWND>(wCheckBE.GetID()),
BM_SETCHECK, pSearcher->unSlash ? BST_CHECKED : BST_UNCHECKED, 0);
entered--;
}
void ReplaceStrip::Show() {
Focus();
HWND combo = GetDlgItem(Hwnd(), IDFINDWHAT);
::SendMessage(combo, CB_RESETCONTENT, 0, 0);
for (int i = 0; i < pSearcher->memFinds.Length(); i++) {
GUI::gui_string gs = GUI::StringFromUTF8(pSearcher->memFinds.At(i).c_str());
::SendMessageW(combo, CB_ADDSTRING, 0,
reinterpret_cast<LPARAM>(gs.c_str()));
}
//::SendMessage(combo, CB_SETCURSEL, 0, 0);
::SetWindowText(HwndOf(wText), GUI::StringFromUTF8(pSearcher->findWhat.c_str()).c_str());
::SendMessage(HwndOf(wText), CB_SETEDITSEL, 0, MAKELPARAM(0, -1));
HWND comboReplace = GetDlgItem(Hwnd(), IDREPLACEWITH);
::SendMessage(comboReplace, CB_RESETCONTENT, 0, 0);
for (int j = 0; j < pSearcher->memReplaces.Length(); j++) {
GUI::gui_string gs = GUI::StringFromUTF8(pSearcher->memReplaces.At(j).c_str());
::SendMessageW(comboReplace, CB_ADDSTRING, 0,
reinterpret_cast<LPARAM>(gs.c_str()));
}
CheckButtons();
if (pSearcher->FindHasText() != 0 && pSearcher->focusOnReplace) {
::SetFocus(comboReplace);
}
pSearcher->ScrollEditorIfNeeded();
}
void UserStrip::Creation() {
Strip::Creation();
// Combo boxes automatically size to a reasonable height so create a temporary and measure
HWND wComboTest = ::CreateWindowEx(0, TEXT("ComboBox"), TEXT("Aby"),
WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | CBS_DROPDOWN | CBS_AUTOHSCROLL,
50, 2, 300, 80,
Hwnd(), 0, ::GetModuleHandle(NULL), 0);
::SendMessage(wComboTest, WM_SETFONT, reinterpret_cast<WPARAM>(fontText), 0);
RECT rc;
::GetWindowRect(reinterpret_cast<HWND>(wComboTest), &rc);
::DestroyWindow(wComboTest);
lineHeight = rc.bottom - rc.top + 3;
}
void UserStrip::Destruction() {
delete psd;
psd = NULL;
Strip::Destruction();
}
void UserStrip::Close() {
Strip::Close();
if (pSciTEWin)
pSciTEWin->UserStripClosed();
}
void UserStrip::Size() {
if (!visible)
return;
Strip::Size();
GUI::Rectangle rcArea = GetPosition();
rcArea.bottom -= rcArea.top;
rcArea.right -= rcArea.left;
rcArea.left = 2;
rcArea.top = 2;
rcArea.right -= 2;
rcArea.bottom -= 2;
if (HasClose())
rcArea.right -= closeSize.cx + 2; // Allow for close box and gap
#ifdef BCM_GETIDEALSIZE
for (size_t line=0; line<psd->controls.size(); line++) {
std::vector<UserControl> &uc = psd->controls[line];
// Push buttons can be measured with BCM_GETIDEALSIZE
for (std::vector<UserControl>::iterator ctl=uc.begin(); ctl != uc.end(); ++ctl) {
if (ctl->controlType == UserControl::ucButton) {
SIZE sz = {0, 0};
::SendMessage(reinterpret_cast<HWND>(ctl->w.GetID()),
BCM_GETIDEALSIZE, 0, reinterpret_cast<LPARAM>(&sz));
if (sz.cx > 0) {
ctl->widthDesired = sz.cx + 2 * WidthText(fontText, TEXT(" "));
}
}
}
}
#endif
psd->CalculateColumnWidths(rcArea.Width());
for (unsigned int line=0; line<psd->controls.size(); line++) {
int top = rcArea.top + line * lineHeight;
int left = rcArea.left;
size_t column = 0;
std::vector<UserControl> &uc = psd->controls[line];
for (std::vector<UserControl>::iterator ctl=uc.begin(); ctl != uc.end(); ++ctl) {
ctl->widthAllocated = psd->widths[column].widthAllocated;
GUI::Rectangle rcSize = ctl->w.GetClientPosition();
int topWithFix = top;
if (ctl->controlType == UserControl::ucButton)
topWithFix--;
if (ctl->controlType == UserControl::ucStatic)
topWithFix += 3;
if (ctl->controlType == UserControl::ucEdit)
rcSize.bottom = rcSize.top + 23;
if (ctl->controlType == UserControl::ucCombo)
rcSize.bottom = rcSize.top + 180;
GUI::Rectangle rcControl(left, topWithFix, left + ctl->widthAllocated, topWithFix + rcSize.Height());
ctl->w.SetPosition(rcControl);
left += ctl->widthAllocated + 4;
column++;
}
}
::InvalidateRect(Hwnd(), NULL, TRUE);
}
bool UserStrip::HasClose() const {
return psd && psd->hasClose;
}
void UserStrip::Focus() {
for (std::vector<std::vector<UserControl> >::iterator line=psd->controls.begin(); line != psd->controls.end(); ++line) {
for (std::vector<UserControl>::iterator ctl=line->begin(); ctl != line->end(); ++ctl) {
if (ctl->controlType != UserControl::ucStatic) {
::SetFocus(HwndOf(ctl->w));
return;
}
}
}
}
bool UserStrip::KeyDown(WPARAM key) {
if (!visible)
return false;
if (Strip::KeyDown(key))
return true;
if (key == VK_RETURN) {
if (IsChild(Hwnd(), ::GetFocus())) {
// Treat Enter as pressing the first default button
for (std::vector<std::vector<UserControl> >::iterator line=psd->controls.begin(); line != psd->controls.end(); ++line) {
for (std::vector<UserControl>::iterator ctl=line->begin(); ctl != line->end(); ++ctl) {
if (ctl->controlType == UserControl::ucDefaultButton) {
extender->OnUserStrip(ctl->item, scClicked);
return true;
}
}
}
}
}
return false;
}
static StripCommand NotificationToStripCommand(int notification) {
switch (notification) {
case BN_CLICKED:
return scClicked;
case EN_CHANGE:
case CBN_EDITCHANGE:
return scChange;
case EN_UPDATE:
return scUnknown;
case EN_SETFOCUS:
return scFocusIn;
case EN_KILLFOCUS:
return scFocusOut;
default:
return scUnknown;
}
}
bool UserStrip::Command(WPARAM wParam) {
if (entered)
return false;
int control = ControlIDOfWParam(wParam);
int notification = HIWORD(wParam);
if (extender) {
StripCommand sc = NotificationToStripCommand(notification);
if (sc != scUnknown)
return extender->OnUserStrip(control, sc);
}
return false;
}
LRESULT UserStrip::WndProc(UINT iMessage, WPARAM wParam, LPARAM lParam) {
try {
return Strip::WndProc(iMessage, wParam, lParam);
} catch (...) {
}
return 0l;
}
int UserStrip::Lines() const {
return psd ? static_cast<int>(psd->controls.size()) : 1;
}
void UserStrip::SetDescription(const char *description) {
entered++;
GUI::gui_string sDescription = GUI::StringFromUTF8(description);
bool resetting = psd != 0;
if (psd) {
for (std::vector<std::vector<UserControl> >::iterator line=psd->controls.begin(); line != psd->controls.end(); ++line) {
for (std::vector<UserControl>::iterator ctl=line->begin(); ctl != line->end(); ++ctl) {
ctl->w.Destroy();
}
}
}
delete psd;
psd = new StripDefinition(sDescription);
int controlID=0;
for (unsigned int line=0; line<psd->controls.size(); line++) {
std::vector<UserControl> &uc = psd->controls[line];
for (unsigned int control=0; control<uc.size(); control++) {
UserControl *puc = &(uc[control]);
switch (puc->controlType) {
case UserControl::ucEdit:
puc->widthDesired = 100;
puc->fixedWidth = false;
puc->w = ::CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("Edit"), puc->text.c_str(),
WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
60 * control, line * lineHeight + 2, puc->widthDesired, 27,
Hwnd(), reinterpret_cast<HMENU>(controlID), ::GetModuleHandle(NULL), 0);
break;
case UserControl::ucCombo:
puc->widthDesired = 100;
puc->fixedWidth = false;
puc->w = ::CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("ComboBox"), puc->text.c_str(),
WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | CBS_DROPDOWN | CBS_AUTOHSCROLL,
60 * control, line * lineHeight + 2, puc->widthDesired, 180,
Hwnd(), reinterpret_cast<HMENU>(controlID), ::GetModuleHandle(NULL), 0);
break;
case UserControl::ucButton:
case UserControl::ucDefaultButton:
puc->widthDesired = WidthText(fontText, puc->text.c_str()) +
2 * ::GetSystemMetrics(SM_CXEDGE) +
2 * WidthText(fontText, TEXT(" "));
puc->w = ::CreateWindowEx(0, TEXT("Button"), puc->text.c_str(),
WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS |
((puc->controlType == UserControl::ucDefaultButton) ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON),
60 * control, line * lineHeight + 2, puc->widthDesired, lineHeight-1,
Hwnd(), reinterpret_cast<HMENU>(controlID), ::GetModuleHandle(NULL), 0);
break;
default:
puc->widthDesired = WidthText(fontText, puc->text.c_str());
puc->w = ::CreateWindowEx(0, TEXT("Static"), puc->text.c_str(),
WS_CHILD | WS_CLIPSIBLINGS | ES_RIGHT,
60 * control, line * lineHeight + 2, puc->widthDesired, lineHeight - 5,
Hwnd(), reinterpret_cast<HMENU>(controlID), ::GetModuleHandle(NULL), 0);
break;
}
puc->w.Show();
SetFontHandle(puc->w, fontText);
controlID++;
}
}
if (resetting)
Size();
entered--;
Focus();
}
void UserStrip::SetExtender(Extension *extender_) {
extender = extender_;
}
void UserStrip::SetSciTE(SciTEWin *pSciTEWin_) {
pSciTEWin = pSciTEWin_;
}
UserControl *UserStrip::FindControl(int control) {
return psd->FindControl(control);
}
void UserStrip::Set(int control, const char *value) {
UserControl *ctl = FindControl(control);
if (ctl) {
GUI::gui_string sValue = GUI::StringFromUTF8(value);
::SetWindowTextW(HwndOf(ctl->w), sValue.c_str());
}
}
void UserStrip::SetList(int control, const char *value) {
UserControl *ctl = FindControl(control);
if (ctl) {
if (ctl->controlType == UserControl::ucCombo) {
GUI::gui_string sValue = GUI::StringFromUTF8(value);
std::vector<GUI::gui_string> listValues = ListFromString(sValue);
HWND combo = HwndOf(ctl->w);
::SendMessage(combo, CB_RESETCONTENT, 0, 0);
for (std::vector<GUI::gui_string>::iterator i = listValues.begin(); i != listValues.end(); ++i) {
::SendMessageW(combo, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(i->c_str()));
}
}
}
}
std::string UserStrip::GetValue(int control) {
UserControl *ctl = FindControl(control);
if (ctl) {
return ControlText(ctl->w).c_str();
}
return "";
}
LRESULT PASCAL BaseWin::StWndProc(
HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) {
// Find C++ object associated with window.
BaseWin *base = reinterpret_cast<BaseWin *>(::PointerFromWindow(hWnd));
// scite will be zero if WM_CREATE not seen yet
if (base == 0) {
if (iMessage == WM_CREATE) {
LPCREATESTRUCT cs = reinterpret_cast<LPCREATESTRUCT>(lParam);
base = reinterpret_cast<BaseWin *>(cs->lpCreateParams);
SetWindowPointer(hWnd, base);
base->SetID(hWnd);
return base->WndProc(iMessage, wParam, lParam);
} else
return ::DefWindowProc(hWnd, iMessage, wParam, lParam);
} else
return base->WndProc(iMessage, wParam, lParam);
}
// Convert String from UTF-8 to doc encoding
SString SciTEWin::EncodeString(const SString &s) {
//::MessageBox(GetFocus(),SString(s).c_str(),"EncodeString:in",0);
UINT codePage = wEditor.Call(SCI_GETCODEPAGE);
if (codePage != SC_CP_UTF8) {
codePage = CodePageFromCharSet(characterSet, codePage);
int cchWide = ::MultiByteToWideChar(CP_UTF8, 0, s.c_str(), static_cast<int>(s.length()), NULL, 0);
wchar_t *pszWide = new wchar_t[cchWide + 1];
::MultiByteToWideChar(CP_UTF8, 0, s.c_str(), static_cast<int>(s.length()), pszWide, cchWide + 1);
int cchMulti = ::WideCharToMultiByte(codePage, 0, pszWide, cchWide, NULL, 0, NULL, NULL);
char *pszMulti = new char[cchMulti + 1];
::WideCharToMultiByte(codePage, 0, pszWide, cchWide, pszMulti, cchMulti + 1, NULL, NULL);
pszMulti[cchMulti] = 0;
SString result(pszMulti);
delete []pszWide;
delete []pszMulti;
//::MessageBox(GetFocus(),result.c_str(),"EncodeString:out",0);
return result;
}
return SciTEBase::EncodeString(s);
}
// Convert String from doc encoding to UTF-8
SString SciTEWin::GetRangeInUIEncoding(GUI::ScintillaWindow &win, int selStart, int selEnd) {
SString s = SciTEBase::GetRangeInUIEncoding(win, selStart, selEnd);
UINT codePage = wEditor.Call(SCI_GETCODEPAGE);
if (codePage != SC_CP_UTF8) {
codePage = CodePageFromCharSet(characterSet, codePage);
int cchWide = ::MultiByteToWideChar(codePage, 0, s.c_str(), static_cast<int>(s.length()), NULL, 0);
wchar_t *pszWide = new wchar_t[cchWide + 1];
::MultiByteToWideChar(codePage, 0, s.c_str(), static_cast<int>(s.length()), pszWide, cchWide + 1);
int cchMulti = ::WideCharToMultiByte(CP_UTF8, 0, pszWide, cchWide, NULL, 0, NULL, NULL);
char *pszMulti = new char[cchMulti + 1];
::WideCharToMultiByte(CP_UTF8, 0, pszWide, cchWide, pszMulti, cchMulti + 1, NULL, NULL);
pszMulti[cchMulti] = 0;
SString result(pszMulti);
delete []pszWide;
delete []pszMulti;
return result;
}
return s;
}
uptr_t SciTEWin::EventLoop() {
MSG msg;
msg.wParam = 0;
bool going = true;
while (going) {
going = ::GetMessageW(&msg, NULL, 0, 0);
if (going) {
if (!ModelessHandler(&msg)) {
if (!GetID() ||
::TranslateAccelerator(reinterpret_cast<HWND>(GetID()), GetAcceleratorTable(), &msg) == 0) {
::TranslateMessage(&msg);
::DispatchMessageW(&msg);
}
}
}
}
return msg.wParam;
}
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) {
typedef BOOL (WINAPI *SetDllDirectorySig)(LPCTSTR lpPathName);
HMODULE kernel32 = ::GetModuleHandle(TEXT("kernel32.dll"));
if (kernel32) {
SetDllDirectorySig SetDllDirectoryFn = (SetDllDirectorySig)::GetProcAddress(
kernel32, "SetDllDirectoryW");
if (SetDllDirectoryFn) {
// For security, remove current directory from the DLL search path
SetDllDirectoryFn(TEXT(""));
}
}
#ifndef NO_EXTENSIONS
MultiplexExtension multiExtender;
#ifndef NO_LUA
multiExtender.RegisterExtension(LuaExtension::Instance());
#endif
#ifndef NO_FILER
multiExtender.RegisterExtension(DirectorExtension::Instance());
#endif
#endif
SciTEWin::Register(hInstance);
#ifdef STATIC_BUILD
Scintilla_LinkLexers();
Scintilla_RegisterClasses(hInstance);
#else
HMODULE hmod = ::LoadLibrary(TEXT("SciLexer.DLL"));
if (hmod == NULL)
::MessageBox(NULL, TEXT("The Scintilla DLL could not be loaded. SciTE will now close"),
TEXT("Error loading Scintilla"), MB_OK | MB_ICONERROR);
#endif
uptr_t result;
{
#ifdef NO_EXTENSIONS
Extension *extender = 0;
#else
Extension *extender = &multiExtender;
#endif
SciTEWin MainWind(extender);
LPTSTR lptszCmdLine = GetCommandLine();
if (*lptszCmdLine == '\"') {
lptszCmdLine++;
while (*lptszCmdLine && (*lptszCmdLine != '\"'))
lptszCmdLine++;
if (*lptszCmdLine == '\"')
lptszCmdLine++;
} else {
while (*lptszCmdLine && (*lptszCmdLine != ' '))
lptszCmdLine++;
}
while (*lptszCmdLine == ' ')
lptszCmdLine++;
MainWind.Run(lptszCmdLine);
result = MainWind.EventLoop();
}
#ifdef STATIC_BUILD
Scintilla_ReleaseResources();
#else
::FreeLibrary(hmod);
#endif
return static_cast<int>(result);
}