[96dcfd]: gtk / SciTEGTK.cxx Maximize Restore History

Download this file

SciTEGTK.cxx    5284 lines (4550 with data), 172.0 kB

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
// SciTE - Scintilla based Text Editor
// SciTEGTK.cxx - main code for the GTK+ version of the editor
// Copyright 1998-2004 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 <ctype.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <assert.h>
#include <time.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <unistd.h>
#include <glib.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <errno.h>
#include "Scintilla.h"
#include "ScintillaWidget.h"
#include "ILexer.h"
#include "GUI.h"
#include "SString.h"
#include "StringList.h"
#include "StringHelpers.h"
#include "FilePath.h"
#include "StyleDefinition.h"
#include "PropSetFile.h"
#include "Extender.h"
#ifndef NO_EXTENSIONS
#include "MultiplexExtension.h"
#ifndef NO_FILER
#include "DirectorExtension.h"
#endif
#ifndef NO_LUA
#include "LuaExtension.h"
#endif
#endif
#include "SciTE.h"
#include "Mutex.h"
#include "JobQueue.h"
#include "pixmapsGNOME.h"
#include "SciIcon.h"
#include "Widget.h"
#include "Cookie.h"
#include "Worker.h"
#include "SciTEBase.h"
#include "SciTEKeys.h"
#include "StripDefinition.h"
#if defined(__clang__)
// Clang 3.0 incorrectly displays sentinel warnings. Fixed by clang 3.1.
#pragma GCC diagnostic ignored "-Wsentinel"
#endif
#if GTK_CHECK_VERSION(2,20,0)
#define WIDGET_SET_NO_FOCUS(w) gtk_widget_set_can_focus(w, FALSE)
#else
#define WIDGET_SET_NO_FOCUS(w) GTK_WIDGET_UNSET_FLAGS(w, GTK_CAN_FOCUS)
#endif
#define MB_ABOUTBOX 0x100000L
// Key names are longer for GTK+ 3
#if GTK_CHECK_VERSION(3,0,0)
#define GKEY_Escape GDK_KEY_Escape
#define GKEY_Tab GDK_KEY_Tab
#define GKEY_ISO_Left_Tab GDK_KEY_ISO_Left_Tab
#define GKEY_KP_Enter GDK_KEY_KP_Enter
#define GKEY_KP_Multiply GDK_KEY_KP_Multiply
#define GKEY_Control_L GDK_KEY_Control_L
#define GKEY_Control_R GDK_KEY_Control_R
#define GKEY_F1 GDK_KEY_F1
#define GKEY_F2 GDK_KEY_F2
#define GKEY_F3 GDK_KEY_F3
#define GKEY_F4 GDK_KEY_F4
#else
#define GKEY_Escape GDK_Escape
#define GKEY_Tab GDK_Tab
#define GKEY_ISO_Left_Tab GDK_ISO_Left_Tab
#define GKEY_KP_Enter GDK_KP_Enter
#define GKEY_KP_Multiply GDK_KP_Multiply
#define GKEY_Control_L GDK_Control_L
#define GKEY_Control_R GDK_Control_R
#define GKEY_F1 GDK_F1
#define GKEY_F2 GDK_F2
#define GKEY_F3 GDK_F3
#define GKEY_F4 GDK_F4
#endif
static GdkWindow *WindowFromWidget(GtkWidget *w) {
#if GTK_CHECK_VERSION(3,0,0)
return gtk_widget_get_window(w);
#else
return w->window;
#endif
}
const char appName[] = "SciTE";
static GtkWidget *PWidget(GUI::Window &w) {
return reinterpret_cast<GtkWidget *>(w.GetID());
}
class SciTEGTK;
typedef void (*SigFunction)(GtkWidget *w, SciTEGTK *app);
// Callback thunk class connects GTK+ signals to a SciTEGTK instance method.
template< void (SciTEGTK::*method)() >
class Signal {
public:
static void Function(GtkWidget */*w*/, SciTEGTK *app) {
(app->*method)();
}
};
// Callback thunk class connects GTK+ signals to a SciTEGTK instance method.
template< void (SciTEGTK::*method)(int responseID) >
class ResponseSignal {
public:
static void Function(GtkDialog */*w*/, gint responseID, SciTEGTK *app) {
(app->*method)(responseID);
}
};
template< void (SciTEGTK::*method)(int responseID) >
inline void AttachResponse(GtkWidget *w, SciTEGTK *object) {
ResponseSignal <method> sig;
g_signal_connect(G_OBJECT(w), "response", G_CALLBACK(sig.Function), object);
}
// Field added to GTK+ 1.x ItemFactoryEntry for 2.x so have a struct that is the same as 1.x
struct SciTEItemFactoryEntry {
const char *path;
const char *accelerator;
GCallback callback;
unsigned int callback_action;
const char *item_type;
};
long SciTEKeys::ParseKeyCode(const char *mnemonic) {
int modsInKey = 0;
int keyval = -1;
if (mnemonic && *mnemonic) {
SString sKey = mnemonic;
if (sKey.contains("Ctrl+")) {
modsInKey |= GDK_CONTROL_MASK;
sKey.remove("Ctrl+");
}
if (sKey.contains("Shift+")) {
modsInKey |= GDK_SHIFT_MASK;
sKey.remove("Shift+");
}
if (sKey.contains("Alt+")) {
modsInKey |= GDK_MOD1_MASK;
sKey.remove("Alt+");
}
if (sKey.length() == 1) {
if (modsInKey & GDK_CONTROL_MASK && !(modsInKey & GDK_SHIFT_MASK))
sKey.lowercase();
keyval = sKey[0];
} else if ((sKey.length() > 1)) {
if ((sKey[0] == 'F') && (isdigit(sKey[1]))) {
sKey.remove("F");
int fkeyNum = sKey.value();
if (fkeyNum >= 1 && fkeyNum <= 12)
#if GTK_CHECK_VERSION(3,0,0)
keyval = fkeyNum - 1 + GDK_KEY_F1;
#else
keyval = fkeyNum - 1 + GDK_F1;
#endif
} else {
#if GTK_CHECK_VERSION(3,0,0)
if (sKey == "Left") {
keyval = GDK_KEY_Left;
} else if (sKey == "Right") {
keyval = GDK_KEY_Right;
} else if (sKey == "Up") {
keyval = GDK_KEY_Up;
} else if (sKey == "Down") {
keyval = GDK_KEY_Down;
} else if (sKey == "Insert") {
keyval = GDK_KEY_Insert;
} else if (sKey == "End") {
keyval = GDK_KEY_End;
} else if (sKey == "Home") {
keyval = GDK_KEY_Home;
} else if (sKey == "Enter") {
keyval = GDK_KEY_Return;
} else if (sKey == "Space") {
keyval = GDK_KEY_space;
} else if (sKey == "Tab") {
keyval = GDK_KEY_Tab;
} else if (sKey == "KeypadPlus") {
keyval = GDK_KEY_KP_Add;
} else if (sKey == "KeypadMinus") {
keyval = GDK_KEY_KP_Subtract;
} else if (sKey == "KeypadMultiply") {
keyval = GDK_KEY_KP_Multiply;
} else if (sKey == "KeypadDivide") {
keyval = GDK_KEY_KP_Divide;
} else if (sKey == "Escape") {
keyval = GDK_KEY_Escape;
} else if (sKey == "Delete") {
keyval = GDK_KEY_Delete;
} else if (sKey == "PageUp") {
keyval = GDK_KEY_Page_Up;
} else if (sKey == "PageDown") {
keyval = GDK_KEY_Page_Down;
} else if (sKey == "Slash") {
keyval = GDK_KEY_slash;
} else if (sKey == "Question") {
keyval = GDK_KEY_question;
} else if (sKey == "Equal") {
keyval = GDK_KEY_equal;
} else if (sKey == "Win") {
keyval = GDK_KEY_Super_L;
} else if (sKey == "Menu") {
keyval = GDK_KEY_Menu;
}
#else
if (sKey == "Left") {
keyval = GDK_Left;
} else if (sKey == "Right") {
keyval = GDK_Right;
} else if (sKey == "Up") {
keyval = GDK_Up;
} else if (sKey == "Down") {
keyval = GDK_Down;
} else if (sKey == "Insert") {
keyval = GDK_Insert;
} else if (sKey == "End") {
keyval = GDK_End;
} else if (sKey == "Home") {
keyval = GDK_Home;
} else if (sKey == "Enter") {
keyval = GDK_Return;
} else if (sKey == "Space") {
keyval = GDK_space;
} else if (sKey == "Tab") {
keyval = GDK_Tab;
} else if (sKey == "KeypadPlus") {
keyval = GDK_KP_Add;
} else if (sKey == "KeypadMinus") {
keyval = GDK_KP_Subtract;
} else if (sKey == "KeypadMultiply") {
keyval = GDK_KP_Multiply;
} else if (sKey == "KeypadDivide") {
keyval = GDK_KP_Divide;
} else if (sKey == "Escape") {
keyval = GDK_Escape;
} else if (sKey == "Delete") {
keyval = GDK_Delete;
} else if (sKey == "PageUp") {
keyval = GDK_Page_Up;
} else if (sKey == "PageDown") {
keyval = GDK_Page_Down;
} else if (sKey == "Slash") {
keyval = GDK_slash;
} else if (sKey == "Question") {
keyval = GDK_question;
} else if (sKey == "Equal") {
keyval = GDK_equal;
} else if (sKey == "Win") {
keyval = GDK_Super_L;
} else if (sKey == "Menu") {
keyval = GDK_Menu;
}
#endif
}
}
}
return (keyval > 0) ? (keyval | (modsInKey<<16)) : 0;
}
bool SciTEKeys::MatchKeyCode(long parsedKeyCode, int keyval, int modifiers) {
return parsedKeyCode && !(0xFFFF0000 & (keyval | modifiers)) && (parsedKeyCode == (keyval | (modifiers<<16)));
}
class BackgroundStrip : public Strip {
public:
WStatic wExplanation;
WProgress wProgress;
BackgroundStrip() {
}
virtual void Creation(GtkWidget *container);
void SetProgress(const GUI::gui_string &explanation, int size, int progress);
};
class DialogGoto : public Dialog {
public:
WEntry entryGoto;
};
class DialogAbbrev : public Dialog {
public:
WComboBoxEntry comboAbbrev;
};
class DialogTabSize : public Dialog {
public:
WEntry entryTabSize;
WEntry entryIndentSize;
WToggle toggleUseTabs;
};
class DialogParameters : public Dialog {
public:
bool paramDialogCanceled;
WEntry entryParam[SciTEBase::maxParam];
DialogParameters() : paramDialogCanceled(true) {
}
};
class DialogFindInFiles : public Dialog, public SearchUI {
public:
WComboBoxEntry wComboFiles;
WComboBoxEntry wComboFindInFiles;
WComboBoxEntry comboDir;
WToggle toggleWord;
WToggle toggleCase;
WButton btnDotDot;
WButton btnBrowse;
void GrabFields();
void FillFields();
};
class DialogFindReplace : public Dialog, public SearchUI {
public:
WStatic labelFind;
WComboBoxEntry wComboFind;
WStatic labelReplace;
WComboBoxEntry wComboReplace;
WToggle toggleWord;
WToggle toggleCase;
WToggle toggleRegExp;
WToggle toggleWrap;
WToggle toggleUnSlash;
WToggle toggleReverse;
void GrabFields();
void FillFields();
};
class FindStrip : public Strip, public SearchUI {
public:
WStatic wStaticFind;
WComboBoxEntry wComboFind;
WButton wButton;
WButton wButtonMarkAll;
enum { checks = 6 };
WCheckDraw wCheck[checks];
FindStrip() {
}
virtual void Creation(GtkWidget *boxMain);
virtual void Destruction();
virtual void Show(int buttonHeight);
virtual void Close();
virtual bool KeyDown(GdkEventKey *event);
void MenuAction(guint action);
static void ActivateSignal(GtkWidget *w, FindStrip *pStrip);
static gboolean EscapeSignal(GtkWidget *w, GdkEventKey *event, FindStrip *pStrip);
void GrabFields();
void SetToggles();
void ShowPopup();
void FindNextCmd();
void MarkAllCmd();
virtual void ChildFocus(GtkWidget *widget);
gboolean Focus(GtkDirectionType direction);
};
class ReplaceStrip : public Strip, public SearchUI {
public:
WStatic wStaticFind;
WComboBoxEntry wComboFind;
WButton wButtonFind;
WButton wButtonReplaceAll;
WStatic wStaticReplace;
WComboBoxEntry wComboReplace;
WButton wButtonReplace;
WButton wButtonReplaceInSelection;
enum { checks = 5 };
WCheckDraw wCheck[checks];
ReplaceStrip() {
}
virtual void Creation(GtkWidget *boxMain);
virtual void Destruction();
virtual void Show(int buttonHeight);
virtual void Close();
virtual bool KeyDown(GdkEventKey *event);
void MenuAction(guint action);
static void ActivateSignal(GtkWidget *w, ReplaceStrip *pStrip);
static gboolean EscapeSignal(GtkWidget *w, GdkEventKey *event, ReplaceStrip *pStrip);
void GrabFields();
void SetToggles();
void FindCmd();
void ReplaceAllCmd();
void ReplaceCmd();
void ReplaceInSelectionCmd();
void ShowPopup();
virtual void ChildFocus(GtkWidget *widget);
gboolean Focus(GtkDirectionType direction);
};
class UserStrip : public Strip {
public:
StripDefinition *psd;
Extension *extender;
SciTEGTK *pSciTEGTK;
WTable tableUser;
UserStrip() : psd(0), extender(0), pSciTEGTK(0), tableUser(1, 1){
}
virtual void Creation(GtkWidget *boxMain);
virtual void Destruction();
virtual void Show(int buttonHeight);
virtual void Close();
virtual bool KeyDown(GdkEventKey *event);
static void ActivateSignal(GtkWidget *w, UserStrip *pStrip);
static gboolean EscapeSignal(GtkWidget *w, GdkEventKey *event, UserStrip *pStrip);
void ClickThis(GtkWidget *w);
static void ClickSignal(GtkWidget *w, UserStrip *pStrip);
virtual void ChildFocus(GtkWidget *widget);
gboolean Focus(GtkDirectionType direction);
void SetDescription(const char *description);
void SetExtender(Extension *extender_);
void SetSciTE(SciTEGTK *pSciTEGTK_);
void Set(int control, const char *value);
void SetList(int control, const char *value);
std::string GetValue(int control);
};
// Manage the use of the GDK thread lock within glib signal handlers
class ThreadLockMinder {
public:
#ifndef GDK_VERSION_3_6
ThreadLockMinder() {
gdk_threads_enter();
}
~ThreadLockMinder() {
gdk_threads_leave();
}
#endif
};
class SciTEGTK : public SciTEBase {
friend class UserStrip;
protected:
GtkWidget *splitPane;
guint sbContextID;
GUI::Window wToolBarBox;
int toolbarDetachable;
int menuSource;
// Control of sub process
FilePath sciteExecutable;
int icmd;
int originalEnd;
int fdFIFO;
GPid pidShell;
bool triedKill;
int exitStatus;
guint pollID;
int inputHandle;
GIOChannel *inputChannel;
GUI::ElapsedTime commandTime;
SString lastOutput;
int lastFlags;
// For single instance
char uniqueInstance[MAX_PATH];
guint32 startupTimestamp;
guint timerID;
BackgroundStrip backgroundStrip;
UserStrip userStrip;
enum FileFormat { sfSource, sfCopy, sfHTML, sfRTF, sfPDF, sfTEX, sfXML } saveFormat;
Dialog dlgFileSelector;
DialogFindInFiles dlgFindInFiles;
DialogGoto dlgGoto;
DialogAbbrev dlgAbbrev;
DialogTabSize dlgTabSize;
GtkWidget *wIncrementPanel;
GtkWidget *IncSearchEntry;
GtkWidget *IncSearchBtnNext;
FindStrip findStrip;
ReplaceStrip replaceStrip;
DialogFindReplace dlgFindReplace;
DialogParameters dlgParameters;
GtkWidget *btnCompile;
GtkWidget *btnBuild;
GtkWidget *btnStop;
GtkWidget *menuBar;
std::map<std::string, GtkWidget *> pulldowns;
std::map<std::string, GSList *> radiogroups;
std::map<int, GtkWidget *> mapMenuItemFromId;
GtkAccelGroup *accelGroup;
gint fileSelectorWidth;
gint fileSelectorHeight;
#if GTK_CHECK_VERSION(2,10,0)
GtkPrintSettings *printSettings;
GtkPageSetup *pageSetup;
std::vector<int> pageStarts;
#endif
// Fullscreen handling
GdkRectangle saved;
GtkWidget *AddMBButton(GtkWidget *dialog, const char *label,
int val, GtkAccelGroup *accel_group, bool isDefault = false);
void SetWindowName();
void ShowFileInStatus();
void SetIcon();
virtual void ReadLocalization();
virtual void ReadPropertiesInitial();
virtual void ReadProperties();
static gboolean TimerTick(SciTEGTK *scitew);
virtual void TimerStart(int mask);
virtual void TimerEnd(int mask);
virtual void GetWindowPosition(int *left, int *top, int *width, int *height, int *maximize);
virtual void SizeContentWindows();
virtual void SizeSubWindows();
bool UpdateOutputSize();
GtkWidget *MenuItemFromAction(int itemID);
virtual void SetMenuItem(int menuNumber, int position, int itemID,
const char *text, const char *mnemonic = 0);
virtual void DestroyMenuItem(int menuNumber, int itemID);
virtual void CheckAMenuItem(int wIDCheckItem, bool val);
virtual void EnableAMenuItem(int wIDCheckItem, bool val);
virtual void CheckMenusClipboard();
virtual void CheckMenus();
static void PopUpCmd(GtkMenuItem *menuItem, SciTEGTK *scitew);
virtual void AddToPopUp(const char *label, int cmd = 0, bool enabled = true);
virtual void ExecuteNext();
void ResetExecution();
virtual void OpenUriList(const char *list);
virtual bool OpenDialog(FilePath directory, const char *filter);
bool HandleSaveAs(const char *savePath);
bool SaveAsXXX(FileFormat fmt, const char *title, const char *ext=0);
virtual bool SaveAsDialog();
virtual void SaveACopy();
virtual void SaveAsHTML();
virtual void SaveAsRTF();
virtual void SaveAsPDF();
virtual void SaveAsTEX();
virtual void SaveAsXML();
virtual void LoadSessionDialog();
virtual void SaveSessionDialog();
#if GTK_CHECK_VERSION(2,10,0)
void SetupFormat(Sci_RangeToFormat &frPrint, GtkPrintContext *context);
void BeginPrintThis(GtkPrintOperation *operation, GtkPrintContext *context);
static void BeginPrint(GtkPrintOperation *operation, GtkPrintContext *context, SciTEGTK *scitew);
void DrawPageThis(GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr);
static void DrawPage(GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr, SciTEGTK *scitew);
#endif
virtual void Print(bool);
virtual void PrintSetup();
virtual SString GetRangeInUIEncoding(GUI::ScintillaWindow &wCurrent, int selStart, int selEnd);
virtual int WindowMessageBox(GUI::Window &w, const GUI::gui_string &msg, int style);
virtual void FindMessageBox(const SString &msg, const SString *findItem=0);
virtual void AboutDialog();
virtual void QuitProgram();
bool FindReplaceAdvanced();
virtual SString EncodeString(const SString &s);
void FindReplaceGrabFields();
virtual void Find();
virtual void UIClosed();
virtual void UIHasFocus();
GtkWidget *TranslatedLabel(const char *original);
virtual void FindIncrement();
void FindInFilesResponse(int responseID);
virtual void FindInFiles();
virtual void Replace();
void FindReplaceResponse(int responseID);
virtual void FindReplace(bool replace);
virtual void DestroyFindReplace();
virtual void GoLineDialog();
virtual bool AbbrevDialog();
virtual void TabSizeDialog();
virtual bool ParametersDialog(bool modal);
virtual FilePath GetDefaultDirectory();
virtual FilePath GetSciteDefaultHome();
virtual FilePath GetSciteUserHome();
virtual void SetStatusBarText(const char *s);
virtual void TabInsert(int index, const GUI::gui_char *title);
virtual void TabSelect(int index);
virtual void RemoveAllTabs();
virtual void SetFileProperties(PropSetFile &ps);
virtual void UpdateStatusBar(bool bUpdateSlowData);
virtual void Notify(SCNotification *notification);
virtual void ShowToolBar();
virtual void ShowTabBar();
virtual void ShowStatusBar();
virtual void ActivateWindow(const char *timestamp);
void CopyPath();
bool &FlagFromCmd(int cmd);
void Command(unsigned long wParam, long lParam = 0);
void ContinueExecute(int fromPoll);
virtual void UserStripShow(const char *description);
virtual void UserStripSet(int control, const char *value);
virtual void UserStripSetList(int control, const char *value);
virtual const char *UserStripValue(int control);
void UserStripClosed();
virtual void ShowBackgroundProgress(const GUI::gui_string &explanation, int size, int progress);
// Single instance
void SendFileName(int sendPipe, const char* filename);
bool CheckForRunningInstance(int argc, char* argv[]);
// GTK+ Signal Handlers
void FindInFilesCmd();
void FindInFilesDotDot();
void FindInFilesBrowse();
void GotoCmd();
void GotoResponse(int responseID);
void AbbrevCmd();
void AbbrevResponse(int responseID);
void TabSizeSet(int &tabSize, bool &useTabs);
void TabSizeCmd();
void TabSizeConvertCmd();
void TabSizeResponse(int responseID);
void FindIncrementSetColour(bool valid);
void FindIncrementNext(bool select);
void FindIncrementChanged();
void FindIncrementCompleteCmd();
static gboolean FindIncrementFocusOutSignal(GtkWidget *w);
static gboolean FindIncrementEscapeSignal(GtkWidget *w, GdkEventKey *event, SciTEGTK *scitew);
void FRFindCmd();
void FRReplaceCmd();
void FRReplaceAllCmd();
void FRReplaceInSelectionCmd();
void FRReplaceInBuffersCmd();
void FRMarkAllCmd();
virtual bool ParametersOpen();
virtual void ParamGrab();
void ParamCancelCmd();
void ParamCmd();
void ParamResponse(int responseID);
static void PanePositionChanged(GObject *object, GParamSpec *pspec, SciTEGTK *scitew);
static gint PaneButtonRelease(GtkWidget *widget, GdkEvent *event, SciTEGTK *scitew);
static gboolean IOSignal(GIOChannel *source, GIOCondition condition, SciTEGTK *scitew);
static gint QuitSignal(GtkWidget *w, GdkEventAny *e, SciTEGTK *scitew);
static void ButtonSignal(GtkWidget *widget, gpointer data);
static void MenuSignal(GtkMenuItem *menuitem, SciTEGTK *scitew);
static void NotifySignal(GtkWidget *w, gint wParam, SCNotification *notification, SciTEGTK *scitew);
static gint KeyPress(GtkWidget *widget, GdkEventKey *event, SciTEGTK *scitew);
static gint KeyRelease(GtkWidget *widget, GdkEventKey *event, SciTEGTK *scitew);
gint Key(GdkEventKey *event);
static gint MousePress(GtkWidget *widget, GdkEventButton *event, SciTEGTK *scitew);
gint Mouse(GdkEventButton *event);
static void DragDataReceived(GtkWidget *widget, GdkDragContext *context,
gint x, gint y, GtkSelectionData *selection_data, guint info, guint time, SciTEGTK *scitew);
gint TabBarRelease(GtkNotebook *notebook, GdkEventButton *event);
gint TabBarScroll(GdkEventScroll *event);
static gint TabBarReleaseSignal(GtkNotebook *notebook, GdkEventButton *event, SciTEGTK *scitew) {
return scitew->TabBarRelease(notebook, event);
}
static gint TabBarScrollSignal(GtkNotebook *, GdkEventScroll *event, SciTEGTK *scitew) {
return scitew->TabBarScroll(event);
}
public:
// TODO: get rid of this - use callback argument to find SciTEGTK
static SciTEGTK *instance;
SciTEGTK(Extension *ext = 0);
~SciTEGTK();
void WarnUser(int warnID);
GtkWidget *AddToolButton(const char *text, int cmd, GtkWidget *toolbar_icon);
void AddToolBar();
SString TranslatePath(const char *path);
void CreateTranslatedMenu(int n, SciTEItemFactoryEntry items[],
int nRepeats = 0, const char *prefix = 0, int startNum = 0,
int startID = 0, const char *radioStart = 0);
void CreateMenu();
void CreateStrips(GtkWidget *boxMain);
bool StripHasFocus();
void CreateUI();
void LayoutUI();
void Run(int argc, char *argv[]);
void ProcessExecute();
virtual void Execute();
virtual void StopExecute();
static int PollTool(SciTEGTK *scitew);
static void ReapChild(GPid, gint, gpointer);
virtual bool PerformOnNewThread(Worker *pWorker);
virtual void PostOnMainThread(int cmd, Worker *pWorker);
static gboolean PostCallback(void *ptr);
// Single instance
void SetStartupTime(const char *timestamp);
};
SciTEGTK *SciTEGTK::instance;
SciTEGTK::SciTEGTK(Extension *ext) : SciTEBase(ext) {
toolbarDetachable = 0;
menuSource = 0;
// Control of sub process
icmd = 0;
originalEnd = 0;
fdFIFO = 0;
pidShell = 0;
triedKill = false;
exitStatus = 0;
pollID = 0;
inputHandle = 0;
inputChannel = 0;
lastFlags = 0;
uniqueInstance[0] = '\0';
startupTimestamp = 0;
timerID = 0;
PropSetFile::SetCaseSensitiveFilenames(true);
propsEmbed.Set("PLAT_GTK", "1");
propsEmbed.Set("PLAT_UNIX", "1");
pathAbbreviations = GetAbbrevPropertiesFileName();
ReadGlobalPropFile();
ReadAbbrevPropFile();
saveFormat = sfSource;
wIncrementPanel = 0;
IncSearchEntry = 0;
IncSearchBtnNext = 0;
btnCompile = 0;
btnBuild = 0;
btnStop = 0;
menuBar = 0;
accelGroup = 0;
splitPane = 0;
heightBar = 0;
fileSelectorWidth = 580;
fileSelectorHeight = 480;
#if GTK_CHECK_VERSION(2,10,0)
printSettings = NULL;
pageSetup = NULL;
#endif
// Fullscreen handling
fullScreen = false;
instance = this;
}
SciTEGTK::~SciTEGTK() {}
static void destroyDialog(GtkWidget *, gpointer *window) {
if (window) {
GUI::Window *pwin = reinterpret_cast<GUI::Window *>(window);
*(pwin) = 0;
}
}
void SciTEGTK::WarnUser(int) {}
static GtkWidget *messageBoxDialog = 0;
static long messageBoxResult = 0;
static gint messageBoxKey(GtkWidget *w, GdkEventKey *event, gpointer p) {
if (event->keyval == GKEY_Escape) {
g_signal_stop_emission_by_name(G_OBJECT(w), "key_press_event");
gtk_widget_destroy(GTK_WIDGET(w));
messageBoxDialog = 0;
messageBoxResult = reinterpret_cast<long>(p);
}
return FALSE;
}
static void messageBoxDestroy(GtkWidget *, gpointer *) {
messageBoxDialog = 0;
messageBoxResult = 0;
}
static void messageBoxOK(GtkWidget *, gpointer p) {
gtk_widget_destroy(GTK_WIDGET(messageBoxDialog));
messageBoxDialog = 0;
messageBoxResult = reinterpret_cast<long>(p);
}
GtkWidget *SciTEGTK::AddMBButton(GtkWidget *dialog, const char *label,
int val, GtkAccelGroup *accel_group, bool isDefault) {
GUI::gui_string translated = localiser.Text(label);
GtkWidget *button = gtk_button_new_with_mnemonic(translated.c_str());
#if GTK_CHECK_VERSION(2,20,0)
gtk_widget_set_can_default(button, TRUE);
#else
GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
#endif
size_t posMnemonic = translated.find('_');
if (posMnemonic != GUI::gui_string::npos) {
// With a "Yes" button want to respond to pressing "y" as well as standard "Alt+y"
guint key = tolower(translated[posMnemonic + 1]);
gtk_widget_add_accelerator(button, "clicked", accel_group,
key, GdkModifierType(0), (GtkAccelFlags)0);
}
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(messageBoxOK), reinterpret_cast<gpointer>(val));
#if GTK_CHECK_VERSION(3,0,0)
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_action_area(GTK_DIALOG(dialog))),
button, TRUE, TRUE, 0);
#else
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area),
button, TRUE, TRUE, 0);
#endif
if (isDefault) {
gtk_widget_grab_default(GTK_WIDGET(button));
}
gtk_widget_show(button);
return button;
}
FilePath SciTEGTK::GetDefaultDirectory() {
const char *where = getenv("SciTE_HOME");
#ifdef SYSCONF_PATH
if (!where) {
where = SYSCONF_PATH;
}
#else
if (!where) {
where = getenv("HOME");
}
#endif
if (where) {
return FilePath(where);
}
return FilePath("");
}
FilePath SciTEGTK::GetSciteDefaultHome() {
const char *where = getenv("SciTE_HOME");
#ifdef SYSCONF_PATH
if (!where) {
where = SYSCONF_PATH;
}
#else
if (!where) {
where = getenv("HOME");
}
#endif
if (where) {
return FilePath(where);
}
return FilePath("");
}
FilePath SciTEGTK::GetSciteUserHome() {
char *where = getenv("SciTE_HOME");
if (!where) {
where = getenv("HOME");
}
return FilePath(where);
}
void SciTEGTK::ShowFileInStatus() {
char sbText[1000];
sprintf(sbText, " File: ");
if (filePath.IsUntitled())
strcat(sbText, "Untitled");
else
strcat(sbText, filePath.AsInternal());
SetStatusBarText(sbText);
}
void SciTEGTK::SetWindowName() {
SciTEBase::SetWindowName();
ShowFileInStatus();
}
void SciTEGTK::SetStatusBarText(const char *s) {
gtk_statusbar_pop(GTK_STATUSBAR(PWidget(wStatusBar)), sbContextID);
gtk_statusbar_push(GTK_STATUSBAR(PWidget(wStatusBar)), sbContextID, s);
}
void SciTEGTK::TabInsert(int index, const GUI::gui_char *title) {
if (wTabBar.GetID()) {
GtkWidget *tablabel = gtk_label_new(title);
GtkWidget *tabcontent;
if (props.GetInt("pathbar.visible")) {
if (buffers.buffers[index].IsUntitled())
tabcontent = gtk_label_new(localiser.Text("Untitled").c_str());
else
tabcontent = gtk_label_new(buffers.buffers[index].AsInternal());
} else {
// No path bar
tabcontent = gtk_image_new();
}
gtk_widget_show(tablabel);
gtk_widget_show(tabcontent);
gtk_notebook_append_page(GTK_NOTEBOOK(wTabBar.GetID()), tabcontent, tablabel);
}
}
void SciTEGTK::TabSelect(int index) {
if (wTabBar.GetID())
gtk_notebook_set_current_page(GTK_NOTEBOOK(wTabBar.GetID()), index);
}
void SciTEGTK::RemoveAllTabs() {
if (wTabBar.GetID()) {
while (gtk_notebook_get_nth_page(GTK_NOTEBOOK(wTabBar.GetID()), 0))
gtk_notebook_remove_page(GTK_NOTEBOOK(wTabBar.GetID()), 0);
}
}
void SciTEGTK::SetFileProperties(PropSetFile &ps) {
char timeBuffer[200];
time_t timeNow = time(NULL);
strftime(timeBuffer, sizeof(timeBuffer), "%x", localtime(&timeNow));
ps.Set("CurrentDate", timeBuffer);
strftime(timeBuffer, sizeof(timeBuffer), "%X", localtime(&timeNow));
ps.Set("CurrentTime", timeBuffer);
time_t timeFileModified = filePath.ModifiedTime();
strftime(timeBuffer, sizeof(timeBuffer), "%x", localtime(&timeFileModified));
ps.Set("FileDate", timeBuffer);
strftime(timeBuffer, sizeof(timeBuffer), "%X", localtime(&timeFileModified));
ps.Set("FileTime", timeBuffer);
SString fa;
if (access(filePath.AsInternal(), W_OK)) {
fa += "R";
}
if (filePath.AsInternal()[0] == '.') {
fa += "H";
}
ps.Set("FileAttr", fa.c_str());
}
void SciTEGTK::UpdateStatusBar(bool bUpdateSlowData) {
SciTEBase::UpdateStatusBar(bUpdateSlowData);
}
void SciTEGTK::Notify(SCNotification *notification) {
if (notification->nmhdr.idFrom == IDM_SRCWIN) {
if (notification->nmhdr.code == SCN_FOCUSIN)
Activate(true);
else if (notification->nmhdr.code == SCN_FOCUSOUT)
Activate(false);
}
SciTEBase::Notify(notification);
}
void SciTEGTK::ShowToolBar() {
if (gtk_toolbar_get_n_items(GTK_TOOLBAR(PWidget(wToolBar))) < 1) {
AddToolBar();
}
if (tbVisible) {
if (toolbarDetachable == 1) {
gtk_widget_show(GTK_WIDGET(PWidget(wToolBarBox)));
} else {
gtk_widget_show(GTK_WIDGET(PWidget(wToolBar)));
}
} else {
if (toolbarDetachable == 1) {
gtk_widget_hide(GTK_WIDGET(PWidget(wToolBarBox)));
} else {
gtk_widget_hide(GTK_WIDGET(PWidget(wToolBar)));
}
}
}
void SciTEGTK::ShowTabBar() {
if (tabVisible && (!tabHideOne || buffers.length > 1) && buffers.size>1) {
gtk_widget_show(GTK_WIDGET(PWidget(wTabBar)));
} else {
gtk_widget_hide(GTK_WIDGET(PWidget(wTabBar)));
}
}
void SciTEGTK::ShowStatusBar() {
if (sbVisible) {
gtk_widget_show(GTK_WIDGET(PWidget(wStatusBar)));
} else {
gtk_widget_hide(GTK_WIDGET(PWidget(wStatusBar)));
}
}
void SciTEGTK::ActivateWindow(const char *timestamp) {
char *end;
// Reset errno so we can reliably test it
errno = 0;
gulong ts = strtoul(timestamp, &end, 0);
if (end != timestamp && errno == 0) {
#if GTK_CHECK_VERSION(2,8,0)
gtk_window_present_with_time(GTK_WINDOW(PWidget(wSciTE)), ts);
#endif
} else {
gtk_window_present(GTK_WINDOW(PWidget(wSciTE)));
}
}
void SciTEGTK::CopyPath() {
gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
filePath.AsInternal(), -1);
}
// The find and replace dialogs and strips often manipulate boolean
// flags based on dialog control IDs and menu IDs.
bool &SciTEGTK::FlagFromCmd(int cmd) {
static bool notFound;
switch (cmd) {
case IDWHOLEWORD:
case IDM_WHOLEWORD:
return wholeWord;
case IDMATCHCASE:
case IDM_MATCHCASE:
return matchCase;
case IDREGEXP:
case IDM_REGEXP:
return regExp;
case IDUNSLASH:
case IDM_UNSLASH:
return unSlash;
case IDWRAP:
case IDM_WRAPAROUND:
return wrapFind;
case IDDIRECTIONUP:
case IDM_DIRECTIONUP:
return reverseFind;
}
return notFound;
}
void SciTEGTK::Command(unsigned long wParam, long) {
int cmdID = ControlIDOfCommand(wParam);
switch (cmdID) {
case IDM_FULLSCREEN:
fullScreen = !fullScreen;
{
GdkWindow *parent_w = WindowFromWidget(PWidget(wSciTE));
if (fullScreen)
gdk_window_fullscreen(parent_w);
else
gdk_window_unfullscreen(parent_w);
}
SizeSubWindows();
CheckMenus();
break;
// override base class
case IDM_SPLITVERTICAL:
splitVertical = !splitVertical;
heightBar = 0;
LayoutUI();
CheckMenus();
break;
default:
SciTEBase::MenuCommand(cmdID, menuSource);
menuSource = 0;
}
// Changes to document produce SCN_UPDATEUI which updates the status
// bar but not too frequently.
UpdateStatusBar(true);
}
void SciTEGTK::ReadLocalization() {
SciTEBase::ReadLocalization();
SString encoding = localiser.Get("translation.encoding");
if (encoding.length()) {
GIConv iconvh = g_iconv_open("UTF-8", encoding.c_str());
const char *key = NULL;
const char *val = NULL;
// Get encoding
bool more = localiser.GetFirst(key, val);
while (more) {
char converted[1000];
converted[0] = '\0';
// Cast needed for some versions of iconv not marking input argument as const
char *pin = const_cast<char *>(val);
size_t inLeft = strlen(val);
char *pout = converted;
size_t outLeft = sizeof(converted);
size_t conversions = g_iconv(iconvh, &pin, &inLeft, &pout, &outLeft);
if (conversions != ((size_t)(-1))) {
*pout = '\0';
localiser.Set(key, converted);
}
more = localiser.GetNext(key, val);
}
g_iconv_close(iconvh);
}
}
void SciTEGTK::ReadPropertiesInitial() {
SciTEBase::ReadPropertiesInitial();
ShowToolBar();
ShowTabBar();
ShowStatusBar();
}
void SciTEGTK::ReadProperties() {
SciTEBase::ReadProperties();
CallChildren(SCI_SETRECTANGULARSELECTIONMODIFIER,
props.GetInt("rectangular.selection.modifier", SCMOD_CTRL));
CheckMenus();
// Need this here to handle tabbar.hide.one properly
ShowTabBar();
}
gboolean SciTEGTK::TimerTick(SciTEGTK *scitew) {
scitew->OnTimer();
return TRUE;
}
void SciTEGTK::TimerStart(int mask) {
int maskNew = timerMask | mask;
if (timerMask != maskNew) {
if (timerMask == 0) {
// Create a 1 second ticker
timerID = g_timeout_add(1000, reinterpret_cast<GSourceFunc>(TimerTick), this);
}
timerMask = maskNew;
}
}
void SciTEGTK::TimerEnd(int mask) {
int maskNew = timerMask & ~mask;
if (timerMask != maskNew) {
if (maskNew == 0) {
g_source_remove(timerID);
timerID = 0;
}
timerMask = maskNew;
}
}
void SciTEGTK::GetWindowPosition(int *left, int *top, int *width, int *height, int *maximize) {
gtk_window_get_position(GTK_WINDOW(PWidget(wSciTE)), left, top);
gtk_window_get_size(GTK_WINDOW(PWidget(wSciTE)), width, height);
*maximize = (gdk_window_get_state(WindowFromWidget(PWidget(wSciTE))) & GDK_WINDOW_STATE_MAXIMIZED) != 0;
}
void SciTEGTK::SizeContentWindows() {
gint max;
g_object_get(G_OBJECT(splitPane), "max-position", &max, NULL);
// This probably means the window hasn't been rendered yet
if (max == 0)
return;
// Since SciTEBase::NormaliseSplit() doesn't use the actual Paned maximum
// position, it may return an invalid heightOutput...
if (heightOutput > max)
heightOutput = max;
gtk_paned_set_position(GTK_PANED(splitPane), max - heightOutput);
// Make sure the focus is somewhere
if (!userStrip.VisibleHasFocus()) {
if (heightOutput == max) {
WindowSetFocus(wOutput);
} else if (heightOutput == 0 || (!wEditor.HasFocus() && !wOutput.HasFocus())) {
WindowSetFocus(wEditor);
}
}
}
void SciTEGTK::SizeSubWindows() {
SizeContentWindows();
}
// Find the menu item with a particular ID so that it can be enable, disabled, set or hidden.
GtkWidget *SciTEGTK::MenuItemFromAction(int itemID) {
std::map<int, GtkWidget *>::iterator it;
it = mapMenuItemFromId.find(itemID);
if (it == mapMenuItemFromId.end())
return 0;
else
return it->second;
}
static SString GtkFromWinCaption(const char *text) {
SString sCaption(text);
// Escape underlines
sCaption.substitute("_", "__");
// Replace Windows-style ampersands with GTK+ underlines
int posFound = sCaption.search("&");
while (posFound >= 0) {
SString nextChar = sCaption.substr(posFound + 1, 1);
if (nextChar == "&") {
// Escaped, move on
posFound += 2;
} else {
sCaption.remove(posFound, 1);
sCaption.insert(posFound, "_", 1);
posFound += 1;
}
posFound = sCaption.search("&", posFound);
}
// Unescape ampersands
sCaption.substitute("&&", "&");
return sCaption;
}
void SciTEGTK::SetMenuItem(int, int, int itemID, const char *text, const char *mnemonic) {
DestroyMenuItem(0, itemID);
// On GTK+ the menuNumber and position are ignored as the menu item already exists and is in the right
// place so only needs to be shown and have its text set.
SString itemText = GtkFromWinCaption(text);
long keycode = 0;
if (mnemonic && *mnemonic) {
keycode = SciTEKeys::ParseKeyCode(mnemonic);
if (keycode) {
itemText += " ";
itemText += mnemonic;
}
// the keycode could be used to make a custom accelerator table
// but for now, the menu's item data is used instead for command
// tools, and for other menu entries it is just discarded.
}
// Reorder shift and ctrl indicators for compatibility with other menus
itemText.substitute("Ctrl+Shift+", "Shift+Ctrl+");
GtkWidget *item = MenuItemFromAction(itemID);
if (item) {
GList *al = gtk_container_get_children(GTK_CONTAINER(item));
for (unsigned int ii = 0; ii < g_list_length(al); ii++) {
gpointer d = g_list_nth(al, ii);
GtkWidget **w = (GtkWidget **)d;
gtk_label_set_text_with_mnemonic(GTK_LABEL(*w), itemText.c_str());
}
g_list_free(al);
gtk_widget_show(item);
if (itemID >= IDM_TOOLS && itemID < IDM_TOOLS + toolMax) {
// Stow the keycode for later retrieval.
// Do this even if 0, in case the menu already existed (e.g. ModifyMenu)
g_object_set_data(G_OBJECT(item), "key", reinterpret_cast<gpointer>(keycode));
}
}
}
void SciTEGTK::DestroyMenuItem(int, int itemID) {
// On GTK+ menu items are just hidden rather than destroyed as they can not be recreated in the middle of a menu
// The menuNumber is ignored as all menu items in GTK+ can be found from the root of the menu tree
if (itemID) {
GtkWidget *item = MenuItemFromAction(itemID);
if (item) {
gtk_widget_hide(item);
g_object_set_data(G_OBJECT(item), "key", 0);
}
}
}
void SciTEGTK::CheckAMenuItem(int wIDCheckItem, bool val) {
GtkWidget *item = MenuItemFromAction(wIDCheckItem);
allowMenuActions = false;
if (item)
gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), val ? TRUE : FALSE);
allowMenuActions = true;
}
void SciTEGTK::EnableAMenuItem(int wIDCheckItem, bool val) {
GtkWidget *item = MenuItemFromAction(wIDCheckItem);
if (item) {
if (GTK_IS_WIDGET(item))
gtk_widget_set_sensitive(item, val);
}
}
void SciTEGTK::CheckMenusClipboard() {
if (StripHasFocus()) {
EnableAMenuItem(IDM_CUT, false);
EnableAMenuItem(IDM_COPY, false);
EnableAMenuItem(IDM_CLEAR, false);
EnableAMenuItem(IDM_PASTE, false);
} else {
SciTEBase::CheckMenusClipboard();
}
}
void SciTEGTK::CheckMenus() {
SciTEBase::CheckMenus();
CheckAMenuItem(IDM_EOL_CRLF, wEditor.Call(SCI_GETEOLMODE) == SC_EOL_CRLF);
CheckAMenuItem(IDM_EOL_CR, wEditor.Call(SCI_GETEOLMODE) == SC_EOL_CR);
CheckAMenuItem(IDM_EOL_LF, wEditor.Call(SCI_GETEOLMODE) == SC_EOL_LF);
CheckAMenuItem(IDM_ENCODING_DEFAULT, CurrentBuffer()->unicodeMode == uni8Bit);
CheckAMenuItem(IDM_ENCODING_UCS2BE, CurrentBuffer()->unicodeMode == uni16BE);
CheckAMenuItem(IDM_ENCODING_UCS2LE, CurrentBuffer()->unicodeMode == uni16LE);
CheckAMenuItem(IDM_ENCODING_UTF8, CurrentBuffer()->unicodeMode == uniUTF8);
CheckAMenuItem(IDM_ENCODING_UCOOKIE, CurrentBuffer()->unicodeMode == uniCookie);
CheckAMenuItem(IDM_VIEWSTATUSBAR, sbVisible);
CheckAMenuItem(IDM_VIEWTABBAR, tabVisible);
if (btnBuild) {
gtk_widget_set_sensitive(btnBuild, !jobQueue.IsExecuting());
gtk_widget_set_sensitive(btnCompile, !jobQueue.IsExecuting());
gtk_widget_set_sensitive(btnStop, jobQueue.IsExecuting());
}
}
/**
* Replace any %xx escapes by their single-character equivalent.
*/
static void unquote(char *s) {
char *o = s;
while (*s) {
if ((*s == '%') && s[1] && s[2]) {
*o = IntFromHexDigit(s[1]) * 16 + IntFromHexDigit(s[2]);
s += 2;
} else {
*o = *s;
}
o++;
s++;
}
*o = '\0';
}
/**
* Open a list of URIs each terminated by "\r\n".
* Only "file:" URIs currently understood.
* In KDE 4, the last URI is not terminated by "\r\n"!
*/
void SciTEGTK::OpenUriList(const char *list) {
if (list) {
char *uri = StringDup(list);
char *lastenduri = uri + strlen(uri);
if (uri) {
while (uri < lastenduri) {
char *enduri = strchr(uri, '\r');
if (enduri == NULL)
enduri = lastenduri; // if last URI has no "\r\n".
*enduri = '\0';
if (isprefix(uri, "file:")) {
uri += strlen("file:");
if (isprefix(uri, "///")) {
uri += 2; // There can be an optional // before the file path that starts with /
}
unquote(uri);
Open(uri);
} else {
GUI::gui_string msg = LocaliseMessage("URI '^0' not understood.", uri);
WindowMessageBox(wSciTE, msg, MB_OK | MB_ICONWARNING);
}
uri = enduri + 1;
if (*uri == '\n')
uri++;
}
}
}
}
bool SciTEGTK::OpenDialog(FilePath directory, const char *filter) {
bool canceled = true;
if (!dlgFileSelector.Created()) {
GtkWidget *dlg = gtk_file_chooser_dialog_new(
localiser.Text("Open File").c_str(),
GTK_WINDOW(wSciTE.GetID()),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dlg), TRUE);
gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_ACCEPT);
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dlg), directory.AsInternal());
SString openFilter = filter;
if (openFilter.length()) {
openFilter.substitute('|', '\0');
size_t start = 0;
while (start < openFilter.length()) {
const char *filterName = openFilter.c_str() + start;
GUI::gui_string localised = localiser.Text(filterName, false);
if (localised.length()) {
openFilter.remove(start, strlen(filterName));
openFilter.insert(start, localised.c_str());
}
if (openFilter.c_str()[start] == '#') {
start += strlen(openFilter.c_str() + start) + 1;
} else {
GtkFileFilter *filter = gtk_file_filter_new();
gtk_file_filter_set_name(filter, openFilter.c_str() + start);
start += strlen(openFilter.c_str() + start) + 1;
SString oneSet(openFilter.c_str() + start);
oneSet.substitute(';', '\0');
size_t item = 0;
while (item < oneSet.length()) {
gtk_file_filter_add_pattern(filter, oneSet.c_str() + item);
item += strlen(oneSet.c_str() + item) + 1;
}
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dlg), filter);
}
start += strlen(openFilter.c_str() + start) + 1;
}
}
gtk_window_set_default_size(GTK_WINDOW(dlg), fileSelectorWidth, fileSelectorHeight);
if (gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_ACCEPT) {
GSList *names = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dlg));
GSList *nameCurrent = names;
while (nameCurrent) {
char *filename = static_cast<char *>(nameCurrent->data);
Open(filename);
g_free(filename);
nameCurrent = g_slist_next(nameCurrent);
}
g_slist_free(names);
canceled = false;
}
gtk_widget_destroy(dlg);
}
return !canceled;
}
bool SciTEGTK::HandleSaveAs(const char *savePath) {
switch (saveFormat) {
case sfCopy:
SaveBuffer(savePath, sfNone);
break;
case sfHTML:
SaveToHTML(savePath);
break;
case sfRTF:
SaveToRTF(savePath);
break;
case sfPDF:
SaveToPDF(savePath);
break;
case sfTEX:
SaveToTEX(savePath);
break;
case sfXML:
SaveToXML(savePath);
break;
default: {
/* Checking that no other buffer refers to the same filename */
FilePath destFile(savePath);
return SaveIfNotOpen(destFile, true);
}
}
dlgFileSelector.Destroy();
return true;
}
bool SciTEGTK::SaveAsXXX(FileFormat fmt, const char *title, const char *ext) {
bool saved = false;
saveFormat = fmt;
if (!dlgFileSelector.Created()) {
GtkWidget *dlg = gtk_file_chooser_dialog_new(
localiser.Text(title).c_str(),
GTK_WINDOW(wSciTE.GetID()),
GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
NULL);
gtk_dialog_set_default_response(GTK_DIALOG(dlg), GTK_RESPONSE_ACCEPT);
FilePath savePath = SaveName(ext);
if (ext) {
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dlg), savePath.Directory().AsInternal());
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dlg), savePath.Name().AsInternal());
} else if (savePath.IsUntitled()) { // saving 'untitled'
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dlg), savePath.Directory().AsInternal());
} else {
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dlg), filePath.Directory().AsInternal());
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dlg), savePath.AsInternal());
}
if (gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_ACCEPT) {
char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dlg));
gtk_widget_destroy(dlg);
saved = HandleSaveAs(filename);
g_free(filename);
} else {
gtk_widget_destroy(dlg);
}
}
return saved;
}
bool SciTEGTK::SaveAsDialog() {
return SaveAsXXX(sfSource, "Save File As");
}
void SciTEGTK::SaveACopy() {
SaveAsXXX(sfCopy, "Save a Copy");
}
void SciTEGTK::SaveAsHTML() {
SaveAsXXX(sfHTML, "Export File As HTML", ".html");
}
void SciTEGTK::SaveAsRTF() {
SaveAsXXX(sfRTF, "Export File As RTF", ".rtf");
}
void SciTEGTK::SaveAsPDF() {
SaveAsXXX(sfPDF, "Export File As PDF", ".pdf");
}
void SciTEGTK::SaveAsTEX() {
SaveAsXXX(sfTEX, "Export File As LaTeX", ".tex");
}
void SciTEGTK::SaveAsXML() {
SaveAsXXX(sfXML, "Export File As XML", ".xml");
}
void SciTEGTK::LoadSessionDialog() {
if (!dlgFileSelector.Created()) {
GtkWidget *dlg = gtk_file_chooser_dialog_new(
localiser.Text("Load Session").c_str(),
GTK_WINDOW(wSciTE.GetID()),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dlg), filePath.Directory().AsInternal());
gtk_window_set_default_size(GTK_WINDOW(dlg), fileSelectorWidth, fileSelectorHeight);
if (gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_ACCEPT) {
char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dlg));
LoadSessionFile(filename);
RestoreSession();
g_free(filename);
}
gtk_widget_destroy(dlg);
}
}
void SciTEGTK::SaveSessionDialog() {
if (!dlgFileSelector.Created()) {
GtkWidget *dlg = gtk_file_chooser_dialog_new(
localiser.Text("Save Session").c_str(),
GTK_WINDOW(wSciTE.GetID()),
GTK_FILE_CHOOSER_ACTION_SAVE,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
NULL);
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dlg), filePath.Directory().AsInternal());
if (gtk_dialog_run(GTK_DIALOG(dlg)) == GTK_RESPONSE_ACCEPT) {
char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dlg));
SaveSessionFile(filename);
g_free(filename);
}
gtk_widget_destroy(dlg);
}
}
#if GTK_CHECK_VERSION(2,10,0)
// Printing with GtkPrintContext appeared in GTK+ 2.10
static PangoLayout *PangoLayoutFromStyleDefinition(GtkPrintContext *context, const StyleDefinition &sd) {
PangoLayout *layout = gtk_print_context_create_pango_layout(context);
if (layout) {
pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
PangoFontDescription *pfd = pango_font_description_new();
if (pfd) {
const char *fontName = "Sans";
if (sd.specified & StyleDefinition::sdFont)
fontName = sd.font.c_str();
if (fontName[0] == '!')
fontName++;
pango_font_description_set_family(pfd, fontName);
pango_font_description_set_size(pfd, PANGO_SCALE * (
(sd.specified & StyleDefinition::sdSize) ? sd.sizeFractional : 9.0));
pango_font_description_set_weight(pfd, static_cast<PangoWeight>(sd.weight));
pango_font_description_set_style(pfd, sd.italics ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL);
pango_layout_set_font_description(layout, pfd);
pango_font_description_free(pfd);
}
}
return layout;
}
void SciTEGTK::SetupFormat(Sci_RangeToFormat &frPrint, GtkPrintContext *context) {
#if GTK_CHECK_VERSION(2,10,0)
cairo_t *cr = gtk_print_context_get_cairo_context(context);
frPrint.hdc = cr;
frPrint.hdcTarget = cr;
#endif
gdouble width = gtk_print_context_get_width(context);
gdouble height = gtk_print_context_get_height(context);
frPrint.rc.left = 0;
frPrint.rc.top = 0;
frPrint.rc.right = width;
frPrint.rc.bottom = height;
#if GTK_CHECK_VERSION(2,20,0)
gdouble marginLeft = 0;
gdouble marginTop = 0;
gdouble marginRight = 0;
gdouble marginBottom = 0;
if (gtk_print_context_get_hard_margins(context,
&marginTop, &marginBottom, &marginLeft, &marginRight)) {
frPrint.rc.left += marginLeft;
frPrint.rc.top += marginTop;
frPrint.rc.right -= marginRight;
frPrint.rc.bottom -= marginBottom;
}
#endif
frPrint.rcPage.left = 0;
frPrint.rcPage.top = 0;
frPrint.rcPage.right = width;
frPrint.rcPage.bottom = height;
SString headerFormat = props.Get("print.header.format");
if (headerFormat.size()) {
StyleDefinition sdHeader(props.Get("print.header.style").c_str());
PangoLayout *layout = PangoLayoutFromStyleDefinition(context, sdHeader);
pango_layout_set_text(layout, "Xg", -1);
gint layoutHeight;
pango_layout_get_size(layout, NULL, &layoutHeight);
frPrint.rc.top += ((gdouble)layoutHeight / PANGO_SCALE) * 1.5;
g_object_unref(layout);
}
SString footerFormat = props.Get("print.footer.format");
if (footerFormat.size()) {
StyleDefinition sdFooter(props.Get("print.footer.style").c_str());
PangoLayout *layout = PangoLayoutFromStyleDefinition(context, sdFooter);
pango_layout_set_text(layout, "Xg", -1);
gint layoutHeight;
pango_layout_get_size(layout, NULL, &layoutHeight);
frPrint.rc.bottom -= ((gdouble)layoutHeight / PANGO_SCALE) * 1.5;
g_object_unref(layout);
}
}
void SciTEGTK::BeginPrintThis(GtkPrintOperation *operation, GtkPrintContext *context) {
pageStarts.clear();
Sci_RangeToFormat frPrint;
SetupFormat(frPrint, context) ;
int lengthDoc = wEditor.Call(SCI_GETLENGTH);
int lengthPrinted = 0;
while (lengthPrinted < lengthDoc) {
pageStarts.push_back(lengthPrinted);
frPrint.chrg.cpMin = lengthPrinted;
frPrint.chrg.cpMax = lengthDoc;
lengthPrinted = wEditor.Call(SCI_FORMATRANGE, false, reinterpret_cast<sptr_t>(&frPrint));
}
pageStarts.push_back(lengthPrinted);
gtk_print_operation_set_n_pages(operation, pageStarts.size()-1);
}
void SciTEGTK::BeginPrint(GtkPrintOperation *operation, GtkPrintContext *context, SciTEGTK *scitew) {
scitew->BeginPrintThis(operation, context);
}
static void SetCairoColour(cairo_t *cr, long co) {
cairo_set_source_rgb(cr,
(co & 0xff) / 255.0,
((co >> 8) & 0xff) / 255.0,
((co >> 16) & 0xff) / 255.0);
}
void SciTEGTK::DrawPageThis(GtkPrintOperation * /* operation */, GtkPrintContext *context, gint page_nr) {
Sci_RangeToFormat frPrint;
SetupFormat(frPrint, context) ;
cairo_t *cr = reinterpret_cast<cairo_t *>(frPrint.hdc);
PropSetFile propsPrint;
propsPrint.superPS = &props;
SetFileProperties(propsPrint);
char pageString[32];
sprintf(pageString, "%0d", page_nr + 1);
propsPrint.Set("CurrentPage", pageString);
SString headerFormat = props.Get("print.header.format");
if (headerFormat.size()) {
StyleDefinition sdHeader(props.Get("print.header.style").c_str());
PangoLayout *layout = PangoLayoutFromStyleDefinition(context, sdHeader);
SetCairoColour(cr, sdHeader.ForeAsLong());
pango_layout_set_text(layout, propsPrint.GetExpanded("print.header.format").c_str(), -1);
gint layout_height;
pango_layout_get_size(layout, NULL, &layout_height);
gdouble text_height = (gdouble)layout_height / PANGO_SCALE;
cairo_move_to(cr, frPrint.rc.left, frPrint.rc.top - text_height * 1.5);
pango_cairo_show_layout(cr, layout);
g_object_unref(layout);
cairo_move_to(cr, frPrint.rc.left, frPrint.rc.top - text_height * 0.25);
cairo_line_to(cr, frPrint.rc.right, frPrint.rc.top - text_height * 0.25);
cairo_stroke(cr);
}
SString footerFormat = props.Get("print.footer.format");
if (footerFormat.size()) {
StyleDefinition sdFooter(props.Get("print.footer.style").c_str());
PangoLayout *layout = PangoLayoutFromStyleDefinition(context, sdFooter);
SetCairoColour(cr, sdFooter.ForeAsLong());
pango_layout_set_text(layout, propsPrint.GetExpanded("print.footer.format").c_str(), -1);
gint layout_height;
pango_layout_get_size(layout, NULL, &layout_height);
gdouble text_height = (gdouble)layout_height / PANGO_SCALE;
cairo_move_to(cr, frPrint.rc.left, frPrint.rc.bottom + text_height * 0.5);
pango_cairo_show_layout(cr, layout);
g_object_unref(layout);
cairo_move_to(cr, frPrint.rc.left, frPrint.rc.bottom + text_height * 0.25);
cairo_line_to(cr, frPrint.rc.right, frPrint.rc.bottom + text_height * 0.25);
cairo_stroke(cr);
}
int lengthDoc = wEditor.Call(SCI_GETLENGTH);
frPrint.chrg.cpMin = pageStarts[page_nr];
frPrint.chrg.cpMax = pageStarts[page_nr+1];
if (frPrint.chrg.cpMax < lengthDoc)
frPrint.chrg.cpMax--;
wEditor.Call(SCI_FORMATRANGE, true, reinterpret_cast<sptr_t>(&frPrint));
}
void SciTEGTK::DrawPage(GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr, SciTEGTK *scitew) {
scitew->DrawPageThis(operation, context, page_nr);
}
#endif
void SciTEGTK::Print(bool) {
RemoveFindMarks();
SelectionIntoProperties();
#if GTK_CHECK_VERSION(2,10,0)
// Printing through the GTK+ API
GtkPrintOperation *printOp = gtk_print_operation_new();
if (printSettings != NULL)
gtk_print_operation_set_print_settings(printOp, printSettings);
if (pageSetup != NULL)
gtk_print_operation_set_default_page_setup(printOp, pageSetup);
g_signal_connect(printOp, "begin_print", G_CALLBACK(BeginPrint), this);
g_signal_connect(printOp, "draw_page", G_CALLBACK(DrawPage), this);
GtkPrintOperationResult res = gtk_print_operation_run(
printOp, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
GTK_WINDOW(PWidget(wSciTE)), NULL);
if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
if (printSettings != NULL)
g_object_unref(printSettings);
printSettings = gtk_print_operation_get_print_settings(printOp);
g_object_ref(printSettings);
}
g_object_unref(printOp);
#else
SString printCommand = props.GetWild("command.print.", filePath.AsInternal());
if (printCommand.length()) {
// Using a command to print
AddCommand(printCommand, "", SubsystemType("command.print.subsystem."));
if (jobQueue.HasCommandToRun()) {
jobQueue.isBuilding = true;
Execute();
}
}
#endif
}
void SciTEGTK::PrintSetup() {
#if GTK_CHECK_VERSION(2,10,0)
if (printSettings == NULL)
printSettings = gtk_print_settings_new();
GtkPageSetup *newPageSetup = gtk_print_run_page_setup_dialog(
GTK_WINDOW(PWidget(wSciTE)), pageSetup, printSettings);
if (pageSetup)
g_object_unref(pageSetup);
pageSetup = newPageSetup;
#endif
}
SString SciTEGTK::GetRangeInUIEncoding(GUI::ScintillaWindow &win, int selStart, int selEnd) {
int len = selEnd - selStart;
SBuffer allocation(len * 3);
win.Call(SCI_SETTARGETSTART, selStart);
win.Call(SCI_SETTARGETEND, selEnd);
int byteLength = win.Call(SCI_TARGETASUTF8, 0, reinterpret_cast<sptr_t>(allocation.ptr()));
SString sel(allocation);
sel.remove(byteLength, 0);
return sel;
}
void SciTEGTK::Find() {
if (dlgFindReplace.Created()) {
dlgFindReplace.Present();
return;
}
SelectionIntoFind();
if (props.GetInt("find.use.strip")) {
replaceStrip.Close();
findStrip.Show(props.GetInt("strip.button.height", -1));
} else {
if (findStrip.visible || replaceStrip.visible)
return;
FindReplace(false);
}
}
void SetFocus(GUI::ScintillaWindow &w) {
w.Call(SCI_GRABFOCUS);
}
void SciTEGTK::UIClosed() {
SciTEBase::UIClosed();
SetFocus(wEditor);
}
void SciTEGTK::UIHasFocus() {
CheckMenusClipboard();
}
GtkWidget *SciTEGTK::TranslatedLabel(const char *original) {
GUI::gui_string text = localiser.Text(original);
return gtk_label_new_with_mnemonic(text.c_str());
}
static void FillComboFromProps(WComboBoxEntry *combo, PropSetFile &props) {
const char *key;
const char *val;
for (int i = 0; i < 10; i++) {
combo->RemoveText(0);
}
if (props.GetFirst(key, val))
combo->AppendText(key);
while (props.GetNext(key, val))
combo->AppendText(key);
}
static void FillComboFromMemory(WComboBoxEntry *combo, const ComboMemory &mem, bool useTop = false) {
for (int i = 0; i < 10; i++) {
combo->RemoveText(0);
}
for (int i = 0; i < mem.Length(); i++) {
combo->AppendText(mem.At(i).c_str());
}
if (useTop) {
combo->SetText(mem.At(0).c_str());
}
}
SString SciTEGTK::EncodeString(const SString &s) {
wEditor.Call(SCI_SETLENGTHFORENCODE, s.length());
int len = wEditor.Call(SCI_ENCODEDFROMUTF8,
reinterpret_cast<uptr_t>(s.c_str()), 0);
SBuffer ret(len);
wEditor.CallString(SCI_ENCODEDFROMUTF8,
reinterpret_cast<uptr_t>(s.c_str()), ret.ptr());
ret.ptr()[len] = '\0';
return SString(ret);
}
void BackgroundStrip::Creation(GtkWidget *container) {
WTable table(1, 2);
SetID(table);
Strip::Creation(container);
gtk_container_set_border_width(GTK_CONTAINER(GetID()), 1);
gtk_box_pack_start(GTK_BOX(container), GTK_WIDGET(GetID()), FALSE, FALSE, 0);
wProgress.Create();
table.Add(wProgress, 1, false, 0, 0);
gtk_widget_show(wProgress);
wExplanation.Create("");
table.Label(wExplanation);
//g_signal_connect(G_OBJECT(GetID()), "set-focus-child", G_CALLBACK(ChildFocusSignal), this);
//g_signal_connect(G_OBJECT(GetID()), "focus", G_CALLBACK(FocusSignal), this);
gtk_widget_show(GTK_WIDGET(GetID()));
}
void BackgroundStrip::SetProgress(const GUI::gui_string &explanation, int size, int progress) {
gtk_label_set_text(GTK_LABEL(wExplanation.GetID()), explanation.c_str());
if (size > 0) {
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(wProgress.GetID()),
static_cast<double>(progress) / static_cast<double>(size));
}
}
void DialogFindReplace::GrabFields() {
pSearcher->SetFind(wComboFind.Text());
if (wComboReplace) {
pSearcher->SetReplace(wComboReplace.Text());
}
pSearcher->wholeWord = toggleWord.Active();
pSearcher->matchCase = toggleCase.Active();
pSearcher->regExp = toggleRegExp.Active();
pSearcher->wrapFind = toggleWrap.Active();
pSearcher->unSlash = toggleUnSlash.Active();
if (toggleReverse) {
pSearcher->reverseFind = toggleReverse.Active();
}
}
void DialogFindReplace::FillFields() {
wComboFind.FillFromMemory(pSearcher->memFinds.AsVector());
if (wComboReplace) {
wComboReplace.FillFromMemory(pSearcher->memReplaces.AsVector());
}
toggleWord.SetActive(pSearcher->wholeWord);
toggleCase.SetActive(pSearcher->matchCase);
toggleRegExp.SetActive(pSearcher->regExp);
toggleWrap.SetActive(pSearcher->wrapFind);
toggleUnSlash.SetActive(pSearcher->unSlash);
if (toggleReverse) {
toggleReverse.SetActive(pSearcher->reverseFind);
}
}
void SciTEGTK::FindReplaceGrabFields() {
dlgFindReplace.GrabFields();
}
void SciTEGTK::FRFindCmd() {
FindReplaceGrabFields();
bool isFindDialog = !dlgFindReplace.wComboReplace;
if (isFindDialog)
dlgFindReplace.Destroy();
if (findWhat[0]) {
FindNext(isFindDialog && reverseFind);
}
}
void SciTEGTK::FRReplaceCmd() {
FindReplaceGrabFields();
ReplaceOnce();
}
void SciTEGTK::FRReplaceAllCmd() {
FindReplaceGrabFields();
if (findWhat[0]) {
ReplaceAll(false);
dlgFindReplace.Destroy();
}
}
void SciTEGTK::FRReplaceInSelectionCmd() {
FindReplaceGrabFields();
if (findWhat[0]) {
ReplaceAll(true);
dlgFindReplace.Destroy();
}
}
void SciTEGTK::FRReplaceInBuffersCmd() {
FindReplaceGrabFields();
if (findWhat[0]) {
ReplaceInBuffers();
dlgFindReplace.Destroy();
}
}
void SciTEGTK::FRMarkAllCmd() {
FindReplaceGrabFields();
MarkAll();
FindNext(reverseFind);
}
void DialogFindInFiles::GrabFields() {
pSearcher->SetFind(wComboFindInFiles.Text());
if (toggleWord.Sensitive())
pSearcher->wholeWord = toggleWord.Active();
if (toggleCase.Sensitive())
pSearcher->matchCase = toggleCase.Active();
}
void DialogFindInFiles::FillFields() {
wComboFindInFiles.FillFromMemory(pSearcher->memFinds.AsVector());
if (toggleWord.Sensitive())
toggleWord.SetActive(pSearcher->wholeWord);
if (toggleCase.Sensitive())
toggleCase.SetActive(pSearcher->matchCase);
}
void SciTEGTK::FindInFilesCmd() {
dlgFindInFiles.GrabFields();
const char *dirEntry = dlgFindInFiles.comboDir.Text();
props.Set("find.directory", dirEntry);
memDirectory.Insert(dirEntry);
const char *filesEntry = dlgFindInFiles.wComboFiles.Text();
props.Set("find.files", filesEntry);
memFiles.Insert(filesEntry);
dlgFindInFiles.Destroy();
//printf("Grepping for <%s> in <%s>\n",
// props.Get("find.what"),
// props.Get("find.files"));
SelectionIntoProperties();
SString findCommand = props.GetNewExpand("find.command");
if (findCommand == "") {
findCommand = sciteExecutable.AsInternal();
findCommand += " -grep ";
findCommand += (wholeWord ? "w" : "~");
findCommand += (matchCase ? "c" : "~");
findCommand += props.GetInt("find.in.dot") ? "d" : "~";
findCommand += props.GetInt("find.in.binary") ? "b" : "~";
findCommand += " \"";
findCommand += props.Get("find.files");
findCommand += "\" \"";
char *quotedForm = Slash(props.Get("find.what").c_str(), true);
findCommand += quotedForm;
findCommand += "\"";
delete []quotedForm;
//~ fprintf(stderr, "%s\n", findCommand.c_str());
}
AddCommand(findCommand, props.Get("find.directory"), jobCLI);
if (jobQueue.HasCommandToRun())
Execute();
}
void SciTEGTK::FindInFilesDotDot() {
FilePath findInDir(dlgFindInFiles.comboDir.Text());
gtk_entry_set_text(dlgFindInFiles.comboDir.Entry(), findInDir.Directory().AsInternal());
}
void SciTEGTK::FindInFilesBrowse() {
FilePath findInDir(dlgFindInFiles.comboDir.Text());
GtkWidget *dialog = gtk_file_chooser_dialog_new(
localiser.Text("Select a folder to search from").c_str(),
GTK_WINDOW(dlgFindInFiles.GetID()), // parent_window,
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
NULL);
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), findInDir.AsInternal());
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
dlgFindInFiles.comboDir.SetText(filename);
g_free(filename);
}
gtk_widget_destroy(dialog);
}
static const char *textFindPrompt = "Fi_nd:";
static const char *textReplacePrompt = "Rep_lace:";
static const char *textFindNext = "_Find Next";
static const char *textMarkAll = "_Mark All";
static const char *textFind = "F_ind";
static const char *textReplace = "_Replace";
static const char *textReplaceAll = "Replace _All";
static const char *textInSelection = "In _Selection";
static const char *textReplaceInBuffers = "Replace In _Buffers";
static const char *textClose = "_Close";
/* XPM */
static const char * word1_x_xpm[] = {
"16 16 15 1",
" c #FFFFFF",
". c #000000",
"+ c #E1E1E1",
"@ c #D9D9D9",
"# c #4D4D4D",
"$ c #7C7C7C",
"% c #D0D0D0",
"& c #A7A7A7",
"* c #8C8C8C",
"= c #BDBDBD",
"- c #B2B2B2",
"; c #686868",
"> c #F0F0F0",
", c #9A9A9A",
"' c #C7C7C7",
" ",
" ",
" ",
" ",
" ",
" ",
" .",
".+.+.@##@ .$%#&.",
"*=.-*;++; .>;++.",
",*.$,. . . . .",
"=#,.=;++; . ;++.",
"'.=.'@##@ . @#&.",
" ",
". .",
". .",
"................"};
/* XPM */
static const char * case_x_xpm[] = {
"16 16 12 1",
" c #FFFFFF",
". c #BDBDBD",
"+ c #4D4D4D",
"@ c #000000",
"# c #D0D0D0",
"$ c #C7C7C7",
"% c #7C7C7C",
"& c #B2B2B2",
"* c #8C8C8C",
"= c #E1E1E1",
"- c #686868",
"; c #9A9A9A",
" ",
" ",
" ",
" ",
" .+@@ ",
" #@$ ",
" %% &+@@ ",
" @* &+= ",
" @* @& ",
" -% @& ",
" .@# ;+= ",
" &+@@ ;@@@ ",
" ",
" ",
" ",
" "};
/* XPM */
static const char * regex_x_xpm[] = {
"16 16 11 1",
" c #FFFFFF",
". c #888888",
"+ c #696969",
"@ c #000000",
"# c #E0E0E0",
"$ c #484848",
"% c #B6B6B6",
"& c #C4C4C4",
"* c #787878",
"= c #383838",
"- c #D3D3D3",
" ",
" ",
" ",
" .+ @ ",
" #$$# % + % ",
" +&&+ #*=@=*#",
"-$ $& +++ ",
"$& &$ -$ =- ",
" ",
" ",
" %@% ",
" %@% ",
" ",
" ",
" ",
" "};
/* XPM */
static const char * backslash_x_xpm[] = {
"16 16 15 1",
" c #FFFFFF",
". c #141414",
"+ c #585858",
"@ c #A6A6A6",
"# c #B6B6B6",
"$ c #272727",
"% c #E0E0E0",
"& c #979797",
"* c #000000",
"= c #696969",
"- c #484848",
"; c #787878",
"> c #D3D3D3",
", c #383838",
"' c #888888",
" ",
" ",
" ",
". . ",
"+@ +@ # ",
"#+ #+ $ ",
" .% .&* .% =*--",
" ;& *& ;& * ",
" >, * >, * ",
" $> * $> * ",
" &; * &; *% ",
" %. * %. '*.",
" ",
" ",
" ",
" "};
/* XPM */
static const char * around_x_xpm[] = {
"16 16 2 1",
" c #FFFFFF",
". c #000000",
" ",
" ..... ",
" ....... ",
" ... ... ",
" .. ",
" .. ",
" .. .. ",
" .... .. ",
" ...... .. ",
" .. .. ",
" ... .. ",
" ... ... ",
" ....... ",
" ..... ",
" ",
" "};
/* XPM */
static const char * up_x_xpm[] = {
"16 16 8 1",
" c None",
". c #FFFFFF",
"+ c #9C9C9C",
"@ c #000000",
"# c #747474",
"$ c #484848",
"% c #DFDFDF",
"& c #BFBFBF",
"................",
"................",
"........+.......",
".......@@#......",
"......@@@@#.....",
".....@@$@$@$....",
"....@@%#@&+@$...",
"...@@%.#@&.&@$..",
"..#@%..#@&..&@&.",
"..#....#@&...&&.",
".......#@&......",
".......#@&......",
".......#@&......",
".......#@&......",
".......#@&......",
"................"};
const static SearchOption toggles[] = {
{"Match _whole word only", IDM_WHOLEWORD, IDWHOLEWORD},
{"Case sensiti_ve", IDM_MATCHCASE, IDMATCHCASE},
{"Regular _expression", IDM_REGEXP, IDREGEXP},
{"Transform _backslash expressions", IDM_UNSLASH, IDUNSLASH},
{"Wrap ar_ound", IDM_WRAPAROUND, IDWRAP},
{"_Up", IDM_DIRECTIONUP, IDDIRECTIONUP},
{0, 0, 0},
};
// Has to be in same order as toggles
static const char **xpmImages[] = {
word1_x_xpm,
case_x_xpm,
regex_x_xpm,
backslash_x_xpm,
around_x_xpm,
up_x_xpm,
};
void SciTEGTK::FindInFilesResponse(int responseID) {
switch (responseID) {
case GTK_RESPONSE_OK:
FindInFilesCmd() ;
break;
case GTK_RESPONSE_CANCEL:
dlgFindInFiles.Destroy();
break;
}
}
void SciTEGTK::FindInFiles() {
dlgFindInFiles.SetSearcher(this);
SelectionIntoFind();
props.Set("find.what", findWhat.c_str());
FilePath findInDir = filePath.Directory().AbsolutePath();
SString directory = props.Get("find.in.directory");
if (directory.length()) {
findInDir = FilePath(directory.c_str());
}
props.Set("find.directory", findInDir.AsInternal());
dlgFindInFiles.Create(localiser.Text("Find in Files"));
WTable table(4, 5);
table.PackInto(GTK_BOX(dlgFindInFiles.ContentArea()));
WStatic labelFind;
labelFind.Create(localiser.Text("Fi_nd what:"));
table.Label(labelFind);
dlgFindInFiles.wComboFindInFiles.Create();
table.Add(dlgFindInFiles.wComboFindInFiles, 4, true);
gtk_entry_set_text(dlgFindInFiles.wComboFindInFiles.Entry(), findWhat.c_str());
dlgFindInFiles.wComboFindInFiles.ActivatesDefault();
labelFind.SetMnemonicFor(dlgFindInFiles.wComboFindInFiles);
WStatic labelFiles;
labelFiles.Create(localiser.Text("_Files:"));
table.Label(labelFiles);
dlgFindInFiles.wComboFiles.Create();
FillComboFromMemory(&dlgFindInFiles.wComboFiles, memFiles, true);
table.Add(dlgFindInFiles.wComboFiles, 4, true);
dlgFindInFiles.wComboFiles.ActivatesDefault();
labelFiles.SetMnemonicFor(dlgFindInFiles.wComboFiles);
WStatic labelDirectory;
labelDirectory.Create(localiser.Text("_Directory:"));
table.Label(labelDirectory);
dlgFindInFiles.comboDir.Create();
FillComboFromMemory(&dlgFindInFiles.comboDir, memDirectory);
table.Add(dlgFindInFiles.comboDir, 2, true);
gtk_entry_set_text(dlgFindInFiles.comboDir.Entry(), findInDir.AsInternal());
// Make a little wider than would happen automatically to show realistic paths
gtk_entry_set_width_chars(dlgFindInFiles.comboDir.Entry(), 40);
dlgFindInFiles.comboDir.ActivatesDefault();
labelDirectory.SetMnemonicFor(dlgFindInFiles.comboDir);
Signal<&SciTEGTK::FindInFilesDotDot> sigDotDot;
dlgFindInFiles.btnDotDot.Create(localiser.Text("_.."), G_CALLBACK(sigDotDot.Function), this);
table.Add(dlgFindInFiles.btnDotDot);
Signal<&SciTEGTK::FindInFilesBrowse> sigBrowse;
dlgFindInFiles.btnBrowse.Create(localiser.Text("_Browse..."), G_CALLBACK(sigBrowse.Function), this);
table.Add(dlgFindInFiles.btnBrowse);
table.Add(); // Space
bool enableToggles = props.GetNewExpand("find.command") == "";
// Whole Word
dlgFindInFiles.toggleWord.Create(localiser.Text(toggles[SearchOption::tWord].label));
gtk_widget_set_sensitive(dlgFindInFiles.toggleWord, enableToggles);
table.Add(dlgFindInFiles.toggleWord, 1, true, 3, 0);
// Case Sensitive
dlgFindInFiles.toggleCase.Create(localiser.Text(toggles[SearchOption::tCase].label));
gtk_widget_set_sensitive(dlgFindInFiles.toggleCase, enableToggles);
table.Add(dlgFindInFiles.toggleCase, 1, true, 3, 0);
AttachResponse<&SciTEGTK::FindInFilesResponse>(PWidget(dlgFindInFiles), this);
dlgFindInFiles.ResponseButton(localiser.Text("_Cancel"), GTK_RESPONSE_CANCEL);
dlgFindInFiles.ResponseButton(localiser.Text("F_ind"), GTK_RESPONSE_OK);
gtk_dialog_set_default_response(GTK_DIALOG(PWidget(dlgFindInFiles)), GTK_RESPONSE_OK);
dlgFindInFiles.FillFields();
gtk_widget_grab_focus(GTK_WIDGET(dlgFindInFiles.wComboFindInFiles.Entry()));
dlgFindInFiles.Display(PWidget(wSciTE));
}
void SciTEGTK::Replace() {
if (dlgFindReplace.Created()) {
dlgFindReplace.Present();
return;
}
SelectionIntoFind();
if (props.GetInt("replace.use.strip")) {
findStrip.Close();
replaceStrip.Show(props.GetInt("strip.button.height", -1));
} else {
if (findStrip.visible || replaceStrip.visible)
return;
FindReplace(true);
}
}
void SciTEGTK::ResetExecution() {
icmd = 0;
jobQueue.SetExecuting(false);
if (needReadProperties)
ReadProperties();
CheckReload();
CheckMenus();
jobQueue.ClearJobs();
}
void SciTEGTK::ExecuteNext() {
icmd++;
if (icmd < jobQueue.commandCurrent && icmd < jobQueue.commandMax) {
Execute();
} else {
ResetExecution();
}
}
void SciTEGTK::ContinueExecute(int fromPoll) {
char buf[8192];
int count = read(fdFIFO, buf, sizeof(buf) - 1);
if (count > 0) {
buf[count] = '\0';
OutputAppendString(buf);
lastOutput += buf;
} else if (count == 0) {
SString sExitMessage(WEXITSTATUS(exitStatus));
sExitMessage.insert(0, ">Exit code: ");
if (WIFSIGNALED(exitStatus)) {
SString sSignal(WTERMSIG(exitStatus));
sSignal.insert(0, " Signal: ");
sExitMessage += sSignal;
}
if (jobQueue.TimeCommands()) {
sExitMessage += " Time: ";
sExitMessage += SString(commandTime.Duration(), 3);
}
if ((lastFlags & jobRepSelYes)
|| ((lastFlags & jobRepSelAuto) && !exitStatus)) {
int cpMin = wEditor.Send(SCI_GETSELECTIONSTART, 0, 0);
wEditor.Send(SCI_REPLACESEL,0,(sptr_t)(lastOutput.c_str()));
wEditor.Send(SCI_SETSEL, cpMin, cpMin+lastOutput.length());
}
sExitMessage.append("\n");
OutputAppendString(sExitMessage.c_str());
// Move selection back to beginning of this run so that F4 will go
// to first error of this run.
if ((scrollOutput == 1) && returnOutputToCommand)
wOutput.Send(SCI_GOTOPOS, originalEnd);
returnOutputToCommand = true;
g_source_remove(inputHandle);
inputHandle = 0;
g_io_channel_unref(inputChannel);
inputChannel = 0;
g_source_remove(pollID);
pollID = 0;
close(fdFIFO);
fdFIFO = 0;
pidShell = 0;
triedKill = false;
if (WEXITSTATUS(exitStatus))
ResetExecution();
else
ExecuteNext();
} else { // count < 0
// The FIFO is not ready - expected when called from polling callback.
if (!fromPoll) {
OutputAppendString(">End Bad\n");
}
}
}
void SciTEGTK::ShowBackgroundProgress(const GUI::gui_string &explanation, int size, int progress) {
backgroundStrip.visible = !explanation.empty();
if (backgroundStrip.visible) {
backgroundStrip.Show(0);
backgroundStrip.SetProgress(explanation, size, progress);
} else {
backgroundStrip.Close();
}
}
void SciTEGTK::UserStripShow(const char *description) {
if (*description) {
userStrip.SetDescription(description);
userStrip.Show(props.GetInt("strip.button.height", -1));
} else {
userStrip.Close();
SizeSubWindows();
}
}
void SciTEGTK::UserStripSet(int control, const char *value) {
userStrip.Set(control, value);
}
void SciTEGTK::UserStripSetList(int control, const char *value) {
userStrip.SetList(control, value);
}
const char *SciTEGTK::UserStripValue(int control) {
std::string val = userStrip.GetValue(control);
char *ret = new char[val.size() + 1];
strcpy(ret, val.c_str());
return ret;
}
void SciTEGTK::UserStripClosed() {
SizeSubWindows();
}
gboolean SciTEGTK::IOSignal(GIOChannel *, GIOCondition, SciTEGTK *scitew) {
#ifndef GDK_VERSION_3_6
ThreadLockMinder minder;
#endif
scitew->ContinueExecute(FALSE);
return TRUE;
}
void SciTEGTK::ReapChild(GPid pid, gint status, gpointer user_data) {
SciTEGTK *self = reinterpret_cast<SciTEGTK*>(user_data);
self->exitStatus = status;
self->pidShell = 0;
self->triedKill = false;
g_spawn_close_pid(pid);
}
static void SetupChild(gpointer) {
dup2(1, 2);
setpgid(0, 0);
}
void SciTEGTK::Execute() {
if (buffers.SavingInBackground())
// May be saving file that should be used by command so wait until all saved
return;
SciTEBase::Execute();
commandTime.Duration(true);
if (scrollOutput)
wOutput.Send(SCI_GOTOPOS, wOutput.Send(SCI_GETTEXTLENGTH));
originalEnd = wOutput.Send(SCI_GETCURRENTPOS);
lastOutput = "";
lastFlags = jobQueue.jobQueue[icmd].flags;
if (jobQueue.jobQueue[icmd].jobType != jobExtension) {
OutputAppendString(">");
OutputAppendString(jobQueue.jobQueue[icmd].command.c_str());
OutputAppendString("\n");
}
if (jobQueue.jobQueue[icmd].directory.IsSet()) {
jobQueue.jobQueue[icmd].directory.SetWorkingDirectory();
}
if (jobQueue.jobQueue[icmd].jobType == jobShell) {
const gchar *argv[] = { "/bin/sh", "-c", jobQueue.jobQueue[icmd].command.c_str(), NULL };
g_spawn_async(NULL, const_cast<gchar**>(argv), NULL, G_SPAWN_DEFAULT, NULL, NULL, NULL, NULL);
ExecuteNext();
} else if (jobQueue.jobQueue[icmd].jobType == jobExtension) {
if (extender)
extender->OnExecute(jobQueue.jobQueue[icmd].command.c_str());
ExecuteNext();
} else {
GError *error = NULL;
gint fdout;
const char *argv[] = { "/bin/sh", "-c", jobQueue.jobQueue[icmd].command.c_str(), NULL };
if (!g_spawn_async_with_pipes(
NULL, const_cast<gchar**>(argv), NULL,
G_SPAWN_DO_NOT_REAP_CHILD, SetupChild, NULL,
&pidShell, NULL, &fdout, NULL, &error
)) {
OutputAppendString(">g_spawn_async_with_pipes: ");
OutputAppendString(error->message);
OutputAppendString("\n");
g_error_free(error);
}
g_child_watch_add(pidShell, SciTEGTK::ReapChild, this);
fdFIFO = fdout;
triedKill = false;
fcntl(fdFIFO, F_SETFL, fcntl(fdFIFO, F_GETFL) | O_NONBLOCK);
inputChannel = g_io_channel_unix_new(fdout);
inputHandle = g_io_add_watch(inputChannel, G_IO_IN, (GIOFunc)IOSignal, this);
// Also add a background task in case there is no output from the tool
pollID = g_timeout_add(20, (gint (*)(void *)) SciTEGTK::PollTool, this);
}
}
void SciTEGTK::StopExecute() {
if (!triedKill && pidShell) {
kill(-pidShell, SIGKILL);
triedKill = true;
}
}
void SciTEGTK::GotoCmd() {
int lineNo = dlgGoto.entryGoto.Value();
GotoLineEnsureVisible(lineNo - 1);
dlgGoto.Destroy();
}
void SciTEGTK::GotoResponse(int responseID) {
switch (responseID) {
case GTK_RESPONSE_OK:
GotoCmd() ;
break;
case GTK_RESPONSE_CANCEL:
dlgGoto.Destroy();
break;
}
}
void SciTEGTK::GoLineDialog() {
dlgGoto.Create(localiser.Text("Go To"));
gtk_container_set_border_width(GTK_CONTAINER(PWidget(dlgGoto)), 0);
WTable table(1, 2);
table.PackInto(GTK_BOX(dlgGoto.ContentArea()));
GtkWidget *labelGoto = TranslatedLabel("_Destination Line Number:");
table.Label(labelGoto);
dlgGoto.entryGoto.Create();
table.Add(dlgGoto.entryGoto);
dlgGoto.entryGoto.ActivatesDefault();
gtk_widget_grab_focus(dlgGoto.entryGoto);
gtk_label_set_mnemonic_widget(GTK_LABEL(labelGoto), dlgGoto.entryGoto);
AttachResponse<&SciTEGTK::GotoResponse>(PWidget(dlgGoto), this);
dlgGoto.ResponseButton(localiser.Text("_Cancel"), GTK_RESPONSE_CANCEL);
dlgGoto.ResponseButton(localiser.Text("_Go To"), GTK_RESPONSE_OK);
gtk_dialog_set_default_response(GTK_DIALOG(PWidget(dlgGoto)), GTK_RESPONSE_OK);
dlgGoto.Display(PWidget(wSciTE));
}
void SciTEGTK::AbbrevCmd() {
abbrevInsert = dlgAbbrev.comboAbbrev.Text();
dlgAbbrev.Destroy();
}
void SciTEGTK::AbbrevResponse(int responseID) {
switch (responseID) {
case GTK_RESPONSE_OK:
AbbrevCmd();
break;
case GTK_RESPONSE_CANCEL:
abbrevInsert = "";
dlgAbbrev.Destroy();
break;
}
}
bool SciTEGTK::AbbrevDialog() {
dlgAbbrev.Create(localiser.Text("Insert Abbreviation"));
gtk_container_set_border_width(GTK_CONTAINER(PWidget(dlgAbbrev)), 0);
WTable table(1, 2);
table.PackInto(GTK_BOX(dlgAbbrev.ContentArea()));
GtkWidget *labelAbbrev = TranslatedLabel("_Abbreviation:");
table.Label(labelAbbrev);
dlgAbbrev.comboAbbrev.Create();
gtk_entry_set_width_chars(dlgAbbrev.comboAbbrev.Entry(), 35);
FillComboFromProps(&dlgAbbrev.comboAbbrev, propsAbbrev);
table.Add(dlgAbbrev.comboAbbrev, 2, true);
gtk_widget_grab_focus(dlgAbbrev.comboAbbrev);
gtk_label_set_mnemonic_widget(GTK_LABEL(labelAbbrev), dlgAbbrev.comboAbbrev);
AttachResponse<&SciTEGTK::AbbrevResponse>(PWidget(dlgAbbrev), this);
dlgAbbrev.ResponseButton(localiser.Text("_Cancel"), GTK_RESPONSE_CANCEL);
dlgAbbrev.ResponseButton(localiser.Text("_Insert"), GTK_RESPONSE_OK);
gtk_dialog_set_default_response(GTK_DIALOG(PWidget(dlgAbbrev)), GTK_RESPONSE_OK);
dlgAbbrev.Display(PWidget(wSciTE));
return TRUE;
}
void SciTEGTK::TabSizeSet(int &tabSize, bool &useTabs) {
tabSize = dlgTabSize.entryTabSize.Value();
if (tabSize > 0)
wEditor.Call(SCI_SETTABWIDTH, tabSize);
int indentSize = dlgTabSize.entryIndentSize.Value();
if (indentSize > 0)
wEditor.Call(SCI_SETINDENT, indentSize);
useTabs = dlgTabSize.toggleUseTabs.Active();
wEditor.Call(SCI_SETUSETABS, useTabs);
}
void SciTEGTK::TabSizeCmd() {
int tabSize;
bool useTabs;
TabSizeSet(tabSize, useTabs);
dlgTabSize.Destroy();
}
void SciTEGTK::TabSizeConvertCmd() {
int tabSize;
bool useTabs;
TabSizeSet(tabSize, useTabs);
ConvertIndentation(tabSize, useTabs);
dlgTabSize.Destroy();
}
#define RESPONSE_CONVERT 1001
void SciTEGTK::TabSizeResponse(int responseID) {
switch (responseID) {
case RESPONSE_CONVERT:
TabSizeConvertCmd();
break;
case GTK_RESPONSE_OK:
TabSizeCmd() ;
break;
case GTK_RESPONSE_CANCEL:
dlgTabSize.Destroy();
break;
}
}
void SciTEGTK::TabSizeDialog() {
dlgTabSize.Create(localiser.Text("Indentation Settings"));
gtk_container_set_border_width(GTK_CONTAINER(PWidget(dlgTabSize)), 0);
WTable table(3, 2);
table.PackInto(GTK_BOX(dlgTabSize.ContentArea()));
GtkWidget *labelTabSize = TranslatedLabel("_Tab Size:");
table.Label(labelTabSize);
SString tabSize(static_cast<int>(wEditor.Call(SCI_GETTABWIDTH)));
dlgTabSize.entryTabSize.Create(tabSize.c_str());
table.Add(dlgTabSize.entryTabSize);
dlgTabSize.entryTabSize.ActivatesDefault();
gtk_widget_grab_focus(dlgTabSize.entryTabSize);
gtk_label_set_mnemonic_widget(GTK_LABEL(labelTabSize), dlgTabSize.entryTabSize);
GtkWidget *labelIndentSize = TranslatedLabel("_Indent Size:");
table.Label(labelIndentSize);
SString indentSize(static_cast<int>(wEditor.Call(SCI_GETINDENT)));
dlgTabSize.entryIndentSize.Create(indentSize.c_str());
table.Add(dlgTabSize.entryIndentSize);
dlgTabSize.entryIndentSize.ActivatesDefault();
gtk_label_set_mnemonic_widget(GTK_LABEL(labelIndentSize), dlgTabSize.entryIndentSize);
bool useTabs = wEditor.Call(SCI_GETUSETABS);
dlgTabSize.toggleUseTabs.Create(localiser.Text("_Use Tabs"));
dlgTabSize.toggleUseTabs.SetActive(useTabs);
table.Add();
table.Add(dlgTabSize.toggleUseTabs);
AttachResponse<&SciTEGTK::TabSizeResponse>(PWidget(dlgTabSize), this);
dlgTabSize.ResponseButton(localiser.Text("Con_vert"), RESPONSE_CONVERT);
dlgTabSize.ResponseButton(localiser.Text("_Cancel"), GTK_RESPONSE_CANCEL);
dlgTabSize.ResponseButton(localiser.Text("_OK"), GTK_RESPONSE_OK);
gtk_dialog_set_default_response(GTK_DIALOG(PWidget(dlgTabSize)), GTK_RESPONSE_OK);
dlgTabSize.Display(PWidget(wSciTE));
}
bool SciTEGTK::ParametersOpen() {
return dlgParameters.Created();
}
void SciTEGTK::ParamGrab() {
if (dlgParameters.Created()) {
for (int param = 0; param < maxParam; param++) {
SString paramText(param + 1);
const char *paramVal = dlgParameters.entryParam[param].Text();
props.Set(paramText.c_str(), paramVal);
}
UpdateStatusBar(true);
}
}
void SciTEGTK::ParamCancelCmd() {
dlgParameters.Destroy();
CheckMenus();
}
void SciTEGTK::ParamCmd() {
dlgParameters.paramDialogCanceled = false;
ParamGrab();
dlgParameters.Destroy();
CheckMenus();
}
void SciTEGTK::ParamResponse(int responseID) {
switch (responseID) {
case GTK_RESPONSE_OK:
ParamCmd() ;
break;
case GTK_RESPONSE_CANCEL:
ParamCancelCmd();
break;
}
}
bool SciTEGTK::ParametersDialog(bool modal) {
if (dlgParameters.Created()) {
ParamGrab();
if (!modal) {
dlgParameters.Destroy();
}
return true;
}
dlgParameters.paramDialogCanceled = true;
dlgParameters.Create(localiser.Text("Parameters"));
g_signal_connect(G_OBJECT(PWidget(dlgParameters)),
"destroy", G_CALLBACK(destroyDialog), &dlgParameters);
WTable table(modal ? 10 : 9, 2);
table.PackInto(GTK_BOX(dlgParameters.ContentArea()));
if (modal) {
GtkWidget *cmd = gtk_label_new(parameterisedCommand.c_str());
table.Add(cmd, 2);
}
for (int param = 0; param < maxParam; param++) {
SString paramText(param + 1);
SString paramTextVal = props.Get(paramText.c_str());
paramText.insert(0, "_");
paramText.append(":");
GtkWidget *label = gtk_label_new_with_mnemonic(paramText.c_str());
table.Label(label);
dlgParameters.entryParam[param].Create(paramTextVal.c_str());
table.Add(dlgParameters.entryParam[param]);
dlgParameters.entryParam[param].ActivatesDefault();
gtk_label_set_mnemonic_widget(GTK_LABEL(label), dlgParameters.entryParam[param]);
}
gtk_widget_grab_focus(dlgParameters.entryParam[0]);
AttachResponse<&SciTEGTK::ParamResponse>(PWidget(dlgParameters), this);
dlgParameters.ResponseButton(localiser.Text(modal ? "_Cancel" : "_Close"), GTK_RESPONSE_CANCEL);
dlgParameters.ResponseButton(localiser.Text(modal ? "_Execute" : "_Set"), GTK_RESPONSE_OK);
gtk_dialog_set_default_response(GTK_DIALOG(PWidget(dlgParameters)), GTK_RESPONSE_OK);
dlgParameters.Display(PWidget(wSciTE), modal);
return !dlgParameters.paramDialogCanceled;
}
bool SciTEGTK::FindReplaceAdvanced() {
return props.GetInt("find.replace.advanced");
}
#define RESPONSE_MARK_ALL 1002
#define RESPONSE_REPLACE 1003
#define RESPONSE_REPLACE_ALL 1004
#define RESPONSE_REPLACE_IN_SELECTION 1005
#define RESPONSE_REPLACE_IN_BUFFERS 1006
void SciTEGTK::FindReplaceResponse(int responseID) {
switch (responseID) {
case GTK_RESPONSE_OK:
FRFindCmd() ;
break;
case GTK_RESPONSE_CANCEL:
dlgFindReplace.Destroy();
break;
case RESPONSE_MARK_ALL:
FRMarkAllCmd();
break;
case RESPONSE_REPLACE:
FRReplaceCmd();
break;
case RESPONSE_REPLACE_ALL:
FRReplaceAllCmd();
break;
case RESPONSE_REPLACE_IN_SELECTION:
FRReplaceInSelectionCmd();
break;
case RESPONSE_REPLACE_IN_BUFFERS:
FRReplaceInBuffersCmd();
break;
}
}
void SciTEGTK::FindReplace(bool replace) {
replacing = replace;
dlgFindReplace.SetSearcher(this);
dlgFindReplace.Create(localiser.Text(replace ? "Replace" : "Find"));
g_signal_connect(G_OBJECT(PWidget(dlgFindReplace)),
"destroy", G_CALLBACK(destroyDialog), &dlgFindReplace);
WTable table(replace ? 8 : 7, 2);
table.PackInto(GTK_BOX(dlgFindReplace.ContentArea()));
dlgFindReplace.labelFind.Create(localiser.Text("Fi_nd what:"));
table.Label(dlgFindReplace.labelFind);
dlgFindReplace.wComboFind.Create();
table.Add(dlgFindReplace.wComboFind, 1, true);
dlgFindReplace.wComboFind.SetText(findWhat.c_str());
gtk_entry_set_width_chars(dlgFindReplace.wComboFind.Entry(), 40);
dlgFindReplace.wComboFind.ActivatesDefault();
dlgFindReplace.labelFind.SetMnemonicFor(dlgFindReplace.wComboFind);
if (replace) {
dlgFindReplace.labelReplace.Create(localiser.Text("Rep_lace with:"));
table.Label(dlgFindReplace.labelReplace);
dlgFindReplace.wComboReplace.Create();
table.Add(dlgFindReplace.wComboReplace, 1, true);
dlgFindReplace.wComboReplace.ActivatesDefault();
dlgFindReplace.labelReplace.SetMnemonicFor(dlgFindReplace.wComboReplace);
} else {
dlgFindReplace.wComboReplace.SetID(0);
}
// Whole Word
dlgFindReplace.toggleWord.Create(localiser.Text(toggles[SearchOption::tWord].label));
table.Add(dlgFindReplace.toggleWord, 2, false, 3, 0);
// Case Sensitive
dlgFindReplace.toggleCase.Create(localiser.Text(toggles[SearchOption::tCase].label));
table.Add(dlgFindReplace.toggleCase, 2, false, 3, 0);
// Regular Expression
dlgFindReplace.toggleRegExp.Create(localiser.Text(toggles[SearchOption::tRegExp].label));
table.Add(dlgFindReplace.toggleRegExp, 2, false, 3, 0);
// Transform backslash expressions
dlgFindReplace.toggleUnSlash.Create(localiser.Text(toggles[SearchOption::tBackslash].label));
table.Add(dlgFindReplace.toggleUnSlash, 2, false, 3, 0);
// Wrap Around
dlgFindReplace.toggleWrap.Create(localiser.Text(toggles[SearchOption::tWrap].label));
table.Add(dlgFindReplace.toggleWrap, 2, false, 3, 0);
if (replace) {
dlgFindReplace.toggleReverse.SetID(0);
} else {
// Reverse
dlgFindReplace.toggleReverse.Create(localiser.Text(toggles[SearchOption::tUp].label));
table.Add(dlgFindReplace.toggleReverse, 2, false, 3, 0);
}
if (!replace) {
dlgFindReplace.ResponseButton(localiser.Text(textMarkAll), RESPONSE_MARK_ALL);
}
if (replace) {
dlgFindReplace.ResponseButton(localiser.Text(textReplace), RESPONSE_REPLACE);
dlgFindReplace.ResponseButton(localiser.Text(textReplaceAll), RESPONSE_REPLACE_ALL);
dlgFindReplace.ResponseButton(localiser.Text(textInSelection), RESPONSE_REPLACE_IN_SELECTION);
if (FindReplaceAdvanced()) {
dlgFindReplace.ResponseButton(localiser.Text(textReplaceInBuffers), RESPONSE_REPLACE_IN_BUFFERS);
}
}
dlgFindReplace.ResponseButton(localiser.Text(textClose), GTK_RESPONSE_CANCEL);
dlgFindReplace.ResponseButton(localiser.Text(textFind), GTK_RESPONSE_OK);
AttachResponse<&SciTEGTK::FindReplaceResponse>(PWidget(dlgFindReplace), this);
gtk_dialog_set_default_response(GTK_DIALOG(PWidget(dlgFindReplace)), GTK_RESPONSE_OK);
dlgFindReplace.FillFields();
gtk_widget_grab_focus(GTK_WIDGET(dlgFindReplace.wComboFind.Entry()));
dlgFindReplace.Display(PWidget(wSciTE), false);
}
void SciTEGTK::DestroyFindReplace() {
dlgFindReplace.Destroy();
}
int SciTEGTK::WindowMessageBox(GUI::Window &w, const GUI::gui_string &msg, int style) {
if (!messageBoxDialog) {
SString sMsg(msg.c_str());
dialogsOnScreen++;
GtkAccelGroup *accel_group = gtk_accel_group_new();
messageBoxResult = -1;
messageBoxDialog = gtk_dialog_new();
gtk_window_set_title(GTK_WINDOW(messageBoxDialog), appName);
gtk_container_set_border_width(GTK_CONTAINER(messageBoxDialog), 0);
g_signal_connect(G_OBJECT(messageBoxDialog),
"destroy", G_CALLBACK(messageBoxDestroy), &messageBoxDialog);
int escapeResult = IDOK;
if ((style & 0xf) == MB_OK) {
AddMBButton(messageBoxDialog, "_OK", IDOK, accel_group, true);
} else {
AddMBButton(messageBoxDialog, "_Yes", IDYES, accel_group, true);
AddMBButton(messageBoxDialog, "_No", IDNO, accel_group);
escapeResult = IDNO;
if ((style & 0xf) == MB_YESNOCANCEL) {
AddMBButton(messageBoxDialog, "_Cancel", IDCANCEL, accel_group);
escapeResult = IDCANCEL;
}
}
g_signal_connect(G_OBJECT(messageBoxDialog),
"key_press_event", G_CALLBACK(messageBoxKey),
reinterpret_cast<gpointer>(escapeResult));
if (style & MB_ABOUTBOX) {
GtkWidget *explanation = scintilla_new();
GUI::ScintillaWindow scExplanation;
scExplanation.SetID(explanation);
scintilla_set_id(SCINTILLA(explanation), 0);
#if GTK_CHECK_VERSION(3,0,0)
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(messageBoxDialog))),
explanation, TRUE, TRUE, 0);
#else
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(messageBoxDialog)->vbox),
explanation, TRUE, TRUE, 0);
#endif
gtk_widget_set_size_request(GTK_WIDGET(explanation), 480, 380);
gtk_widget_show_all(explanation);
SetAboutMessage(scExplanation, "SciTE");
} else {
GtkWidget *label = gtk_label_new(sMsg.c_str());
gtk_misc_set_padding(GTK_MISC(label), 10, 10);
#if GTK_CHECK_VERSION(3,0,0)
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(messageBoxDialog))),
label, TRUE, TRUE, 0);
#else
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(messageBoxDialog)->vbox),
label, TRUE, TRUE, 0);
#endif
gtk_widget_show(label);
}
// Mark it as a modal transient dialog
gtk_window_set_modal(GTK_WINDOW(messageBoxDialog), TRUE);
gtk_window_set_transient_for(GTK_WINDOW(messageBoxDialog),
GTK_WINDOW(PWidget(w)));
gtk_widget_show(messageBoxDialog);
gtk_window_add_accel_group(GTK_WINDOW(messageBoxDialog), accel_group);
while (messageBoxResult < 0) {
gtk_main_iteration();
}
dialogsOnScreen--;
}
return messageBoxResult;
}
void SciTEGTK::FindMessageBox(const SString &msg, const SString *findItem) {
if (findItem == 0) {
GUI::gui_string msgBuf = LocaliseMessage(msg.c_str());
WindowMessageBox(wSciTE, msgBuf, MB_OK | MB_ICONWARNING);
} else {
GUI::gui_string msgBuf = LocaliseMessage(msg.c_str(), findItem->c_str());
WindowMessageBox(wSciTE, msgBuf, MB_OK | MB_ICONWARNING);
}
}
void SciTEGTK::AboutDialog() {
WindowMessageBox(wSciTE, GUI::gui_string("SciTE\nby Neil Hodgson neilh@scintilla.org ."),
MB_OK | MB_ABOUTBOX);
}
void SciTEGTK::QuitProgram() {
if (SaveIfUnsureAll() != IDCANCEL) {
quitting = true;
// If ongoing saves, wait for them to complete.
if (!buffers.SavingInBackground()) {
gtk_main_quit();
}
}
}
void SciTEGTK::PanePositionChanged(GObject *, GParamSpec *, SciTEGTK *scitew) {
bool sizeForced = scitew->UpdateOutputSize();
if (sizeForced) {
// Calling SizeContentWindows sets position on the H/VPaned and thus
// prevents the user setting the size of either output or editor to less
// than 20px.
// Setting the position again may lead to this function being called
// twice, but it doesn't lead to an infinite loop, since sizeForced is
// only true when the position really changed.
scitew->SizeContentWindows();
}
}
gint SciTEGTK::PaneButtonRelease(GtkWidget *, GdkEvent *, SciTEGTK *scitew) {
// Only register previousHeightOutput when the user stops dragging
scitew->UpdateOutputSize();
if (scitew->heightOutput > 0) {
scitew->previousHeightOutput = scitew->heightOutput;
}
return FALSE;
}
bool SciTEGTK::UpdateOutputSize() {
// This sets heightOutput and returns a boolean indicating whether
// heightOutput is equal to the H/VPaned position or an adjustment was made.
gint max;
int pos;
int newHeight;
g_object_get(G_OBJECT(splitPane), "max-position", &max, NULL);
pos = gtk_paned_get_position(GTK_PANED(splitPane));
newHeight = max - pos;
// Return false if the height hasn't changed
// This prevents an infinite loop in PanePositionChanged()
if (newHeight == heightOutput)
return false;
heightOutput = newHeight;
if (heightOutput > (max - 20)) {
heightOutput = max;
return true;
} else if (heightOutput < 20) {
heightOutput = 0;
return true;
}
return false;
}
gint SciTEGTK::QuitSignal(GtkWidget *, GdkEventAny *, SciTEGTK *scitew) {
scitew->QuitProgram();
return TRUE;
}
void SciTEGTK::ButtonSignal(GtkWidget *, gpointer data) {
instance->Command((guint)(long)data);
}
void SciTEGTK::MenuSignal(GtkMenuItem *menuitem, SciTEGTK *scitew) {
if (scitew->allowMenuActions) {
guint action = (guint)(sptr_t)(g_object_get_data(G_OBJECT(menuitem), "CmdNum"));
scitew->Command(action);
}
}
void SciTEGTK::NotifySignal(GtkWidget *, gint /*wParam*/, SCNotification *notification, SciTEGTK *scitew) {
scitew->Notify(notification);
}
gint SciTEGTK::KeyPress(GtkWidget * /*widget*/, GdkEventKey *event, SciTEGTK *scitew) {
return scitew->Key(event);
}
gint SciTEGTK::KeyRelease(GtkWidget * /*widget*/, GdkEventKey *event, SciTEGTK *scitew) {
return scitew->Key(event);
}
gint SciTEGTK::MousePress(GtkWidget * /*widget*/, GdkEventButton *event, SciTEGTK *scitew) {
return scitew->Mouse(event);
}
// Translate key strokes that are not in a menu into commands
class KeyToCommand {
public:
int modifiers;
unsigned int key; // For alphabetic keys has to match the shift modifier.
int msg;
};
enum {
m__ = 0,
mS_ = GDK_SHIFT_MASK,
m_C = GDK_CONTROL_MASK,
mSC = GDK_SHIFT_MASK | GDK_CONTROL_MASK
};
static KeyToCommand kmap[] = {
{m_C, GKEY_Tab, IDM_NEXTFILESTACK},
{mSC, GKEY_ISO_Left_Tab, IDM_PREVFILESTACK},
{m_C, GKEY_KP_Enter, IDM_COMPLETEWORD},
{GDK_MOD1_MASK, GKEY_F2, IDM_BOOKMARK_NEXT_SELECT},
{GDK_MOD1_MASK|GDK_SHIFT_MASK, GKEY_F2, IDM_BOOKMARK_PREV_SELECT},
{m_C, GKEY_F3, IDM_FINDNEXTSEL},
{mSC, GKEY_F3, IDM_FINDNEXTBACKSEL},
{m_C, GKEY_F4, IDM_CLOSE},
{m_C, 'j', IDM_PREVMATCHPPC},
{mSC, 'J', IDM_SELECTTOPREVMATCHPPC},
{m_C, 'k', IDM_NEXTMATCHPPC},
{mSC, 'K', IDM_SELECTTONEXTMATCHPPC},
{m_C, GKEY_KP_Multiply, IDM_EXPAND},
{0, 0, 0},
};
inline bool KeyMatch(const char *menuKey, int keyval, int modifiers) {
return SciTEKeys::MatchKeyCode(
SciTEKeys::ParseKeyCode(menuKey), keyval, modifiers);
}
gint SciTEGTK::Key(GdkEventKey *event) {
//printf("S-key: %d %x %x %x %x\n",event->keyval, event->state, GDK_SHIFT_MASK, GDK_CONTROL_MASK, GDK_F3);
if (event->type == GDK_KEY_RELEASE) {
if (event->keyval == GKEY_Control_L || event->keyval == GKEY_Control_R) {
g_signal_stop_emission_by_name(
G_OBJECT(PWidget(wSciTE)), "key-release-event");
this->EndStackedTabbing();
return 1;
} else {
return 0;
}
}
int modifiers = event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK);
int cmodifiers = // modifier mask for Lua extension
(event->state & GDK_SHIFT_MASK ? SCMOD_SHIFT : 0) |
(event->state & GDK_CONTROL_MASK ? SCMOD_CTRL : 0) |
(event->state & GDK_MOD1_MASK ? SCMOD_ALT : 0);
if (extender && extender->OnKey(event->keyval, cmodifiers))
return 1;
int commandID = 0;
for (int i = 0; kmap[i].msg; i++) {
if ((event->keyval == kmap[i].key) && (modifiers == kmap[i].modifiers)) {
commandID = kmap[i].msg;
}
}
if (!commandID) {
// Look through language menu
for (int j = 0; j < languageItems; j++) {
if (KeyMatch(languageMenu[j].menuKey.c_str(), event->keyval, modifiers)) {
commandID = IDM_LANGUAGE + j;
}
}
}
if (commandID) {
Command(commandID);
}
if ((commandID == IDM_NEXTFILE) ||
(commandID == IDM_PREVFILE) ||
(commandID == IDM_NEXTFILESTACK) ||
(commandID == IDM_PREVFILESTACK)) {
// Stop the default key processing from moving the focus
g_signal_stop_emission_by_name(
G_OBJECT(PWidget(wSciTE)), "key_press_event");
}
// check tools menu command shortcuts
for (int tool_i = 0; tool_i < toolMax; ++tool_i) {
GtkWidget *item = MenuItemFromAction(IDM_TOOLS + tool_i);
if (item) {
long keycode = reinterpret_cast<long>(g_object_get_data(G_OBJECT(item), "key"));
if (keycode && SciTEKeys::MatchKeyCode(keycode, event->keyval, modifiers)) {
SciTEBase::MenuCommand(IDM_TOOLS + tool_i);
return 1;
}
}
}
// check user defined keys
for (size_t cut_i = 0; cut_i < shortCutItemList.size(); cut_i++) {
if (KeyMatch(shortCutItemList[cut_i].menuKey.c_str(), event->keyval, modifiers)) {
int commandNum = SciTEBase::GetMenuCommandAsInt(shortCutItemList[cut_i].menuCommand);
if (commandNum != -1) {
if (commandNum < 2000) {
SciTEBase::MenuCommand(commandNum);
} else {
SciTEBase::CallFocused(commandNum);
}
g_signal_stop_emission_by_name(
G_OBJECT(PWidget(wSciTE)), "key_press_event");
return 1;
}
}
}
if (findStrip.KeyDown(event) || replaceStrip.KeyDown(event) || userStrip.KeyDown(event)) {
g_signal_stop_emission_by_name(G_OBJECT(PWidget(wSciTE)), "key_press_event");
return 1;
}
return 0;
}
void SciTEGTK::PopUpCmd(GtkMenuItem *menuItem, SciTEGTK *scitew) {
sptr_t cmd = (sptr_t)(g_object_get_data(G_OBJECT(menuItem), "CmdNum"));
scitew->Command(cmd);
}
void SciTEGTK::AddToPopUp(const char *label, int cmd, bool enabled) {
GUI::gui_string localised = localiser.Text(label);
GtkWidget *menuItem;
if (label[0])
menuItem = gtk_menu_item_new_with_label(localised.c_str());
else
menuItem = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(popup.GetID()), menuItem);
g_object_set_data(G_OBJECT(menuItem), "CmdNum", reinterpret_cast<void *>((sptr_t)(cmd)));
g_signal_connect(G_OBJECT(menuItem),"activate", G_CALLBACK(PopUpCmd), this);
if (cmd) {
if (menuItem)
gtk_widget_set_sensitive(menuItem, enabled);
}
}
gint SciTEGTK::Mouse(GdkEventButton *event) {
if (event->button == 3) {
// PopUp menu
GUI::ScintillaWindow *w = &wEditor;
menuSource = IDM_SRCWIN;
if (WindowFromWidget(PWidget(*w)) != event->window) {
if (WindowFromWidget(PWidget(wOutput)) == event->window) {
menuSource = IDM_RUNWIN;
w = &wOutput;
} else {
menuSource = 0;
//fprintf(stderr, "Menu source focus\n");
return FALSE;
}
}
// Convert to screen
int ox = 0;
int oy = 0;
gdk_window_get_origin(WindowFromWidget(PWidget(*w)), &ox, &oy);
ContextMenu(*w, GUI::Point(static_cast<int>(event->x) + ox,
static_cast<int>(event->y) + oy), wSciTE);
//fprintf(stderr, "Menu source %s\n",
// (menuSource == IDM_SRCWIN) ? "IDM_SRCWIN" : "IDM_RUNWIN");
} else {
menuSource = 0;
//fprintf(stderr, "Menu source focus\n");
}
return FALSE;
}
void SciTEGTK::DragDataReceived(GtkWidget *, GdkDragContext *context,
gint /*x*/, gint /*y*/, GtkSelectionData *seldata, guint /*info*/, guint time, SciTEGTK *scitew) {
#if GTK_CHECK_VERSION(3,0,0)
scitew->OpenUriList(reinterpret_cast<const char *>(gtk_selection_data_get_data(seldata)));
#else
scitew->OpenUriList(reinterpret_cast<const char *>(seldata->data));
#endif
gtk_drag_finish(context, TRUE, FALSE, time);
}
gint SciTEGTK::TabBarRelease(GtkNotebook *notebook, GdkEventButton *event) {
if (event->button == 1) {
SetDocumentAt(gtk_notebook_get_current_page(GTK_NOTEBOOK(wTabBar.GetID())));
CheckReload();
} else if (event->button == 2) {
for (int pageNum=0;pageNum<gtk_notebook_get_n_pages(notebook);pageNum++) {
GtkWidget *page = gtk_notebook_get_nth_page(notebook, pageNum);
if (page) {
GtkWidget *label = gtk_notebook_get_tab_label(notebook, page);
GtkAllocation allocation;
#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_get_allocation(label, &allocation);
#else
allocation = label->allocation;
#endif
if (event->x < (allocation.x + allocation.width)) {
CloseTab(pageNum);
break;
}
}
}
}
return FALSE;
}
gint SciTEGTK::TabBarScroll(GdkEventScroll *event) {
switch (event->direction) {
case GDK_SCROLL_RIGHT:
case GDK_SCROLL_DOWN:
Next();
WindowSetFocus(wEditor);
break;
case GDK_SCROLL_LEFT:
case GDK_SCROLL_UP:
Prev();
WindowSetFocus(wEditor);
break;
#if GTK_CHECK_VERSION(3,4,0)
case GDK_SCROLL_SMOOTH:
break;
#endif
}
// Return true because Next() or Prev() already switches the tab
return TRUE;
}
static GtkWidget *pixmap_new(gchar **xpm) {
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)(char **)xpm);
return gtk_image_new_from_pixbuf(pixbuf);
}
GtkWidget *SciTEGTK::AddToolButton(const char *text, int cmd, GtkWidget *toolbar_icon) {
gtk_widget_show(GTK_WIDGET(toolbar_icon));
GtkToolItem *button = gtk_tool_button_new(toolbar_icon, text);
#if GTK_CHECK_VERSION(2,12,0)
gtk_widget_set_tooltip_text(GTK_WIDGET(button), text);
#endif
gtk_widget_show(GTK_WIDGET(button));
gtk_toolbar_insert(GTK_TOOLBAR(PWidget(wToolBar)), button, -1);
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(ButtonSignal),
GINT_TO_POINTER(cmd));
return GTK_WIDGET(button);
}
static void AddToolSpace(GtkToolbar *toolbar) {
GtkToolItem *space = gtk_separator_tool_item_new();
gtk_widget_show(GTK_WIDGET(space));
gtk_toolbar_insert(toolbar, space, -1);
}
void SciTEGTK::AddToolBar() {
if (props.GetInt("toolbar.usestockicons") == 1) {
AddToolButton("New", IDM_NEW, gtk_image_new_from_stock("gtk-new", GTK_ICON_SIZE_LARGE_TOOLBAR));
AddToolButton("Open", IDM_OPEN, gtk_image_new_from_stock("gtk-open", GTK_ICON_SIZE_LARGE_TOOLBAR));
AddToolButton("Save", IDM_SAVE, gtk_image_new_from_stock("gtk-save", GTK_ICON_SIZE_LARGE_TOOLBAR));
AddToolButton("Close", IDM_CLOSE, gtk_image_new_from_stock("gtk-close", GTK_ICON_SIZE_LARGE_TOOLBAR));
AddToolSpace(GTK_TOOLBAR(PWidget(wToolBar)));
AddToolButton("Undo", IDM_UNDO, gtk_image_new_from_stock("gtk-undo", GTK_ICON_SIZE_LARGE_TOOLBAR));
AddToolButton("Redo", IDM_REDO, gtk_image_new_from_stock("gtk-redo", GTK_ICON_SIZE_LARGE_TOOLBAR));
AddToolSpace(GTK_TOOLBAR(PWidget(wToolBar)));
AddToolButton("Cut", IDM_CUT, gtk_image_new_from_stock("gtk-cut", GTK_ICON_SIZE_LARGE_TOOLBAR));
AddToolButton("Copy", IDM_COPY, gtk_image_new_from_stock("gtk-copy", GTK_ICON_SIZE_LARGE_TOOLBAR));
AddToolButton("Paste", IDM_PASTE, gtk_image_new_from_stock("gtk-paste", GTK_ICON_SIZE_LARGE_TOOLBAR));
AddToolSpace(GTK_TOOLBAR(PWidget(wToolBar)));
AddToolButton("Find in Files", IDM_FINDINFILES, gtk_image_new_from_stock("gtk-find", GTK_ICON_SIZE_LARGE_TOOLBAR));
AddToolButton("Find", IDM_FIND, gtk_image_new_from_stock("gtk-zoom-fit", GTK_ICON_SIZE_LARGE_TOOLBAR));
AddToolButton("Find Next", IDM_FINDNEXT, gtk_image_new_from_stock("gtk-jump-to", GTK_ICON_SIZE_LARGE_TOOLBAR));
AddToolButton("Replace", IDM_REPLACE, gtk_image_new_from_stock("gtk-find-and-replace", GTK_ICON_SIZE_LARGE_TOOLBAR));
AddToolSpace(GTK_TOOLBAR(PWidget(wToolBar)));
btnCompile = AddToolButton("Compile", IDM_COMPILE, gtk_image_new_from_stock("gtk-execute", GTK_ICON_SIZE_LARGE_TOOLBAR));
btnBuild = AddToolButton("Build", IDM_BUILD, gtk_image_new_from_stock("gtk-convert", GTK_ICON_SIZE_LARGE_TOOLBAR));
btnStop = AddToolButton("Stop", IDM_STOPEXECUTE, gtk_image_new_from_stock("gtk-stop", GTK_ICON_SIZE_LARGE_TOOLBAR));
AddToolSpace(GTK_TOOLBAR(PWidget(wToolBar)));
AddToolButton("Previous", IDM_PREVFILE, gtk_image_new_from_stock("gtk-go-back", GTK_ICON_SIZE_LARGE_TOOLBAR));
AddToolButton("Next Buffer", IDM_NEXTFILE, gtk_image_new_from_stock("gtk-go-forward", GTK_ICON_SIZE_LARGE_TOOLBAR));
return;
}
AddToolButton("New", IDM_NEW, pixmap_new((gchar**)filenew_xpm));
AddToolButton("Open", IDM_OPEN, pixmap_new((gchar**)fileopen_xpm));
AddToolButton("Save", IDM_SAVE, pixmap_new((gchar**)filesave_xpm));
AddToolButton("Close", IDM_CLOSE, pixmap_new((gchar**)close_xpm));
AddToolSpace(GTK_TOOLBAR(PWidget(wToolBar)));
AddToolButton("Undo", IDM_UNDO, pixmap_new((gchar**)undo_xpm));
AddToolButton("Redo", IDM_REDO, pixmap_new((gchar**)redo_xpm));
AddToolSpace(GTK_TOOLBAR(PWidget(wToolBar)));
AddToolButton("Cut", IDM_CUT, pixmap_new((gchar**)editcut_xpm));
AddToolButton("Copy", IDM_COPY, pixmap_new((gchar**)editcopy_xpm));
AddToolButton("Paste", IDM_PASTE, pixmap_new((gchar**)editpaste_xpm));
AddToolSpace(GTK_TOOLBAR(PWidget(wToolBar)));
AddToolButton("Find in Files", IDM_FINDINFILES, pixmap_new((gchar**)findinfiles_xpm));
AddToolButton("Find", IDM_FIND, pixmap_new((gchar**)search_xpm));
AddToolButton("Find Next", IDM_FINDNEXT, pixmap_new((gchar**)findnext_xpm));
AddToolButton("Replace", IDM_REPLACE, pixmap_new((gchar**)replace_xpm));
AddToolSpace(GTK_TOOLBAR(PWidget(wToolBar)));
btnCompile = AddToolButton("Compile", IDM_COMPILE, pixmap_new((gchar**)compile_xpm));
btnBuild = AddToolButton("Build", IDM_BUILD, pixmap_new((gchar**)build_xpm));
btnStop = AddToolButton("Stop", IDM_STOPEXECUTE, pixmap_new((gchar**)stop_xpm));
AddToolSpace(GTK_TOOLBAR(PWidget(wToolBar)));
AddToolButton("Previous", IDM_PREVFILE, pixmap_new((gchar**)prev_xpm));
AddToolButton("Next Buffer", IDM_NEXTFILE, pixmap_new((gchar**)next_xpm));
}
SString SciTEGTK::TranslatePath(const char *path) {
if (path && path[0] == '/') {
SString spathTranslated;
SString spath(path, 1, strlen(path));
spath.append("/");
int end = spath.search("/");
while (spath.length() > 1) {
SString segment(spath.c_str(), 0, end);
GUI::gui_string segmentLocalised = localiser.Text(segment.c_str());
std::replace(segmentLocalised.begin(), segmentLocalised.end(), '/', '|');
spathTranslated.append("/");
spathTranslated.append(segmentLocalised.c_str());
spath.remove(0, end + 1);
end = spath.search("/");
}
return spathTranslated;
} else {
return path;
}
}
static std::string WithoutUnderscore(const char *s) {
std::string ret;
while (*s) {
if (*s != '_')
ret += *s;
s++;
}
return ret;
}
void SciTEGTK::CreateTranslatedMenu(int n, SciTEItemFactoryEntry items[],
int nRepeats, const char *prefix, int startNum,
int startID, const char *radioStart) {
int dim = n + nRepeats;
SciTEItemFactoryEntry *translatedItems = new SciTEItemFactoryEntry[dim];
SString *translatedText = new SString[dim];
SString *translatedRadios = new SString[dim];
char **userDefinedAccels = new char*[n];
SString menuPath;
int i = 0;
for (; i < n; i++) {
// Try to find user-defined accelerator key
menuPath = "menukey"; // menupath="menukey"
menuPath += items[i].path; // menupath="menukey/File/Save _As..."
menuPath.remove("_"); // menupath="menukey/File/Save As..."
menuPath.remove("."); // menupath="menukey/File/Save As"
menuPath.substitute('/', '.'); // menupath="menukey.File.Save As"
menuPath.substitute(' ', '_'); // menupath="menukey.File.Save_As"
menuPath.lowercase(); // menupath="menukey.file.save_as"
SString accelKey = props.Get(menuPath.c_str());
int accLength = accelKey.length();
if (accLength > 0) {
if (accelKey == "\"\"" || accelKey == "none") {
accelKey.clear(); // Allow user to clear accelerator key
}
userDefinedAccels[i] = new char[accLength + 1];
strncpy(userDefinedAccels[i], accelKey.c_str(), accLength + 1);
items[i].accelerator = userDefinedAccels[i];
} else {
userDefinedAccels[i] = NULL;
}
translatedItems[i].path = (gchar*) items[i].path;
translatedItems[i].accelerator = (gchar*) items[i].accelerator;
translatedItems[i].callback_action = items[i].callback_action;
translatedItems[i].item_type = (gchar*) items[i].item_type;
translatedText[i] = TranslatePath(translatedItems[i].path);
translatedItems[i].path = const_cast<char *>(translatedText[i].c_str());
translatedRadios[i] = TranslatePath(translatedItems[i].item_type);
translatedItems[i].item_type = const_cast<char *>(translatedRadios[i].c_str());
}
for (; i < dim; i++) {
int suffix = i - n + startNum;
SString ssnum(suffix);
translatedText[i] = TranslatePath(prefix);
translatedText[i] += ssnum;
translatedItems[i].path = const_cast<char *>(translatedText[i].c_str());
translatedItems[i].accelerator = NULL;
translatedItems[i].callback_action = startID + suffix;
translatedRadios[i] = TranslatePath(radioStart);
translatedItems[i].item_type = const_cast<char *>(translatedRadios[i].c_str());
}
// Only two levels of submenu supported
for (int itMenu=0; itMenu < dim; itMenu++) {
SciTEItemFactoryEntry *psife = translatedItems + itMenu;
const char *afterSlash = psife->path+1;
const char *lastSlash = strrchr(afterSlash, '/');
std::string menuName(afterSlash, lastSlash ? (lastSlash-afterSlash) : 0);
GtkWidget *menuParent = menuBar;
if (!menuName.empty()) {
if (pulldowns.count(menuName) > 0) {
menuParent = pulldowns[menuName];
} else {
fprintf(stderr, "*** failed to find parent %s\n", psife->path);
}
}
if (psife->item_type && strcmp(psife->item_type, "<Branch>") == 0) {
// Submenu "/_Tools" "/File/Encodin_g"
const char *menuTitle = lastSlash ? (lastSlash + 1) : afterSlash;
GtkWidget *menuItemPullDown = gtk_menu_item_new_with_mnemonic(menuTitle);
GtkWidget *menuPullDown = gtk_menu_new();
gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuItemPullDown), menuPullDown);
gtk_menu_shell_append(GTK_MENU_SHELL(menuParent), menuItemPullDown);
std::string baseName = WithoutUnderscore(afterSlash);
pulldowns[baseName] = menuPullDown;
} else {
// Item "/File/_New"
std::string itemName(lastSlash+1);
GtkWidget *menuParent = menuBar;
if (pulldowns.count(menuName) > 0) {
menuParent = pulldowns[menuName];
}
GtkWidget *menuItemCommand = 0;
if (!psife->item_type) {
menuItemCommand = gtk_menu_item_new_with_mnemonic(itemName.c_str());
} else if (strcmp(psife->item_type, "<CheckItem>") == 0) {
menuItemCommand = gtk_check_menu_item_new_with_mnemonic(itemName.c_str());
} else if ((strcmp(psife->item_type, "<RadioItem>") == 0) || (psife->item_type[0] == '/')) {
menuItemCommand = gtk_radio_menu_item_new_with_mnemonic(radiogroups[menuName], itemName.c_str());
radiogroups[menuName] = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(menuItemCommand));
} else if (strcmp(psife->item_type, "<Separator>") == 0) {
menuItemCommand = gtk_separator_menu_item_new();
} else {
menuItemCommand = gtk_menu_item_new_with_mnemonic(itemName.c_str());
}
if (psife->accelerator && psife->accelerator[0]) {
guint acceleratorKey;
GdkModifierType acceleratorMods;
gtk_accelerator_parse(psife->accelerator, &acceleratorKey, &acceleratorMods);
if (acceleratorKey) {
gtk_widget_add_accelerator(menuItemCommand, "activate", accelGroup,
acceleratorKey, acceleratorMods, GTK_ACCEL_VISIBLE);
} else {
//fprintf(stderr, "Failed to add accelerator '%s' for '%s'\n", psife->accelerator, psife->path);
}
}
g_object_set_data(G_OBJECT(menuItemCommand), "CmdNum",
reinterpret_cast<void *>(psife->callback_action));
g_signal_connect(G_OBJECT(menuItemCommand),"activate", G_CALLBACK(MenuSignal), this);
gtk_menu_shell_append(GTK_MENU_SHELL(menuParent), menuItemCommand);
mapMenuItemFromId[psife->callback_action] = menuItemCommand;
}
}
delete []translatedRadios;
delete []translatedText;
delete []translatedItems;
// Release all the memory allocated for the user-defined accelerator keys
for (i = 0; i < n; i++) {
if (userDefinedAccels[i] != NULL)
delete[] userDefinedAccels[i];
}
delete[] userDefinedAccels;
}
void SciTEGTK::CreateMenu() {
GCallback menuSig = G_CALLBACK(MenuSignal);
SciTEItemFactoryEntry menuItems[] = {
{"/_File", NULL, NULL, 0, "<Branch>"},
{"/File/_New", "<control>N", menuSig, IDM_NEW, 0},
{"/File/_Open...", "<control>O", menuSig, IDM_OPEN, 0},
{"/File/Open Selected _Filename", "<control><shift>O", menuSig, IDM_OPENSELECTED, 0},
{"/File/_Revert", "<control>R", menuSig, IDM_REVERT, 0},
{"/File/_Close", "<control>W", menuSig, IDM_CLOSE, 0},
{"/File/_Save", "<control>S", menuSig, IDM_SAVE, 0},
{"/File/Save _As...", "<control><shift>S", menuSig, IDM_SAVEAS, 0},
{"/File/Save a Cop_y...", "<control><shift>P", menuSig, IDM_SAVEACOPY, 0},
{"/File/Copy Pat_h", NULL, menuSig, IDM_COPYPATH, 0},
{"/File/Encodin_g", NULL, NULL, 0, "<Branch>"},
{"/File/Encoding/_Code Page Property", NULL, menuSig, IDM_ENCODING_DEFAULT, "<RadioItem>"},
{"/File/Encoding/UTF-16 _Big Endian", NULL, menuSig, IDM_ENCODING_UCS2BE, "/File/Encoding/Code Page Property"},
{"/File/Encoding/UTF-16 _Little Endian", NULL, menuSig, IDM_ENCODING_UCS2LE, "/File/Encoding/Code Page Property"},
{"/File/Encoding/UTF-8 _with BOM", NULL, menuSig, IDM_ENCODING_UTF8, "/File/Encoding/Code Page Property"},
{"/File/Encoding/_UTF-8", NULL, menuSig, IDM_ENCODING_UCOOKIE, "/File/Encoding/Code Page Property"},
{"/File/_Export", "", 0, 0, "<Branch>"},
{"/File/Export/As _HTML...", NULL, menuSig, IDM_SAVEASHTML, 0},
{"/File/Export/As _RTF...", NULL, menuSig, IDM_SAVEASRTF, 0},
{"/File/Export/As _PDF...", NULL, menuSig, IDM_SAVEASPDF, 0},
{"/File/Export/As _LaTeX...", NULL, menuSig, IDM_SAVEASTEX, 0},
{"/File/Export/As _XML...", NULL, menuSig, IDM_SAVEASXML, 0},
#if GTK_CHECK_VERSION(2,10,0)
{"/File/Page Set_up", NULL, menuSig, IDM_PRINTSETUP, 0},
#endif
{"/File/_Print", "<control>P", menuSig, IDM_PRINT, 0},
{"/File/sep1", NULL, NULL, 0, "<Separator>"},
{"/File/_Load Session...", "", menuSig, IDM_LOADSESSION, 0},
{"/File/Sa_ve Session...", "", menuSig, IDM_SAVESESSION, 0},
{"/File/sep2", NULL, menuSig, IDM_MRU_SEP, "<Separator>"},
{"/File/File0", "", menuSig, fileStackCmdID + 0, 0},
{"/File/File1", "", menuSig, fileStackCmdID + 1, 0},
{"/File/File2", "", menuSig, fileStackCmdID + 2, 0},
{"/File/File3", "", menuSig, fileStackCmdID + 3, 0},
{"/File/File4", "", menuSig, fileStackCmdID + 4, 0},
{"/File/File5", "", menuSig, fileStackCmdID + 5, 0},
{"/File/File6", "", menuSig, fileStackCmdID + 6, 0},
{"/File/File7", "", menuSig, fileStackCmdID + 7, 0},
{"/File/File8", "", menuSig, fileStackCmdID + 8, 0},
{"/File/File9", "", menuSig, fileStackCmdID + 9, 0},
{"/File/sep3", NULL, NULL, 0, "<Separator>"},
{"/File/E_xit", "", menuSig, IDM_QUIT, 0},
{"/_Edit", NULL, NULL, 0, "<Branch>"},
{"/Edit/_Undo", "<control>Z", menuSig, IDM_UNDO, 0},
{"/Edit/_Redo", "<control>Y", menuSig, IDM_REDO, 0},
{"/Edit/sep1", NULL, NULL, 0, "<Separator>"},
{"/Edit/Cu_t", "<control>X", menuSig, IDM_CUT, 0},
{"/Edit/_Copy", "<control>C", menuSig, IDM_COPY, 0},
{"/Edit/_Paste", "<control>V", menuSig, IDM_PASTE, 0},
{"/Edit/Duplicat_e", "<control>D", menuSig, IDM_DUPLICATE, 0},
{"/Edit/_Delete", "Delete", menuSig, IDM_CLEAR, 0},
{"/Edit/Select _All", "<control>A", menuSig, IDM_SELECTALL, 0},
{"/Edit/sep2", NULL, NULL, 0, "<Separator>"},
{"/Edit/Match _Brace", "<control>E", menuSig, IDM_MATCHBRACE, 0},
{"/Edit/Select t_o Brace", "<control><shift>E", menuSig, IDM_SELECTTOBRACE, 0},
{"/Edit/S_how Calltip", "<control><shift>space", menuSig, IDM_SHOWCALLTIP, 0},
{"/Edit/Complete S_ymbol", "<control>I", menuSig, IDM_COMPLETE, 0},
{"/Edit/Complete _Word", "<control>Return", menuSig, IDM_COMPLETEWORD, 0},
{"/Edit/Expand Abbre_viation", "<control>B", menuSig, IDM_ABBREV, 0},
{"/Edit/_Insert Abbreviation", "<control><shift>R", menuSig, IDM_INS_ABBREV, 0},
{"/Edit/Block Co_mment or Uncomment", "<control>Q", menuSig, IDM_BLOCK_COMMENT, 0},
{"/Edit/Bo_x Comment", "<control><shift>B", menuSig, IDM_BOX_COMMENT, 0},
{"/Edit/Stream Comme_nt", "<control><shift>Q", menuSig, IDM_STREAM_COMMENT, 0},
{"/Edit/Make _Selection Uppercase", "<control><shift>U", menuSig, IDM_UPRCASE, 0},
{"/Edit/Make Selection _Lowercase", "<control>U", menuSig, IDM_LWRCASE, 0},
{"/Edit/Para_graph", NULL, NULL, 0, "<Branch>"},
{"/Edit/Paragraph/_Join", NULL, menuSig, IDM_JOIN, 0},
{"/Edit/Paragraph/_Split", NULL, menuSig, IDM_SPLIT, 0},
{"/_Search", NULL, NULL, 0, "<Branch>"},
{"/Search/_Find...", "<control>F", menuSig, IDM_FIND, 0},
{"/Search/Find _Next", "F3", menuSig, IDM_FINDNEXT, 0},
{"/Search/Find Previou_s", "<shift>F3", menuSig, IDM_FINDNEXTBACK, 0},
{"/Search/F_ind in Files...", "<control><shift>F", menuSig, IDM_FINDINFILES, 0},
{"/Search/R_eplace...", "<control>H", menuSig, IDM_REPLACE, 0},
{"/Search/Incrementa_l Search", "<control><alt>I", menuSig, IDM_INCSEARCH, 0},
{"/Search/sep3", NULL, NULL, 0, "<Separator>"},
{"/Search/_Go To...", "<control>G", menuSig, IDM_GOTO, 0},
{"/Search/Next Book_mark", "F2", menuSig, IDM_BOOKMARK_NEXT, 0},
{"/Search/Pre_vious Bookmark", "<shift>F2", menuSig, IDM_BOOKMARK_PREV, 0},
{"/Search/Toggle Bookmar_k", "<control>F2", menuSig, IDM_BOOKMARK_TOGGLE, 0},
{"/Search/_Clear All Bookmarks", "", menuSig, IDM_BOOKMARK_CLEARALL, 0},
{"/_View", NULL, NULL, 0, "<Branch>"},
{"/View/Toggle _current fold", "", menuSig, IDM_EXPAND, 0},
{"/View/Toggle _all folds", "", menuSig, IDM_TOGGLE_FOLDALL, 0},
{"/View/sep1", NULL, NULL, 0, "<Separator>"},
{"/View/Full Scree_n", "F11", menuSig, IDM_FULLSCREEN, "<CheckItem>"},
{"/View/_Tool Bar", "", menuSig, IDM_VIEWTOOLBAR, "<CheckItem>"},
{"/View/Tab _Bar", "", menuSig, IDM_VIEWTABBAR, "<CheckItem>"},
{"/View/_Status Bar", "", menuSig, IDM_VIEWSTATUSBAR, "<CheckItem>"},
{"/View/sep2", NULL, NULL, 0, "<Separator>"},
{"/View/_Whitespace", "<control><shift>A", menuSig, IDM_VIEWSPACE, "<CheckItem>"},
{"/View/_End of Line", "<control><shift>D", menuSig, IDM_VIEWEOL, "<CheckItem>"},
{"/View/_Indentation Guides", NULL, menuSig, IDM_VIEWGUIDES, "<CheckItem>"},
{"/View/_Line Numbers", "", menuSig, IDM_LINENUMBERMARGIN, "<CheckItem>"},
{"/View/_Margin", NULL, menuSig, IDM_SELMARGIN, "<CheckItem>"},
{"/View/_Fold Margin", NULL, menuSig, IDM_FOLDMARGIN, "<CheckItem>"},
{"/View/_Output", "F8", menuSig, IDM_TOGGLEOUTPUT, "<CheckItem>"},
{"/View/_Parameters", NULL, menuSig, IDM_TOGGLEPARAMETERS, "<CheckItem>"},
{"/_Tools", NULL, NULL, 0, "<Branch>"},
{"/Tools/_Compile", "<control>F7", menuSig, IDM_COMPILE, 0},
{"/Tools/_Build", "F7", menuSig, IDM_BUILD, 0},
{"/Tools/_Go", "F5", menuSig, IDM_GO, 0},
{"/Tools/Tool0", NULL, menuSig, IDM_TOOLS + 0, 0},
{"/Tools/Tool1", NULL, menuSig, IDM_TOOLS + 1, 0},
{"/Tools/Tool2", NULL, menuSig, IDM_TOOLS + 2, 0},
{"/Tools/Tool3", NULL, menuSig, IDM_TOOLS + 3, 0},
{"/Tools/Tool4", NULL, menuSig, IDM_TOOLS + 4, 0},
{"/Tools/Tool5", NULL, menuSig, IDM_TOOLS + 5, 0},
{"/Tools/Tool6", NULL, menuSig, IDM_TOOLS + 6, 0},
{"/Tools/Tool7", NULL, menuSig, IDM_TOOLS + 7, 0},
{"/Tools/Tool8", NULL, menuSig, IDM_TOOLS + 8, 0},
{"/Tools/Tool9", NULL, menuSig, IDM_TOOLS + 9, 0},
{"/Tools/Tool10", NULL, menuSig, IDM_TOOLS + 10, 0},
{"/Tools/Tool11", NULL, menuSig, IDM_TOOLS + 11, 0},
{"/Tools/Tool12", NULL, menuSig, IDM_TOOLS + 12, 0},
{"/Tools/Tool13", NULL, menuSig, IDM_TOOLS + 13, 0},
{"/Tools/Tool14", NULL, menuSig, IDM_TOOLS + 14, 0},
{"/Tools/Tool15", NULL, menuSig, IDM_TOOLS + 15, 0},
{"/Tools/Tool16", NULL, menuSig, IDM_TOOLS + 16, 0},
{"/Tools/Tool17", NULL, menuSig, IDM_TOOLS + 17, 0},
{"/Tools/Tool18", NULL, menuSig, IDM_TOOLS + 18, 0},
{"/Tools/Tool19", NULL, menuSig, IDM_TOOLS + 19, 0},
{"/Tools/Tool20", NULL, menuSig, IDM_TOOLS + 20, 0},
{"/Tools/Tool21", NULL, menuSig, IDM_TOOLS + 21, 0},
{"/Tools/Tool22", NULL, menuSig, IDM_TOOLS + 22, 0},
{"/Tools/Tool23", NULL, menuSig, IDM_TOOLS + 23, 0},
{"/Tools/Tool24", NULL, menuSig, IDM_TOOLS + 24, 0},
{"/Tools/Tool25", NULL, menuSig, IDM_TOOLS + 25, 0},
{"/Tools/Tool26", NULL, menuSig, IDM_TOOLS + 26, 0},
{"/Tools/Tool27", NULL, menuSig, IDM_TOOLS + 27, 0},
{"/Tools/Tool28", NULL, menuSig, IDM_TOOLS + 28, 0},
{"/Tools/Tool29", NULL, menuSig, IDM_TOOLS + 29, 0},
{"/Tools/Tool30", NULL, menuSig, IDM_TOOLS + 30, 0},
{"/Tools/Tool31", NULL, menuSig, IDM_TOOLS + 31, 0},
{"/Tools/Tool32", NULL, menuSig, IDM_TOOLS + 32, 0},
{"/Tools/Tool33", NULL, menuSig, IDM_TOOLS + 33, 0},
{"/Tools/Tool34", NULL, menuSig, IDM_TOOLS + 34, 0},
{"/Tools/Tool35", NULL, menuSig, IDM_TOOLS + 35, 0},
{"/Tools/Tool36", NULL, menuSig, IDM_TOOLS + 36, 0},
{"/Tools/Tool37", NULL, menuSig, IDM_TOOLS + 37, 0},
{"/Tools/Tool38", NULL, menuSig, IDM_TOOLS + 38, 0},
{"/Tools/Tool39", NULL, menuSig, IDM_TOOLS + 39, 0},
{"/Tools/Tool40", NULL, menuSig, IDM_TOOLS + 40, 0},
{"/Tools/Tool41", NULL, menuSig, IDM_TOOLS + 41, 0},
{"/Tools/Tool42", NULL, menuSig, IDM_TOOLS + 42, 0},
{"/Tools/Tool43", NULL, menuSig, IDM_TOOLS + 43, 0},
{"/Tools/Tool44", NULL, menuSig, IDM_TOOLS + 44, 0},
{"/Tools/Tool45", NULL, menuSig, IDM_TOOLS + 45, 0},
{"/Tools/Tool46", NULL, menuSig, IDM_TOOLS + 46, 0},
{"/Tools/Tool47", NULL, menuSig, IDM_TOOLS + 47, 0},
{"/Tools/Tool48", NULL, menuSig, IDM_TOOLS + 48, 0},
{"/Tools/Tool49", NULL, menuSig, IDM_TOOLS + 49, 0},
{"/Tools/_Stop Executing", "<control>.", menuSig, IDM_STOPEXECUTE, NULL},
{"/Tools/sep1", NULL, NULL, 0, "<Separator>"},
{"/Tools/_Next Message", "F4", menuSig, IDM_NEXTMSG, 0},
{"/Tools/_Previous Message", "<shift>F4", menuSig, IDM_PREVMSG, 0},
{"/Tools/Clear _Output", "<shift>F5", menuSig, IDM_CLEAROUTPUT, 0},
{"/Tools/_Switch Pane", "<control>F6", menuSig, IDM_SWITCHPANE, 0},
};
SciTEItemFactoryEntry menuItemsOptions[] = {
{"/_Options", NULL, NULL, 0, "<Branch>"},
{"/Options/Vertical _Split", "", menuSig, IDM_SPLITVERTICAL, "<CheckItem>"},
{"/Options/_Wrap", "", menuSig, IDM_WRAP, "<CheckItem>"},
{"/Options/Wrap Out_put", "", menuSig, IDM_WRAPOUTPUT, "<CheckItem>"},
{"/Options/_Read-Only", "", menuSig, IDM_READONLY, "<CheckItem>"},
{"/Options/sep1", NULL, NULL, 0, "<Separator>"},
{"/Options/_Line End Characters", "", 0, 0, "<Branch>"},
{"/Options/Line End Characters/CR _+ LF", "", menuSig, IDM_EOL_CRLF, "<RadioItem>"},
{"/Options/Line End Characters/_CR", "", menuSig, IDM_EOL_CR, "/Options/Line End Characters/CR + LF"},
{"/Options/Line End Characters/_LF", "", menuSig, IDM_EOL_LF, "/Options/Line End Characters/CR + LF"},
{"/Options/_Convert Line End Characters", "", menuSig, IDM_EOL_CONVERT, 0},
{"/Options/sep2", NULL, NULL, 0, "<Separator>"},
{"/Options/Change Inden_tation Settings", "<control><shift>I", menuSig, IDM_TABSIZE, 0},
{"/Options/Use _Monospaced Font", "<control>F11", menuSig, IDM_MONOFONT, "<CheckItem>"},
{"/Options/sep3", NULL, NULL, 0, "<Separator>"},
{"/Options/Open Local _Options File", "", menuSig, IDM_OPENLOCALPROPERTIES, 0},
{"/Options/Open _Directory Options File", "", menuSig, IDM_OPENDIRECTORYPROPERTIES, 0},
{"/Options/Open _User Options File", "", menuSig, IDM_OPENUSERPROPERTIES, 0},
{"/Options/Open _Global Options File", "", menuSig, IDM_OPENGLOBALPROPERTIES, 0},
{"/Options/Open A_bbreviations File", "", menuSig, IDM_OPENABBREVPROPERTIES, 0},
{"/Options/Open Lua Startup Scr_ipt", "", menuSig, IDM_OPENLUAEXTERNALFILE, 0},
{"/Options/sep4", NULL, NULL, 0, "<Separator>"},
{"/Options/_Edit Properties", "", 0, 0, "<Branch>"},
};
SciTEItemFactoryEntry menuItemsLanguage[] = {
{"/_Language", NULL, NULL, 0, "<Branch>"},
};
SciTEItemFactoryEntry menuItemsBuffer[] = {
{"/_Buffers", NULL, NULL, 0, "<Branch>"},
{"/Buffers/_Previous", "<shift>F6", menuSig, IDM_PREVFILE, 0},
{"/Buffers/_Next", "F6", menuSig, IDM_NEXTFILE, 0},
{"/Buffers/_Close All", "", menuSig, IDM_CLOSEALL, 0},
{"/Buffers/_Save All", "", menuSig, IDM_SAVEALL, 0},
{"/Buffers/sep2", NULL, NULL, 0, "<Separator>"},
{"/Buffers/Buffer0", "<alt>1", menuSig, bufferCmdID + 0, "<RadioItem>"},
{"/Buffers/Buffer1", "<alt>2", menuSig, bufferCmdID + 1, "/Buffers/Buffer0"},
{"/Buffers/Buffer2", "<alt>3", menuSig, bufferCmdID + 2, "/Buffers/Buffer0"},
{"/Buffers/Buffer3", "<alt>4", menuSig, bufferCmdID + 3, "/Buffers/Buffer0"},
{"/Buffers/Buffer4", "<alt>5", menuSig, bufferCmdID + 4, "/Buffers/Buffer0"},
{"/Buffers/Buffer5", "<alt>6", menuSig, bufferCmdID + 5, "/Buffers/Buffer0"},
{"/Buffers/Buffer6", "<alt>7", menuSig, bufferCmdID + 6, "/Buffers/Buffer0"},
{"/Buffers/Buffer7", "<alt>8", menuSig, bufferCmdID + 7, "/Buffers/Buffer0"},
{"/Buffers/Buffer8", "<alt>9", menuSig, bufferCmdID + 8, "/Buffers/Buffer0"},
{"/Buffers/Buffer9", "<alt>0", menuSig, bufferCmdID + 9, "/Buffers/Buffer0"},
};
SciTEItemFactoryEntry menuItemsHelp[] = {
{"/_Help", NULL, NULL, 0, "<Branch>"},
{"/Help/_Help", "F1", menuSig, IDM_HELP, 0},
{"/Help/_SciTE Help", "", menuSig, IDM_HELP_SCITE, 0},
{"/Help/_About SciTE", "", menuSig, IDM_ABOUT, 0},
};
accelGroup = gtk_accel_group_new();
menuBar = gtk_menu_bar_new();
CreateTranslatedMenu(ELEMENTS(menuItems), menuItems);
CreateTranslatedMenu(ELEMENTS(menuItemsOptions), menuItemsOptions,
50, "/Options/Edit Properties/Props", 0, IDM_IMPORT, 0);
CreateTranslatedMenu(ELEMENTS(menuItemsLanguage), menuItemsLanguage,
100, "/Language/Language", 0, IDM_LANGUAGE, 0);
if (props.GetInt("buffers") > 1)
CreateTranslatedMenu(ELEMENTS(menuItemsBuffer), menuItemsBuffer,
bufferMax - 10, "/Buffers/Buffer", 10, bufferCmdID, "/Buffers/Buffer0");
CreateTranslatedMenu(ELEMENTS(menuItemsHelp), menuItemsHelp);
gtk_window_add_accel_group(GTK_WINDOW(PWidget(wSciTE)), accelGroup);
}
const int stripButtonWidth = 16 + 3 * 2 + 1;
const int stripButtonPitch = stripButtonWidth;
void FindStrip::Creation(GtkWidget *container) {
WTable table(1, 10);
SetID(table);
Strip::Creation(container);
gtk_container_set_border_width(GTK_CONTAINER(GetID()), 1);
gtk_box_pack_start(GTK_BOX(container), GTK_WIDGET(GetID()), FALSE, FALSE, 0);
wStaticFind.Create(localiser->Text(textFindPrompt).c_str());
table.Label(wStaticFind);
g_signal_connect(G_OBJECT(GetID()), "set-focus-child", G_CALLBACK(ChildFocusSignal), this);
g_signal_connect(G_OBJECT(GetID()), "focus", G_CALLBACK(FocusSignal), this);
wComboFind.Create();
table.Add(wComboFind, 1, true, 0, 0);
gtk_widget_show(wComboFind);
gtk_widget_show(GTK_WIDGET(GetID()));
g_signal_connect(G_OBJECT(wComboFind.Entry()), "key-press-event",
G_CALLBACK(EscapeSignal), this);
g_signal_connect(G_OBJECT(wComboFind.Entry()), "activate",
G_CALLBACK(ActivateSignal), this);
gtk_label_set_mnemonic_widget(GTK_LABEL(wStaticFind.GetID()), GTK_WIDGET(wComboFind.Entry()));
static ObjectSignal<FindStrip, &FindStrip::FindNextCmd> sigFindNext;
wButton.Create(localiser->Text(textFindNext), G_CALLBACK(sigFindNext.Function), this);
table.Add(wButton, 1, false, 0, 0);
static ObjectSignal<FindStrip, &FindStrip::MarkAllCmd> sigMarkAll;
wButtonMarkAll.Create(localiser->Text(textMarkAll), G_CALLBACK(sigMarkAll.Function), this);
table.Add(wButtonMarkAll, 1, false, 0, 0);
#if !GTK_CHECK_VERSION(3,4,0)
gtk_widget_ensure_style(wButton);
#endif
for (int i=0;i<checks;i++) {
#if GTK_CHECK_VERSION(3,4,0)
wCheck[i].Create(xpmImages[i], localiser->Text(toggles[i].label), NULL);
#elif GTK_CHECK_VERSION(3,0,0)
wCheck[i].Create(xpmImages[i], localiser->Text(toggles[i].label), gtk_widget_get_style(wButton.Pointer()));
#else
wCheck[i].Create(xpmImages[i], localiser->Text(toggles[i].label), wButton.Pointer()->style);
#endif
wCheck[i].SetActive(pSearcher->FlagFromCmd(toggles[i].cmd));
table.Add(wCheck[i], 1, false, 0, 0);
}
}
void FindStrip::Destruction() {
}
void FindStrip::Show(int buttonHeight) {
Strip::Show(buttonHeight);
gtk_widget_set_size_request(wButton, -1, buttonHeight);
gtk_widget_set_size_request(wButtonMarkAll, -1, buttonHeight);
gtk_widget_set_size_request(wComboFind, widthCombo, buttonHeight);
gtk_widget_set_size_request(GTK_WIDGET(wComboFind.Entry()), -1, buttonHeight);
gtk_widget_set_size_request(wStaticFind, -1, heightStatic);
for (int i=0; i<checks; i++)
gtk_widget_set_size_request(wCheck[i], stripButtonPitch, buttonHeight);
wComboFind.FillFromMemory(pSearcher->memFinds.AsVector());
gtk_entry_set_text(wComboFind.Entry(), pSearcher->findWhat.c_str());
SetToggles();
gtk_widget_grab_focus(GTK_WIDGET(wComboFind.Entry()));
}
void FindStrip::Close() {
if (visible) {
Strip::Close();
pSearcher->UIClosed();
}
}
bool FindStrip::KeyDown(GdkEventKey *event) {
if (visible) {
if (Strip::KeyDown(event))
return true;
if (event->state & GDK_MOD1_MASK) {
for (int i=SearchOption::tWord; i<=SearchOption::tUp; i++) {
GUI::gui_string localised = localiser->Text(toggles[i].label);
char key = KeyFromLabel(localised);
if (static_cast<unsigned int>(key) == event->keyval) {
wCheck[i].Toggle();
return true;
}
}
}
}
return false;
}
void FindStrip::MenuAction(guint action) {
if (allowMenuActions) {
pSearcher->FlagFromCmd(action) = !pSearcher->FlagFromCmd(action);
SetToggles();
InvalidateAll();
}
}
void FindStrip::ActivateSignal(GtkWidget *, FindStrip *pStrip) {
pStrip->FindNextCmd();
}
gboolean FindStrip::EscapeSignal(GtkWidget *w, GdkEventKey *event, FindStrip *pStrip) {
if (event->keyval == GKEY_Escape) {
g_signal_stop_emission_by_name(G_OBJECT(w), "key-press-event");
pStrip->Close();
}
return FALSE;
}
void FindStrip::GrabFields() {
pSearcher->SetFind(wComboFind.Text());
for (int i=0;i<checks;i++) {
pSearcher->FlagFromCmd(toggles[i].cmd) = wCheck[i].Active();
}
}
void FindStrip::SetToggles() {
for (int i=0;i<checks;i++) {
wCheck[i].SetActive(pSearcher->FlagFromCmd(toggles[i].cmd));
}
}
void FindStrip::ShowPopup() {
GUI::Menu popup;
popup.CreatePopUp();
for (int i=SearchOption::tWord; i<=SearchOption::tUp; i++) {
AddToPopUp(popup, toggles[i].label, toggles[i].cmd, pSearcher->FlagFromCmd(toggles[i].cmd));
}
GUI::Rectangle rcButton = wCheck[0].GetPosition();
GUI::Point pt(rcButton.left, rcButton.bottom);
popup.Show(pt, *this);
}
void FindStrip::FindNextCmd() {
GrabFields();
if (pSearcher->FindHasText()) {
pSearcher->FindNext(pSearcher->reverseFind);
}
Close();
}
void FindStrip::MarkAllCmd() {
GrabFields();
pSearcher->MarkAll();
pSearcher->FindNext(pSearcher->reverseFind);
Close();
}
void FindStrip::ChildFocus(GtkWidget *widget) {
Strip::ChildFocus(widget);
pSearcher->UIHasFocus();
}
gboolean FindStrip::Focus(GtkDirectionType direction) {
const int lastFocusCheck = 5;
if ((direction == GTK_DIR_TAB_BACKWARD) && wComboFind.HasFocusOnSelfOrChild()) {
gtk_widget_grab_focus(wCheck[lastFocusCheck]);
return TRUE;
} else if ((direction == GTK_DIR_TAB_FORWARD) && wCheck[lastFocusCheck].HasFocus()) {
gtk_widget_grab_focus(GTK_WIDGET(wComboFind.Entry()));
return TRUE;
}
return FALSE;
}
void ReplaceStrip::Creation(GtkWidget *container) {
WTable tableReplace(2, 7);
SetID(tableReplace);
Strip::Creation(container);
tableReplace.PackInto(GTK_BOX(container), false);
wStaticFind.Create(localiser->Text(textFindPrompt));
tableReplace.Label(wStaticFind);
g_signal_connect(G_OBJECT(GetID()), "set-focus-child", G_CALLBACK(ChildFocusSignal), this);
g_signal_connect(G_OBJECT(GetID()), "focus", G_CALLBACK(FocusSignal), this);
wComboFind.Create();
tableReplace.Add(wComboFind, 1, true, 0, 0);
wComboFind.Show();
g_signal_connect(G_OBJECT(wComboFind.Entry()), "key-press-event",
G_CALLBACK(EscapeSignal), this);
g_signal_connect(G_OBJECT(wComboFind.Entry()), "activate",
G_CALLBACK(ActivateSignal), this);
gtk_label_set_mnemonic_widget(GTK_LABEL(wStaticFind.GetID()), GTK_WIDGET(wComboFind.Entry()));
static ObjectSignal<ReplaceStrip, &ReplaceStrip::FindCmd> sigFindNext;
wButtonFind.Create(localiser->Text(textFindNext),
G_CALLBACK(sigFindNext.Function), this);
tableReplace.Add(wButtonFind, 1, false, 0, 0);
static ObjectSignal<ReplaceStrip, &ReplaceStrip::ReplaceAllCmd> sigReplaceAll;
wButtonReplaceAll.Create(localiser->Text("Replace _All"),
G_CALLBACK(sigReplaceAll.Function), this);
tableReplace.Add(wButtonReplaceAll, 1, false, 0, 0);
#if !GTK_CHECK_VERSION(3,4,0)
gtk_widget_ensure_style(wButtonFind);
#endif
for (int i=0;i<checks;i++) {
#if GTK_CHECK_VERSION(3,4,0)
wCheck[i].Create(xpmImages[i], localiser->Text(toggles[i].label), NULL);
#elif GTK_CHECK_VERSION(3,0,0)
wCheck[i].Create(xpmImages[i], localiser->Text(toggles[i].label), gtk_widget_get_style(wButtonFind.Pointer()));
#else
wCheck[i].Create(xpmImages[i], localiser->Text(toggles[i].label), wButtonFind.Pointer()->style);
#endif
wCheck[i].SetActive(pSearcher->FlagFromCmd(toggles[i].cmd));
}
tableReplace.Add(wCheck[SearchOption::tWord], 1, false, 0, 0);
tableReplace.Add(wCheck[SearchOption::tCase], 1, false, 0, 0);
tableReplace.Add(wCheck[SearchOption::tRegExp], 1, false, 0, 0);
wStaticReplace.Create(localiser->Text(textReplacePrompt));
tableReplace.Label(wStaticReplace);
wComboReplace.Create();
tableReplace.Add(wComboReplace, 1, true, 0, 0);
g_signal_connect(G_OBJECT(wComboReplace.Entry()), "key-press-event",
G_CALLBACK(EscapeSignal), this);
g_signal_connect(G_OBJECT(wComboReplace.Entry()), "activate",
G_CALLBACK(ActivateSignal), this);
gtk_label_set_mnemonic_widget(GTK_LABEL(wStaticReplace.GetID()), GTK_WIDGET(wComboReplace.Entry()));
static ObjectSignal<ReplaceStrip, &ReplaceStrip::ReplaceCmd> sigReplace;
wButtonReplace.Create(localiser->Text(textReplace),
G_CALLBACK(sigReplace.Function), this);
tableReplace.Add(wButtonReplace, 1, false, 0, 0);
static ObjectSignal<ReplaceStrip, &ReplaceStrip::ReplaceInSelectionCmd> sigReplaceInSelection;
wButtonReplaceInSelection.Create(localiser->Text(textInSelection),
G_CALLBACK(sigReplaceInSelection.Function), this);
tableReplace.Add(wButtonReplaceInSelection, 1, false, 0, 0);
tableReplace.Add(wCheck[SearchOption::tBackslash], 1, false, 0, 0);
tableReplace.Add(wCheck[SearchOption::tWrap], 1, false, 0, 0);
// Make the fccus chain move down before moving right
GList *focusChain = 0;
focusChain = g_list_append(focusChain, wComboFind.Pointer());
focusChain = g_list_append(focusChain, wComboReplace.Pointer());
focusChain = g_list_append(focusChain, wButtonFind.Pointer());
focusChain = g_list_append(focusChain, wButtonReplace.Pointer());
focusChain = g_list_append(focusChain, wButtonReplaceAll.Pointer());
focusChain = g_list_append(focusChain, wButtonReplaceInSelection.Pointer());
focusChain = g_list_append(focusChain, wCheck[SearchOption::tWord].Pointer());
focusChain = g_list_append(focusChain, wCheck[SearchOption::tBackslash].Pointer());
focusChain = g_list_append(focusChain, wCheck[SearchOption::tCase].Pointer());
focusChain = g_list_append(focusChain, wCheck[SearchOption::tWrap].Pointer());
focusChain = g_list_append(focusChain, wCheck[SearchOption::tRegExp].Pointer());
gtk_container_set_focus_chain(GTK_CONTAINER(GetID()), focusChain);
g_list_free(focusChain);
}
void ReplaceStrip::Destruction() {
}
void ReplaceStrip::Show(int buttonHeight) {
Strip::Show(buttonHeight);
gtk_widget_set_size_request(wButtonFind, -1, buttonHeight);
gtk_widget_set_size_request(wButtonReplaceAll, -1, buttonHeight);
gtk_widget_set_size_request(wButtonReplace, -1, buttonHeight);
gtk_widget_set_size_request(wButtonReplaceInSelection, -1, buttonHeight);
gtk_widget_set_size_request(wComboFind, widthCombo, buttonHeight);
gtk_widget_set_size_request(GTK_WIDGET(wComboFind.Entry()), -1, buttonHeight);
gtk_widget_set_size_request(wComboReplace, widthCombo, buttonHeight);
gtk_widget_set_size_request(GTK_WIDGET(wComboReplace.Entry()), -1, buttonHeight);
gtk_widget_set_size_request(wStaticFind, -1, heightStatic);
gtk_widget_set_size_request(wStaticReplace, -1, heightStatic);
for (int i=0; i<checks; i++)
gtk_widget_set_size_request(wCheck[i], stripButtonPitch, buttonHeight);
wComboFind.FillFromMemory(pSearcher->memFinds.AsVector());
wComboReplace.FillFromMemory(pSearcher->memReplaces.AsVector());
gtk_entry_set_text(wComboFind.Entry(), pSearcher->findWhat.c_str());
SetToggles();
gtk_widget_grab_focus(GTK_WIDGET(wComboFind.Entry()));
}
void ReplaceStrip::Close() {
if (visible) {
Strip::Close();
pSearcher->UIClosed();
}
}
bool ReplaceStrip::KeyDown(GdkEventKey *event) {
if (visible) {
if (Strip::KeyDown(event))
return true;
if (event->state & GDK_MOD1_MASK) {
for (int i=SearchOption::tWord; i<=SearchOption::tUp; i++) {
GUI::gui_string localised = localiser->Text(toggles[i].label);
char key = KeyFromLabel(localised);
if (static_cast<unsigned int>(key) == event->keyval) {
wCheck[i].Toggle();
return true;
}
}
}
}
return false;
}
void ReplaceStrip::MenuAction(guint action) {
if (allowMenuActions) {
pSearcher->FlagFromCmd(action) = !pSearcher->FlagFromCmd(action);
SetToggles();
InvalidateAll();
}
}
void ReplaceStrip::ActivateSignal(GtkWidget *, ReplaceStrip *pStrip) {
pStrip->FindCmd();
}
gboolean ReplaceStrip::EscapeSignal(GtkWidget *w, GdkEventKey *event, ReplaceStrip *pStrip) {
if (event->keyval == GKEY_Escape) {
g_signal_stop_emission_by_name(G_OBJECT(w), "key-press-event");
pStrip->Close();
}
return FALSE;
}
void ReplaceStrip::GrabFields() {
pSearcher->SetFind(wComboFind.Text());
pSearcher->SetReplace(wComboReplace.Text());
for (int i=0;i<checks;i++) {
pSearcher->FlagFromCmd(toggles[i].cmd) = wCheck[i].Active();
}
}
void ReplaceStrip::SetToggles() {
for (int i=0;i<checks;i++) {
wCheck[i].SetActive(pSearcher->FlagFromCmd(toggles[i].cmd));
}
}
void ReplaceStrip::FindCmd() {
GrabFields();
if (pSearcher->FindHasText()) {
pSearcher->FindNext(pSearcher->reverseFind);
}
}
void ReplaceStrip::ReplaceAllCmd() {
GrabFields();
if (pSearcher->FindHasText()) {
pSearcher->ReplaceAll(false);
}
}
void ReplaceStrip::ReplaceCmd() {
GrabFields();
pSearcher->ReplaceOnce();
}
void ReplaceStrip::ReplaceInSelectionCmd() {
GrabFields();
if (pSearcher->FindHasText()) {
pSearcher->ReplaceAll(true);
}
}
void ReplaceStrip::ShowPopup() {
GUI::Menu popup;
popup.CreatePopUp();
for (int i=SearchOption::tWord; i<=SearchOption::tWrap; i++) {
AddToPopUp(popup, toggles[i].label, toggles[i].cmd, pSearcher->FlagFromCmd(toggles[i].cmd));
}
GUI::Rectangle rcButton = wCheck[0].GetPosition();
GUI::Point pt(rcButton.left, rcButton.bottom);
popup.Show(pt, *this);
}
void ReplaceStrip::ChildFocus(GtkWidget *widget) {
Strip::ChildFocus(widget);
pSearcher->UIHasFocus();
}
gboolean ReplaceStrip::Focus(GtkDirectionType direction) {
const int lastFocusCheck = 2; // Due to last column starting with the thirs checkbox
if ((direction == GTK_DIR_TAB_BACKWARD) && wComboFind.HasFocusOnSelfOrChild()) {
gtk_widget_grab_focus(wCheck[lastFocusCheck]);
return TRUE;
} else if ((direction == GTK_DIR_TAB_FORWARD) && wCheck[lastFocusCheck].HasFocus()) {
gtk_widget_grab_focus(GTK_WIDGET(wComboFind.Entry()));
return TRUE;
}
return FALSE;
}
void UserStrip::Creation(GtkWidget *container) {
SetID(tableUser);
Strip::Creation(container);
gtk_container_set_border_width(GTK_CONTAINER(GetID()), 1);
tableUser.PackInto(GTK_BOX(container), false);
g_signal_connect(G_OBJECT(GetID()), "set-focus-child", G_CALLBACK(ChildFocusSignal), this);
g_signal_connect(G_OBJECT(GetID()), "focus", G_CALLBACK(FocusSignal), this);
}
void UserStrip::Destruction() {
}
void UserStrip::Show(int buttonHeight) {
Strip::Show(buttonHeight);
for (std::vector<std::vector<UserControl> >::iterator line=psd->controls.begin(); line != psd->controls.end(); ++line) {
for (std::vector<UserControl>::iterator ctl=line->begin(); ctl != line->end(); ++ctl) {
if (ctl->controlType == UserControl::ucStatic) {
gtk_widget_set_size_request(GTK_WIDGET(ctl->w.GetID()), -1, heightStatic);
} else if (ctl->controlType == UserControl::ucEdit) {
gtk_widget_set_size_request(GTK_WIDGET(ctl->w.GetID()), -1, buttonHeight);
} else if (ctl->controlType == UserControl::ucCombo) {
GtkEntry *entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(ctl->w.GetID())));
gtk_widget_set_size_request(GTK_WIDGET(entry), -1, buttonHeight);
} else if (ctl->controlType == UserControl::ucButton || ctl->controlType == UserControl::ucDefaultButton) {
gtk_widget_set_size_request(GTK_WIDGET(ctl->w.GetID()), -1, buttonHeight);
}
}
}
}
void UserStrip::Close() {
if (visible) {
Strip::Close();
if (pSciTEGTK)
pSciTEGTK->UserStripClosed();
}
}
bool UserStrip::KeyDown(GdkEventKey *event) {
if (visible) {
if (Strip::KeyDown(event))
return true;
}
return false;
}
void UserStrip::ActivateSignal(GtkWidget *, UserStrip *pStrip) {
// Treat Enter as pressing the first default button
for (std::vector<std::vector<UserControl> >::iterator line=pStrip->psd->controls.begin(); line != pStrip->psd->controls.end(); ++line) {
for (std::vector<UserControl>::iterator ctl=line->begin(); ctl != line->end(); ++ctl) {
if (ctl->controlType == UserControl::ucDefaultButton) {
pStrip->extender->OnUserStrip(ctl->item, scClicked);
return;
}
}
}
}
gboolean UserStrip::EscapeSignal(GtkWidget *w, GdkEventKey *event, UserStrip *pStrip) {
if (event->keyval == GKEY_Escape) {
g_signal_stop_emission_by_name(G_OBJECT(w), "key-press-event");
pStrip->Close();
}
return FALSE;
}
void UserStrip::ClickThis(GtkWidget *w) {
for (std::vector<std::vector<UserControl> >::iterator line=psd->controls.begin(); line != psd->controls.end(); ++line) {
for (std::vector<UserControl>::iterator ctl=line->begin(); ctl != line->end(); ++ctl) {
if (w == GTK_WIDGET(ctl->w.GetID())) {
extender->OnUserStrip(ctl->item, scClicked);
}
}
}
}
void UserStrip::ClickSignal(GtkWidget *w, UserStrip *pStrip) {
pStrip->ClickThis(w);
}
void UserStrip::ChildFocus(GtkWidget *widget) {
Strip::ChildFocus(widget);
}
static bool WidgetHasFocus(UserControl *ctl) {
if (!ctl) {
return false;
} else if (ctl->controlType == UserControl::ucCombo) {
WComboBoxEntry *pwc = static_cast<WComboBoxEntry *>(&(ctl->w));
return pwc->HasFocusOnSelfOrChild();
} else {
return ctl->w.HasFocus();
}
}
gboolean UserStrip::Focus(GtkDirectionType direction) {
UserControl *ctlFirstFocus = 0;
UserControl *ctlLastFocus = 0;
for (std::vector<std::vector<UserControl> >::iterator line=psd->controls.begin(); line != psd->controls.end(); ++line) {
for (std::vector<UserControl>::iterator ctl=line->begin(); ctl != line->end(); ++ctl) {
if (ctl->controlType != UserControl::ucStatic) {
// Widget can have focus
ctlLastFocus = &*ctl;
if (!ctlFirstFocus)
ctlFirstFocus = ctlLastFocus;
}
}
}
if ((direction == GTK_DIR_TAB_BACKWARD) && WidgetHasFocus(ctlFirstFocus)) {
gtk_widget_grab_focus(GTK_WIDGET(ctlLastFocus->w.GetID()));
return TRUE;
} else if ((direction == GTK_DIR_TAB_FORWARD) && WidgetHasFocus(ctlLastFocus)) {
gtk_widget_grab_focus(GTK_WIDGET(ctlFirstFocus->w.GetID()));
return TRUE;
}
return FALSE;
}
void UserStrip::SetDescription(const char *description) {
if (psd) {
for (std::vector<std::vector<UserControl> >::iterator line=psd->controls.begin(); line != psd->controls.end(); ++line) {
for (std::vector<UserControl>::iterator ctl=line->begin(); ctl != line->end(); ++ctl) {
gtk_widget_destroy(GTK_WIDGET(ctl->w.GetID()));
}
}
}
delete psd;
psd = new StripDefinition(description);
tableUser.Resize(psd->controls.size(), psd->columns);
bool hasSetFocus = false;
GtkWidget *pwWithAccelerator = 0;
for (size_t line=0; line<psd->controls.size(); line++) {
std::vector<UserControl> &uc = psd->controls[line];
for (size_t control=0; control<uc.size(); control++) {
UserControl *puc = &(uc[control]);
SString sCaption = GtkFromWinCaption(puc->text.c_str());
switch (puc->controlType) {
case UserControl::ucEdit: {
WEntry we;
we.Create(puc->text.c_str());
puc->w.SetID(we.GetID());
tableUser.Add(we, 1, true, 0, 0);
break;
}
case UserControl::ucCombo: {
WComboBoxEntry wc;
wc.Create();
wc.SetText(puc->text.c_str());
puc->w.SetID(wc.GetID());
tableUser.Add(wc, 1, true, 0, 0);
break;
}
case UserControl::ucButton:
case UserControl::ucDefaultButton: {
WButton wb;
wb.Create(sCaption.c_str(), reinterpret_cast<GCallback>(UserStrip::ClickSignal), this);
puc->w.SetID(wb.GetID());
tableUser.Add(wb, 1, false, 0, 0);
if (puc->controlType == UserControl::ucDefaultButton) {
gtk_widget_grab_default(GTK_WIDGET(puc->w.GetID()));
}
break;
}
default: {
WStatic ws;
ws.Create(sCaption.c_str());
puc->w.SetID(ws.GetID());
gtk_misc_set_alignment(GTK_MISC(puc->w.GetID()), 1.0, 0.5);
tableUser.Add(ws, 1, false, 5, 0);
if (ws.HasMnemonic())
pwWithAccelerator = GTK_WIDGET(puc->w.GetID());
}
}
gtk_widget_show(GTK_WIDGET(puc->w.GetID()));
if (!hasSetFocus && (puc->controlType != UserControl::ucStatic)) {
gtk_widget_grab_focus(GTK_WIDGET(puc->w.GetID()));
hasSetFocus = true;
}
if (pwWithAccelerator && (puc->controlType != UserControl::ucStatic)) {
gtk_label_set_mnemonic_widget(GTK_LABEL(pwWithAccelerator), GTK_WIDGET(puc->w.GetID()));
pwWithAccelerator = 0;
}
}
tableUser.NextLine() ;
}
for (std::vector<std::vector<UserControl> >::iterator line=psd->controls.begin(); line != psd->controls.end(); ++line) {
for (std::vector<UserControl>::iterator ctl=line->begin(); ctl != line->end(); ++ctl) {
if ((ctl->controlType == UserControl::ucEdit) || (ctl->controlType == UserControl::ucCombo)) {
GtkEntry *entry;
if (ctl->controlType == UserControl::ucEdit)
entry = GTK_ENTRY(ctl->w.GetID());
else
entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(ctl->w.GetID())));
g_signal_connect(G_OBJECT(entry), "key-press-event", G_CALLBACK(EscapeSignal), this);
g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(ActivateSignal), this);
}
}
}
}
void UserStrip::SetExtender(Extension *extender_) {
extender = extender_;
}
void UserStrip::SetSciTE(SciTEGTK *pSciTEGTK_) {
pSciTEGTK = pSciTEGTK_;
}
void UserStrip::Set(int control, const char *value) {
if (psd) {
UserControl *ctl = psd->FindControl(control);
if (ctl) {
if (ctl->controlType == UserControl::ucEdit) {
WEntry *pwe = static_cast<WEntry *>(&(ctl->w));
pwe->SetText(value);
} else if (ctl->controlType == UserControl::ucCombo) {
WComboBoxEntry *pwc = static_cast<WComboBoxEntry *>(&(ctl->w));
pwc->SetText(value);
}
}
}
}
void UserStrip::SetList(int control, const char *value) {
if (psd) {
UserControl *ctl = psd->FindControl(control);
if (ctl) {
if (ctl->controlType == UserControl::ucCombo) {
GUI::gui_string sValue = GUI::StringFromUTF8(value);
std::vector<std::string> listValues = ListFromString(sValue);
WComboBoxEntry *pwc = static_cast<WComboBoxEntry *>(&(ctl->w));
pwc->FillFromMemory(listValues);
}
}
}
}
std::string UserStrip::GetValue(int control) {
if (psd) {
UserControl *ctl = psd->FindControl(control);
if (ctl->controlType == UserControl::ucEdit) {
WEntry *pwe = static_cast<WEntry *>(&(ctl->w));
return pwe->Text();
} else if (ctl->controlType == UserControl::ucCombo) {
WComboBoxEntry *pwc = static_cast<WComboBoxEntry *>(&(ctl->w));
return pwc->Text();
}
}
return "";
}
void SciTEGTK::CreateStrips(GtkWidget *boxMain) {
backgroundStrip.SetLocalizer(&localiser);
backgroundStrip.Creation(boxMain);
userStrip.SetSciTE(this);
userStrip.SetExtender(extender);
userStrip.SetLocalizer(&localiser);
userStrip.Creation(boxMain);
findStrip.SetLocalizer(&localiser);
findStrip.SetSearcher(this);
findStrip.Creation(boxMain);
replaceStrip.SetLocalizer(&localiser);
replaceStrip.SetSearcher(this);
replaceStrip.Creation(boxMain);
}
bool SciTEGTK::StripHasFocus() {
return findStrip.VisibleHasFocus() || replaceStrip.VisibleHasFocus() || userStrip.VisibleHasFocus();
}
void SciTEGTK::LayoutUI() {
bool focusOutput = false;
if (splitPane) {
#if GTK_CHECK_VERSION(2,16,0)
// If GtkOrientable is available (GTK+ 2.16 and newer), just switch the
// orientation if needed, don't recreate the H/VPaned
GtkOrientation orient;
orient = (splitVertical) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL;
gtk_orientable_set_orientation(GTK_ORIENTABLE(splitPane), orient);
return;
#endif
focusOutput = wOutput.HasFocus();
gtk_container_remove(GTK_CONTAINER(splitPane), PWidget(wEditor));
gtk_container_remove(GTK_CONTAINER(splitPane), PWidget(wOutput));
gtk_widget_destroy(GTK_WIDGET(splitPane));
}
if (splitVertical) {
#if GTK_CHECK_VERSION(3,0,0)
splitPane = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
#else
splitPane = gtk_hpaned_new();
#endif
gtk_widget_set_size_request(PWidget(wOutput), heightOutput, -1);
} else {
#if GTK_CHECK_VERSION(3,0,0)
splitPane = gtk_paned_new(GTK_ORIENTATION_VERTICAL);
#else
splitPane = gtk_vpaned_new();
#endif
gtk_widget_set_size_request(PWidget(wOutput), -1, heightOutput);
}
gtk_container_add(GTK_CONTAINER(PWidget(wContent)), GTK_WIDGET(splitPane));
gtk_paned_pack1(GTK_PANED(splitPane), PWidget(wEditor), TRUE, TRUE);
gtk_paned_pack2(GTK_PANED(splitPane), PWidget(wOutput), FALSE, TRUE);
g_signal_connect(GTK_WIDGET(splitPane), "button-release-event",
G_CALLBACK(PaneButtonRelease), reinterpret_cast<char *>(this));
g_signal_connect(G_OBJECT(splitPane), "notify::position",
G_CALLBACK(PanePositionChanged), reinterpret_cast<char *>(this));
if (focusOutput)
WindowSetFocus(wOutput);
else
WindowSetFocus(wEditor);
gtk_widget_show_all(GTK_WIDGET(splitPane));
}
void SciTEGTK::CreateUI() {
CreateBuffers();
wSciTE = gtk_window_new(GTK_WINDOW_TOPLEVEL);
char *gthis = reinterpret_cast<char *>(this);
gtk_widget_set_events(PWidget(wSciTE),
GDK_EXPOSURE_MASK
| GDK_LEAVE_NOTIFY_MASK
| GDK_BUTTON_PRESS_MASK
| GDK_BUTTON_RELEASE_MASK
);
g_signal_connect(G_OBJECT(PWidget(wSciTE)), "delete_event",
G_CALLBACK(QuitSignal), gthis);
g_signal_connect(G_OBJECT(PWidget(wSciTE)), "key_press_event",
G_CALLBACK(KeyPress), gthis);
g_signal_connect(G_OBJECT(PWidget(wSciTE)), "key-release-event",
G_CALLBACK(KeyRelease), gthis);
g_signal_connect(G_OBJECT(PWidget(wSciTE)), "button_press_event",
G_CALLBACK(MousePress), gthis);
gtk_window_set_title(GTK_WINDOW(PWidget(wSciTE)), appName);
const int useDefault = 0x10000000;
int left = props.GetInt("position.left", useDefault);
int top = props.GetInt("position.top", useDefault);
int width = props.GetInt("position.width", useDefault);
int height = props.GetInt("position.height", useDefault);
bool maximize = props.GetInt("position.maximize", 0) ? true : false;
if (width == -1 || height == -1) {
maximize = true;
width = gdk_screen_width() - left - 10;
height = gdk_screen_height() - top - 30;
}
if (props.GetInt("save.position")) {
left = propsSession.GetInt("position.left", useDefault);
top = propsSession.GetInt("position.top", useDefault);
width = propsSession.GetInt("position.width", useDefault);
height = propsSession.GetInt("position.height", useDefault);
maximize = propsSession.GetInt("position.maximize", 0) ? true : false;
}
fileSelectorWidth = props.GetInt("fileselector.width", fileSelectorWidth);
fileSelectorHeight = props.GetInt("fileselector.height", fileSelectorHeight);
#if GTK_CHECK_VERSION(3,0,0)
GtkWidget *boxMain = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_box_set_homogeneous(GTK_BOX(boxMain), FALSE);
#else
GtkWidget *boxMain = gtk_vbox_new(FALSE, 0);
#endif
gtk_container_add(GTK_CONTAINER(PWidget(wSciTE)), boxMain);
WIDGET_SET_NO_FOCUS(boxMain);
// The Menubar
CreateMenu();
gtk_box_pack_start(GTK_BOX(boxMain), menuBar, FALSE, FALSE, 0);
// The Toolbar
wToolBar = gtk_toolbar_new();
gtk_toolbar_set_style(GTK_TOOLBAR(PWidget(wToolBar)), GTK_TOOLBAR_ICONS);
gtk_box_pack_start(GTK_BOX(boxMain), PWidget(wToolBar), FALSE, FALSE, 0);
gtk_widget_hide(GTK_WIDGET(PWidget(wToolBar)));
gtk_container_set_border_width(GTK_CONTAINER(PWidget(wToolBar)), 0);
tbVisible = false;
// The Notebook (GTK2)
wTabBar = gtk_notebook_new();
WIDGET_SET_NO_FOCUS(PWidget(wTabBar));
gtk_box_pack_start(GTK_BOX(boxMain),PWidget(wTabBar),FALSE,FALSE,0);
g_signal_connect(G_OBJECT(PWidget(wTabBar)),
"button-release-event", G_CALLBACK(TabBarReleaseSignal), gthis);
g_signal_connect(G_OBJECT(PWidget(wTabBar)),
"scroll-event", G_CALLBACK(TabBarScrollSignal), gthis);
gtk_notebook_set_scrollable(GTK_NOTEBOOK(PWidget(wTabBar)), TRUE);
tabVisible = false;
wContent = gtk_alignment_new(0, 0, 1, 1);
// Ensure the content area is viable at 60 pixels high
gtk_widget_set_size_request(PWidget(wContent), 20, 60);
WIDGET_SET_NO_FOCUS(PWidget(wContent));
gtk_box_pack_start(GTK_BOX(boxMain), PWidget(wContent), TRUE, TRUE, 0);
wEditor.SetID(scintilla_new());
g_object_ref(G_OBJECT(PWidget(wEditor)));
scintilla_set_id(SCINTILLA(PWidget(wEditor)), IDM_SRCWIN);
wEditor.Call(SCI_USEPOPUP, 0);
g_signal_connect(G_OBJECT(PWidget(wEditor)), SCINTILLA_NOTIFY,
G_CALLBACK(NotifySignal), this);
wOutput.SetID(scintilla_new());
g_object_ref(G_OBJECT(PWidget(wOutput)));
scintilla_set_id(SCINTILLA(PWidget(wOutput)), IDM_RUNWIN);
wOutput.Call(SCI_USEPOPUP, 0);
g_signal_connect(G_OBJECT(PWidget(wOutput)), SCINTILLA_NOTIFY,
G_CALLBACK(NotifySignal), this);
splitVertical = props.GetInt("split.vertical", 0);
LayoutUI();
WTable table(1, 3);
wIncrementPanel = table;
table.PackInto(GTK_BOX(boxMain), false);
table.Label(TranslatedLabel("Find:"));
IncSearchEntry = gtk_entry_new();
table.Add(IncSearchEntry, 1, true, 5, 1);
Signal<&SciTEGTK::FindIncrementCompleteCmd> sigFindIncrementComplete;
g_signal_connect(G_OBJECT(IncSearchEntry),"activate", G_CALLBACK(sigFindIncrementComplete.Function), this);
g_signal_connect(G_OBJECT(IncSearchEntry), "key-press-event", G_CALLBACK(FindIncrementEscapeSignal), this);
Signal<&SciTEGTK::FindIncrementChanged> sigFindIncrementChanged;
g_signal_connect(G_OBJECT(IncSearchEntry),"changed", G_CALLBACK(sigFindIncrementChanged.Function), this);
g_signal_connect(G_OBJECT(IncSearchEntry),"focus-out-event", G_CALLBACK(FindIncrementFocusOutSignal), NULL);
gtk_widget_show(IncSearchEntry);
GUI::gui_string translated = localiser.Text("Find Next");
IncSearchBtnNext = gtk_button_new_with_mnemonic(translated.c_str());
table.Add(IncSearchBtnNext, 1, false, 5, 1);
g_signal_connect(G_OBJECT(IncSearchBtnNext), "clicked",
G_CALLBACK(sigFindIncrementComplete.Function), this);
gtk_widget_show(IncSearchBtnNext);
CreateStrips(boxMain);
wOutput.Call(SCI_SETMARGINWIDTHN, 1, 0);
wStatusBar = gtk_statusbar_new();
sbContextID = gtk_statusbar_get_context_id(
GTK_STATUSBAR(PWidget(wStatusBar)), "global");
gtk_box_pack_start(GTK_BOX(boxMain), PWidget(wStatusBar), FALSE, FALSE, 0);
gtk_statusbar_push(GTK_STATUSBAR(PWidget(wStatusBar)), sbContextID, "Initial");
sbVisible = false;
static const GtkTargetEntry dragtypes[] = { { (gchar*)"text/uri-list", 0, 0 } };
static const gint n_dragtypes = ELEMENTS(dragtypes);
gtk_drag_dest_set(PWidget(wSciTE), GTK_DEST_DEFAULT_ALL, dragtypes,
n_dragtypes, GDK_ACTION_COPY);
g_signal_connect(G_OBJECT(PWidget(wSciTE)), "drag_data_received",
G_CALLBACK(DragDataReceived), this);
SetFocus(wOutput);
if ((left != useDefault) && (top != useDefault))
gtk_window_move(GTK_WINDOW(PWidget(wSciTE)), left, top);
if ((width != useDefault) && (height != useDefault))
gtk_window_set_default_size(GTK_WINDOW(PWidget(wSciTE)), width, height);
gtk_widget_show_all(PWidget(wSciTE));
SetIcon();
if (maximize)
gtk_window_maximize(GTK_WINDOW(PWidget(wSciTE)));
gtk_widget_hide(PWidget(backgroundStrip));
gtk_widget_hide(PWidget(userStrip));
gtk_widget_hide(wIncrementPanel);
gtk_widget_hide(PWidget(findStrip));
gtk_widget_hide(PWidget(replaceStrip));
UIAvailable();
}
void SciTEGTK::FindIncrementSetColour(bool valid) {
#if GTK_CHECK_VERSION(3,0,0)
if (valid) {
GdkRGBA black = { 0, 0, 0, 1};
gtk_widget_override_color(GTK_WIDGET(IncSearchEntry), (GtkStateFlags)GTK_STATE_NORMAL, &black);
} else {
GdkRGBA red = { 1.0, 0, 0, 1};
gtk_widget_override_color(GTK_WIDGET(IncSearchEntry), (GtkStateFlags)GTK_STATE_NORMAL, &red);
}
#else
if (valid) {
GdkColor white = { 0, 0xFFFF, 0xFFFF, 0xFFFF};
gtk_widget_modify_base(GTK_WIDGET(IncSearchEntry), GTK_STATE_NORMAL, &white);
} else {
GdkColor red = { 0, 0xFFFF, 0x6666, 0x6666 };
gtk_widget_modify_base(GTK_WIDGET(IncSearchEntry), GTK_STATE_NORMAL, &red);
}
#endif
}
void SciTEGTK::FindIncrementNext(bool select) {
if (select) {
MoveBack();
}
const char *lineEntry = gtk_entry_get_text(GTK_ENTRY(IncSearchEntry));
findWhat = lineEntry;
wholeWord = false;
if (FindHasText()) {