Menu

[r1098]: / trunk / ext / scintilla / win32 / ScintillaWin.cxx  Maximize  Restore  History

Download this file

3429 lines (3047 with data), 105.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
// Scintilla source code edit control
/** @file ScintillaWin.cxx
** Windows specific subclass of ScintillaBase.
**/
// Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <cmath>
#include <stdexcept>
#include <new>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#undef WINVER
#define WINVER 0x0500
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include <windowsx.h>
#include <zmouse.h>
#include <ole2.h>
#if defined(NTDDI_WIN7) && !defined(DISABLE_D2D)
#define USE_D2D 1
#endif
#if defined(USE_D2D)
#include <d2d1.h>
#include <dwrite.h>
#endif
#include "Platform.h"
#include "ILexer.h"
#include "Scintilla.h"
#ifdef SCI_LEXER
#include "SciLexer.h"
#endif
#include "StringCopy.h"
#ifdef SCI_LEXER
#include "LexerModule.h"
#endif
#include "Position.h"
#include "SplitVector.h"
#include "Partitioning.h"
#include "RunStyles.h"
#include "ContractionState.h"
#include "CellBuffer.h"
#include "CallTip.h"
#include "KeyMap.h"
#include "Indicator.h"
#include "XPM.h"
#include "LineMarker.h"
#include "Style.h"
#include "ViewStyle.h"
#include "CharClassify.h"
#include "Decoration.h"
#include "CaseFolder.h"
#include "Document.h"
#include "CaseConvert.h"
#include "UniConversion.h"
#include "Selection.h"
#include "PositionCache.h"
#include "EditModel.h"
#include "MarginView.h"
#include "EditView.h"
#include "Editor.h"
#include "AutoComplete.h"
#include "ScintillaBase.h"
#ifdef SCI_LEXER
#include "ExternalLexer.h"
#endif
#include "PlatWin.h"
#include "HanjaDic.h"
#ifndef SPI_GETWHEELSCROLLLINES
#define SPI_GETWHEELSCROLLLINES 104
#endif
#ifndef WM_UNICHAR
#define WM_UNICHAR 0x0109
#endif
#ifndef UNICODE_NOCHAR
#define UNICODE_NOCHAR 0xFFFF
#endif
#ifndef MK_ALT
#define MK_ALT 32
#endif
#define SC_WIN_IDLE 5001
#define SC_INDICATOR_INPUT INDIC_IME
#define SC_INDICATOR_TARGET INDIC_IME+1
#define SC_INDICATOR_CONVERTED INDIC_IME+2
#define SC_INDICATOR_UNKNOWN INDIC_IME_MAX
#ifndef SCS_CAP_SETRECONVERTSTRING
#define SCS_CAP_SETRECONVERTSTRING 0x00000004
#define SCS_QUERYRECONVERTSTRING 0x00020000
#define SCS_SETRECONVERTSTRING 0x00010000
#endif
typedef BOOL (WINAPI *TrackMouseEventSig)(LPTRACKMOUSEEVENT);
typedef UINT_PTR (WINAPI *SetCoalescableTimerSig)(HWND hwnd, UINT_PTR nIDEvent,
UINT uElapse, TIMERPROC lpTimerFunc, ULONG uToleranceDelay);
// GCC has trouble with the standard COM ABI so do it the old C way with explicit vtables.
const TCHAR callClassName[] = TEXT("CallTip");
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
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));
}
static void SetWindowID(HWND hWnd, int identifier) {
::SetWindowLongPtr(hWnd, GWLP_ID, identifier);
}
static Point PointFromPOINT(POINT pt) {
return Point::FromInts(pt.x, pt.y);
}
class ScintillaWin; // Forward declaration for COM interface subobjects
typedef void VFunction(void);
static HMODULE commctrl32 = 0;
/**
*/
class FormatEnumerator {
public:
VFunction **vtbl;
int ref;
unsigned int pos;
std::vector<CLIPFORMAT> formats;
FormatEnumerator(int pos_, CLIPFORMAT formats_[], size_t formatsLen_);
};
/**
*/
class DropSource {
public:
VFunction **vtbl;
ScintillaWin *sci;
DropSource();
};
/**
*/
class DataObject {
public:
VFunction **vtbl;
ScintillaWin *sci;
DataObject();
};
/**
*/
class DropTarget {
public:
VFunction **vtbl;
ScintillaWin *sci;
DropTarget();
};
namespace {
class IMContext {
HWND hwnd;
public:
HIMC hIMC;
IMContext(HWND hwnd_) :
hwnd(hwnd_), hIMC(::ImmGetContext(hwnd_)) {
}
~IMContext() {
if (hIMC)
::ImmReleaseContext(hwnd, hIMC);
}
};
}
/**
*/
class ScintillaWin :
public ScintillaBase {
bool lastKeyDownConsumed;
bool capturedMouse;
bool trackedMouseLeave;
TrackMouseEventSig TrackMouseEventFn;
SetCoalescableTimerSig SetCoalescableTimerFn;
unsigned int linesPerScroll; ///< Intellimouse support
int wheelDelta; ///< Wheel delta from roll
HRGN hRgnUpdate;
bool hasOKText;
CLIPFORMAT cfColumnSelect;
CLIPFORMAT cfBorlandIDEBlockType;
CLIPFORMAT cfLineSelect;
CLIPFORMAT cfVSLineTag;
HRESULT hrOle;
DropSource ds;
DataObject dob;
DropTarget dt;
static HINSTANCE hInstance;
static ATOM scintillaClassAtom;
static ATOM callClassAtom;
#if defined(USE_D2D)
ID2D1RenderTarget *pRenderTarget;
bool renderTargetValid;
#endif
explicit ScintillaWin(HWND hwnd);
ScintillaWin(const ScintillaWin &);
virtual ~ScintillaWin();
ScintillaWin &operator=(const ScintillaWin &);
virtual void Initialise();
virtual void Finalise();
#if defined(USE_D2D)
void EnsureRenderTarget(HDC hdc);
void DropRenderTarget();
#endif
HWND MainHWND();
static sptr_t DirectFunction(
sptr_t ptr, UINT iMessage, uptr_t wParam, sptr_t lParam);
static LRESULT PASCAL SWndProc(
HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam);
static LRESULT PASCAL CTWndProc(
HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam);
enum { invalidTimerID, standardTimerID, idleTimerID, fineTimerStart };
virtual bool DragThreshold(Point ptStart, Point ptNow);
virtual void StartDrag();
int TargetAsUTF8(char *text);
int EncodedFromUTF8(char *utf8, char *encoded) const;
sptr_t WndPaint(uptr_t wParam);
sptr_t HandleCompositionWindowed(uptr_t wParam, sptr_t lParam);
sptr_t HandleCompositionInline(uptr_t wParam, sptr_t lParam);
static bool KoreanIME();
void MoveImeCarets(int offset);
void DrawImeIndicator(int indicator, int len);
void SetCandidateWindowPos();
void SelectionToHangul();
void EscapeHanja();
void ToggleHanja();
UINT CodePageOfDocument() const;
virtual bool ValidCodePage(int codePage) const;
virtual sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
virtual bool SetIdle(bool on);
UINT_PTR timers[tickDwell+1];
virtual bool FineTickerAvailable();
virtual bool FineTickerRunning(TickReason reason);
virtual void FineTickerStart(TickReason reason, int millis, int tolerance);
virtual void FineTickerCancel(TickReason reason);
virtual void SetMouseCapture(bool on);
virtual bool HaveMouseCapture();
virtual void SetTrackMouseLeaveEvent(bool on);
virtual bool PaintContains(PRectangle rc);
virtual void ScrollText(int linesToMove);
virtual void UpdateSystemCaret();
virtual void SetVerticalScrollPos();
virtual void SetHorizontalScrollPos();
virtual bool ModifyScrollBars(int nMax, int nPage);
virtual void NotifyChange();
virtual void NotifyFocus(bool focus);
virtual void SetCtrlID(int identifier);
virtual int GetCtrlID();
virtual void NotifyParent(SCNotification scn);
virtual void NotifyDoubleClick(Point pt, int modifiers);
virtual CaseFolder *CaseFolderForEncoding();
virtual std::string CaseMapString(const std::string &s, int caseMapping);
virtual void Copy();
virtual void CopyAllowLine();
virtual bool CanPaste();
virtual void Paste();
virtual void CreateCallTipWindow(PRectangle rc);
virtual void AddToPopUp(const char *label, int cmd = 0, bool enabled = true);
virtual void ClaimSelection();
// DBCS
void ImeStartComposition();
void ImeEndComposition();
LRESULT ImeOnReconvert(LPARAM lParam);
void GetIntelliMouseParameters();
virtual void CopyToClipboard(const SelectionText &selectedText);
void ScrollMessage(WPARAM wParam);
void HorizontalScrollMessage(WPARAM wParam);
void FullPaint();
void FullPaintDC(HDC dc);
bool IsCompatibleDC(HDC dc);
DWORD EffectFromState(DWORD grfKeyState) const;
virtual int SetScrollInfo(int nBar, LPCSCROLLINFO lpsi, BOOL bRedraw);
virtual bool GetScrollInfo(int nBar, LPSCROLLINFO lpsi);
void ChangeScrollPos(int barType, int pos);
sptr_t GetTextLength();
sptr_t GetText(uptr_t wParam, sptr_t lParam);
public:
// Public for benefit of Scintilla_DirectFunction
virtual sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
/// Implement IUnknown
STDMETHODIMP QueryInterface(REFIID riid, PVOID *ppv);
STDMETHODIMP_(ULONG)AddRef();
STDMETHODIMP_(ULONG)Release();
/// Implement IDropTarget
STDMETHODIMP DragEnter(LPDATAOBJECT pIDataSource, DWORD grfKeyState,
POINTL pt, PDWORD pdwEffect);
STDMETHODIMP DragOver(DWORD grfKeyState, POINTL pt, PDWORD pdwEffect);
STDMETHODIMP DragLeave();
STDMETHODIMP Drop(LPDATAOBJECT pIDataSource, DWORD grfKeyState,
POINTL pt, PDWORD pdwEffect);
/// Implement important part of IDataObject
STDMETHODIMP GetData(FORMATETC *pFEIn, STGMEDIUM *pSTM);
static bool Register(HINSTANCE hInstance_);
static bool Unregister();
friend class DropSource;
friend class DataObject;
friend class DropTarget;
bool DragIsRectangularOK(CLIPFORMAT fmt) const {
return drag.rectangular && (fmt == cfColumnSelect);
}
private:
// For use in creating a system caret
bool HasCaretSizeChanged() const;
BOOL CreateSystemCaret();
BOOL DestroySystemCaret();
HBITMAP sysCaretBitmap;
int sysCaretWidth;
int sysCaretHeight;
};
HINSTANCE ScintillaWin::hInstance = 0;
ATOM ScintillaWin::scintillaClassAtom = 0;
ATOM ScintillaWin::callClassAtom = 0;
ScintillaWin::ScintillaWin(HWND hwnd) {
lastKeyDownConsumed = false;
capturedMouse = false;
trackedMouseLeave = false;
TrackMouseEventFn = 0;
SetCoalescableTimerFn = 0;
linesPerScroll = 0;
wheelDelta = 0; // Wheel delta from roll
hRgnUpdate = 0;
hasOKText = false;
// There does not seem to be a real standard for indicating that the clipboard
// contains a rectangular selection, so copy Developer Studio and Borland Delphi.
cfColumnSelect = static_cast<CLIPFORMAT>(
::RegisterClipboardFormat(TEXT("MSDEVColumnSelect")));
cfBorlandIDEBlockType = static_cast<CLIPFORMAT>(
::RegisterClipboardFormat(TEXT("Borland IDE Block Type")));
// Likewise for line-copy (copies a full line when no text is selected)
cfLineSelect = static_cast<CLIPFORMAT>(
::RegisterClipboardFormat(TEXT("MSDEVLineSelect")));
cfVSLineTag = static_cast<CLIPFORMAT>(
::RegisterClipboardFormat(TEXT("VisualStudioEditorOperationsLineCutCopyClipboardTag")));
hrOle = E_FAIL;
wMain = hwnd;
dob.sci = this;
ds.sci = this;
dt.sci = this;
sysCaretBitmap = 0;
sysCaretWidth = 0;
sysCaretHeight = 0;
#if defined(USE_D2D)
pRenderTarget = 0;
renderTargetValid = true;
#endif
caret.period = ::GetCaretBlinkTime();
if (caret.period < 0)
caret.period = 0;
Initialise();
}
ScintillaWin::~ScintillaWin() {}
void ScintillaWin::Initialise() {
// Initialize COM. If the app has already done this it will have
// no effect. If the app hasn't, we really shouldn't ask them to call
// it just so this internal feature works.
hrOle = ::OleInitialize(NULL);
// Find TrackMouseEvent which is available on Windows > 95
HMODULE user32 = ::GetModuleHandle(TEXT("user32.dll"));
if (user32) {
TrackMouseEventFn = (TrackMouseEventSig)::GetProcAddress(user32, "TrackMouseEvent");
SetCoalescableTimerFn = (SetCoalescableTimerSig)::GetProcAddress(user32, "SetCoalescableTimer");
}
if (TrackMouseEventFn == NULL) {
// Windows 95 has an emulation in comctl32.dll:_TrackMouseEvent
if (!commctrl32)
commctrl32 = ::LoadLibrary(TEXT("comctl32.dll"));
if (commctrl32 != NULL) {
TrackMouseEventFn = (TrackMouseEventSig)
::GetProcAddress(commctrl32, "_TrackMouseEvent");
}
}
for (TickReason tr = tickCaret; tr <= tickDwell; tr = static_cast<TickReason>(tr + 1)) {
timers[tr] = 0;
}
vs.indicators[SC_INDICATOR_UNKNOWN] = Indicator(INDIC_HIDDEN, ColourDesired(0, 0, 0xff));
vs.indicators[SC_INDICATOR_INPUT] = Indicator(INDIC_DOTS, ColourDesired(0, 0, 0xff));
vs.indicators[SC_INDICATOR_CONVERTED] = Indicator(INDIC_COMPOSITIONTHICK, ColourDesired(0, 0, 0xff));
vs.indicators[SC_INDICATOR_TARGET] = Indicator(INDIC_STRAIGHTBOX, ColourDesired(0, 0, 0xff));
}
void ScintillaWin::Finalise() {
ScintillaBase::Finalise();
for (TickReason tr = tickCaret; tr <= tickDwell; tr = static_cast<TickReason>(tr + 1)) {
FineTickerCancel(tr);
}
SetIdle(false);
#if defined(USE_D2D)
DropRenderTarget();
#endif
::RevokeDragDrop(MainHWND());
if (SUCCEEDED(hrOle)) {
::OleUninitialize();
}
}
#if defined(USE_D2D)
void ScintillaWin::EnsureRenderTarget(HDC hdc) {
if (!renderTargetValid) {
DropRenderTarget();
renderTargetValid = true;
}
if (pD2DFactory && !pRenderTarget) {
RECT rc;
HWND hw = MainHWND();
GetClientRect(hw, &rc);
D2D1_SIZE_U size = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top);
// Create a Direct2D render target.
#if 1
D2D1_RENDER_TARGET_PROPERTIES drtp;
drtp.type = D2D1_RENDER_TARGET_TYPE_DEFAULT;
drtp.pixelFormat.format = DXGI_FORMAT_UNKNOWN;
drtp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_UNKNOWN;
drtp.dpiX = 96.0;
drtp.dpiY = 96.0;
drtp.usage = D2D1_RENDER_TARGET_USAGE_NONE;
drtp.minLevel = D2D1_FEATURE_LEVEL_DEFAULT;
if (technology == SC_TECHNOLOGY_DIRECTWRITEDC) {
// Explicit pixel format needed.
drtp.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM,
D2D1_ALPHA_MODE_IGNORE);
ID2D1DCRenderTarget *pDCRT = NULL;
HRESULT hr = pD2DFactory->CreateDCRenderTarget(&drtp, &pDCRT);
if (SUCCEEDED(hr)) {
pRenderTarget = pDCRT;
} else {
Platform::DebugPrintf("Failed CreateDCRenderTarget 0x%x\n", hr);
pRenderTarget = NULL;
}
} else {
D2D1_HWND_RENDER_TARGET_PROPERTIES dhrtp;
dhrtp.hwnd = hw;
dhrtp.pixelSize = size;
dhrtp.presentOptions = (technology == SC_TECHNOLOGY_DIRECTWRITERETAIN) ?
D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS : D2D1_PRESENT_OPTIONS_NONE;
ID2D1HwndRenderTarget *pHwndRenderTarget = NULL;
HRESULT hr = pD2DFactory->CreateHwndRenderTarget(drtp, dhrtp, &pHwndRenderTarget);
if (SUCCEEDED(hr)) {
pRenderTarget = pHwndRenderTarget;
} else {
Platform::DebugPrintf("Failed CreateHwndRenderTarget 0x%x\n", hr);
pRenderTarget = NULL;
}
}
#else
pD2DFactory->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(
D2D1_RENDER_TARGET_TYPE_DEFAULT ,
D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED),
96.0f, 96.0f, D2D1_RENDER_TARGET_USAGE_NONE, D2D1_FEATURE_LEVEL_DEFAULT),
D2D1::HwndRenderTargetProperties(hw, size),
&pRenderTarget);
#endif
// Pixmaps were created to be compatible with previous render target so
// need to be recreated.
DropGraphics(false);
}
if ((technology == SC_TECHNOLOGY_DIRECTWRITEDC) && pRenderTarget) {
RECT rcWindow;
GetClientRect(MainHWND(), &rcWindow);
HRESULT hr = static_cast<ID2D1DCRenderTarget*>(pRenderTarget)->BindDC(hdc, &rcWindow);
if (FAILED(hr)) {
Platform::DebugPrintf("BindDC failed 0x%x\n", hr);
DropRenderTarget();
}
}
}
void ScintillaWin::DropRenderTarget() {
if (pRenderTarget) {
pRenderTarget->Release();
pRenderTarget = 0;
}
}
#endif
HWND ScintillaWin::MainHWND() {
return reinterpret_cast<HWND>(wMain.GetID());
}
bool ScintillaWin::DragThreshold(Point ptStart, Point ptNow) {
int xMove = static_cast<int>(std::abs(ptStart.x - ptNow.x));
int yMove = static_cast<int>(std::abs(ptStart.y - ptNow.y));
return (xMove > ::GetSystemMetrics(SM_CXDRAG)) ||
(yMove > ::GetSystemMetrics(SM_CYDRAG));
}
void ScintillaWin::StartDrag() {
inDragDrop = ddDragging;
DWORD dwEffect = 0;
dropWentOutside = true;
IDataObject *pDataObject = reinterpret_cast<IDataObject *>(&dob);
IDropSource *pDropSource = reinterpret_cast<IDropSource *>(&ds);
//Platform::DebugPrintf("About to DoDragDrop %x %x\n", pDataObject, pDropSource);
HRESULT hr = ::DoDragDrop(
pDataObject,
pDropSource,
DROPEFFECT_COPY | DROPEFFECT_MOVE, &dwEffect);
//Platform::DebugPrintf("DoDragDrop = %x\n", hr);
if (SUCCEEDED(hr)) {
if ((hr == DRAGDROP_S_DROP) && (dwEffect == DROPEFFECT_MOVE) && dropWentOutside) {
// Remove dragged out text
ClearSelection();
}
}
inDragDrop = ddNone;
SetDragPosition(SelectionPosition(invalidPosition));
}
// Avoid warnings everywhere for old style casts by concentrating them here
static WORD LoWord(uptr_t l) {
return LOWORD(l);
}
static WORD HiWord(uptr_t l) {
return HIWORD(l);
}
static int InputCodePage() {
HKL inputLocale = ::GetKeyboardLayout(0);
LANGID inputLang = LOWORD(inputLocale);
char sCodePage[10];
int res = ::GetLocaleInfoA(MAKELCID(inputLang, SORT_DEFAULT),
LOCALE_IDEFAULTANSICODEPAGE, sCodePage, sizeof(sCodePage));
if (!res)
return 0;
return atoi(sCodePage);
}
/** Map the key codes to their equivalent SCK_ form. */
static int KeyTranslate(int keyIn) {
//PLATFORM_ASSERT(!keyIn);
switch (keyIn) {
case VK_DOWN: return SCK_DOWN;
case VK_UP: return SCK_UP;
case VK_LEFT: return SCK_LEFT;
case VK_RIGHT: return SCK_RIGHT;
case VK_HOME: return SCK_HOME;
case VK_END: return SCK_END;
case VK_PRIOR: return SCK_PRIOR;
case VK_NEXT: return SCK_NEXT;
case VK_DELETE: return SCK_DELETE;
case VK_INSERT: return SCK_INSERT;
case VK_ESCAPE: return SCK_ESCAPE;
case VK_BACK: return SCK_BACK;
case VK_TAB: return SCK_TAB;
case VK_RETURN: return SCK_RETURN;
case VK_ADD: return SCK_ADD;
case VK_SUBTRACT: return SCK_SUBTRACT;
case VK_DIVIDE: return SCK_DIVIDE;
case VK_LWIN: return SCK_WIN;
case VK_RWIN: return SCK_RWIN;
case VK_APPS: return SCK_MENU;
case VK_OEM_2: return '/';
case VK_OEM_3: return '`';
case VK_OEM_4: return '[';
case VK_OEM_5: return '\\';
case VK_OEM_6: return ']';
default: return keyIn;
}
}
static bool BoundsContains(PRectangle rcBounds, HRGN hRgnBounds, PRectangle rcCheck) {
bool contains = true;
if (!rcCheck.Empty()) {
if (!rcBounds.Contains(rcCheck)) {
contains = false;
} else if (hRgnBounds) {
// In bounding rectangle so check more accurately using region
HRGN hRgnCheck = ::CreateRectRgn(static_cast<int>(rcCheck.left), static_cast<int>(rcCheck.top),
static_cast<int>(rcCheck.right), static_cast<int>(rcCheck.bottom));
if (hRgnCheck) {
HRGN hRgnDifference = ::CreateRectRgn(0, 0, 0, 0);
if (hRgnDifference) {
int combination = ::CombineRgn(hRgnDifference, hRgnCheck, hRgnBounds, RGN_DIFF);
if (combination != NULLREGION) {
contains = false;
}
::DeleteRgn(hRgnDifference);
}
::DeleteRgn(hRgnCheck);
}
}
}
return contains;
}
// Returns the target converted to UTF8.
// Return the length in bytes.
int ScintillaWin::TargetAsUTF8(char *text) {
int targetLength = targetEnd - targetStart;
if (IsUnicodeMode()) {
if (text) {
pdoc->GetCharRange(text, targetStart, targetLength);
}
} else {
// Need to convert
std::string s = RangeText(targetStart, targetEnd);
int charsLen = ::MultiByteToWideChar(CodePageOfDocument(), 0, &s[0], targetLength, NULL, 0);
std::wstring characters(charsLen, '\0');
::MultiByteToWideChar(CodePageOfDocument(), 0, &s[0], targetLength, &characters[0], charsLen);
int utf8Len = ::WideCharToMultiByte(CP_UTF8, 0, &characters[0], charsLen, NULL, 0, 0, 0);
if (text) {
::WideCharToMultiByte(CP_UTF8, 0, &characters[0], charsLen, text, utf8Len, 0, 0);
text[utf8Len] = '\0';
}
return utf8Len;
}
return targetLength;
}
// Translates a nul terminated UTF8 string into the document encoding.
// Return the length of the result in bytes.
int ScintillaWin::EncodedFromUTF8(char *utf8, char *encoded) const {
int inputLength = (lengthForEncode >= 0) ? lengthForEncode : static_cast<int>(strlen(utf8));
if (IsUnicodeMode()) {
if (encoded) {
memcpy(encoded, utf8, inputLength);
}
return inputLength;
} else {
// Need to convert
int charsLen = ::MultiByteToWideChar(CP_UTF8, 0, utf8, inputLength, NULL, 0);
std::wstring characters(charsLen, '\0');
::MultiByteToWideChar(CP_UTF8, 0, utf8, inputLength, &characters[0], charsLen);
int encodedLen = ::WideCharToMultiByte(CodePageOfDocument(),
0, &characters[0], charsLen, NULL, 0, 0, 0);
if (encoded) {
::WideCharToMultiByte(CodePageOfDocument(), 0, &characters[0], charsLen, encoded, encodedLen, 0, 0);
encoded[encodedLen] = '\0';
}
return encodedLen;
}
}
sptr_t ScintillaWin::WndPaint(uptr_t wParam) {
//ElapsedTime et;
// Redirect assertions to debug output and save current state
bool assertsPopup = Platform::ShowAssertionPopUps(false);
paintState = painting;
PAINTSTRUCT ps;
PAINTSTRUCT *pps;
bool IsOcxCtrl = (wParam != 0); // if wParam != 0, it contains
// a PAINSTRUCT* from the OCX
// Removed since this interferes with reporting other assertions as it occurs repeatedly
//PLATFORM_ASSERT(hRgnUpdate == NULL);
hRgnUpdate = ::CreateRectRgn(0, 0, 0, 0);
if (IsOcxCtrl) {
pps = reinterpret_cast<PAINTSTRUCT*>(wParam);
} else {
::GetUpdateRgn(MainHWND(), hRgnUpdate, FALSE);
pps = &ps;
::BeginPaint(MainHWND(), pps);
}
rcPaint = PRectangle::FromInts(pps->rcPaint.left, pps->rcPaint.top, pps->rcPaint.right, pps->rcPaint.bottom);
PRectangle rcClient = GetClientRectangle();
paintingAllText = BoundsContains(rcPaint, hRgnUpdate, rcClient);
if (technology == SC_TECHNOLOGY_DEFAULT) {
AutoSurface surfaceWindow(pps->hdc, this);
if (surfaceWindow) {
Paint(surfaceWindow, rcPaint);
surfaceWindow->Release();
}
} else {
#if defined(USE_D2D)
EnsureRenderTarget(pps->hdc);
AutoSurface surfaceWindow(pRenderTarget, this);
if (surfaceWindow) {
pRenderTarget->BeginDraw();
Paint(surfaceWindow, rcPaint);
surfaceWindow->Release();
HRESULT hr = pRenderTarget->EndDraw();
if (hr == D2DERR_RECREATE_TARGET) {
DropRenderTarget();
paintState = paintAbandoned;
}
}
#endif
}
if (hRgnUpdate) {
::DeleteRgn(hRgnUpdate);
hRgnUpdate = 0;
}
if (!IsOcxCtrl)
::EndPaint(MainHWND(), pps);
if (paintState == paintAbandoned) {
// Painting area was insufficient to cover new styling or brace highlight positions
if (IsOcxCtrl) {
FullPaintDC(pps->hdc);
} else {
FullPaint();
}
}
paintState = notPainting;
// Restore debug output state
Platform::ShowAssertionPopUps(assertsPopup);
//Platform::DebugPrintf("Paint took %g\n", et.Duration());
return 0l;
}
sptr_t ScintillaWin::HandleCompositionWindowed(uptr_t wParam, sptr_t lParam) {
if (lParam & GCS_RESULTSTR) {
IMContext imc(MainHWND());
if (imc.hIMC) {
wchar_t wcs[maxLenInputIME];
LONG bytes = ::ImmGetCompositionStringW(imc.hIMC,
GCS_RESULTSTR, wcs, (maxLenInputIME-1)*2);
int wides = bytes / 2;
if (IsUnicodeMode()) {
char utfval[maxLenInputIME * 3];
unsigned int len = UTF8Length(wcs, wides);
UTF8FromUTF16(wcs, wides, utfval, len);
utfval[len] = '\0';
AddCharUTF(utfval, len);
} else {
char dbcsval[maxLenInputIME * 2];
int size = ::WideCharToMultiByte(InputCodePage(),
0, wcs, wides, dbcsval, sizeof(dbcsval) - 1, 0, 0);
for (int i=0; i<size; i++) {
AddChar(dbcsval[i]);
}
}
// Set new position after converted
Point pos = PointMainCaret();
COMPOSITIONFORM CompForm;
CompForm.dwStyle = CFS_POINT;
CompForm.ptCurrentPos.x = static_cast<int>(pos.x);
CompForm.ptCurrentPos.y = static_cast<int>(pos.y);
::ImmSetCompositionWindow(imc.hIMC, &CompForm);
}
return 0;
}
return ::DefWindowProc(MainHWND(), WM_IME_COMPOSITION, wParam, lParam);
}
bool ScintillaWin::KoreanIME() {
const int codePage = InputCodePage();
return codePage == 949 || codePage == 1361;
}
void ScintillaWin::MoveImeCarets(int offset) {
// Move carets relatively by bytes.
for (size_t r=0; r<sel.Count(); r++) {
int positionInsert = sel.Range(r).Start().Position();
sel.Range(r).caret.SetPosition(positionInsert + offset);
sel.Range(r).anchor.SetPosition(positionInsert + offset);
}
}
void ScintillaWin::DrawImeIndicator(int indicator, int len) {
// Emulate the visual style of IME characters with indicators.
// Draw an indicator on the character before caret by the character bytes of len
// so it should be called after addCharUTF().
// It does not affect caret positions.
if (indicator < 8 || indicator > INDIC_MAX) {
return;
}
pdoc->decorations.SetCurrentIndicator(indicator);
for (size_t r=0; r<sel.Count(); r++) {
int positionInsert = sel.Range(r).Start().Position();
pdoc->DecorationFillRange(positionInsert - len, 1, len);
}
}
void ScintillaWin::SetCandidateWindowPos() {
IMContext imc(MainHWND());
if (imc.hIMC) {
Point pos = PointMainCaret();
CANDIDATEFORM CandForm;
CandForm.dwIndex = 0;
CandForm.dwStyle = CFS_CANDIDATEPOS;
CandForm.ptCurrentPos.x = static_cast<int>(pos.x);
CandForm.ptCurrentPos.y = static_cast<int>(pos.y + vs.lineHeight);
::ImmSetCandidateWindow(imc.hIMC, &CandForm);
}
}
static std::string StringEncode(std::wstring s, int codePage) {
if (s.length()) {
int cchMulti = ::WideCharToMultiByte(codePage, 0, s.c_str(), static_cast<int>(s.length()), NULL, 0, NULL, NULL);
std::string sMulti(cchMulti, 0);
::WideCharToMultiByte(codePage, 0, s.c_str(), static_cast<int>(s.size()), &sMulti[0], cchMulti, NULL, NULL);
return sMulti;
} else {
return std::string();
}
}
static std::wstring StringDecode(std::string s, int codePage) {
if (s.length()) {
int cchWide = ::MultiByteToWideChar(codePage, 0, s.c_str(), static_cast<int>(s.length()), NULL, 0);
std::wstring sWide(cchWide, 0);
::MultiByteToWideChar(codePage, 0, s.c_str(), static_cast<int>(s.length()), &sWide[0], cchWide);
return sWide;
} else {
return std::wstring();
}
}
void ScintillaWin::SelectionToHangul() {
// Convert every hanja to hangul within the main range.
const int selStart = sel.RangeMain().Start().Position();
const int documentStrLen = sel.RangeMain().Length();
const int selEnd = selStart + documentStrLen;
const int utf16Len = pdoc->CountUTF16(selStart, selEnd);
if (utf16Len > 0) {
std::string documentStr(documentStrLen, '\0');
pdoc->GetCharRange(&documentStr[0], selStart, documentStrLen);
std::wstring uniStr = StringDecode(documentStr, CodePageOfDocument());
int converted = HanjaDict::GetHangulOfHanja(&uniStr[0]);
documentStr = StringEncode(uniStr, CodePageOfDocument());
if (converted > 0) {
pdoc->BeginUndoAction();
ClearSelection();
InsertPaste(&documentStr[0], static_cast<int>(documentStr.size()));
pdoc->EndUndoAction();
}
}
}
void ScintillaWin::EscapeHanja() {
// The candidate box pops up to user to select a hanja.
// It comes into WM_IME_COMPOSITION with GCS_RESULTSTR.
// The existing hangul or hanja is replaced with it.
if (sel.Count() > 1) {
return; // Do not allow multi carets.
}
int currentPos = CurrentPosition();
int oneCharLen = pdoc->LenChar(currentPos);
if (oneCharLen < 2) {
return; // No need to handle SBCS.
}
// ImmEscapeW() may overwrite uniChar[] with a null terminated string.
// So enlarge it enough to Maximum 4 as in UTF-8.
unsigned int const safeLength = UTF8MaxBytes+1;
std::string oneChar(safeLength, '\0');
pdoc->GetCharRange(&oneChar[0], currentPos, oneCharLen);
std::wstring uniChar = StringDecode(oneChar, CodePageOfDocument());
IMContext imc(MainHWND());
if (imc.hIMC) {
// Set the candidate box position since IME may show it.
SetCandidateWindowPos();
// IME_ESC_HANJA_MODE appears to receive the first character only.
if (ImmEscapeW(GetKeyboardLayout(0), imc.hIMC, IME_ESC_HANJA_MODE, &uniChar[0])) {
SetSelection (currentPos, currentPos + oneCharLen);
}
}
}
void ScintillaWin::ToggleHanja() {
// If selection, convert every hanja to hangul within the main range.
// If no selection, commit to IME.
if (sel.Count() > 1) {
return; // Do not allow multi carets.
}
if (sel.Empty()) {
EscapeHanja();
} else {
SelectionToHangul();
}
}
sptr_t ScintillaWin::HandleCompositionInline(uptr_t, sptr_t lParam) {
// Copy & paste by johnsonj with a lot of helps of Neil.
// Great thanks for my foreruners, jiniya and BLUEnLIVE.
IMContext imc(MainHWND());
if (!imc.hIMC) {
return 0;
}
if (pdoc->TentativeActive()) {
pdoc->TentativeUndo();
} else {
// No tentative undo means start of this composition so
// fill in any virtual spaces.
ClearBeforeTentativeStart();
}
view.imeCaretBlockOverride = false;
if (lParam & GCS_COMPSTR) {
wchar_t wcs[maxLenInputIME] = { 0 };
long bytes = ::ImmGetCompositionStringW
(imc.hIMC, GCS_COMPSTR, wcs, maxLenInputIME);
unsigned int wcsLen = bytes / 2;
if ((wcsLen == 0) || (wcsLen >= maxLenInputIME)) {
ShowCaretAtCurrentPosition();
return 0;
}
pdoc->TentativeStart(); // TentativeActive from now on.
// Get attribute information from composition string.
BYTE compAttr[maxLenInputIME] = { 0 };
unsigned int imeCursorPos = 0;
if (lParam & GCS_COMPATTR) {
ImmGetCompositionStringW(imc.hIMC, GCS_COMPATTR, compAttr, sizeof(compAttr));
}
if (lParam & GCS_CURSORPOS) {
imeCursorPos = ImmGetCompositionStringW(imc.hIMC, GCS_CURSORPOS, NULL, 0);
}
// Display character by character.
int numBytes = 0;
int imeCharPos[maxLenInputIME + 1] = { 0 };
bool tmpRecordingMacro = recordingMacro;
recordingMacro = false;
for (size_t i = 0; i < wcsLen; ) {
const size_t ucWidth = UTF16CharLength(wcs[i]);
const std::wstring uniChar(wcs+i, ucWidth);
char oneChar[UTF8MaxBytes + 1] = "\0\0\0\0"; // Maximum 4 bytes in utf8
unsigned int oneCharLen = 0;
if (IsUnicodeMode()) {
oneCharLen = UTF8Length(uniChar.c_str(), static_cast<unsigned int>(uniChar.length()));
UTF8FromUTF16(uniChar.c_str(), static_cast<unsigned int>(uniChar.length()), oneChar, oneCharLen);
} else {
oneCharLen = ::WideCharToMultiByte(InputCodePage(), 0,
uniChar.c_str(), static_cast<unsigned int>(uniChar.length()), oneChar, sizeof(oneChar)-1, 0, 0);
}
oneChar[oneCharLen] = '\0';
// Display a character.
AddCharUTF(oneChar, oneCharLen);
// Record compstr character positions for moving IME carets.
numBytes += oneCharLen;
imeCharPos[i + ucWidth] = numBytes;
// Draw an indicator on the character.
int indicator = SC_INDICATOR_UNKNOWN;
switch ((int)compAttr[i]) {
case ATTR_INPUT:
indicator = SC_INDICATOR_INPUT;
break;
case ATTR_TARGET_NOTCONVERTED:
case ATTR_TARGET_CONVERTED:
indicator = SC_INDICATOR_TARGET;
break;
case ATTR_CONVERTED:
indicator = SC_INDICATOR_CONVERTED;
break;
}
DrawImeIndicator(indicator, oneCharLen);
i += ucWidth;
}
recordingMacro = tmpRecordingMacro;
// Move IME caret position.
MoveImeCarets(-imeCharPos[wcsLen] + imeCharPos[imeCursorPos]);
if (KoreanIME()) {
view.imeCaretBlockOverride = true;
}
} else if (lParam & GCS_RESULTSTR) {
wchar_t wcs[maxLenInputIME] = { 0 };
long bytes = ::ImmGetCompositionStringW
(imc.hIMC, GCS_RESULTSTR, wcs, maxLenInputIME);
unsigned int wcsLen = bytes / 2;
for (size_t i = 0; i < wcsLen;) {
const size_t ucWidth = UTF16CharLength(wcs[i]);
const std::wstring uniChar(wcs+i, ucWidth);
char oneChar[UTF8MaxBytes+1] = "\0\0\0\0"; // Maximum 4 bytes in UTF-8.
unsigned int oneCharLen = 0;
if (IsUnicodeMode()) {
oneCharLen = UTF8Length(uniChar.c_str(), static_cast<unsigned int>(uniChar.length()));
UTF8FromUTF16(uniChar.c_str(), static_cast<unsigned int>(uniChar.length()), oneChar, oneCharLen);
} else {
oneCharLen = ::WideCharToMultiByte(InputCodePage(), 0,
uniChar.c_str(), static_cast<unsigned int>(uniChar.length()), oneChar, sizeof(oneChar)-1, 0, 0);
}
oneChar[oneCharLen] = '\0';
AddCharUTF(oneChar, oneCharLen);
i += ucWidth;
}
}
EnsureCaretVisible();
SetCandidateWindowPos();
ShowCaretAtCurrentPosition();
return 0;
}
// Translate message IDs from WM_* and EM_* to SCI_* so can partly emulate Windows Edit control
static unsigned int SciMessageFromEM(unsigned int iMessage) {
switch (iMessage) {
case EM_CANPASTE: return SCI_CANPASTE;
case EM_CANUNDO: return SCI_CANUNDO;
case EM_EMPTYUNDOBUFFER: return SCI_EMPTYUNDOBUFFER;
case EM_FINDTEXTEX: return SCI_FINDTEXT;
case EM_FORMATRANGE: return SCI_FORMATRANGE;
case EM_GETFIRSTVISIBLELINE: return SCI_GETFIRSTVISIBLELINE;
case EM_GETLINECOUNT: return SCI_GETLINECOUNT;
case EM_GETSELTEXT: return SCI_GETSELTEXT;
case EM_GETTEXTRANGE: return SCI_GETTEXTRANGE;
case EM_HIDESELECTION: return SCI_HIDESELECTION;
case EM_LINEINDEX: return SCI_POSITIONFROMLINE;
case EM_LINESCROLL: return SCI_LINESCROLL;
case EM_REPLACESEL: return SCI_REPLACESEL;
case EM_SCROLLCARET: return SCI_SCROLLCARET;
case EM_SETREADONLY: return SCI_SETREADONLY;
case WM_CLEAR: return SCI_CLEAR;
case WM_COPY: return SCI_COPY;
case WM_CUT: return SCI_CUT;
case WM_SETTEXT: return SCI_SETTEXT;
case WM_PASTE: return SCI_PASTE;
case WM_UNDO: return SCI_UNDO;
}
return iMessage;
}
UINT CodePageFromCharSet(DWORD characterSet, UINT documentCodePage) {
if (documentCodePage == SC_CP_UTF8) {
return SC_CP_UTF8;
}
switch (characterSet) {
case SC_CHARSET_ANSI: return 1252;
case SC_CHARSET_DEFAULT: return documentCodePage;
case SC_CHARSET_BALTIC: return 1257;
case SC_CHARSET_CHINESEBIG5: return 950;
case SC_CHARSET_EASTEUROPE: return 1250;
case SC_CHARSET_GB2312: return 936;
case SC_CHARSET_GREEK: return 1253;
case SC_CHARSET_HANGUL: return 949;
case SC_CHARSET_MAC: return 10000;
case SC_CHARSET_OEM: return 437;
case SC_CHARSET_RUSSIAN: return 1251;
case SC_CHARSET_SHIFTJIS: return 932;
case SC_CHARSET_TURKISH: return 1254;
case SC_CHARSET_JOHAB: return 1361;
case SC_CHARSET_HEBREW: return 1255;
case SC_CHARSET_ARABIC: return 1256;
case SC_CHARSET_VIETNAMESE: return 1258;
case SC_CHARSET_THAI: return 874;
case SC_CHARSET_8859_15: return 28605;
// Not supported
case SC_CHARSET_CYRILLIC: return documentCodePage;
case SC_CHARSET_SYMBOL: return documentCodePage;
}
return documentCodePage;
}
UINT ScintillaWin::CodePageOfDocument() const {
return CodePageFromCharSet(vs.styles[STYLE_DEFAULT].characterSet, pdoc->dbcsCodePage);
}
sptr_t ScintillaWin::GetTextLength() {
if (pdoc->Length() == 0)
return 0;
std::vector<char> docBytes(pdoc->Length(), '\0');
pdoc->GetCharRange(&docBytes[0], 0, pdoc->Length());
if (IsUnicodeMode()) {
return UTF16Length(&docBytes[0], static_cast<unsigned int>(docBytes.size()));
} else {
return ::MultiByteToWideChar(CodePageOfDocument(), 0, &docBytes[0],
static_cast<int>(docBytes.size()), NULL, 0);
}
}
sptr_t ScintillaWin::GetText(uptr_t wParam, sptr_t lParam) {
wchar_t *ptr = reinterpret_cast<wchar_t *>(lParam);
if (pdoc->Length() == 0) {
*ptr = L'\0';
return 0;
}
std::vector<char> docBytes(pdoc->Length(), '\0');
pdoc->GetCharRange(&docBytes[0], 0, pdoc->Length());
if (IsUnicodeMode()) {
size_t lengthUTF16 = UTF16Length(&docBytes[0], static_cast<unsigned int>(docBytes.size()));
if (lParam == 0)
return lengthUTF16;
if (wParam == 0)
return 0;
size_t uLen = UTF16FromUTF8(&docBytes[0], docBytes.size(),
ptr, static_cast<int>(wParam) - 1);
ptr[uLen] = L'\0';
return uLen;
} else {
// Not Unicode mode
// Convert to Unicode using the current Scintilla code page
const UINT cpSrc = CodePageOfDocument();
int lengthUTF16 = ::MultiByteToWideChar(cpSrc, 0, &docBytes[0],
static_cast<int>(docBytes.size()), NULL, 0);
if (lengthUTF16 >= static_cast<int>(wParam))
lengthUTF16 = static_cast<int>(wParam)-1;
::MultiByteToWideChar(cpSrc, 0, &docBytes[0],
static_cast<int>(docBytes.size()),
ptr, lengthUTF16);
ptr[lengthUTF16] = L'\0';
return lengthUTF16;
}
}
sptr_t ScintillaWin::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
try {
//Platform::DebugPrintf("S M:%x WP:%x L:%x\n", iMessage, wParam, lParam);
iMessage = SciMessageFromEM(iMessage);
switch (iMessage) {
case WM_CREATE:
ctrlID = ::GetDlgCtrlID(reinterpret_cast<HWND>(wMain.GetID()));
// Get Intellimouse scroll line parameters
GetIntelliMouseParameters();
::RegisterDragDrop(MainHWND(), reinterpret_cast<IDropTarget *>(&dt));
break;
case WM_COMMAND:
Command(LoWord(wParam));
break;
case WM_PAINT:
return WndPaint(wParam);
case WM_PRINTCLIENT: {
HDC hdc = reinterpret_cast<HDC>(wParam);
if (!IsCompatibleDC(hdc)) {
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
}
FullPaintDC(hdc);
}
break;
case WM_VSCROLL:
ScrollMessage(wParam);
break;
case WM_HSCROLL:
HorizontalScrollMessage(wParam);
break;
case WM_SIZE: {
#if defined(USE_D2D)
if (paintState == notPainting) {
DropRenderTarget();
} else {
renderTargetValid = false;
}
#endif
//Platform::DebugPrintf("Scintilla WM_SIZE %d %d\n", LoWord(lParam), HiWord(lParam));
ChangeSize();
}
break;
case WM_MOUSEWHEEL:
// if autocomplete list active then send mousewheel message to it
if (ac.Active()) {
HWND hWnd = reinterpret_cast<HWND>(ac.lb->GetID());
::SendMessage(hWnd, iMessage, wParam, lParam);
break;
}
// Don't handle datazoom.
// (A good idea for datazoom would be to "fold" or "unfold" details.
// i.e. if datazoomed out only class structures are visible, when datazooming in the control
// structures appear, then eventually the individual statements...)
if (wParam & MK_SHIFT) {
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
}
// Either SCROLL or ZOOM. We handle the wheel steppings calculation
wheelDelta -= static_cast<short>(HiWord(wParam));
if (abs(wheelDelta) >= WHEEL_DELTA && linesPerScroll > 0) {
int linesToScroll = linesPerScroll;
if (linesPerScroll == WHEEL_PAGESCROLL)
linesToScroll = LinesOnScreen() - 1;
if (linesToScroll == 0) {
linesToScroll = 1;
}
linesToScroll *= (wheelDelta / WHEEL_DELTA);
if (wheelDelta >= 0)
wheelDelta = wheelDelta % WHEEL_DELTA;
else
wheelDelta = - (-wheelDelta % WHEEL_DELTA);
if (wParam & MK_CONTROL) {
// Zoom! We play with the font sizes in the styles.
// Number of steps/line is ignored, we just care if sizing up or down
if (linesToScroll < 0) {
KeyCommand(SCI_ZOOMIN);
} else {
KeyCommand(SCI_ZOOMOUT);
}
} else {
// Scroll
ScrollTo(topLine + linesToScroll);
}
}
return 0;
case WM_TIMER:
if (wParam == idleTimerID && idler.state) {
SendMessage(MainHWND(), SC_WIN_IDLE, 0, 1);
} else {
TickFor(static_cast<TickReason>(wParam - fineTimerStart));
}
break;
case SC_WIN_IDLE:
// wParam=dwTickCountInitial, or 0 to initialize. lParam=bSkipUserInputTest
if (idler.state) {
if (lParam || (WAIT_TIMEOUT == MsgWaitForMultipleObjects(0, 0, 0, 0, QS_INPUT|QS_HOTKEY))) {
if (Idle()) {
// User input was given priority above, but all events do get a turn. Other
// messages, notifications, etc. will get interleaved with the idle messages.
// However, some things like WM_PAINT are a lower priority, and will not fire
// when there's a message posted. So, several times a second, we stop and let
// the low priority events have a turn (after which the timer will fire again).
DWORD dwCurrent = GetTickCount();
DWORD dwStart = wParam ? static_cast<DWORD>(wParam) : dwCurrent;
const DWORD maxWorkTime = 50;
if (dwCurrent >= dwStart && dwCurrent > maxWorkTime && dwCurrent - maxWorkTime < dwStart)
PostMessage(MainHWND(), SC_WIN_IDLE, dwStart, 0);
} else {
SetIdle(false);
}
}
}
break;
case WM_GETMINMAXINFO:
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
case WM_LBUTTONDOWN: {
// For IME, set the composition string as the result string.
IMContext imc(MainHWND());
::ImmNotifyIME(imc.hIMC, NI_COMPOSITIONSTR, CPS_COMPLETE, 0);
//
//Platform::DebugPrintf("Buttdown %d %x %x %x %x %x\n",iMessage, wParam, lParam,
// Platform::IsKeyDown(VK_SHIFT),
// Platform::IsKeyDown(VK_CONTROL),
// Platform::IsKeyDown(VK_MENU));
::SetFocus(MainHWND());
ButtonDown(Point::FromLong(static_cast<long>(lParam)), ::GetMessageTime(),
(wParam & MK_SHIFT) != 0,
(wParam & MK_CONTROL) != 0,
Platform::IsKeyDown(VK_MENU));
}
break;
case WM_MOUSEMOVE: {
const Point pt = Point::FromLong(static_cast<long>(lParam));
// Windows might send WM_MOUSEMOVE even though the mouse has not been moved:
// http://blogs.msdn.com/b/oldnewthing/archive/2003/10/01/55108.aspx
if (ptMouseLast.x != pt.x || ptMouseLast.y != pt.y) {
SetTrackMouseLeaveEvent(true);
ButtonMoveWithModifiers(pt,
((wParam & MK_SHIFT) != 0 ? SCI_SHIFT : 0) |
((wParam & MK_CONTROL) != 0 ? SCI_CTRL : 0) |
(Platform::IsKeyDown(VK_MENU) ? SCI_ALT : 0));
}
}
break;
case WM_MOUSELEAVE:
SetTrackMouseLeaveEvent(false);
MouseLeave();
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
case WM_LBUTTONUP:
ButtonUp(Point::FromLong(static_cast<long>(lParam)),
::GetMessageTime(),
(wParam & MK_CONTROL) != 0);
break;
case WM_RBUTTONDOWN:
::SetFocus(MainHWND());
if (!PointInSelection(Point::FromLong(static_cast<long>(lParam)))) {
CancelModes();
SetEmptySelection(PositionFromLocation(Point::FromLong(static_cast<long>(lParam))));
}
break;
case WM_SETCURSOR:
if (LoWord(lParam) == HTCLIENT) {
if (inDragDrop == ddDragging) {
DisplayCursor(Window::cursorUp);
} else {
// Display regular (drag) cursor over selection
POINT pt;
if (0 != ::GetCursorPos(&pt)) {
::ScreenToClient(MainHWND(), &pt);
if (PointInSelMargin(PointFromPOINT(pt))) {
DisplayCursor(GetMarginCursor(PointFromPOINT(pt)));
} else if (PointInSelection(PointFromPOINT(pt)) && !SelectionEmpty()) {
DisplayCursor(Window::cursorArrow);
} else if (PointIsHotspot(PointFromPOINT(pt))) {
DisplayCursor(Window::cursorHand);
} else {
DisplayCursor(Window::cursorText);
}
}
}
return TRUE;
} else {
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
}
case WM_CHAR:
if (((wParam >= 128) || !iscntrl(static_cast<int>(wParam))) || !lastKeyDownConsumed) {
wchar_t wcs[2] = {static_cast<wchar_t>(wParam), 0};
if (IsUnicodeMode()) {
// For a wide character version of the window:
char utfval[UTF8MaxBytes];
unsigned int len = UTF8Length(wcs, 1);
UTF8FromUTF16(wcs, 1, utfval, len);
AddCharUTF(utfval, len);
} else {
UINT cpDest = CodePageOfDocument();
char inBufferCP[20];
int size = ::WideCharToMultiByte(cpDest,
0, wcs, 1, inBufferCP, sizeof(inBufferCP) - 1, 0, 0);
inBufferCP[size] = '\0';
AddCharUTF(inBufferCP, size);
}
}
return 0;
case WM_UNICHAR:
if (wParam == UNICODE_NOCHAR) {
return IsUnicodeMode() ? 1 : 0;
} else if (lastKeyDownConsumed) {
return 1;
} else {
if (IsUnicodeMode()) {
char utfval[UTF8MaxBytes];
wchar_t wcs[2] = {static_cast<wchar_t>(wParam), 0};
unsigned int len = UTF8Length(wcs, 1);
UTF8FromUTF16(wcs, 1, utfval, len);
AddCharUTF(utfval, len);
return 1;
} else {
return 0;
}
}
case WM_SYSKEYDOWN:
case WM_KEYDOWN: {
//Platform::DebugPrintf("S keydown %d %x %x %x %x\n",iMessage, wParam, lParam, ::IsKeyDown(VK_SHIFT), ::IsKeyDown(VK_CONTROL));
lastKeyDownConsumed = false;
int ret = KeyDown(KeyTranslate(static_cast<int>(wParam)),
Platform::IsKeyDown(VK_SHIFT),
Platform::IsKeyDown(VK_CONTROL),
Platform::IsKeyDown(VK_MENU),
&lastKeyDownConsumed);
if (!ret && !lastKeyDownConsumed) {
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
}
break;
}
case WM_IME_KEYDOWN: {
if (wParam == VK_HANJA) {
ToggleHanja();
}
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
}
case WM_IME_REQUEST: {
if (wParam == IMR_RECONVERTSTRING) {
return ImeOnReconvert(lParam);
}
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
}
case WM_KEYUP:
//Platform::DebugPrintf("S keyup %d %x %x\n",iMessage, wParam, lParam);
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
case WM_SETTINGCHANGE:
//Platform::DebugPrintf("Setting Changed\n");
InvalidateStyleData();
// Get Intellimouse scroll line parameters
GetIntelliMouseParameters();
break;
case WM_GETDLGCODE:
return DLGC_HASSETSEL | DLGC_WANTALLKEYS;
case WM_KILLFOCUS: {
HWND wOther = reinterpret_cast<HWND>(wParam);
HWND wThis = MainHWND();
HWND wCT = reinterpret_cast<HWND>(ct.wCallTip.GetID());
if (!wParam ||
!(::IsChild(wThis, wOther) || (wOther == wCT))) {
SetFocusState(false);
DestroySystemCaret();
}
// Explicitly complete any IME composition
IMContext imc(MainHWND());
if (imc.hIMC) {
::ImmNotifyIME(imc.hIMC, NI_COMPOSITIONSTR, CPS_COMPLETE, 0);
}
}
break;
case WM_SETFOCUS:
SetFocusState(true);
DestroySystemCaret();
CreateSystemCaret();
break;
case WM_SYSCOLORCHANGE:
//Platform::DebugPrintf("Setting Changed\n");
InvalidateStyleData();
break;
case WM_IME_STARTCOMPOSITION: // dbcs
if (KoreanIME() || imeInteraction == imeInline) {
return 0;
} else {
ImeStartComposition();
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
}
case WM_IME_ENDCOMPOSITION: // dbcs
ImeEndComposition();
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
case WM_IME_COMPOSITION:
if (KoreanIME() || imeInteraction == imeInline) {
return HandleCompositionInline(wParam, lParam);
} else {
return HandleCompositionWindowed(wParam, lParam);
}
case WM_CONTEXTMENU:
if (displayPopupMenu) {
Point pt = Point::FromLong(static_cast<long>(lParam));
if ((pt.x == -1) && (pt.y == -1)) {
// Caused by keyboard so display menu near caret
pt = PointMainCaret();
POINT spt = {static_cast<int>(pt.x), static_cast<int>(pt.y)};
::ClientToScreen(MainHWND(), &spt);
pt = PointFromPOINT(spt);
}
ContextMenu(pt);
return 0;
}
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
case WM_INPUTLANGCHANGE:
//::SetThreadLocale(LOWORD(lParam));
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
case WM_INPUTLANGCHANGEREQUEST:
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
case WM_ERASEBKGND:
return 1; // Avoid any background erasure as whole window painted.
case WM_CAPTURECHANGED:
capturedMouse = false;
return 0;
case WM_IME_SETCONTEXT:
if (KoreanIME() || imeInteraction == imeInline) {
if (wParam) {
LPARAM NoImeWin = lParam;
NoImeWin = NoImeWin & (~ISC_SHOWUICOMPOSITIONWINDOW);
return ::DefWindowProc(MainHWND(), iMessage, wParam, NoImeWin);
}
}
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
// These are not handled in Scintilla and its faster to dispatch them here.
// Also moves time out to here so profile doesn't count lots of empty message calls.
case WM_MOVE:
case WM_MOUSEACTIVATE:
case WM_NCHITTEST:
case WM_NCCALCSIZE:
case WM_NCPAINT:
case WM_NCMOUSEMOVE:
case WM_NCLBUTTONDOWN:
case WM_IME_NOTIFY:
case WM_SYSCOMMAND:
case WM_WINDOWPOSCHANGING:
case WM_WINDOWPOSCHANGED:
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
case WM_GETTEXTLENGTH:
return GetTextLength();
case WM_GETTEXT:
return GetText(wParam, lParam);
case EM_LINEFROMCHAR:
if (static_cast<int>(wParam) < 0) {
wParam = SelectionStart().Position();
}
return pdoc->LineFromPosition(static_cast<int>(wParam));
case EM_EXLINEFROMCHAR:
return pdoc->LineFromPosition(static_cast<int>(lParam));
case EM_GETSEL:
if (wParam) {
*reinterpret_cast<int *>(wParam) = SelectionStart().Position();
}
if (lParam) {
*reinterpret_cast<int *>(lParam) = SelectionEnd().Position();
}
return MAKELONG(SelectionStart().Position(), SelectionEnd().Position());
case EM_EXGETSEL: {
if (lParam == 0) {
return 0;
}
Sci_CharacterRange *pCR = reinterpret_cast<Sci_CharacterRange *>(lParam);
pCR->cpMin = SelectionStart().Position();
pCR->cpMax = SelectionEnd().Position();
}
break;
case EM_SETSEL: {
int nStart = static_cast<int>(wParam);
int nEnd = static_cast<int>(lParam);
if (nStart == 0 && nEnd == -1) {
nEnd = pdoc->Length();
}
if (nStart == -1) {
nStart = nEnd; // Remove selection
}
if (nStart > nEnd) {
SetSelection(nEnd, nStart);
} else {
SetSelection(nStart, nEnd);
}
EnsureCaretVisible();
}
break;
case EM_EXSETSEL: {
if (lParam == 0) {
return 0;
}
Sci_CharacterRange *pCR = reinterpret_cast<Sci_CharacterRange *>(lParam);
sel.selType = Selection::selStream;
if (pCR->cpMin == 0 && pCR->cpMax == -1) {
SetSelection(pCR->cpMin, pdoc->Length());
} else {
SetSelection(pCR->cpMin, pCR->cpMax);
}
EnsureCaretVisible();
return pdoc->LineFromPosition(SelectionStart().Position());
}
case SCI_GETDIRECTFUNCTION:
return reinterpret_cast<sptr_t>(DirectFunction);
case SCI_GETDIRECTPOINTER:
return reinterpret_cast<sptr_t>(this);
case SCI_GRABFOCUS:
::SetFocus(MainHWND());
break;
#ifdef INCLUDE_DEPRECATED_FEATURES
case SCI_SETKEYSUNICODE:
break;
case SCI_GETKEYSUNICODE:
return true;
#endif
case SCI_SETTECHNOLOGY:
if ((wParam == SC_TECHNOLOGY_DEFAULT) ||
(wParam == SC_TECHNOLOGY_DIRECTWRITERETAIN) ||
(wParam == SC_TECHNOLOGY_DIRECTWRITEDC) ||
(wParam == SC_TECHNOLOGY_DIRECTWRITE)) {
if (technology != static_cast<int>(wParam)) {
if (static_cast<int>(wParam) > SC_TECHNOLOGY_DEFAULT) {
#if defined(USE_D2D)
if (!LoadD2D())
// Failed to load Direct2D or DirectWrite so no effect
return 0;
#else
return 0;
#endif
}
#if defined(USE_D2D)
DropRenderTarget();
#endif
technology = static_cast<int>(wParam);
// Invalidate all cached information including layout.
DropGraphics(true);
InvalidateStyleRedraw();
}
}
break;
#ifdef SCI_LEXER
case SCI_LOADLEXERLIBRARY:
LexerManager::GetInstance()->Load(reinterpret_cast<const char *>(lParam));
break;
#endif
case SCI_TARGETASUTF8:
return TargetAsUTF8(reinterpret_cast<char*>(lParam));
case SCI_ENCODEDFROMUTF8:
return EncodedFromUTF8(reinterpret_cast<char*>(wParam),
reinterpret_cast<char*>(lParam));
default:
return ScintillaBase::WndProc(iMessage, wParam, lParam);
}
} catch (std::bad_alloc &) {
errorStatus = SC_STATUS_BADALLOC;
} catch (...) {
errorStatus = SC_STATUS_FAILURE;
}
return 0l;
}
bool ScintillaWin::ValidCodePage(int codePage) const {
return codePage == 0 || codePage == SC_CP_UTF8 ||
codePage == 932 || codePage == 936 || codePage == 949 ||
codePage == 950 || codePage == 1361;
}
sptr_t ScintillaWin::DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
}
/**
* Report that this Editor subclass has a working implementation of FineTickerStart.
*/
bool ScintillaWin::FineTickerAvailable() {
return true;
}
bool ScintillaWin::FineTickerRunning(TickReason reason) {
return timers[reason] != 0;
}
void ScintillaWin::FineTickerStart(TickReason reason, int millis, int tolerance) {
FineTickerCancel(reason);
if (SetCoalescableTimerFn && tolerance) {
timers[reason] = SetCoalescableTimerFn(MainHWND(), fineTimerStart + reason, millis, NULL, tolerance);
} else {
timers[reason] = ::SetTimer(MainHWND(), fineTimerStart + reason, millis, NULL);
}
}
void ScintillaWin::FineTickerCancel(TickReason reason) {
if (timers[reason]) {
::KillTimer(MainHWND(), timers[reason]);
timers[reason] = 0;
}
}
bool ScintillaWin::SetIdle(bool on) {
// On Win32 the Idler is implemented as a Timer on the Scintilla window. This
// takes advantage of the fact that WM_TIMER messages are very low priority,
// and are only posted when the message queue is empty, i.e. during idle time.
if (idler.state != on) {
if (on) {
idler.idlerID = ::SetTimer(MainHWND(), idleTimerID, 10, NULL)
? reinterpret_cast<IdlerID>(idleTimerID) : 0;
} else {
::KillTimer(MainHWND(), reinterpret_cast<uptr_t>(idler.idlerID));
idler.idlerID = 0;
}
idler.state = idler.idlerID != 0;
}
return idler.state;
}
void ScintillaWin::SetMouseCapture(bool on) {
if (mouseDownCaptures) {
if (on) {
::SetCapture(MainHWND());
} else {
::ReleaseCapture();
}
}
capturedMouse = on;
}
bool ScintillaWin::HaveMouseCapture() {
// Cannot just see if GetCapture is this window as the scroll bar also sets capture for the window
return capturedMouse;
//return capturedMouse && (::GetCapture() == MainHWND());
}
void ScintillaWin::SetTrackMouseLeaveEvent(bool on) {
if (on && TrackMouseEventFn && !trackedMouseLeave) {
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = MainHWND();
tme.dwHoverTime = HOVER_DEFAULT; // Unused but triggers Dr. Memory if not initialized
TrackMouseEventFn(&tme);
}
trackedMouseLeave = on;
}
bool ScintillaWin::PaintContains(PRectangle rc) {
if (paintState == painting) {
return BoundsContains(rcPaint, hRgnUpdate, rc);
}
return true;
}
void ScintillaWin::ScrollText(int /* linesToMove */) {
//Platform::DebugPrintf("ScintillaWin::ScrollText %d\n", linesToMove);
//::ScrollWindow(MainHWND(), 0,
// vs.lineHeight * linesToMove, 0, 0);
//::UpdateWindow(MainHWND());
Redraw();
UpdateSystemCaret();
}
void ScintillaWin::UpdateSystemCaret() {
if (hasFocus) {
if (HasCaretSizeChanged()) {
DestroySystemCaret();
CreateSystemCaret();
}
Point pos = PointMainCaret();
::SetCaretPos(static_cast<int>(pos.x), static_cast<int>(pos.y));
}
}
int ScintillaWin::SetScrollInfo(int nBar, LPCSCROLLINFO lpsi, BOOL bRedraw) {
return ::SetScrollInfo(MainHWND(), nBar, lpsi, bRedraw);
}
bool ScintillaWin::GetScrollInfo(int nBar, LPSCROLLINFO lpsi) {
return ::GetScrollInfo(MainHWND(), nBar, lpsi) ? true : false;
}
// Change the scroll position but avoid repaint if changing to same value
void ScintillaWin::ChangeScrollPos(int barType, int pos) {
SCROLLINFO sci = {
sizeof(sci), 0, 0, 0, 0, 0, 0
};
sci.fMask = SIF_POS;
GetScrollInfo(barType, &sci);
if (sci.nPos != pos) {
DwellEnd(true);
sci.nPos = pos;
SetScrollInfo(barType, &sci, TRUE);
}
}
void ScintillaWin::SetVerticalScrollPos() {
ChangeScrollPos(SB_VERT, topLine);
}
void ScintillaWin::SetHorizontalScrollPos() {
ChangeScrollPos(SB_HORZ, xOffset);
}
bool ScintillaWin::ModifyScrollBars(int nMax, int nPage) {
bool modified = false;
SCROLLINFO sci = {
sizeof(sci), 0, 0, 0, 0, 0, 0
};
sci.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(SB_VERT, &sci);
int vertEndPreferred = nMax;
if (!verticalScrollBarVisible)
nPage = vertEndPreferred + 1;
if ((sci.nMin != 0) ||
(sci.nMax != vertEndPreferred) ||
(sci.nPage != static_cast<unsigned int>(nPage)) ||
(sci.nPos != 0)) {
sci.fMask = SIF_PAGE | SIF_RANGE;
sci.nMin = 0;
sci.nMax = vertEndPreferred;
sci.nPage = nPage;
sci.nPos = 0;
sci.nTrackPos = 1;
SetScrollInfo(SB_VERT, &sci, TRUE);
modified = true;
}
PRectangle rcText = GetTextRectangle();
int horizEndPreferred = scrollWidth;
if (horizEndPreferred < 0)
horizEndPreferred = 0;
unsigned int pageWidth = static_cast<unsigned int>(rcText.Width());
if (!horizontalScrollBarVisible || Wrapping())
pageWidth = horizEndPreferred + 1;
sci.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(SB_HORZ, &sci);
if ((sci.nMin != 0) ||
(sci.nMax != horizEndPreferred) ||
(sci.nPage != pageWidth) ||
(sci.nPos != 0)) {
sci.fMask = SIF_PAGE | SIF_RANGE;
sci.nMin = 0;
sci.nMax = horizEndPreferred;
sci.nPage = pageWidth;
sci.nPos = 0;
sci.nTrackPos = 1;
SetScrollInfo(SB_HORZ, &sci, TRUE);
modified = true;
if (scrollWidth < static_cast<int>(pageWidth)) {
HorizontalScrollTo(0);
}
}
return modified;
}
void ScintillaWin::NotifyChange() {
::SendMessage(::GetParent(MainHWND()), WM_COMMAND,
MAKELONG(GetCtrlID(), SCEN_CHANGE),
reinterpret_cast<LPARAM>(MainHWND()));
}
void ScintillaWin::NotifyFocus(bool focus) {
::SendMessage(::GetParent(MainHWND()), WM_COMMAND,
MAKELONG(GetCtrlID(), focus ? SCEN_SETFOCUS : SCEN_KILLFOCUS),
reinterpret_cast<LPARAM>(MainHWND()));
Editor::NotifyFocus(focus);
}
void ScintillaWin::SetCtrlID(int identifier) {
::SetWindowID(reinterpret_cast<HWND>(wMain.GetID()), identifier);
}
int ScintillaWin::GetCtrlID() {
return ::GetDlgCtrlID(reinterpret_cast<HWND>(wMain.GetID()));
}
void ScintillaWin::NotifyParent(SCNotification scn) {
scn.nmhdr.hwndFrom = MainHWND();
scn.nmhdr.idFrom = GetCtrlID();
::SendMessage(::GetParent(MainHWND()), WM_NOTIFY,
GetCtrlID(), reinterpret_cast<LPARAM>(&scn));
}
void ScintillaWin::NotifyDoubleClick(Point pt, int modifiers) {
//Platform::DebugPrintf("ScintillaWin Double click 0\n");
ScintillaBase::NotifyDoubleClick(pt, modifiers);
// Send myself a WM_LBUTTONDBLCLK, so the container can handle it too.
::SendMessage(MainHWND(),
WM_LBUTTONDBLCLK,
(modifiers & SCI_SHIFT) ? MK_SHIFT : 0,
MAKELPARAM(pt.x, pt.y));
}
class CaseFolderDBCS : public CaseFolderTable {
// Allocate the expandable storage here so that it does not need to be reallocated
// for each call to Fold.
std::vector<wchar_t> utf16Mixed;
std::vector<wchar_t> utf16Folded;
UINT cp;
public:
explicit CaseFolderDBCS(UINT cp_) : cp(cp_) {
StandardASCII();
}
virtual size_t Fold(char *folded, size_t sizeFolded, const char *mixed, size_t lenMixed) {
if ((lenMixed == 1) && (sizeFolded > 0)) {
folded[0] = mapping[static_cast<unsigned char>(mixed[0])];
return 1;
} else {
if (lenMixed > utf16Mixed.size()) {
utf16Mixed.resize(lenMixed + 8);
}
size_t nUtf16Mixed = ::MultiByteToWideChar(cp, 0, mixed,
static_cast<int>(lenMixed),
&utf16Mixed[0],
static_cast<int>(utf16Mixed.size()));
if (nUtf16Mixed == 0) {
// Failed to convert -> bad input
folded[0] = '\0';
return 1;
}
unsigned int lenFlat = 0;
for (size_t mixIndex=0; mixIndex < nUtf16Mixed; mixIndex++) {
if ((lenFlat + 20) > utf16Folded.size())
utf16Folded.resize(lenFlat + 60);
const char *foldedUTF8 = CaseConvert(utf16Mixed[mixIndex], CaseConversionFold);
if (foldedUTF8) {
// Maximum length of a case conversion is 6 bytes, 3 characters
wchar_t wFolded[20];
size_t charsConverted = UTF16FromUTF8(foldedUTF8,
strlen(foldedUTF8),
wFolded, ELEMENTS(wFolded));
for (size_t j=0; j<charsConverted; j++)
utf16Folded[lenFlat++] = wFolded[j];
} else {
utf16Folded[lenFlat++] = utf16Mixed[mixIndex];
}
}
size_t lenOut = ::WideCharToMultiByte(cp, 0,
&utf16Folded[0], lenFlat,
NULL, 0, NULL, 0);
if (lenOut < sizeFolded) {
::WideCharToMultiByte(cp, 0,
&utf16Folded[0], lenFlat,
folded, static_cast<int>(lenOut), NULL, 0);
return lenOut;
} else {
return 0;
}
}
}
};
CaseFolder *ScintillaWin::CaseFolderForEncoding() {
UINT cpDest = CodePageOfDocument();
if (cpDest == SC_CP_UTF8) {
return new CaseFolderUnicode();
} else {
if (pdoc->dbcsCodePage == 0) {
CaseFolderTable *pcf = new CaseFolderTable();
pcf->StandardASCII();
// Only for single byte encodings
UINT cpDoc = CodePageOfDocument();
for (int i=0x80; i<0x100; i++) {
char sCharacter[2] = "A";
sCharacter[0] = static_cast<char>(i);
wchar_t wCharacter[20];
unsigned int lengthUTF16 = ::MultiByteToWideChar(cpDoc, 0, sCharacter, 1,
wCharacter, ELEMENTS(wCharacter));
if (lengthUTF16 == 1) {
const char *caseFolded = CaseConvert(wCharacter[0], CaseConversionFold);
if (caseFolded) {
wchar_t wLower[20];
size_t charsConverted = UTF16FromUTF8(caseFolded,
strlen(caseFolded),
wLower, ELEMENTS(wLower));
if (charsConverted == 1) {
char sCharacterLowered[20];
unsigned int lengthConverted = ::WideCharToMultiByte(cpDoc, 0,
wLower, static_cast<int>(charsConverted),
sCharacterLowered, ELEMENTS(sCharacterLowered), NULL, 0);
if ((lengthConverted == 1) && (sCharacter[0] != sCharacterLowered[0])) {
pcf->SetTranslation(sCharacter[0], sCharacterLowered[0]);
}
}
}
}
}
return pcf;
} else {
return new CaseFolderDBCS(cpDest);
}
}
}
std::string ScintillaWin::CaseMapString(const std::string &s, int caseMapping) {
if ((s.size() == 0) || (caseMapping == cmSame))
return s;
UINT cpDoc = CodePageOfDocument();
if (cpDoc == SC_CP_UTF8) {
std::string retMapped(s.length() * maxExpansionCaseConversion, 0);
size_t lenMapped = CaseConvertString(&retMapped[0], retMapped.length(), s.c_str(), s.length(),
(caseMapping == cmUpper) ? CaseConversionUpper : CaseConversionLower);
retMapped.resize(lenMapped);
return retMapped;
}
unsigned int lengthUTF16 = ::MultiByteToWideChar(cpDoc, 0, s.c_str(),
static_cast<int>(s.size()), NULL, 0);
if (lengthUTF16 == 0) // Failed to convert
return s;
DWORD mapFlags = LCMAP_LINGUISTIC_CASING |
((caseMapping == cmUpper) ? LCMAP_UPPERCASE : LCMAP_LOWERCASE);
// Change text to UTF-16
std::vector<wchar_t> vwcText(lengthUTF16);
::MultiByteToWideChar(cpDoc, 0, s.c_str(), static_cast<int>(s.size()), &vwcText[0], lengthUTF16);
// Change case
int charsConverted = ::LCMapStringW(LOCALE_SYSTEM_DEFAULT, mapFlags,
&vwcText[0], lengthUTF16, NULL, 0);
std::vector<wchar_t> vwcConverted(charsConverted);
::LCMapStringW(LOCALE_SYSTEM_DEFAULT, mapFlags,
&vwcText[0], lengthUTF16, &vwcConverted[0], charsConverted);
// Change back to document encoding
unsigned int lengthConverted = ::WideCharToMultiByte(cpDoc, 0,
&vwcConverted[0], static_cast<int>(vwcConverted.size()),
NULL, 0, NULL, 0);
std::vector<char> vcConverted(lengthConverted);
::WideCharToMultiByte(cpDoc, 0,
&vwcConverted[0], static_cast<int>(vwcConverted.size()),
&vcConverted[0], static_cast<int>(vcConverted.size()), NULL, 0);
return std::string(&vcConverted[0], vcConverted.size());
}
void ScintillaWin::Copy() {
//Platform::DebugPrintf("Copy\n");
if (!sel.Empty()) {
SelectionText selectedText;
CopySelectionRange(&selectedText);
CopyToClipboard(selectedText);
}
}
void ScintillaWin::CopyAllowLine() {
SelectionText selectedText;
CopySelectionRange(&selectedText, true);
CopyToClipboard(selectedText);
}
bool ScintillaWin::CanPaste() {
if (!Editor::CanPaste())
return false;
if (::IsClipboardFormatAvailable(CF_TEXT))
return true;
if (IsUnicodeMode())
return ::IsClipboardFormatAvailable(CF_UNICODETEXT) != 0;
return false;
}
class GlobalMemory {
HGLOBAL hand;
public:
void *ptr;
GlobalMemory() : hand(0), ptr(0) {
}
explicit GlobalMemory(HGLOBAL hand_) : hand(hand_), ptr(0) {
if (hand) {
ptr = ::GlobalLock(hand);
}
}
~GlobalMemory() {
PLATFORM_ASSERT(!ptr);
assert(!hand);
}
void Allocate(size_t bytes) {
assert(!hand);
hand = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, bytes);
if (hand) {
ptr = ::GlobalLock(hand);
}
}
HGLOBAL Unlock() {
PLATFORM_ASSERT(ptr);
HGLOBAL handCopy = hand;
::GlobalUnlock(hand);
ptr = 0;
hand = 0;
return handCopy;
}
void SetClip(UINT uFormat) {
::SetClipboardData(uFormat, Unlock());
}
operator bool() const {
return ptr != 0;
}
SIZE_T Size() {
return ::GlobalSize(hand);
}
};
void ScintillaWin::Paste() {
if (!::OpenClipboard(MainHWND()))
return;
UndoGroup ug(pdoc);
const bool isLine = SelectionEmpty() &&
(::IsClipboardFormatAvailable(cfLineSelect) || ::IsClipboardFormatAvailable(cfVSLineTag));
ClearSelection(multiPasteMode == SC_MULTIPASTE_EACH);
bool isRectangular = (::IsClipboardFormatAvailable(cfColumnSelect) != 0);
if (!isRectangular) {
// Evaluate "Borland IDE Block Type" explicitly
GlobalMemory memBorlandSelection(::GetClipboardData(cfBorlandIDEBlockType));
if (memBorlandSelection) {
isRectangular = (memBorlandSelection.Size() == 1) && (static_cast<BYTE *>(memBorlandSelection.ptr)[0] == 0x02);
memBorlandSelection.Unlock();
}
}
const PasteShape pasteShape = isRectangular ? pasteRectangular : (isLine ? pasteLine : pasteStream);
// Always use CF_UNICODETEXT if available
GlobalMemory memUSelection(::GetClipboardData(CF_UNICODETEXT));
if (memUSelection) {
wchar_t *uptr = static_cast<wchar_t *>(memUSelection.ptr);
if (uptr) {
unsigned int len;
std::vector<char> putf;
// Default Scintilla behaviour in Unicode mode
if (IsUnicodeMode()) {
unsigned int bytes = static_cast<unsigned int>(memUSelection.Size());
len = UTF8Length(uptr, bytes / 2);
putf.resize(len + 1);
UTF8FromUTF16(uptr, bytes / 2, &putf[0], len);
} else {
// CF_UNICODETEXT available, but not in Unicode mode
// Convert from Unicode to current Scintilla code page
UINT cpDest = CodePageOfDocument();
len = ::WideCharToMultiByte(cpDest, 0, uptr, -1,
NULL, 0, NULL, NULL) - 1; // subtract 0 terminator
putf.resize(len + 1);
::WideCharToMultiByte(cpDest, 0, uptr, -1,
&putf[0], len + 1, NULL, NULL);
}
InsertPasteShape(&putf[0], len, pasteShape);
}
memUSelection.Unlock();
} else {
// CF_UNICODETEXT not available, paste ANSI text
GlobalMemory memSelection(::GetClipboardData(CF_TEXT));
if (memSelection) {
char *ptr = static_cast<char *>(memSelection.ptr);
if (ptr) {
unsigned int bytes = static_cast<unsigned int>(memSelection.Size());
unsigned int len = bytes;
for (unsigned int i = 0; i < bytes; i++) {
if ((len == bytes) && (0 == ptr[i]))
len = i;
}
// In Unicode mode, convert clipboard text to UTF-8
if (IsUnicodeMode()) {
std::vector<wchar_t> uptr(len+1);
unsigned int ulen = ::MultiByteToWideChar(CP_ACP, 0,
ptr, len, &uptr[0], len+1);
unsigned int mlen = UTF8Length(&uptr[0], ulen);
std::vector<char> putf(mlen+1);
UTF8FromUTF16(&uptr[0], ulen, &putf[0], mlen);
InsertPasteShape(&putf[0], mlen, pasteShape);
} else {
InsertPasteShape(ptr, len, pasteShape);
}
}
memSelection.Unlock();
}
}
::CloseClipboard();
Redraw();
}
void ScintillaWin::CreateCallTipWindow(PRectangle) {
if (!ct.wCallTip.Created()) {
ct.wCallTip = ::CreateWindow(callClassName, TEXT("ACallTip"),
WS_POPUP, 100, 100, 150, 20,
MainHWND(), 0,
GetWindowInstance(MainHWND()),
this);
ct.wDraw = ct.wCallTip;
}
}
void ScintillaWin::AddToPopUp(const char *label, int cmd, bool enabled) {
HMENU hmenuPopup = reinterpret_cast<HMENU>(popup.GetID());
if (!label[0])
::AppendMenuA(hmenuPopup, MF_SEPARATOR, 0, "");
else if (enabled)
::AppendMenuA(hmenuPopup, MF_STRING, cmd, label);
else
::AppendMenuA(hmenuPopup, MF_STRING | MF_DISABLED | MF_GRAYED, cmd, label);
}
void ScintillaWin::ClaimSelection() {
// Windows does not have a primary selection
}
/// Implement IUnknown
STDMETHODIMP_(ULONG)FormatEnumerator_AddRef(FormatEnumerator *fe);
STDMETHODIMP FormatEnumerator_QueryInterface(FormatEnumerator *fe, REFIID riid, PVOID *ppv) {
//Platform::DebugPrintf("EFE QI");
*ppv = NULL;
if (riid == IID_IUnknown)
*ppv = reinterpret_cast<IEnumFORMATETC *>(fe);
if (riid == IID_IEnumFORMATETC)
*ppv = reinterpret_cast<IEnumFORMATETC *>(fe);
if (!*ppv)
return E_NOINTERFACE;
FormatEnumerator_AddRef(fe);
return S_OK;
}
STDMETHODIMP_(ULONG)FormatEnumerator_AddRef(FormatEnumerator *fe) {
return ++fe->ref;
}
STDMETHODIMP_(ULONG)FormatEnumerator_Release(FormatEnumerator *fe) {
fe->ref--;
if (fe->ref > 0)
return fe->ref;
delete fe;
return 0;
}
/// Implement IEnumFORMATETC
STDMETHODIMP FormatEnumerator_Next(FormatEnumerator *fe, ULONG celt, FORMATETC *rgelt, ULONG *pceltFetched) {
if (rgelt == NULL) return E_POINTER;
unsigned int putPos = 0;
while ((fe->pos < fe->formats.size()) && (putPos < celt)) {
rgelt->cfFormat = fe->formats[fe->pos];
rgelt->ptd = 0;
rgelt->dwAspect = DVASPECT_CONTENT;
rgelt->lindex = -1;
rgelt->tymed = TYMED_HGLOBAL;
rgelt++;
fe->pos++;
putPos++;
}
if (pceltFetched)
*pceltFetched = putPos;
return putPos ? S_OK : S_FALSE;
}
STDMETHODIMP FormatEnumerator_Skip(FormatEnumerator *fe, ULONG celt) {
fe->pos += celt;
return S_OK;
}
STDMETHODIMP FormatEnumerator_Reset(FormatEnumerator *fe) {
fe->pos = 0;
return S_OK;
}
STDMETHODIMP FormatEnumerator_Clone(FormatEnumerator *fe, IEnumFORMATETC **ppenum) {
FormatEnumerator *pfe;
try {
pfe = new FormatEnumerator(fe->pos, &fe->formats[0], fe->formats.size());
} catch (...) {
return E_OUTOFMEMORY;
}
return FormatEnumerator_QueryInterface(pfe, IID_IEnumFORMATETC,
reinterpret_cast<void **>(ppenum));
}
static VFunction *vtFormatEnumerator[] = {
(VFunction *)(FormatEnumerator_QueryInterface),
(VFunction *)(FormatEnumerator_AddRef),
(VFunction *)(FormatEnumerator_Release),
(VFunction *)(FormatEnumerator_Next),
(VFunction *)(FormatEnumerator_Skip),
(VFunction *)(FormatEnumerator_Reset),
(VFunction *)(FormatEnumerator_Clone)
};
FormatEnumerator::FormatEnumerator(int pos_, CLIPFORMAT formats_[], size_t formatsLen_) {
vtbl = vtFormatEnumerator;
ref = 0; // First QI adds first reference...
pos = pos_;
formats.insert(formats.begin(), formats_, formats_+formatsLen_);
}
/// Implement IUnknown
STDMETHODIMP DropSource_QueryInterface(DropSource *ds, REFIID riid, PVOID *ppv) {
return ds->sci->QueryInterface(riid, ppv);
}
STDMETHODIMP_(ULONG)DropSource_AddRef(DropSource *ds) {
return ds->sci->AddRef();
}
STDMETHODIMP_(ULONG)DropSource_Release(DropSource *ds) {
return ds->sci->Release();
}
/// Implement IDropSource
STDMETHODIMP DropSource_QueryContinueDrag(DropSource *, BOOL fEsc, DWORD grfKeyState) {
if (fEsc)
return DRAGDROP_S_CANCEL;
if (!(grfKeyState & MK_LBUTTON))
return DRAGDROP_S_DROP;
return S_OK;
}
STDMETHODIMP DropSource_GiveFeedback(DropSource *, DWORD) {
return DRAGDROP_S_USEDEFAULTCURSORS;
}
static VFunction *vtDropSource[] = {
(VFunction *)(DropSource_QueryInterface),
(VFunction *)(DropSource_AddRef),
(VFunction *)(DropSource_Release),
(VFunction *)(DropSource_QueryContinueDrag),
(VFunction *)(DropSource_GiveFeedback)
};
DropSource::DropSource() {
vtbl = vtDropSource;
sci = 0;
}
/// Implement IUnkown
STDMETHODIMP DataObject_QueryInterface(DataObject *pd, REFIID riid, PVOID *ppv) {
//Platform::DebugPrintf("DO QI %x\n", pd);
return pd->sci->QueryInterface(riid, ppv);
}
STDMETHODIMP_(ULONG)DataObject_AddRef(DataObject *pd) {
return pd->sci->AddRef();
}
STDMETHODIMP_(ULONG)DataObject_Release(DataObject *pd) {
return pd->sci->Release();
}
/// Implement IDataObject
STDMETHODIMP DataObject_GetData(DataObject *pd, FORMATETC *pFEIn, STGMEDIUM *pSTM) {
return pd->sci->GetData(pFEIn, pSTM);
}
STDMETHODIMP DataObject_GetDataHere(DataObject *, FORMATETC *, STGMEDIUM *) {
//Platform::DebugPrintf("DOB GetDataHere\n");
return E_NOTIMPL;
}
STDMETHODIMP DataObject_QueryGetData(DataObject *pd, FORMATETC *pFE) {
if (pd->sci->DragIsRectangularOK(pFE->cfFormat) &&
pFE->ptd == 0 &&
(pFE->dwAspect & DVASPECT_CONTENT) != 0 &&
pFE->lindex == -1 &&
(pFE->tymed & TYMED_HGLOBAL) != 0
) {
return S_OK;
}
bool formatOK = (pFE->cfFormat == CF_TEXT) ||
((pFE->cfFormat == CF_UNICODETEXT) && pd->sci->IsUnicodeMode());
if (!formatOK ||
pFE->ptd != 0 ||
(pFE->dwAspect & DVASPECT_CONTENT) == 0 ||
pFE->lindex != -1 ||
(pFE->tymed & TYMED_HGLOBAL) == 0
) {
//Platform::DebugPrintf("DOB QueryGetData No %x\n",pFE->cfFormat);
//return DATA_E_FORMATETC;
return S_FALSE;
}
//Platform::DebugPrintf("DOB QueryGetData OK %x\n",pFE->cfFormat);
return S_OK;
}
STDMETHODIMP DataObject_GetCanonicalFormatEtc(DataObject *pd, FORMATETC *, FORMATETC *pFEOut) {
//Platform::DebugPrintf("DOB GetCanon\n");
if (pd->sci->IsUnicodeMode())
pFEOut->cfFormat = CF_UNICODETEXT;
else
pFEOut->cfFormat = CF_TEXT;
pFEOut->ptd = 0;
pFEOut->dwAspect = DVASPECT_CONTENT;
pFEOut->lindex = -1;
pFEOut->tymed = TYMED_HGLOBAL;
return S_OK;
}
STDMETHODIMP DataObject_SetData(DataObject *, FORMATETC *, STGMEDIUM *, BOOL) {
//Platform::DebugPrintf("DOB SetData\n");
return E_FAIL;
}
STDMETHODIMP DataObject_EnumFormatEtc(DataObject *pd, DWORD dwDirection, IEnumFORMATETC **ppEnum) {
try {
//Platform::DebugPrintf("DOB EnumFormatEtc %d\n", dwDirection);
if (dwDirection != DATADIR_GET) {
*ppEnum = 0;
return E_FAIL;
}
FormatEnumerator *pfe;
if (pd->sci->IsUnicodeMode()) {
CLIPFORMAT formats[] = {CF_UNICODETEXT, CF_TEXT};
pfe = new FormatEnumerator(0, formats, ELEMENTS(formats));
} else {
CLIPFORMAT formats[] = {CF_TEXT};
pfe = new FormatEnumerator(0, formats, ELEMENTS(formats));
}
return FormatEnumerator_QueryInterface(pfe, IID_IEnumFORMATETC,
reinterpret_cast<void **>(ppEnum));
} catch (std::bad_alloc &) {
pd->sci->errorStatus = SC_STATUS_BADALLOC;
return E_OUTOFMEMORY;
} catch (...) {
pd->sci->errorStatus = SC_STATUS_FAILURE;
return E_FAIL;
}
}
STDMETHODIMP DataObject_DAdvise(DataObject *, FORMATETC *, DWORD, IAdviseSink *, PDWORD) {
//Platform::DebugPrintf("DOB DAdvise\n");
return E_FAIL;
}
STDMETHODIMP DataObject_DUnadvise(DataObject *, DWORD) {
//Platform::DebugPrintf("DOB DUnadvise\n");
return E_FAIL;
}
STDMETHODIMP DataObject_EnumDAdvise(DataObject *, IEnumSTATDATA **) {
//Platform::DebugPrintf("DOB EnumDAdvise\n");
return E_FAIL;
}
static VFunction *vtDataObject[] = {
(VFunction *)(DataObject_QueryInterface),
(VFunction *)(DataObject_AddRef),
(VFunction *)(DataObject_Release),
(VFunction *)(DataObject_GetData),
(VFunction *)(DataObject_GetDataHere),
(VFunction *)(DataObject_QueryGetData),
(VFunction *)(DataObject_GetCanonicalFormatEtc),
(VFunction *)(DataObject_SetData),
(VFunction *)(DataObject_EnumFormatEtc),
(VFunction *)(DataObject_DAdvise),
(VFunction *)(DataObject_DUnadvise),
(VFunction *)(DataObject_EnumDAdvise)
};
DataObject::DataObject() {
vtbl = vtDataObject;
sci = 0;
}
/// Implement IUnknown
STDMETHODIMP DropTarget_QueryInterface(DropTarget *dt, REFIID riid, PVOID *ppv) {
//Platform::DebugPrintf("DT QI %x\n", dt);
return dt->sci->QueryInterface(riid, ppv);
}
STDMETHODIMP_(ULONG)DropTarget_AddRef(DropTarget *dt) {
return dt->sci->AddRef();
}
STDMETHODIMP_(ULONG)DropTarget_Release(DropTarget *dt) {
return dt->sci->Release();
}
/// Implement IDropTarget by forwarding to Scintilla
STDMETHODIMP DropTarget_DragEnter(DropTarget *dt, LPDATAOBJECT pIDataSource, DWORD grfKeyState,
POINTL pt, PDWORD pdwEffect) {
try {
return dt->sci->DragEnter(pIDataSource, grfKeyState, pt, pdwEffect);
} catch (...) {
dt->sci->errorStatus = SC_STATUS_FAILURE;
}
return E_FAIL;
}
STDMETHODIMP DropTarget_DragOver(DropTarget *dt, DWORD grfKeyState, POINTL pt, PDWORD pdwEffect) {
try {
return dt->sci->DragOver(grfKeyState, pt, pdwEffect);
} catch (...) {
dt->sci->errorStatus = SC_STATUS_FAILURE;
}
return E_FAIL;
}
STDMETHODIMP DropTarget_DragLeave(DropTarget *dt) {
try {
return dt->sci->DragLeave();
} catch (...) {
dt->sci->errorStatus = SC_STATUS_FAILURE;
}
return E_FAIL;
}
STDMETHODIMP DropTarget_Drop(DropTarget *dt, LPDATAOBJECT pIDataSource, DWORD grfKeyState,
POINTL pt, PDWORD pdwEffect) {
try {
return dt->sci->Drop(pIDataSource, grfKeyState, pt, pdwEffect);
} catch (...) {
dt->sci->errorStatus = SC_STATUS_FAILURE;
}
return E_FAIL;
}
static VFunction *vtDropTarget[] = {
(VFunction *)(DropTarget_QueryInterface),
(VFunction *)(DropTarget_AddRef),
(VFunction *)(DropTarget_Release),
(VFunction *)(DropTarget_DragEnter),
(VFunction *)(DropTarget_DragOver),
(VFunction *)(DropTarget_DragLeave),
(VFunction *)(DropTarget_Drop)
};
DropTarget::DropTarget() {
vtbl = vtDropTarget;
sci = 0;
}
/**
* DBCS: support Input Method Editor (IME).
* Called when IME Window opened.
*/
void ScintillaWin::ImeStartComposition() {
if (caret.active) {
// Move IME Window to current caret position
IMContext imc(MainHWND());
Point pos = PointMainCaret();
COMPOSITIONFORM CompForm;
CompForm.dwStyle = CFS_POINT;
CompForm.ptCurrentPos.x = static_cast<int>(pos.x);
CompForm.ptCurrentPos.y = static_cast<int>(pos.y);
::ImmSetCompositionWindow(imc.hIMC, &CompForm);
// Set font of IME window to same as surrounded text.
if (stylesValid) {
// Since the style creation code has been made platform independent,
// The logfont for the IME is recreated here.
int styleHere = (pdoc->StyleAt(sel.MainCaret())) & 31;
LOGFONTW lf = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L""};
int sizeZoomed = vs.styles[styleHere].size + vs.zoomLevel * SC_FONT_SIZE_MULTIPLIER;
if (sizeZoomed <= 2 * SC_FONT_SIZE_MULTIPLIER) // Hangs if sizeZoomed <= 1
sizeZoomed = 2 * SC_FONT_SIZE_MULTIPLIER;
AutoSurface surface(this);
int deviceHeight = sizeZoomed;
if (surface) {
deviceHeight = (sizeZoomed * surface->LogPixelsY()) / 72;
}
// The negative is to allow for leading
lf.lfHeight = -(abs(deviceHeight / SC_FONT_SIZE_MULTIPLIER));
lf.lfWeight = vs.styles[styleHere].weight;
lf.lfItalic = static_cast<BYTE>(vs.styles[styleHere].italic ? 1 : 0);
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfFaceName[0] = L'\0';
if (vs.styles[styleHere].fontName) {
const char* fontName = vs.styles[styleHere].fontName;
UTF16FromUTF8(fontName, strlen(fontName)+1, lf.lfFaceName, LF_FACESIZE);
}
::ImmSetCompositionFontW(imc.hIMC, &lf);
}
// Caret is displayed in IME window. So, caret in Scintilla is useless.
DropCaret();
}
}
/** Called when IME Window closed. */
void ScintillaWin::ImeEndComposition() {
ShowCaretAtCurrentPosition();
}
LRESULT ScintillaWin::ImeOnReconvert(LPARAM lParam) {
// Reconversion on windows limits within one line without eol.
// Look around: baseStart <-- (|mainStart| -- mainEnd) --> baseEnd.
const int mainStart = sel.RangeMain().Start().Position();
const int mainEnd = sel.RangeMain().End().Position();
const int curLine = pdoc->LineFromPosition(mainStart);
if (curLine != pdoc->LineFromPosition(mainEnd))
return 0;
const int baseStart = pdoc->LineStart(curLine);
const int baseEnd = pdoc->LineEnd(curLine);
if ((baseStart == baseEnd) || (mainEnd > baseEnd))
return 0;
const int codePage = CodePageOfDocument();
const std::wstring rcFeed = StringDecode(RangeText(baseStart, baseEnd), codePage);
const int rcFeedLen = static_cast<int>(rcFeed.length()) * sizeof(wchar_t);
const int rcSize = sizeof(RECONVERTSTRING) + rcFeedLen + sizeof(wchar_t);
RECONVERTSTRING *rc = (RECONVERTSTRING *)lParam;
if (!rc)
return rcSize; // Immediately be back with rcSize of memory block.
wchar_t *rcFeedStart = (wchar_t*)(rc + 1);
memcpy(rcFeedStart, &rcFeed[0], rcFeedLen);
std::string rcCompString = RangeText(mainStart, mainEnd);
std::wstring rcCompWstring = StringDecode(rcCompString, codePage);
std::string rcCompStart = RangeText(baseStart, mainStart);
std::wstring rcCompWstart = StringDecode(rcCompStart, codePage);
// Map selection to dwCompStr.
// No selection assumes current caret as rcCompString without length.
rc->dwVersion = 0; // It should be absolutely 0.
rc->dwStrLen = (DWORD)static_cast<int>(rcFeed.length());
rc->dwStrOffset = sizeof(RECONVERTSTRING);
rc->dwCompStrLen = (DWORD)static_cast<int>(rcCompWstring.length());
rc->dwCompStrOffset = (DWORD)static_cast<int>(rcCompWstart.length()) * sizeof(wchar_t);
rc->dwTargetStrLen = rc->dwCompStrLen;
rc->dwTargetStrOffset =rc->dwCompStrOffset;
IMContext imc(MainHWND());
if (!imc.hIMC)
return 0;
if (!::ImmSetCompositionStringW(imc.hIMC, SCS_QUERYRECONVERTSTRING, rc, rcSize, NULL, 0))
return 0;
// No selection asks IME to fill target fields with its own value.
int tgWlen = rc->dwTargetStrLen;
int tgWstart = rc->dwTargetStrOffset / sizeof(wchar_t);
std::string tgCompStart = StringEncode(rcFeed.substr(0, tgWstart), codePage);
std::string tgComp = StringEncode(rcFeed.substr(tgWstart, tgWlen), codePage);
// No selection needs to adjust reconvert start position for IME set.
int adjust = static_cast<int>(tgCompStart.length() - rcCompStart.length());
int docCompLen = static_cast<int>(tgComp.length());
// Make place for next composition string to sit in.
for (size_t r=0; r<sel.Count(); r++) {
int rBase = sel.Range(r).Start().Position();
int docCompStart = rBase + adjust;
if (inOverstrike) { // the docCompLen of bytes will be overstriked.
sel.Range(r).caret.SetPosition(docCompStart);
sel.Range(r).anchor.SetPosition(docCompStart);
} else {
// Ensure docCompStart+docCompLen be not beyond lineEnd.
// since docCompLen by byte might break eol.
int lineEnd = pdoc->LineEnd(pdoc->LineFromPosition(rBase));
int overflow = (docCompStart + docCompLen) - lineEnd;
if (overflow > 0) {
pdoc->DeleteChars(docCompStart, docCompLen - overflow);
} else {
pdoc->DeleteChars(docCompStart, docCompLen);
}
}
}
// Immediately Target Input or candidate box choice with GCS_COMPSTR.
return rcSize;
}
void ScintillaWin::GetIntelliMouseParameters() {
// This retrieves the number of lines per scroll as configured inthe Mouse Properties sheet in Control Panel
::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &linesPerScroll, 0);
}
void ScintillaWin::CopyToClipboard(const SelectionText &selectedText) {
if (!::OpenClipboard(MainHWND()))
return;
::EmptyClipboard();
GlobalMemory uniText;
// Default Scintilla behaviour in Unicode mode
if (IsUnicodeMode()) {
size_t uchars = UTF16Length(selectedText.Data(),
static_cast<int>(selectedText.LengthWithTerminator()));
uniText.Allocate(2 * uchars);
if (uniText) {
UTF16FromUTF8(selectedText.Data(), selectedText.LengthWithTerminator(),
static_cast<wchar_t *>(uniText.ptr), uchars);
}
} else {
// Not Unicode mode
// Convert to Unicode using the current Scintilla code page
UINT cpSrc = CodePageFromCharSet(
selectedText.characterSet, selectedText.codePage);
int uLen = ::MultiByteToWideChar(cpSrc, 0, selectedText.Data(),
static_cast<int>(selectedText.LengthWithTerminator()), 0, 0);
uniText.Allocate(2 * uLen);
if (uniText) {
::MultiByteToWideChar(cpSrc, 0, selectedText.Data(),
static_cast<int>(selectedText.LengthWithTerminator()),
static_cast<wchar_t *>(uniText.ptr), uLen);
}
}
if (uniText) {
uniText.SetClip(CF_UNICODETEXT);
} else {
// There was a failure - try to copy at least ANSI text
GlobalMemory ansiText;
ansiText.Allocate(selectedText.LengthWithTerminator());
if (ansiText) {
memcpy(static_cast<char *>(ansiText.ptr), selectedText.Data(), selectedText.LengthWithTerminator());
ansiText.SetClip(CF_TEXT);
}
}
if (selectedText.rectangular) {
::SetClipboardData(cfColumnSelect, 0);
GlobalMemory borlandSelection;
borlandSelection.Allocate(1);
if (borlandSelection) {
static_cast<BYTE *>(borlandSelection.ptr)[0] = 0x02;
borlandSelection.SetClip(cfBorlandIDEBlockType);
}
}
if (selectedText.lineCopy) {
::SetClipboardData(cfLineSelect, 0);
::SetClipboardData(cfVSLineTag, 0);
}
::CloseClipboard();
}
void ScintillaWin::ScrollMessage(WPARAM wParam) {
//DWORD dwStart = timeGetTime();
//Platform::DebugPrintf("Scroll %x %d\n", wParam, lParam);
SCROLLINFO sci = {};
sci.cbSize = sizeof(sci);
sci.fMask = SIF_ALL;
GetScrollInfo(SB_VERT, &sci);
//Platform::DebugPrintf("ScrollInfo %d mask=%x min=%d max=%d page=%d pos=%d track=%d\n", b,sci.fMask,
//sci.nMin, sci.nMax, sci.nPage, sci.nPos, sci.nTrackPos);
int topLineNew = topLine;
switch (LoWord(wParam)) {
case SB_LINEUP:
topLineNew -= 1;
break;
case SB_LINEDOWN:
topLineNew += 1;
break;
case SB_PAGEUP:
topLineNew -= LinesToScroll(); break;
case SB_PAGEDOWN: topLineNew += LinesToScroll(); break;
case SB_TOP: topLineNew = 0; break;
case SB_BOTTOM: topLineNew = MaxScrollPos(); break;
case SB_THUMBPOSITION: topLineNew = sci.nTrackPos; break;
case SB_THUMBTRACK: topLineNew = sci.nTrackPos; break;
}
ScrollTo(topLineNew);
}
void ScintillaWin::HorizontalScrollMessage(WPARAM wParam) {
int xPos = xOffset;
PRectangle rcText = GetTextRectangle();
int pageWidth = static_cast<int>(rcText.Width() * 2 / 3);
switch (LoWord(wParam)) {
case SB_LINEUP:
xPos -= 20;
break;
case SB_LINEDOWN: // May move past the logical end
xPos += 20;
break;
case SB_PAGEUP:
xPos -= pageWidth;
break;
case SB_PAGEDOWN:
xPos += pageWidth;
if (xPos > scrollWidth - rcText.Width()) { // Hit the end exactly
xPos = scrollWidth - static_cast<int>(rcText.Width());
}
break;
case SB_TOP:
xPos = 0;
break;
case SB_BOTTOM:
xPos = scrollWidth;
break;
case SB_THUMBPOSITION:
case SB_THUMBTRACK: {
// Do NOT use wParam, its 16 bit and not enough for very long lines. Its still possible to overflow the 32 bit but you have to try harder =]
SCROLLINFO si;
si.cbSize = sizeof(si);
si.fMask = SIF_TRACKPOS;
if (GetScrollInfo(SB_HORZ, &si)) {
xPos = si.nTrackPos;
}
}
break;
}
HorizontalScrollTo(xPos);
}
/**
* Redraw all of text area.
* This paint will not be abandoned.
*/
void ScintillaWin::FullPaint() {
if ((technology == SC_TECHNOLOGY_DEFAULT) || (technology == SC_TECHNOLOGY_DIRECTWRITEDC)) {
HDC hdc = ::GetDC(MainHWND());
FullPaintDC(hdc);
::ReleaseDC(MainHWND(), hdc);
} else {
FullPaintDC(0);
}
}
/**
* Redraw all of text area on the specified DC.
* This paint will not be abandoned.
*/
void ScintillaWin::FullPaintDC(HDC hdc) {
paintState = painting;
rcPaint = GetClientRectangle();
paintingAllText = true;
if (technology == SC_TECHNOLOGY_DEFAULT) {
AutoSurface surfaceWindow(hdc, this);
if (surfaceWindow) {
Paint(surfaceWindow, rcPaint);
surfaceWindow->Release();
}
} else {
#if defined(USE_D2D)
EnsureRenderTarget(hdc);
AutoSurface surfaceWindow(pRenderTarget, this);
if (surfaceWindow) {
pRenderTarget->BeginDraw();
Paint(surfaceWindow, rcPaint);
surfaceWindow->Release();
HRESULT hr = pRenderTarget->EndDraw();
if (hr == D2DERR_RECREATE_TARGET) {
DropRenderTarget();
}
}
#endif
}
paintState = notPainting;
}
static bool CompareDevCap(HDC hdc, HDC hOtherDC, int nIndex) {
return ::GetDeviceCaps(hdc, nIndex) == ::GetDeviceCaps(hOtherDC, nIndex);
}
bool ScintillaWin::IsCompatibleDC(HDC hOtherDC) {
HDC hdc = ::GetDC(MainHWND());
bool isCompatible =
CompareDevCap(hdc, hOtherDC, TECHNOLOGY) &&
CompareDevCap(hdc, hOtherDC, LOGPIXELSY) &&
CompareDevCap(hdc, hOtherDC, LOGPIXELSX) &&
CompareDevCap(hdc, hOtherDC, BITSPIXEL) &&
CompareDevCap(hdc, hOtherDC, PLANES);
::ReleaseDC(MainHWND(), hdc);
return isCompatible;
}
DWORD ScintillaWin::EffectFromState(DWORD grfKeyState) const {
// These are the Wordpad semantics.
DWORD dwEffect;
if (inDragDrop == ddDragging) // Internal defaults to move
dwEffect = DROPEFFECT_MOVE;
else
dwEffect = DROPEFFECT_COPY;
if (grfKeyState & MK_ALT)
dwEffect = DROPEFFECT_MOVE;
if (grfKeyState & MK_CONTROL)
dwEffect = DROPEFFECT_COPY;
return dwEffect;
}
/// Implement IUnknown
STDMETHODIMP ScintillaWin::QueryInterface(REFIID riid, PVOID *ppv) {
*ppv = NULL;
if (riid == IID_IUnknown)
*ppv = reinterpret_cast<IDropTarget *>(&dt);
if (riid == IID_IDropSource)
*ppv = reinterpret_cast<IDropSource *>(&ds);
if (riid == IID_IDropTarget)
*ppv = reinterpret_cast<IDropTarget *>(&dt);
if (riid == IID_IDataObject)
*ppv = reinterpret_cast<IDataObject *>(&dob);
if (!*ppv)
return E_NOINTERFACE;
return S_OK;
}
STDMETHODIMP_(ULONG) ScintillaWin::AddRef() {
return 1;
}
STDMETHODIMP_(ULONG) ScintillaWin::Release() {
return 1;
}
/// Implement IDropTarget
STDMETHODIMP ScintillaWin::DragEnter(LPDATAOBJECT pIDataSource, DWORD grfKeyState,
POINTL, PDWORD pdwEffect) {
if (pIDataSource == NULL)
return E_POINTER;
FORMATETC fmtu = {CF_UNICODETEXT, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
HRESULT hrHasUText = pIDataSource->QueryGetData(&fmtu);
hasOKText = (hrHasUText == S_OK);
if (!hasOKText) {
FORMATETC fmte = {CF_TEXT, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
HRESULT hrHasText = pIDataSource->QueryGetData(&fmte);
hasOKText = (hrHasText == S_OK);
}
if (!hasOKText) {
*pdwEffect = DROPEFFECT_NONE;
return S_OK;
}
*pdwEffect = EffectFromState(grfKeyState);
return S_OK;
}
STDMETHODIMP ScintillaWin::DragOver(DWORD grfKeyState, POINTL pt, PDWORD pdwEffect) {
try {
if (!hasOKText || pdoc->IsReadOnly()) {
*pdwEffect = DROPEFFECT_NONE;
return S_OK;
}
*pdwEffect = EffectFromState(grfKeyState);
// Update the cursor.
POINT rpt = {pt.x, pt.y};
::ScreenToClient(MainHWND(), &rpt);
SetDragPosition(SPositionFromLocation(PointFromPOINT(rpt), false, false, UserVirtualSpace()));
return S_OK;
} catch (...) {
errorStatus = SC_STATUS_FAILURE;
}
return E_FAIL;
}
STDMETHODIMP ScintillaWin::DragLeave() {
try {
SetDragPosition(SelectionPosition(invalidPosition));
return S_OK;
} catch (...) {
errorStatus = SC_STATUS_FAILURE;
}
return E_FAIL;
}
STDMETHODIMP ScintillaWin::Drop(LPDATAOBJECT pIDataSource, DWORD grfKeyState,
POINTL pt, PDWORD pdwEffect) {
try {
*pdwEffect = EffectFromState(grfKeyState);
if (pIDataSource == NULL)
return E_POINTER;
SetDragPosition(SelectionPosition(invalidPosition));
STGMEDIUM medium = {0, {0}, 0};
std::vector<char> data; // Includes terminating NUL
FORMATETC fmtu = {CF_UNICODETEXT, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
HRESULT hr = pIDataSource->GetData(&fmtu, &medium);
if (SUCCEEDED(hr) && medium.hGlobal) {
GlobalMemory memUDrop(medium.hGlobal);
wchar_t *udata = static_cast<wchar_t *>(memUDrop.ptr);
if (udata) {
if (IsUnicodeMode()) {
int tlen = static_cast<int>(memUDrop.Size());
// Convert UTF-16 to UTF-8
int dataLen = UTF8Length(udata, tlen/2);
data.resize(dataLen+1);
UTF8FromUTF16(udata, tlen/2, &data[0], dataLen);
} else {
// Convert UTF-16 to ANSI
//
// Default Scintilla behavior in Unicode mode
// CF_UNICODETEXT available, but not in Unicode mode
// Convert from Unicode to current Scintilla code page
UINT cpDest = CodePageOfDocument();
int tlen = ::WideCharToMultiByte(cpDest, 0, udata, -1,
NULL, 0, NULL, NULL) - 1; // subtract 0 terminator
data.resize(tlen + 1);
::WideCharToMultiByte(cpDest, 0, udata, -1,
&data[0], tlen + 1, NULL, NULL);
}
}
memUDrop.Unlock();
} else {
FORMATETC fmte = {CF_TEXT, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
hr = pIDataSource->GetData(&fmte, &medium);
if (SUCCEEDED(hr) && medium.hGlobal) {
GlobalMemory memDrop(medium.hGlobal);
const char *cdata = static_cast<char *>(memDrop.ptr);
if (cdata)
data.assign(cdata, cdata+strlen(cdata)+1);
memDrop.Unlock();
}
}
if (!SUCCEEDED(hr) || data.empty()) {
//Platform::DebugPrintf("Bad data format: 0x%x\n", hres);
return hr;
}
FORMATETC fmtr = {cfColumnSelect, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
HRESULT hrRectangular = pIDataSource->QueryGetData(&fmtr);
POINT rpt = {pt.x, pt.y};
::ScreenToClient(MainHWND(), &rpt);
SelectionPosition movePos = SPositionFromLocation(PointFromPOINT(rpt), false, false, UserVirtualSpace());
DropAt(movePos, &data[0], data.size() - 1, *pdwEffect == DROPEFFECT_MOVE, hrRectangular == S_OK);
// Free data
if (medium.pUnkForRelease != NULL)
medium.pUnkForRelease->Release();
else
::GlobalFree(medium.hGlobal);
return S_OK;
} catch (...) {
errorStatus = SC_STATUS_FAILURE;
}
return E_FAIL;
}
/// Implement important part of IDataObject
STDMETHODIMP ScintillaWin::GetData(FORMATETC *pFEIn, STGMEDIUM *pSTM) {
bool formatOK = (pFEIn->cfFormat == CF_TEXT) ||
((pFEIn->cfFormat == CF_UNICODETEXT) && IsUnicodeMode());
if (!formatOK ||
pFEIn->ptd != 0 ||
(pFEIn->dwAspect & DVASPECT_CONTENT) == 0 ||
pFEIn->lindex != -1 ||
(pFEIn->tymed & TYMED_HGLOBAL) == 0
) {
//Platform::DebugPrintf("DOB GetData No %d %x %x fmt=%x\n", lenDrag, pFEIn, pSTM, pFEIn->cfFormat);
return DATA_E_FORMATETC;
}
pSTM->tymed = TYMED_HGLOBAL;
//Platform::DebugPrintf("DOB GetData OK %d %x %x\n", lenDrag, pFEIn, pSTM);
GlobalMemory text;
if (pFEIn->cfFormat == CF_UNICODETEXT) {
size_t uchars = UTF16Length(drag.Data(), static_cast<int>(drag.LengthWithTerminator()));
text.Allocate(2 * uchars);
if (text) {
UTF16FromUTF8(drag.Data(), drag.LengthWithTerminator(),
static_cast<wchar_t *>(text.ptr), uchars);
}
} else {
text.Allocate(drag.LengthWithTerminator());
if (text) {
memcpy(static_cast<char *>(text.ptr), drag.Data(), drag.LengthWithTerminator());
}
}
pSTM->hGlobal = text ? text.Unlock() : 0;
pSTM->pUnkForRelease = 0;
return S_OK;
}
bool ScintillaWin::Register(HINSTANCE hInstance_) {
hInstance = hInstance_;
bool result;
// Register the Scintilla class
// Register Scintilla as a wide character window
WNDCLASSEXW wndclass;
wndclass.cbSize = sizeof(wndclass);
wndclass.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = ScintillaWin::SWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = sizeof(ScintillaWin *);
wndclass.hInstance = hInstance;
wndclass.hIcon = NULL;
wndclass.hCursor = NULL;
wndclass.hbrBackground = NULL;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = L"Scintilla";
wndclass.hIconSm = 0;
scintillaClassAtom = ::RegisterClassExW(&wndclass);
result = 0 != scintillaClassAtom;
if (result) {
// Register the CallTip class
WNDCLASSEX wndclassc;
wndclassc.cbSize = sizeof(wndclassc);
wndclassc.style = CS_GLOBALCLASS | CS_HREDRAW | CS_VREDRAW;
wndclassc.cbClsExtra = 0;
wndclassc.cbWndExtra = sizeof(ScintillaWin *);
wndclassc.hInstance = hInstance;
wndclassc.hIcon = NULL;
wndclassc.hbrBackground = NULL;
wndclassc.lpszMenuName = NULL;
wndclassc.lpfnWndProc = ScintillaWin::CTWndProc;
wndclassc.hCursor = ::LoadCursor(NULL, IDC_ARROW);
wndclassc.lpszClassName = callClassName;
wndclassc.hIconSm = 0;
callClassAtom = ::RegisterClassEx(&wndclassc);
result = 0 != callClassAtom;
}
return result;
}
bool ScintillaWin::Unregister() {
bool result = true;
if (0 != scintillaClassAtom) {
if (::UnregisterClass(MAKEINTATOM(scintillaClassAtom), hInstance) == 0) {
result = false;
}
scintillaClassAtom = 0;
}
if (0 != callClassAtom) {
if (::UnregisterClass(MAKEINTATOM(callClassAtom), hInstance) == 0) {
result = false;
}
callClassAtom = 0;
}
return result;
}
bool ScintillaWin::HasCaretSizeChanged() const {
if (
( (0 != vs.caretWidth) && (sysCaretWidth != vs.caretWidth) )
|| ((0 != vs.lineHeight) && (sysCaretHeight != vs.lineHeight))
) {
return true;
}
return false;
}
BOOL ScintillaWin::CreateSystemCaret() {
sysCaretWidth = vs.caretWidth;
if (0 == sysCaretWidth) {
sysCaretWidth = 1;
}
sysCaretHeight = vs.lineHeight;
int bitmapSize = (((sysCaretWidth + 15) & ~15) >> 3) *
sysCaretHeight;
std::vector<char> bits(bitmapSize);
sysCaretBitmap = ::CreateBitmap(sysCaretWidth, sysCaretHeight, 1,
1, reinterpret_cast<BYTE *>(&bits[0]));
BOOL retval = ::CreateCaret(
MainHWND(), sysCaretBitmap,
sysCaretWidth, sysCaretHeight);
if (technology == SC_TECHNOLOGY_DEFAULT) {
// System caret interferes with Direct2D drawing so only show it for GDI.
::ShowCaret(MainHWND());
}
return retval;
}
BOOL ScintillaWin::DestroySystemCaret() {
::HideCaret(MainHWND());
BOOL retval = ::DestroyCaret();
if (sysCaretBitmap) {
::DeleteObject(sysCaretBitmap);
sysCaretBitmap = 0;
}
return retval;
}
LRESULT PASCAL ScintillaWin::CTWndProc(
HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) {
// Find C++ object associated with window.
ScintillaWin *sciThis = reinterpret_cast<ScintillaWin *>(PointerFromWindow(hWnd));
try {
// ctp will be zero if WM_CREATE not seen yet
if (sciThis == 0) {
if (iMessage == WM_CREATE) {
// Associate CallTip object with window
CREATESTRUCT *pCreate = reinterpret_cast<CREATESTRUCT *>(lParam);
SetWindowPointer(hWnd, pCreate->lpCreateParams);
return 0;
} else {
return ::DefWindowProc(hWnd, iMessage, wParam, lParam);
}
} else {
if (iMessage == WM_NCDESTROY) {
::SetWindowLong(hWnd, 0, 0);
return ::DefWindowProc(hWnd, iMessage, wParam, lParam);
} else if (iMessage == WM_PAINT) {
PAINTSTRUCT ps;
::BeginPaint(hWnd, &ps);
Surface *surfaceWindow = Surface::Allocate(sciThis->technology);
if (surfaceWindow) {
#if defined(USE_D2D)
ID2D1HwndRenderTarget *pCTRenderTarget = 0;
#endif
RECT rc;
GetClientRect(hWnd, &rc);
// Create a Direct2D render target.
if (sciThis->technology == SC_TECHNOLOGY_DEFAULT) {
surfaceWindow->Init(ps.hdc, hWnd);
} else {
#if defined(USE_D2D)
D2D1_HWND_RENDER_TARGET_PROPERTIES dhrtp;
dhrtp.hwnd = hWnd;
dhrtp.pixelSize = D2D1::SizeU(rc.right - rc.left, rc.bottom - rc.top);
dhrtp.presentOptions = (sciThis->technology == SC_TECHNOLOGY_DIRECTWRITERETAIN) ?
D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS : D2D1_PRESENT_OPTIONS_NONE;
D2D1_RENDER_TARGET_PROPERTIES drtp;
drtp.type = D2D1_RENDER_TARGET_TYPE_DEFAULT;
drtp.pixelFormat.format = DXGI_FORMAT_UNKNOWN;
drtp.pixelFormat.alphaMode = D2D1_ALPHA_MODE_UNKNOWN;
drtp.dpiX = 96.0;
drtp.dpiY = 96.0;
drtp.usage = D2D1_RENDER_TARGET_USAGE_NONE;
drtp.minLevel = D2D1_FEATURE_LEVEL_DEFAULT;
if (!SUCCEEDED(pD2DFactory->CreateHwndRenderTarget(drtp, dhrtp, &pCTRenderTarget))) {
surfaceWindow->Release();
delete surfaceWindow;
::EndPaint(hWnd, &ps);
return 0;
}
surfaceWindow->Init(pCTRenderTarget, hWnd);
pCTRenderTarget->BeginDraw();
#endif
}
surfaceWindow->SetUnicodeMode(SC_CP_UTF8 == sciThis->ct.codePage);
surfaceWindow->SetDBCSMode(sciThis->ct.codePage);
sciThis->ct.PaintCT(surfaceWindow);
#if defined(USE_D2D)
if (pCTRenderTarget)
pCTRenderTarget->EndDraw();
#endif
surfaceWindow->Release();
delete surfaceWindow;
#if defined(USE_D2D)
if (pCTRenderTarget)
pCTRenderTarget->Release();
#endif
}
::EndPaint(hWnd, &ps);
return 0;
} else if ((iMessage == WM_NCLBUTTONDOWN) || (iMessage == WM_NCLBUTTONDBLCLK)) {
POINT pt;
pt.x = static_cast<short>(LOWORD(lParam));
pt.y = static_cast<short>(HIWORD(lParam));
ScreenToClient(hWnd, &pt);
sciThis->ct.MouseClick(PointFromPOINT(pt));
sciThis->CallTipClick();
return 0;
} else if (iMessage == WM_LBUTTONDOWN) {
// This does not fire due to the hit test code
sciThis->ct.MouseClick(Point::FromLong(static_cast<long>(lParam)));
sciThis->CallTipClick();
return 0;
} else if (iMessage == WM_SETCURSOR) {
::SetCursor(::LoadCursor(NULL, IDC_ARROW));
return 0;
} else if (iMessage == WM_NCHITTEST) {
return HTCAPTION;
} else {
return ::DefWindowProc(hWnd, iMessage, wParam, lParam);
}
}
} catch (...) {
sciThis->errorStatus = SC_STATUS_FAILURE;
}
return ::DefWindowProc(hWnd, iMessage, wParam, lParam);
}
sptr_t ScintillaWin::DirectFunction(
sptr_t ptr, UINT iMessage, uptr_t wParam, sptr_t lParam) {
PLATFORM_ASSERT(::GetCurrentThreadId() == ::GetWindowThreadProcessId(reinterpret_cast<ScintillaWin *>(ptr)->MainHWND(), NULL));
return reinterpret_cast<ScintillaWin *>(ptr)->WndProc(iMessage, wParam, lParam);
}
extern "C"
#ifndef STATIC_BUILD
__declspec(dllexport)
#endif
sptr_t __stdcall Scintilla_DirectFunction(
ScintillaWin *sci, UINT iMessage, uptr_t wParam, sptr_t lParam) {
return sci->WndProc(iMessage, wParam, lParam);
}
LRESULT PASCAL ScintillaWin::SWndProc(
HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam) {
//Platform::DebugPrintf("S W:%x M:%x WP:%x L:%x\n", hWnd, iMessage, wParam, lParam);
// Find C++ object associated with window.
ScintillaWin *sci = reinterpret_cast<ScintillaWin *>(PointerFromWindow(hWnd));
// sci will be zero if WM_CREATE not seen yet
if (sci == 0) {
try {
if (iMessage == WM_CREATE) {
// Create C++ object associated with window
sci = new ScintillaWin(hWnd);
SetWindowPointer(hWnd, sci);
return sci->WndProc(iMessage, wParam, lParam);
}
} catch (...) {
}
return ::DefWindowProc(hWnd, iMessage, wParam, lParam);
} else {
if (iMessage == WM_NCDESTROY) {
try {
sci->Finalise();
delete sci;
} catch (...) {
}
::SetWindowLong(hWnd, 0, 0);
return ::DefWindowProc(hWnd, iMessage, wParam, lParam);
} else {
return sci->WndProc(iMessage, wParam, lParam);
}
}
}
// This function is externally visible so it can be called from container when building statically.
// Must be called once only.
int Scintilla_RegisterClasses(void *hInstance) {
Platform_Initialise(hInstance);
bool result = ScintillaWin::Register(reinterpret_cast<HINSTANCE>(hInstance));
#ifdef SCI_LEXER
Scintilla_LinkLexers();
#endif
return result;
}
static int ResourcesRelease(bool fromDllMain) {
bool result = ScintillaWin::Unregister();
if (commctrl32) {
FreeLibrary(commctrl32);
commctrl32 = NULL;
}
Platform_Finalise(fromDllMain);
return result;
}
// This function is externally visible so it can be called from container when building statically.
int Scintilla_ReleaseResources() {
return ResourcesRelease(false);
}
#ifndef STATIC_BUILD
extern "C" int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpvReserved) {
//Platform::DebugPrintf("Scintilla::DllMain %d %d\n", hInstance, dwReason);
if (dwReason == DLL_PROCESS_ATTACH) {
if (!Scintilla_RegisterClasses(hInstance))
return FALSE;
} else if (dwReason == DLL_PROCESS_DETACH) {
if (lpvReserved == NULL) {
ResourcesRelease(true);
}
}
return TRUE;
}
#endif
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.