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
|
// Scintilla source code edit control
// ScintillaGTK.cxx - GTK+ specific subclass of ScintillaBase
// Copyright 1998-2003 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "Platform.h"
#if PLAT_GTK_WIN32
#include "Windows.h"
#endif
#include "Scintilla.h"
#include "ScintillaWidget.h"
#ifdef SCI_LEXER
#include "SciLexer.h"
#include "PropSet.h"
#include "Accessor.h"
#include "KeyWords.h"
#endif
#include "ContractionState.h"
#include "SVector.h"
#include "CellBuffer.h"
#include "CallTip.h"
#include "KeyMap.h"
#include "Indicator.h"
#include "XPM.h"
#include "LineMarker.h"
#include "Style.h"
#include "AutoComplete.h"
#include "ViewStyle.h"
#include "Document.h"
#include "Editor.h"
#include "SString.h"
#include "ScintillaBase.h"
#include "UniConversion.h"
#include "gtk/gtksignal.h"
#include "gtk/gtkmarshal.h"
#ifdef SCI_LEXER
#include <glib.h>
#include <gmodule.h>
#include "ExternalLexer.h"
#endif
#if GTK_MAJOR_VERSION < 2
#define INTERNATIONAL_INPUT
#endif
#if !PLAT_GTK_WIN32
#include <iconv.h>
#endif
#ifdef _MSC_VER
// Constant conditional expressions are because of GTK+ headers
#pragma warning(disable: 4127)
// Ignore unreferenced local functions in GTK+ headers
#pragma warning(disable: 4505)
#endif
class ScintillaGTK : public ScintillaBase {
_ScintillaObject *sci;
Window wText;
Window scrollbarv;
Window scrollbarh;
GtkObject *adjustmentv;
GtkObject *adjustmenth;
int scrollBarWidth;
int scrollBarHeight;
// Because clipboard access is asynchronous, copyText is created by Copy
SelectionText copyText;
SelectionText primary;
GdkEventButton evbtn;
bool capturedMouse;
bool dragWasDropped;
int lastKey;
GtkWidgetClass *parentClass;
GdkAtom atomClipboard;
GdkAtom atomSought;
GdkAtom atomUTF8;
GdkAtom atomString;
#if PLAT_GTK_WIN32
CLIPFORMAT cfColumnSelect;
#endif
#ifdef INTERNATIONAL_INPUT
// Input context used for supporting internationalized key entry
GdkIC *ic;
GdkICAttr *ic_attr;
#endif
// Wheel mouse support
unsigned int linesPerScroll;
GTimeVal lastWheelMouseTime;
gint lastWheelMouseDirection;
gint wheelMouseIntensity;
// Private so ScintillaGTK objects can not be copied
ScintillaGTK(const ScintillaGTK &) : ScintillaBase() {}
ScintillaGTK &operator=(const ScintillaGTK &) { return * this; }
public:
ScintillaGTK(_ScintillaObject *sci_);
virtual ~ScintillaGTK();
static void ClassInit(GtkObjectClass* object_class, GtkWidgetClass *widget_class);
private:
virtual void Initialise();
virtual void Finalise();
virtual void DisplayCursor(Window::Cursor c);
virtual void StartDrag();
public: // Public for scintilla_send_message
virtual sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
private:
virtual sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
virtual void SetTicking(bool on);
virtual bool SetIdle(bool on);
virtual void SetMouseCapture(bool on);
virtual bool HaveMouseCapture();
void FullPaint();
virtual PRectangle GetClientRectangle();
void SyncPaint(PRectangle rc);
virtual void ScrollText(int linesToMove);
virtual void SetVerticalScrollPos();
virtual void SetHorizontalScrollPos();
virtual bool ModifyScrollBars(int nMax, int nPage);
void ReconfigureScrollBars();
virtual void NotifyChange();
virtual void NotifyFocus(bool focus);
virtual void NotifyParent(SCNotification scn);
void NotifyKey(int key, int modifiers);
void NotifyURIDropped(const char *list);
virtual int KeyDefault(int key, int modifiers);
virtual void CopyToClipboard(const SelectionText &selectedText);
virtual void Copy();
virtual void Paste();
virtual void CreateCallTipWindow(PRectangle rc);
virtual void AddToPopUp(const char *label, int cmd = 0, bool enabled = true);
bool OwnPrimarySelection();
virtual void ClaimSelection();
void GetGtkSelectionText(const GtkSelectionData *selectionData, SelectionText &selText);
void ReceivedSelection(GtkSelectionData *selection_data);
void ReceivedDrop(GtkSelectionData *selection_data);
void GetSelection(GtkSelectionData *selection_data, guint info, SelectionText *selected);
void UnclaimSelection(GdkEventSelection *selection_event);
void Resize(int width, int height);
// Callback functions
void RealizeThis(GtkWidget *widget);
static void Realize(GtkWidget *widget);
void UnRealizeThis(GtkWidget *widget);
static void UnRealize(GtkWidget *widget);
void MapThis();
static void Map(GtkWidget *widget);
void UnMapThis();
static void UnMap(GtkWidget *widget);
static gint CursorMoved(GtkWidget *widget, int xoffset, int yoffset, ScintillaGTK *sciThis);
static gint FocusIn(GtkWidget *widget, GdkEventFocus *event);
static gint FocusOut(GtkWidget *widget, GdkEventFocus *event);
static void SizeRequest(GtkWidget *widget, GtkRequisition *requisition);
static void SizeAllocate(GtkWidget *widget, GtkAllocation *allocation);
gint Expose(GtkWidget *widget, GdkEventExpose *ose);
static gint ExposeMain(GtkWidget *widget, GdkEventExpose *ose);
static void Draw(GtkWidget *widget, GdkRectangle *area);
static void ScrollSignal(GtkAdjustment *adj, ScintillaGTK *sciThis);
static void ScrollHSignal(GtkAdjustment *adj, ScintillaGTK *sciThis);
gint PressThis(GdkEventButton *event);
static gint Press(GtkWidget *widget, GdkEventButton *event);
static gint MouseRelease(GtkWidget *widget, GdkEventButton *event);
#if PLAT_GTK_WIN32 || (GTK_MAJOR_VERSION >= 2)
static gint ScrollEvent(GtkWidget *widget, GdkEventScroll *event);
#endif
static gint Motion(GtkWidget *widget, GdkEventMotion *event);
gint KeyThis(GdkEventKey *event);
static gint KeyPress(GtkWidget *widget, GdkEventKey *event);
static gint KeyRelease(GtkWidget *widget, GdkEventKey *event);
static void Destroy(GtkObject *object);
static void SelectionReceived(GtkWidget *widget, GtkSelectionData *selection_data,
guint time);
static void SelectionGet(GtkWidget *widget, GtkSelectionData *selection_data,
guint info, guint time);
static gint SelectionClear(GtkWidget *widget, GdkEventSelection *selection_event);
#if GTK_MAJOR_VERSION < 2
static gint SelectionNotify(GtkWidget *widget, GdkEventSelection *selection_event);
#endif
static void DragBegin(GtkWidget *widget, GdkDragContext *context);
static gboolean DragMotion(GtkWidget *widget, GdkDragContext *context,
gint x, gint y, guint time);
static void DragLeave(GtkWidget *widget, GdkDragContext *context,
guint time);
static void DragEnd(GtkWidget *widget, GdkDragContext *context);
static gboolean Drop(GtkWidget *widget, GdkDragContext *context,
gint x, gint y, guint time);
static void DragDataReceived(GtkWidget *widget, GdkDragContext *context,
gint x, gint y, GtkSelectionData *selection_data, guint info, guint time);
static void DragDataGet(GtkWidget *widget, GdkDragContext *context,
GtkSelectionData *selection_data, guint info, guint time);
static gint TimeOut(ScintillaGTK *sciThis);
static gint IdleCallback(ScintillaGTK *sciThis);
static void PopUpCB(ScintillaGTK *sciThis, guint action, GtkWidget *widget);
gint ExposeTextThis(GtkWidget *widget, GdkEventExpose *ose);
static gint ExposeText(GtkWidget *widget, GdkEventExpose *ose, ScintillaGTK *sciThis);
static gint ExposeCT(GtkWidget *widget, GdkEventExpose *ose, CallTip *ct);
static gint PressCT(GtkWidget *widget, GdkEventButton *event, ScintillaGTK *sciThis);
static sptr_t DirectFunction(ScintillaGTK *sciThis,
unsigned int iMessage, uptr_t wParam, sptr_t lParam);
};
enum {
COMMAND_SIGNAL,
NOTIFY_SIGNAL,
LAST_SIGNAL
};
static gint scintilla_signals[LAST_SIGNAL] = { 0 };
static GtkWidgetClass* parent_class = NULL;
enum {
TARGET_STRING,
TARGET_TEXT,
TARGET_COMPOUND_TEXT,
TARGET_UTF8_STRING
};
static GtkWidget *PWidget(Window &w) {
return reinterpret_cast<GtkWidget *>(w.GetID());
}
static ScintillaGTK *ScintillaFromWidget(GtkWidget *widget) {
ScintillaObject *scio = reinterpret_cast<ScintillaObject *>(widget);
return reinterpret_cast<ScintillaGTK *>(scio->pscin);
}
ScintillaGTK::ScintillaGTK(_ScintillaObject *sci_) :
adjustmentv(0), adjustmenth(0),
scrollBarWidth(30), scrollBarHeight(30),
capturedMouse(false), dragWasDropped(false),
lastKey(0), parentClass(0),
#ifdef INTERNATIONAL_INPUT
ic(NULL),
ic_attr(NULL),
#endif
lastWheelMouseDirection(0),
wheelMouseIntensity(0) {
sci = sci_;
wMain = GTK_WIDGET(sci);
atomClipboard = GDK_NONE;
atomSought = GDK_NONE;
atomUTF8 = GDK_NONE;
atomString = GDK_NONE;
#if PLAT_GTK_WIN32
// There does not seem to be a real standard for indicating that the clipboard
// contains a rectangular selection, so copy Developer Studio.
cfColumnSelect = static_cast<CLIPFORMAT>(
::RegisterClipboardFormat("MSDEVColumnSelect"));
// Get intellimouse parameters when running on win32; otherwise use
// reasonable default
#ifndef SPI_GETWHEELSCROLLLINES
#define SPI_GETWHEELSCROLLLINES 104
#endif
::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &linesPerScroll, 0);
#else
linesPerScroll = 4;
#endif
lastWheelMouseTime.tv_sec = 0;
lastWheelMouseTime.tv_usec = 0;
Initialise();
}
ScintillaGTK::~ScintillaGTK() {
}
void ScintillaGTK::RealizeThis(GtkWidget *widget) {
//Platform::DebugPrintf("ScintillaGTK::realize this\n");
GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
GdkWindowAttr attrs;
attrs.window_type = GDK_WINDOW_CHILD;
attrs.x = widget->allocation.x;
attrs.y = widget->allocation.y;
attrs.width = widget->allocation.width;
attrs.height = widget->allocation.height;
attrs.wclass = GDK_INPUT_OUTPUT;
attrs.visual = gtk_widget_get_visual(widget);
attrs.colormap = gtk_widget_get_colormap(widget);
attrs.event_mask = gtk_widget_get_events(widget) | GDK_EXPOSURE_MASK;
GdkCursor *cursor = gdk_cursor_new(GDK_XTERM);
attrs.cursor = cursor;
widget->window = gdk_window_new(gtk_widget_get_parent_window(widget), &attrs,
GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP | GDK_WA_CURSOR);
gdk_window_set_user_data(widget->window, widget);
gdk_window_set_background(widget->window, &widget->style->bg[GTK_STATE_NORMAL]);
gdk_window_show(widget->window);
gdk_cursor_destroy(cursor);
#ifdef INTERNATIONAL_INPUT
if (gdk_im_ready() && (ic_attr = gdk_ic_attr_new()) != NULL) {
gint width, height;
GdkColormap *colormap;
GdkEventMask mask;
GdkICAttr *attr = ic_attr;
GdkICAttributesType attrmask = GDK_IC_ALL_REQ;
GdkIMStyle style;
GdkIMStyle supported_style = (GdkIMStyle) (GDK_IM_PREEDIT_NONE |
GDK_IM_PREEDIT_NOTHING |
GDK_IM_PREEDIT_POSITION |
GDK_IM_STATUS_NONE |
GDK_IM_STATUS_NOTHING);
if (widget->style && widget->style->font->type != GDK_FONT_FONTSET)
supported_style = (GdkIMStyle) ((int) supported_style & ~GDK_IM_PREEDIT_POSITION);
attr->style = style = gdk_im_decide_style(supported_style);
attr->client_window = widget->window;
if ((colormap = gtk_widget_get_colormap (widget)) != gtk_widget_get_default_colormap ()) {
attrmask = (GdkICAttributesType) ((int) attrmask | GDK_IC_PREEDIT_COLORMAP);
attr->preedit_colormap = colormap;
}
switch (style & GDK_IM_PREEDIT_MASK) {
case GDK_IM_PREEDIT_POSITION:
if (widget->style && widget->style->font->type != GDK_FONT_FONTSET) {
g_warning("over-the-spot style requires fontset");
break;
}
attrmask = (GdkICAttributesType) ((int) attrmask | GDK_IC_PREEDIT_POSITION_REQ);
gdk_window_get_size(widget->window, &width, &height);
attr->spot_location.x = 0;
attr->spot_location.y = height;
attr->preedit_area.x = 0;
attr->preedit_area.y = 0;
attr->preedit_area.width = width;
attr->preedit_area.height = height;
attr->preedit_fontset = widget->style->font;
break;
}
ic = gdk_ic_new(attr, attrmask);
if (ic == NULL) {
g_warning("Can't create input context.");
} else {
mask = gdk_window_get_events(widget->window);
mask = (GdkEventMask) ((int) mask | gdk_ic_get_events(ic));
gdk_window_set_events(widget->window, mask);
if (GTK_WIDGET_HAS_FOCUS(widget))
gdk_im_begin(ic, widget->window);
}
}
#endif
gtk_widget_realize(PWidget(wText));
gtk_widget_realize(PWidget(scrollbarv));
gtk_widget_realize(PWidget(scrollbarh));
}
void ScintillaGTK::Realize(GtkWidget *widget) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
sciThis->RealizeThis(widget);
}
void ScintillaGTK::UnRealizeThis(GtkWidget *widget) {
if (GTK_WIDGET_MAPPED(widget)) {
gtk_widget_unmap(widget);
}
GTK_WIDGET_UNSET_FLAGS(widget, GTK_REALIZED);
gtk_widget_unrealize(PWidget(wText));
gtk_widget_unrealize(PWidget(scrollbarv));
gtk_widget_unrealize(PWidget(scrollbarh));
#ifdef INTERNATIONAL_INPUT
if (ic) {
gdk_ic_destroy(ic);
ic = NULL;
}
if (ic_attr) {
gdk_ic_attr_destroy(ic_attr);
ic_attr = NULL;
}
#endif
if (GTK_WIDGET_CLASS(parentClass)->unrealize)
GTK_WIDGET_CLASS(parentClass)->unrealize(widget);
Finalise();
}
void ScintillaGTK::UnRealize(GtkWidget *widget) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
sciThis->UnRealizeThis(widget);
}
static void MapWidget(GtkWidget *widget) {
if (widget &&
GTK_WIDGET_VISIBLE(widget) &&
!GTK_WIDGET_MAPPED(widget)) {
gtk_widget_map(widget);
}
}
void ScintillaGTK::MapThis() {
//Platform::DebugPrintf("ScintillaGTK::map this\n");
GTK_WIDGET_SET_FLAGS(PWidget(wMain), GTK_MAPPED);
MapWidget(PWidget(wText));
MapWidget(PWidget(scrollbarh));
MapWidget(PWidget(scrollbarv));
wMain.SetCursor(Window::cursorArrow);
scrollbarv.SetCursor(Window::cursorArrow);
scrollbarh.SetCursor(Window::cursorArrow);
gdk_window_show(PWidget(wMain)->window);
}
void ScintillaGTK::Map(GtkWidget *widget) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
sciThis->MapThis();
}
void ScintillaGTK::UnMapThis() {
//Platform::DebugPrintf("ScintillaGTK::unmap this\n");
GTK_WIDGET_UNSET_FLAGS(PWidget(wMain), GTK_MAPPED);
gdk_window_hide(PWidget(wMain)->window);
gtk_widget_unmap(PWidget(wText));
gtk_widget_unmap(PWidget(scrollbarh));
gtk_widget_unmap(PWidget(scrollbarv));
}
void ScintillaGTK::UnMap(GtkWidget *widget) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
sciThis->UnMapThis();
}
#ifdef INTERNATIONAL_INPUT
gint ScintillaGTK::CursorMoved(GtkWidget *widget, int xoffset, int yoffset, ScintillaGTK *sciThis) {
if (GTK_WIDGET_HAS_FOCUS(widget) && gdk_im_ready() && sciThis->ic &&
(gdk_ic_get_style (sciThis->ic) & GDK_IM_PREEDIT_POSITION)) {
sciThis->ic_attr->spot_location.x = xoffset;
sciThis->ic_attr->spot_location.y = yoffset;
gdk_ic_set_attr (sciThis->ic, sciThis->ic_attr, GDK_IC_SPOT_LOCATION);
}
return FALSE;
}
#else
gint ScintillaGTK::CursorMoved(GtkWidget *, int, int, ScintillaGTK *) {
return FALSE;
}
#endif
gint ScintillaGTK::FocusIn(GtkWidget *widget, GdkEventFocus * /*event*/) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("ScintillaGTK::focus in %x\n", sciThis);
GTK_WIDGET_SET_FLAGS(widget, GTK_HAS_FOCUS);
sciThis->SetFocusState(true);
#ifdef INTERNATIONAL_INPUT
if (sciThis->ic)
gdk_im_begin(sciThis->ic, widget->window);
#endif
return FALSE;
}
gint ScintillaGTK::FocusOut(GtkWidget *widget, GdkEventFocus * /*event*/) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("ScintillaGTK::focus out %x\n", sciThis);
GTK_WIDGET_UNSET_FLAGS(widget, GTK_HAS_FOCUS);
sciThis->SetFocusState(false);
#ifdef INTERNATIONAL_INPUT
gdk_im_end();
#endif
return FALSE;
}
void ScintillaGTK::SizeRequest(GtkWidget *widget, GtkRequisition *requisition) {
requisition->width = 600;
requisition->height = 2000;
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
GtkRequisition child_requisition;
gtk_widget_size_request(PWidget(sciThis->scrollbarh), &child_requisition);
gtk_widget_size_request(PWidget(sciThis->scrollbarv), &child_requisition);
}
void ScintillaGTK::SizeAllocate(GtkWidget *widget, GtkAllocation *allocation) {
widget->allocation = *allocation;
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
if (GTK_WIDGET_REALIZED(widget))
gdk_window_move_resize(widget->window,
widget->allocation.x,
widget->allocation.y,
widget->allocation.width,
widget->allocation.height);
sciThis->Resize(allocation->width, allocation->height);
#ifdef INTERNATIONAL_INPUT
if (sciThis->ic && (gdk_ic_get_style (sciThis->ic) & GDK_IM_PREEDIT_POSITION)) {
gint width, height;
gdk_window_get_size(widget->window, &width, &height);
sciThis->ic_attr->preedit_area.width = width;
sciThis->ic_attr->preedit_area.height = height;
gdk_ic_set_attr(sciThis->ic, sciThis->ic_attr, GDK_IC_PREEDIT_AREA);
}
#endif
}
void ScintillaGTK::Initialise() {
//Platform::DebugPrintf("ScintillaGTK::Initialise\n");
parentClass = reinterpret_cast<GtkWidgetClass *>(
gtk_type_class(gtk_container_get_type()));
GTK_WIDGET_SET_FLAGS(PWidget(wMain), GTK_CAN_FOCUS);
GTK_WIDGET_SET_FLAGS(GTK_WIDGET(PWidget(wMain)), GTK_SENSITIVE);
gtk_widget_set_events(PWidget(wMain),
GDK_EXPOSURE_MASK
| GDK_STRUCTURE_MASK
| GDK_KEY_PRESS_MASK
| GDK_KEY_RELEASE_MASK
| GDK_FOCUS_CHANGE_MASK
| GDK_LEAVE_NOTIFY_MASK
| GDK_BUTTON_PRESS_MASK
| GDK_BUTTON_RELEASE_MASK
| GDK_POINTER_MOTION_MASK
| GDK_POINTER_MOTION_HINT_MASK);
wText = gtk_drawing_area_new();
gtk_widget_set_parent(PWidget(wText), PWidget(wMain));
gtk_widget_show(PWidget(wText));
gtk_signal_connect(GTK_OBJECT(PWidget(wText)), "expose_event",
GtkSignalFunc(ScintillaGTK::ExposeText), this);
gtk_widget_set_events(PWidget(wText), GDK_EXPOSURE_MASK);
#if GTK_MAJOR_VERSION >= 2
// Avoid background drawing flash
gtk_widget_set_double_buffered(PWidget(wText), FALSE);
#endif
gtk_drawing_area_size(GTK_DRAWING_AREA(PWidget(wText)),
100,100);
adjustmentv = gtk_adjustment_new(0.0, 0.0, 201.0, 1.0, 20.0, 20.0);
scrollbarv = gtk_vscrollbar_new(GTK_ADJUSTMENT(adjustmentv));
GTK_WIDGET_UNSET_FLAGS(PWidget(scrollbarv), GTK_CAN_FOCUS);
gtk_signal_connect(GTK_OBJECT(adjustmentv), "value_changed",
GTK_SIGNAL_FUNC(ScrollSignal), this);
gtk_widget_set_parent(PWidget(scrollbarv), PWidget(wMain));
gtk_widget_show(PWidget(scrollbarv));
adjustmenth = gtk_adjustment_new(0.0, 0.0, 101.0, 1.0, 20.0, 20.0);
scrollbarh = gtk_hscrollbar_new(GTK_ADJUSTMENT(adjustmenth));
GTK_WIDGET_UNSET_FLAGS(PWidget(scrollbarh), GTK_CAN_FOCUS);
gtk_signal_connect(GTK_OBJECT(adjustmenth), "value_changed",
GTK_SIGNAL_FUNC(ScrollHSignal), this);
gtk_widget_set_parent(PWidget(scrollbarh), PWidget(wMain));
gtk_widget_show(PWidget(scrollbarh));
gtk_widget_grab_focus(PWidget(wMain));
static const GtkTargetEntry targets[] = {
{ "UTF8_STRING", 0, TARGET_UTF8_STRING },
{ "STRING", 0, TARGET_STRING },
// { "TEXT", 0, TARGET_TEXT },
// { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT },
{ "text/uri-list", 0, 0 },
};
static const gint n_targets = sizeof(targets) / sizeof(targets[0]);
gtk_selection_add_targets(GTK_WIDGET(PWidget(wMain)), GDK_SELECTION_PRIMARY,
targets, n_targets);
atomClipboard = gdk_atom_intern("CLIPBOARD", FALSE);
atomUTF8 = gdk_atom_intern("UTF8_STRING", FALSE);
atomString = gdk_atom_intern("STRING", FALSE);
gtk_selection_add_targets(GTK_WIDGET(PWidget(wMain)), atomClipboard,
targets, n_targets);
gtk_drag_dest_set(GTK_WIDGET(PWidget(wMain)),
GTK_DEST_DEFAULT_ALL, targets, n_targets,
static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE));
SetTicking(true);
}
void ScintillaGTK::Finalise() {
SetTicking(false);
ScintillaBase::Finalise();
}
void ScintillaGTK::DisplayCursor(Window::Cursor c) {
if (cursorMode == SC_CURSORNORMAL)
wText.SetCursor(c);
else
wText.SetCursor(static_cast<Window::Cursor>(cursorMode));
}
void ScintillaGTK::StartDrag() {
dragWasDropped = false;
static const GtkTargetEntry targets[] = {
{ "STRING", 0, TARGET_STRING },
{ "TEXT", 0, TARGET_TEXT },
{ "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT },
};
static const gint n_targets = sizeof(targets) / sizeof(targets[0]);
GtkTargetList *tl = gtk_target_list_new(targets, n_targets);
gtk_drag_begin(GTK_WIDGET(PWidget(wMain)),
tl,
static_cast<GdkDragAction>(GDK_ACTION_COPY | GDK_ACTION_MOVE),
evbtn.button,
reinterpret_cast<GdkEvent *>(&evbtn));
}
sptr_t ScintillaGTK::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
switch (iMessage) {
case SCI_GRABFOCUS:
gtk_widget_grab_focus(PWidget(wMain));
break;
case SCI_GETDIRECTFUNCTION:
return reinterpret_cast<sptr_t>(DirectFunction);
case SCI_GETDIRECTPOINTER:
return reinterpret_cast<sptr_t>(this);
#ifdef SCI_LEXER
case SCI_LOADLEXERLIBRARY:
LexerManager::GetInstance()->Load(reinterpret_cast<const char*>( wParam ));
break;
#endif
default:
return ScintillaBase::WndProc(iMessage, wParam, lParam);
}
return 0l;
}
sptr_t ScintillaGTK::DefWndProc(unsigned int, uptr_t, sptr_t) {
return 0;
}
void ScintillaGTK::SetTicking(bool on) {
if (timer.ticking != on) {
timer.ticking = on;
if (timer.ticking) {
timer.tickerID = reinterpret_cast<TickerID>(gtk_timeout_add(timer.tickSize, (GtkFunction)TimeOut, this));
} else {
gtk_timeout_remove(GPOINTER_TO_UINT(timer.tickerID));
}
}
timer.ticksToWait = caret.period;
}
bool ScintillaGTK::SetIdle(bool on) {
if (on) {
// Start idler, if it's not running.
if (idler.state == false) {
idler.state = true;
idler.idlerID = reinterpret_cast<IdlerID>
(gtk_idle_add((GtkFunction)IdleCallback, this));
}
} else {
// Stop idler, if it's running
if (idler.state == true) {
idler.state = false;
gtk_idle_remove(GPOINTER_TO_UINT(idler.idlerID));
}
}
return true;
}
void ScintillaGTK::SetMouseCapture(bool on) {
if (mouseDownCaptures) {
if (on) {
gtk_grab_add(GTK_WIDGET(PWidget(wMain)));
} else {
gtk_grab_remove(GTK_WIDGET(PWidget(wMain)));
}
}
capturedMouse = on;
}
bool ScintillaGTK::HaveMouseCapture() {
return capturedMouse;
}
// Redraw all of text area. This paint will not be abandoned.
void ScintillaGTK::FullPaint() {
#if GTK_MAJOR_VERSION < 2
paintState = painting;
rcPaint = GetClientRectangle();
//Platform::DebugPrintf("ScintillaGTK::FullPaint %0d,%0d %0d,%0d\n",
// rcPaint.left, rcPaint.top, rcPaint.right, rcPaint.bottom);
paintingAllText = true;
if ((PWidget(wText))->window) {
Surface *sw = Surface::Allocate();
if (sw) {
sw->Init(PWidget(wText)->window, PWidget(wText));
Paint(sw, rcPaint);
sw->Release();
delete sw;
}
}
paintState = notPainting;
#else
wText.InvalidateAll();
#endif
}
PRectangle ScintillaGTK::GetClientRectangle() {
PRectangle rc = wMain.GetClientPosition();
if (verticalScrollBarVisible)
rc.right -= scrollBarWidth;
if (horizontalScrollBarVisible && (wrapState == eWrapNone))
rc.bottom -= scrollBarHeight;
// Move to origin
rc.right -= rc.left;
rc.bottom -= rc.top;
rc.left = 0;
rc.top = 0;
return rc;
}
// Synchronously paint a rectangle of the window.
void ScintillaGTK::SyncPaint(PRectangle rc) {
paintState = painting;
rcPaint = rc;
PRectangle rcClient = GetClientRectangle();
paintingAllText = rcPaint.Contains(rcClient);
if ((PWidget(wText))->window) {
Surface *sw = Surface::Allocate();
if (sw) {
sw->Init(PWidget(wText)->window, PWidget(wText));
Paint(sw, rc);
sw->Release();
delete sw;
}
}
if (paintState == paintAbandoned) {
// Painting area was insufficient to cover new styling or brace highlight positions
FullPaint();
}
paintState = notPainting;
}
void ScintillaGTK::ScrollText(int linesToMove) {
int diff = vs.lineHeight * -linesToMove;
//Platform::DebugPrintf("ScintillaGTK::ScrollText %d %d %0d,%0d %0d,%0d\n", linesToMove, diff,
// rc.left, rc.top, rc.right, rc.bottom);
GtkWidget *wi = PWidget(wText);
#if GTK_MAJOR_VERSION < 2
PRectangle rc = GetClientRectangle();
GdkGC *gc = gdk_gc_new(wi->window);
// Set up gc so we get GraphicsExposures from gdk_draw_pixmap
// which calls XCopyArea
gdk_gc_set_exposures(gc, TRUE);
// Redraw exposed bit : scrolling upwards
if (diff > 0) {
gdk_draw_pixmap(wi->window,
gc, wi->window,
0, diff,
0, 0,
rc.Width()-1, rc.Height() - diff);
SyncPaint(PRectangle(0, rc.Height() - diff,
rc.Width(), rc.Height()+1));
// Redraw exposed bit : scrolling downwards
} else {
gdk_draw_pixmap(wi->window,
gc, wi->window,
0, 0,
0, -diff,
rc.Width()-1, rc.Height() + diff);
SyncPaint(PRectangle(0, 0, rc.Width(), -diff));
}
// Look for any graphics expose
GdkEvent* event;
while ((event = gdk_event_get_graphics_expose(wi->window)) != NULL) {
gtk_widget_event(wi, event);
if (event->expose.count == 0) {
gdk_event_free(event);
break;
}
gdk_event_free(event);
}
gdk_gc_unref(gc);
#else
gdk_window_scroll(wi->window, 0, -diff);
#endif
}
void ScintillaGTK::SetVerticalScrollPos() {
gtk_adjustment_set_value(GTK_ADJUSTMENT(adjustmentv), topLine);
}
void ScintillaGTK::SetHorizontalScrollPos() {
gtk_adjustment_set_value(GTK_ADJUSTMENT(adjustmenth), xOffset / 2);
}
bool ScintillaGTK::ModifyScrollBars(int nMax, int nPage) {
bool modified = false;
int pageScroll = LinesToScroll();
if (GTK_ADJUSTMENT(adjustmentv)->upper != (nMax + 1) ||
GTK_ADJUSTMENT(adjustmentv)->page_size != nPage ||
GTK_ADJUSTMENT(adjustmentv)->page_increment != pageScroll) {
GTK_ADJUSTMENT(adjustmentv)->upper = nMax + 1;
GTK_ADJUSTMENT(adjustmentv)->page_size = nPage;
GTK_ADJUSTMENT(adjustmentv)->page_increment = pageScroll;
gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmentv));
modified = true;
}
PRectangle rcText = GetTextRectangle();
int horizEndPreferred = scrollWidth;
if (horizEndPreferred < 0)
horizEndPreferred = 0;
unsigned int pageWidth = rcText.Width();
if (GTK_ADJUSTMENT(adjustmenth)->upper != horizEndPreferred ||
GTK_ADJUSTMENT(adjustmenth)->page_size != pageWidth) {
GTK_ADJUSTMENT(adjustmenth)->upper = horizEndPreferred;
GTK_ADJUSTMENT(adjustmenth)->page_size = pageWidth;
gtk_adjustment_changed(GTK_ADJUSTMENT(adjustmenth));
modified = true;
}
return modified;
}
void ScintillaGTK::ReconfigureScrollBars() {
PRectangle rc = wMain.GetClientPosition();
Resize(rc.Width(), rc.Height());
}
void ScintillaGTK::NotifyChange() {
gtk_signal_emit(GTK_OBJECT(sci), scintilla_signals[COMMAND_SIGNAL],
Platform::LongFromTwoShorts(GetCtrlID(), SCEN_CHANGE), PWidget(wMain));
}
void ScintillaGTK::NotifyFocus(bool focus) {
gtk_signal_emit(GTK_OBJECT(sci), scintilla_signals[COMMAND_SIGNAL],
Platform::LongFromTwoShorts(GetCtrlID(), focus ? SCEN_SETFOCUS : SCEN_KILLFOCUS), PWidget(wMain));
}
void ScintillaGTK::NotifyParent(SCNotification scn) {
scn.nmhdr.hwndFrom = PWidget(wMain);
scn.nmhdr.idFrom = GetCtrlID();
gtk_signal_emit(GTK_OBJECT(sci), scintilla_signals[NOTIFY_SIGNAL],
GetCtrlID(), &scn);
}
void ScintillaGTK::NotifyKey(int key, int modifiers) {
SCNotification scn;
scn.nmhdr.code = SCN_KEY;
scn.ch = key;
scn.modifiers = modifiers;
NotifyParent(scn);
}
void ScintillaGTK::NotifyURIDropped(const char *list) {
SCNotification scn;
scn.nmhdr.code = SCN_URIDROPPED;
scn.text = list;
NotifyParent(scn);
}
const char *CharacterSetID(int characterSet);
#if GTK_MAJOR_VERSION >= 2
#define IS_ACC(x) \
((x) >= 65103 && (x) <= 65111)
#define IS_CHAR(x) \
((x) >= 0 && (x) <= 128)
#define IS_ACC_OR_CHAR(x) \
(IS_CHAR(x)) || (IS_ACC(x))
#define IS_ACC(x) \
((x) >= 65103 && (x) <= 65111)
#define IS_CHAR(x) \
((x) >= 0 && (x) <= 128)
#define IS_ACC_OR_CHAR(x) \
(IS_CHAR(x)) || (IS_ACC(x))
static int MakeAccent(int key, int acc) {
const char *conv[] = {
"aeiounc AEIOUNC",
"�ei�u�c~�EI�U�C",
"�����n�'�����N�",
"�����nc`�����NC",
"�����nc^�����NC",
"�����nc������NC"
};
int idx;
for (idx = 0; idx < 15; ++idx) {
if (char(key) == conv[0][idx]) {
break;
}
}
if (idx == 15) {
return key;
}
if (acc == GDK_dead_tilde) { // ~
return int((unsigned char)(conv[1][idx]));
} else if (acc == GDK_dead_acute) { // '
return int((unsigned char)(conv[2][idx]));
} else if (acc == GDK_dead_grave) { // `
return int((unsigned char)(conv[3][idx]));
} else if (acc == GDK_dead_circumflex) { // ^
return int((unsigned char)(conv[4][idx]));
} else if (acc == GDK_dead_diaeresis) { // "
return int((unsigned char)(conv[5][idx]));
}
return key;
}
#endif
int ScintillaGTK::KeyDefault(int key, int modifiers) {
if (!(modifiers & SCI_CTRL) && !(modifiers & SCI_ALT)) {
#if GTK_MAJOR_VERSION >= 2
char utfVal[4]="\0\0\0";
wchar_t wcs[2];
if (IS_CHAR(key) && IS_ACC(lastKey)) {
lastKey = key = MakeAccent(key, lastKey);
}
if (IS_ACC_OR_CHAR(key)) {
lastKey = key;
}
wcs[0] = gdk_keyval_to_unicode(key);
wcs[1] = 0;
UTF8FromUCS2(wcs, 1, utfVal, 3);
if (key <= 0xFE00) {
if (IsUnicodeMode()) {
AddCharUTF(utfVal,strlen(utfVal));
return 1;
} else {
const char *source =
CharacterSetID(vs.styles[STYLE_DEFAULT].characterSet);
if (*source) {
iconv_t iconvh = iconv_open(source, "UTF-8");
if (iconvh != ((iconv_t)(-1))) {
char localeVal[4]="\0\0\0";
char *pin = utfVal;
size_t inLeft = strlen(utfVal);
char *pout = localeVal;
size_t outLeft = sizeof(localeVal);
size_t conversions = iconv(iconvh, &pin, &inLeft, &pout, &outLeft);
iconv_close(iconvh);
if (conversions != ((size_t)(-1))) {
*pout = '\0';
for (int i=0; localeVal[i]; i++) {
AddChar(localeVal[i]);
}
return 1;
}
}
}
}
}
#endif
if (key < 256) {
AddChar(key);
return 1;
} else {
// Pass up to container in case it is an accelerator
NotifyKey(key, modifiers);
return 0;
}
} else {
// Pass up to container in case it is an accelerator
NotifyKey(key, modifiers);
return 0;
}
//Platform::DebugPrintf("SK-key: %d %x %x\n",key, modifiers);
}
void ScintillaGTK::CopyToClipboard(const SelectionText &selectedText) {
copyText.Copy(selectedText.s, selectedText.len);
gtk_selection_owner_set(GTK_WIDGET(PWidget(wMain)),
atomClipboard,
GDK_CURRENT_TIME);
}
void ScintillaGTK::Copy() {
if (currentPos != anchor) {
CopySelectionRange(©Text);
gtk_selection_owner_set(GTK_WIDGET(PWidget(wMain)),
atomClipboard,
GDK_CURRENT_TIME);
#if PLAT_GTK_WIN32
if (selType == selRectangle) {
::OpenClipboard(NULL);
::SetClipboardData(cfColumnSelect, 0);
::CloseClipboard();
}
#endif
}
}
void ScintillaGTK::Paste() {
atomSought = atomUTF8;
gtk_selection_convert(GTK_WIDGET(PWidget(wMain)),
atomClipboard, atomSought, GDK_CURRENT_TIME);
}
void ScintillaGTK::CreateCallTipWindow(PRectangle rc) {
if (!ct.wCallTip.Created()) {
ct.wCallTip = gtk_window_new(GTK_WINDOW_POPUP);
ct.wDraw = gtk_drawing_area_new();
gtk_container_add(GTK_CONTAINER(PWidget(ct.wCallTip)), PWidget(ct.wDraw));
gtk_signal_connect(GTK_OBJECT(PWidget(ct.wDraw)), "expose_event",
GtkSignalFunc(ScintillaGTK::ExposeCT), &ct);
gtk_signal_connect(GTK_OBJECT(PWidget(ct.wDraw)), "button_press_event",
GtkSignalFunc(ScintillaGTK::PressCT), static_cast<void *>(this));
gtk_widget_set_events(PWidget(ct.wDraw),
GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);
}
gtk_drawing_area_size(GTK_DRAWING_AREA(PWidget(ct.wDraw)),
rc.Width(), rc.Height());
ct.wDraw.Show();
ct.wCallTip.Show();
//gtk_widget_set_usize(PWidget(ct.wCallTip), rc.Width(), rc.Height());
gdk_window_resize(PWidget(ct.wCallTip)->window, rc.Width(), rc.Height());
}
void ScintillaGTK::AddToPopUp(const char *label, int cmd, bool enabled) {
char fulllabel[200];
strcpy(fulllabel, "/");
strcat(fulllabel, label);
GtkItemFactoryCallback menuSig = GtkItemFactoryCallback(PopUpCB);
GtkItemFactoryEntry itemEntry = {
fulllabel, NULL,
menuSig,
cmd,
const_cast<gchar *>(label[0] ? "<Item>" : "<Separator>"),
#if GTK_MAJOR_VERSION >= 2
NULL
#endif
};
gtk_item_factory_create_item(GTK_ITEM_FACTORY(popup.GetID()),
&itemEntry, this, 1);
if (cmd) {
GtkWidget *item = gtk_item_factory_get_widget_by_action(
reinterpret_cast<GtkItemFactory *>(popup.GetID()), cmd);
if (item)
gtk_widget_set_sensitive(item, enabled);
}
}
bool ScintillaGTK::OwnPrimarySelection() {
return ((gdk_selection_owner_get(GDK_SELECTION_PRIMARY)
== GTK_WIDGET(PWidget(wMain))->window) &&
(GTK_WIDGET(PWidget(wMain))->window != NULL));
}
void ScintillaGTK::ClaimSelection() {
// X Windows has a 'primary selection' as well as the clipboard.
// Whenever the user selects some text, we become the primary selection
if (currentPos != anchor) {
primarySelection = true;
gtk_selection_owner_set(GTK_WIDGET(PWidget(wMain)),
GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME);
primary.Set(0, 0);
} else if (OwnPrimarySelection()) {
primarySelection = true;
if (primary.s == NULL)
gtk_selection_owner_set(NULL, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME);
} else {
primarySelection = false;
primary.Set(0, 0);
}
}
#if !PLAT_GTK_WIN32
static char *ConvertText(size_t *lenResult, char *s, size_t len, const char *charSetDest, const char *charSetSource) {
*lenResult = 0;
char *destForm = 0;
iconv_t iconvh = iconv_open(charSetDest, charSetSource);
if (iconvh != ((iconv_t)(-1))) {
destForm = new char[len*3+1];
char *pin = s;
size_t inLeft = len;
char *pout = destForm;
size_t outLeft = len*3+1;
size_t conversions = iconv(iconvh, &pin, &inLeft, &pout, &outLeft);
if (conversions == ((size_t)(-1))) {
fprintf(stderr, "iconv failed for %s\n", static_cast<char *>(s));
delete []destForm;
destForm = 0;
} else {
//fprintf(stderr, "iconv OK %s %d\n", destForm, pout - destForm);
*pout = '\0';
*lenResult = pout - destForm;
}
iconv_close(iconvh);
} else {
//fprintf(stderr, "Can not iconv %s %s\n", charSetDest, charSetSource);
}
if (!destForm) {
destForm = new char[1];
destForm[0] = '\0';
*lenResult = 0;
}
return destForm;
}
#endif
// Convert line endings for a piece of text to a particular mode.
// Stop at len or when a NUL is found.
char *ConvertLineEnds(size_t *pLenOut, const char *s, size_t len, int eolMode) {
char *dest = new char[2 * len + 1];
const char *sptr = s;
char *dptr = dest;
for (size_t i = 0; (i < len) && (*sptr != '\0'); i++) {
if (*sptr == '\n' || *sptr == '\r') {
if (eolMode == SC_EOL_CR) {
*dptr++ = '\r';
} else if (eolMode == SC_EOL_LF) {
*dptr++ = '\n';
} else { // eolMode == SC_EOL_CRLF
*dptr++ = '\r';
*dptr++ = '\n';
}
if ((*sptr == '\r') && (i+1 < len) && (*(sptr+1) == '\n')) {
i++;
sptr++;
}
sptr++;
} else {
*dptr++ = *sptr++;
}
}
*dptr++ = '\0';
*pLenOut = (dptr - dest) - 1;
return dest;
}
// Detect rectangular text, convert line ends to current mode, convert from or to UTF-8
void ScintillaGTK::GetGtkSelectionText(const GtkSelectionData *selectionData, SelectionText &selText) {
char *data = reinterpret_cast<char *>(selectionData->data);
size_t len = selectionData->length;
GdkAtom selectionType = selectionData->type;
// Return empty string if selection is not a string
if ((selectionType != GDK_TARGET_STRING) && (selectionType != atomUTF8)) {
char *empty = new char[1];
empty[0] = '\0';
selText.Set(empty,0);
return;
}
// Check for "\n\0" ending to string indicating that selection is rectangular
bool isRectangular = ((len > 2) && (data[len - 1] == 0 && data[len - 2] == '\n'));
// Need to convert to correct newline form for this file: win32gtk *always* returns
// only \n line delimiter from clipboard, and linux/unix gtk may also not send the
// form that matches the document (this is probably not effectively standardized by X)
char *dest = ConvertLineEnds(&len, data, len, pdoc->eolMode);
selText.Set(dest, len, isRectangular);
#if !PLAT_GTK_WIN32
// Possible character set conversion
const char *charSetBuffer =
CharacterSetID(vs.styles[STYLE_DEFAULT].characterSet);
if (*charSetBuffer) {
if (IsUnicodeMode()) {
if (selectionType == GDK_TARGET_STRING) {
// Convert to UTF-8
//fprintf(stderr, "Convert to UTF-8 from %s\n", charSetBuffer);
dest = ConvertText(&len, dest, len, "UTF-8", charSetBuffer);
selText.Set(dest, len, isRectangular);
}
} else {
if (selectionType == atomUTF8) {
//fprintf(stderr, "Convert to locale %s\n", charSetBuffer);
// Convert to locale
dest = ConvertText(&len, dest, len, charSetBuffer, "UTF-8");
selText.Set(dest, len, isRectangular);
}
}
}
#endif
}
void ScintillaGTK::ReceivedSelection(GtkSelectionData *selection_data) {
if ((selection_data->selection == atomClipboard) ||
(selection_data->selection == GDK_SELECTION_PRIMARY)) {
if ((atomSought == atomUTF8) && (selection_data->length <= 0)) {
atomSought = atomString;
gtk_selection_convert(GTK_WIDGET(PWidget(wMain)),
atomClipboard, atomSought, GDK_CURRENT_TIME);
} else if ((selection_data->length > 0) &&
((selection_data->type == GDK_TARGET_STRING) || (selection_data->type == atomUTF8))) {
SelectionText selText;
GetGtkSelectionText(selection_data, selText);
#if PLAT_GTK_WIN32
selText.rectangular = ::IsClipboardFormatAvailable(cfColumnSelect) != 0;
#endif
pdoc->BeginUndoAction();
int selStart = SelectionStart();
if (selection_data->selection != GDK_SELECTION_PRIMARY) {
ClearSelection();
}
if (selText.rectangular) {
PasteRectangular(selStart, selText.s, selText.len);
} else {
pdoc->InsertString(currentPos, selText.s, selText.len);
SetEmptySelection(currentPos + selText.len);
}
pdoc->EndUndoAction();
}
}
// else fprintf(stderr, "Target non string %d %d\n", (int)(selection_data->type),
// (int)(atomUTF8));
Redraw();
}
void ScintillaGTK::ReceivedDrop(GtkSelectionData *selection_data) {
dragWasDropped = true;
if ((selection_data->type == GDK_TARGET_STRING) || (selection_data->type == atomUTF8)) {
if (selection_data->length > 0) {
SelectionText selText;
GetGtkSelectionText(selection_data, selText);
DropAt(posDrop, selText.s, false, selText.rectangular);
}
} else {
char *ptr = reinterpret_cast<char *>(selection_data->data);
NotifyURIDropped(ptr);
}
Redraw();
}
void ScintillaGTK::GetSelection(GtkSelectionData *selection_data, guint info, SelectionText *text) {
if (selection_data->selection == GDK_SELECTION_PRIMARY) {
if (primary.s == NULL) {
CopySelectionRange(&primary);
}
text = &primary;
}
char *selBuffer = text->s;
#if PLAT_GTK_WIN32
// win32gtk requires \n delimited lines and doesn't work right with
// other line formats, so make a copy of the clip text now with
// newlines converted
char *tmpstr = new char[text->len + 1];
char *sptr = selBuffer;
char *dptr = tmpstr;
while (*sptr != '\0') {
if (pdoc->eolMode == SC_EOL_CR && *sptr == '\r') {
*dptr++ = '\n';
sptr++;
} else if (pdoc->eolMode != SC_EOL_CR && *sptr == '\r') {
sptr++;
} else {
*dptr++ = *sptr++;
}
}
*dptr = '\0';
selBuffer = tmpstr;
#endif
char *tmputf = 0;
if ((info == TARGET_UTF8_STRING) || (info == TARGET_STRING)) {
size_t len = strlen(selBuffer);
#if !PLAT_GTK_WIN32
// Possible character set conversion
const char *charSetBuffer =
CharacterSetID(vs.styles[STYLE_DEFAULT].characterSet);
if (info == TARGET_UTF8_STRING) {
//fprintf(stderr, "Copy to clipboard as UTF-8\n");
if (!IsUnicodeMode()) {
// Convert to UTF-8
//fprintf(stderr, "Convert to UTF-8 from %s\n", charSetBuffer);
tmputf = ConvertText(&len, selBuffer, len, "UTF-8", charSetBuffer);
selBuffer = tmputf;
}
} else if (info == TARGET_STRING) {
if (IsUnicodeMode()) {
//fprintf(stderr, "Convert to locale %s\n", charSetBuffer);
// Convert to locale
tmputf = ConvertText(&len, selBuffer, len, charSetBuffer, "UTF-8");
selBuffer = tmputf;
}
}
#endif
// Here is a somewhat evil kludge.
// As I can not work out how to store data on the clipboard in multiple formats
// and need some way to mark the clipping as being stream or rectangular,
// the terminating \0 is included in the length for rectangular clippings.
// All other tested aplications behave benignly by ignoring the \0.
// The #if is here because on Windows cfColumnSelect clip entry is used
// instead as standard indicator of rectangularness (so no need to kludge)
#if PLAT_GTK_WIN32 == 0
if (text->rectangular)
len++;
#endif
gtk_selection_data_set(selection_data,
(info == TARGET_STRING) ?
GDK_SELECTION_TYPE_STRING : atomUTF8,
8, reinterpret_cast<unsigned char *>(selBuffer),
len);
} else if ((info == TARGET_TEXT) || (info == TARGET_COMPOUND_TEXT)) {
guchar *text;
GdkAtom encoding;
gint format;
gint new_length;
gdk_string_to_compound_text(reinterpret_cast<char *>(selBuffer),
&encoding, &format, &text, &new_length);
gtk_selection_data_set(selection_data, encoding, format, text, new_length);
gdk_free_compound_text(text);
}
delete []tmputf;
#if PLAT_GTK_WIN32
delete []tmpstr;
#endif
}
void ScintillaGTK::UnclaimSelection(GdkEventSelection *selection_event) {
//Platform::DebugPrintf("UnclaimSelection\n");
if (selection_event->selection == GDK_SELECTION_PRIMARY) {
//Platform::DebugPrintf("UnclaimPrimarySelection\n");
if (!OwnPrimarySelection()) {
primary.Set(0, 0);
primarySelection = false;
FullPaint();
}
}
}
void ScintillaGTK::Resize(int width, int height) {
//Platform::DebugPrintf("Resize %d %d\n", width, height);
//printf("Resize %d %d\n", width, height);
// Not always needed, but some themes can have different sizes of scrollbars
scrollBarWidth = GTK_WIDGET(PWidget(scrollbarv))->requisition.width;
scrollBarHeight = GTK_WIDGET(PWidget(scrollbarh))->requisition.height;
// These allocations should never produce negative sizes as they would wrap around to huge
// unsigned numbers inside GTK+ causing warnings.
bool showSBHorizontal = horizontalScrollBarVisible && (wrapState == eWrapNone);
int horizontalScrollBarHeight = scrollBarHeight;
if (!showSBHorizontal)
horizontalScrollBarHeight = 0;
int verticalScrollBarHeight = scrollBarWidth;
if (!verticalScrollBarVisible)
verticalScrollBarHeight = 0;
GtkAllocation alloc;
alloc.x = 0;
if (showSBHorizontal) {
alloc.y = height - scrollBarHeight;
alloc.width = Platform::Maximum(1, width - scrollBarWidth) + 1;
alloc.height = horizontalScrollBarHeight;
} else {
alloc.y = -scrollBarHeight;
alloc.width = 0;
alloc.height = 0;
}
gtk_widget_size_allocate(GTK_WIDGET(PWidget(scrollbarh)), &alloc);
alloc.y = 0;
if (verticalScrollBarVisible) {
alloc.x = width - scrollBarWidth;
alloc.width = scrollBarWidth;
alloc.height = Platform::Maximum(1, height - scrollBarHeight) + 1;
if (!showSBHorizontal)
alloc.height += scrollBarWidth-1;
} else {
alloc.x = -scrollBarWidth;
alloc.width = 0;
alloc.height = 0;
}
gtk_widget_size_allocate(GTK_WIDGET(PWidget(scrollbarv)), &alloc);
if (GTK_WIDGET_MAPPED(PWidget(wMain))) {
ChangeSize();
}
alloc.x = 0;
alloc.y = 0;
alloc.width = Platform::Maximum(1, width - scrollBarWidth);
alloc.height = Platform::Maximum(1, height - scrollBarHeight);
if (!showSBHorizontal)
alloc.height += scrollBarWidth;
gtk_widget_size_allocate(GTK_WIDGET(PWidget(wText)), &alloc);
}
static void SetAdjustmentValue(GtkObject *object, int value) {
GtkAdjustment *adjustment = GTK_ADJUSTMENT(object);
int maxValue = static_cast<int>(
adjustment->upper - adjustment->page_size);
if (value > maxValue)
value = maxValue;
if (value < 0)
value = 0;
gtk_adjustment_set_value(adjustment, value);
}
gint ScintillaGTK::PressThis(GdkEventButton *event) {
//Platform::DebugPrintf("Press %x time=%d state = %x button = %x\n",this,event->time, event->state, event->button);
// Do not use GTK+ double click events as Scintilla has its own double click detection
if (event->type != GDK_BUTTON_PRESS)
return FALSE;
evbtn = *event;
Point pt;
pt.x = int(event->x);
pt.y = int(event->y);
PRectangle rcClient = GetClientRectangle();
//Platform::DebugPrintf("Press %0d,%0d in %0d,%0d %0d,%0d\n",
// pt.x, pt.y, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
if ((pt.x > rcClient.right) || (pt.y > rcClient.bottom)) {
Platform::DebugPrintf("Bad location\n");
return FALSE;
}
bool ctrl = (event->state & GDK_CONTROL_MASK) != 0;
gtk_widget_grab_focus(PWidget(wMain));
if (event->button == 1) {
//ButtonDown(pt, event->time,
// event->state & GDK_SHIFT_MASK,
// event->state & GDK_CONTROL_MASK,
// event->state & GDK_MOD1_MASK);
// Instead of sending literal modifiers use control instead of alt
// This is because all the window managers seem to grab alt + click for moving
ButtonDown(pt, event->time,
(event->state & GDK_SHIFT_MASK) != 0,
(event->state & GDK_CONTROL_MASK) != 0,
(event->state & GDK_CONTROL_MASK) != 0);
} else if (event->button == 2) {
// Grab the primary selection if it exists
Position pos = PositionFromLocation(pt);
if (OwnPrimarySelection() && primary.s == NULL)
CopySelectionRange(&primary);
SetSelection(pos, pos);
atomSought = atomUTF8;
gtk_selection_convert(GTK_WIDGET(PWidget(wMain)), GDK_SELECTION_PRIMARY,
atomSought, event->time);
} else if (event->button == 3) {
if (displayPopupMenu) {
// PopUp menu
// Convert to screen
int ox = 0;
int oy = 0;
gdk_window_get_origin(PWidget(wMain)->window, &ox, &oy);
ContextMenu(Point(pt.x + ox, pt.y + oy));
} else {
return FALSE;
}
} else if (event->button == 4) {
// Wheel scrolling up (only xwin gtk does it this way)
if (ctrl)
SetAdjustmentValue(adjustmenth, (xOffset / 2) - 6);
else
SetAdjustmentValue(adjustmentv, topLine - 3);
} else if (event->button == 5) {
// Wheel scrolling down (only xwin gtk does it this way)
if (ctrl)
SetAdjustmentValue(adjustmenth, (xOffset / 2) + 6);
else
SetAdjustmentValue(adjustmentv, topLine + 3);
}
#if GTK_MAJOR_VERSION >= 2
return TRUE;
#else
return FALSE;
#endif
}
gint ScintillaGTK::Press(GtkWidget *widget, GdkEventButton *event) {
if (event->window != widget->window)
return FALSE;
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
return sciThis->PressThis(event);
}
gint ScintillaGTK::MouseRelease(GtkWidget *widget, GdkEventButton *event) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("Release %x %d %d\n",sciThis,event->time,event->state);
if (!sciThis->HaveMouseCapture())
return FALSE;
if (event->button == 1) {
Point pt;
pt.x = int(event->x);
pt.y = int(event->y);
//Platform::DebugPrintf("Up %x %x %d %d %d\n",
// sciThis,event->window,event->time, pt.x, pt.y);
if (event->window != PWidget(sciThis->wMain)->window)
// If mouse released on scroll bar then the position is relative to the
// scrollbar, not the drawing window so just repeat the most recent point.
pt = sciThis->ptMouseLast;
sciThis->ButtonUp(pt, event->time, (event->state & 4) != 0);
}
return FALSE;
}
// win32gtk has a special wheel mouse event for whatever reason and doesn't
// use the button4/5 trick used under X windows.
#if PLAT_GTK_WIN32 || (GTK_MAJOR_VERSION >= 2)
gint ScintillaGTK::ScrollEvent(GtkWidget *widget,
GdkEventScroll *event) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
if (widget == NULL || event == NULL)
return FALSE;
// Compute amount and direction to scroll (even tho on win32 there is
// intensity of scrolling info in the native message, gtk doesn't
// support this so we simulate similarly adaptive scrolling)
int cLineScroll;
int timeDelta = 1000000;
GTimeVal curTime;
g_get_current_time(&curTime);
if (curTime.tv_sec == sciThis->lastWheelMouseTime.tv_sec)
timeDelta = curTime.tv_usec - sciThis->lastWheelMouseTime.tv_usec;
else if (curTime.tv_sec == sciThis->lastWheelMouseTime.tv_sec + 1)
timeDelta = 1000000 + (curTime.tv_usec - sciThis->lastWheelMouseTime.tv_usec);
if ((event->direction == sciThis->lastWheelMouseDirection) && (timeDelta < 250000)) {
if (sciThis->wheelMouseIntensity < 12)
sciThis->wheelMouseIntensity++;
cLineScroll = sciThis->wheelMouseIntensity;
} else {
cLineScroll = sciThis->linesPerScroll;
if (cLineScroll == 0)
cLineScroll = 4;
sciThis->wheelMouseIntensity = cLineScroll;
}
if (event->direction == GDK_SCROLL_UP) {
cLineScroll *= -1;
}
g_get_current_time(&sciThis->lastWheelMouseTime);
sciThis->lastWheelMouseDirection = event->direction;
// Note: Unpatched versions of win32gtk don't set the 'state' value so
// only regular scrolling is supported there. Also, unpatched win32gtk
// issues spurious button 2 mouse events during wheeling, which can cause
// problems (a patch for both was submitted by archaeopteryx.com on 13Jun2001)
// Data zoom not supported
if (event->state & GDK_SHIFT_MASK) {
return FALSE;
}
// Text font size zoom
if (event->state & GDK_CONTROL_MASK) {
if (cLineScroll < 0) {
sciThis->KeyCommand(SCI_ZOOMIN);
return TRUE;
} else {
sciThis->KeyCommand(SCI_ZOOMOUT);
return TRUE;
}
// Regular scrolling
} else {
sciThis->ScrollTo(sciThis->topLine + cLineScroll);
return TRUE;
}
}
#endif
gint ScintillaGTK::Motion(GtkWidget *widget, GdkEventMotion *event) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("Motion %x %d\n",sciThis,event->time);
if (event->window != widget->window)
return FALSE;
int x = 0;
int y = 0;
GdkModifierType state;
if (event->is_hint) {
gdk_window_get_pointer(event->window, &x, &y, &state);
} else {
x = static_cast<int>(event->x);
y = static_cast<int>(event->y);
state = static_cast<GdkModifierType>(event->state);
}
//Platform::DebugPrintf("Move %x %x %d %c %d %d\n",
// sciThis,event->window,event->time,event->is_hint? 'h' :'.', x, y);
Point pt(x, y);
sciThis->ButtonMove(pt);
return FALSE;
}
// Map the keypad keys to their equivalent functions
static int KeyTranslate(int keyIn) {
switch (keyIn) {
case GDK_ISO_Left_Tab:
return SCK_TAB;
case GDK_KP_Down:
return SCK_DOWN;
case GDK_KP_Up:
return SCK_UP;
case GDK_KP_Left:
return SCK_LEFT;
case GDK_KP_Right:
return SCK_RIGHT;
case GDK_KP_Home:
return SCK_HOME;
case GDK_KP_End:
return SCK_END;
case GDK_KP_Page_Up:
return SCK_PRIOR;
case GDK_KP_Page_Down:
return SCK_NEXT;
case GDK_KP_Delete:
return SCK_DELETE;
case GDK_KP_Insert:
return SCK_INSERT;
case GDK_KP_Enter:
return SCK_RETURN;
case GDK_Down:
return SCK_DOWN;
case GDK_Up:
return SCK_UP;
case GDK_Left:
return SCK_LEFT;
case GDK_Right:
return SCK_RIGHT;
case GDK_Home:
return SCK_HOME;
case GDK_End:
return SCK_END;
case GDK_Page_Up:
return SCK_PRIOR;
case GDK_Page_Down:
return SCK_NEXT;
case GDK_Delete:
return SCK_DELETE;
case GDK_Insert:
return SCK_INSERT;
case GDK_Escape:
return SCK_ESCAPE;
case GDK_BackSpace:
return SCK_BACK;
case GDK_Tab:
return SCK_TAB;
case GDK_Return:
return SCK_RETURN;
case GDK_KP_Add:
return SCK_ADD;
case GDK_KP_Subtract:
return SCK_SUBTRACT;
case GDK_KP_Divide:
return SCK_DIVIDE;
default:
return keyIn;
}
}
gint ScintillaGTK::KeyThis(GdkEventKey *event) {
//Platform::DebugPrintf("SC-key: %d %x [%s]\n",
// event->keyval, event->state, (event->length > 0) ? event->string : "empty");
if (!event->keyval) {
return true;
}
bool shift = (event->state & GDK_SHIFT_MASK) != 0;
bool ctrl = (event->state & GDK_CONTROL_MASK) != 0;
bool alt = (event->state & GDK_MOD1_MASK) != 0;
int key = event->keyval;
if (ctrl && (key < 128))
key = toupper(key);
else if (!ctrl && (key >= GDK_KP_Multiply && key <= GDK_KP_9))
key &= 0x7F;
// Hack for keys over 256 and below command keys but makes Hungarian work.
// This will have to change for Unicode
else if (key >= 0xFE00)
key = KeyTranslate(key);
else if (IsUnicodeMode())
; // No operation
#if GTK_MAJOR_VERSION < 2
else if ((key >= 0x100) && (key < 0x1000))
key &= 0xff;
#endif
bool consumed = false;
bool added = KeyDown(key, shift, ctrl, alt, &consumed) != 0;
if (!consumed)
consumed = added;
//Platform::DebugPrintf("SK-key: %d %x %x\n",event->keyval, event->state, consumed);
if (event->keyval == 0xffffff && event->length > 0) {
ClearSelection();
if (pdoc->InsertString(CurrentPosition(), event->string)) {
MovePositionTo(CurrentPosition() + event->length);
}
}
return consumed;
}
gint ScintillaGTK::KeyPress(GtkWidget *widget, GdkEventKey *event) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
return sciThis->KeyThis(event);
}
gint ScintillaGTK::KeyRelease(GtkWidget *, GdkEventKey * /*event*/) {
//Platform::DebugPrintf("SC-keyrel: %d %x %3s\n",event->keyval, event->state, event->string);
return FALSE;
}
void ScintillaGTK::Destroy(GtkObject* object) {
ScintillaObject *scio = reinterpret_cast<ScintillaObject *>(object);
// This avoids a double destruction
if (!scio->pscin)
return;
ScintillaGTK *sciThis = reinterpret_cast<ScintillaGTK *>(scio->pscin);
//Platform::DebugPrintf("Destroying %x %x\n", sciThis, object);
sciThis->Finalise();
if (GTK_OBJECT_CLASS (parent_class)->destroy)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
delete sciThis;
scio->pscin = 0;
}
static void DrawChild(GtkWidget *widget, GdkRectangle *area) {
GdkRectangle areaIntersect;
if (widget &&
GTK_WIDGET_DRAWABLE(widget) &&
gtk_widget_intersect(widget, area, &areaIntersect)) {
gtk_widget_draw(widget, &areaIntersect);
}
}
void ScintillaGTK::Draw(GtkWidget *widget, GdkRectangle *area) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("Draw %p %0d,%0d %0d,%0d\n", widget, area->x, area->y, area->width, area->height);
PRectangle rcPaint(area->x, area->y, area->x + area->width, area->y + area->height);
sciThis->SyncPaint(rcPaint);
if (GTK_WIDGET_DRAWABLE(PWidget(sciThis->wMain))) {
DrawChild(PWidget(sciThis->scrollbarh), area);
DrawChild(PWidget(sciThis->scrollbarv), area);
}
#ifdef INTERNATIONAL_INPUT
Point pt = sciThis->LocationFromPosition(sciThis->currentPos);
pt.y += sciThis->vs.lineHeight - 2;
if (pt.x < 0) pt.x = 0;
if (pt.y < 0) pt.y = 0;
CursorMoved(widget, pt.x, pt.y, sciThis);
#endif
}
gint ScintillaGTK::ExposeTextThis(GtkWidget * /*widget*/, GdkEventExpose *ose) {
paintState = painting;
rcPaint.left = ose->area.x;
rcPaint.top = ose->area.y;
rcPaint.right = ose->area.x + ose->area.width;
rcPaint.bottom = ose->area.y + ose->area.height;
PRectangle rcClient = GetClientRectangle();
paintingAllText = rcPaint.Contains(rcClient);
Surface *surfaceWindow = Surface::Allocate();
if (surfaceWindow) {
surfaceWindow->Init(PWidget(wText)->window, PWidget(wText));
Paint(surfaceWindow, rcPaint);
surfaceWindow->Release();
delete surfaceWindow;
}
if (paintState == paintAbandoned) {
// Painting area was insufficient to cover new styling or brace highlight positions
FullPaint();
}
paintState = notPainting;
return FALSE;
}
gint ScintillaGTK::ExposeText(GtkWidget *widget, GdkEventExpose *ose, ScintillaGTK *sciThis) {
return sciThis->ExposeTextThis(widget, ose);
}
gint ScintillaGTK::ExposeMain(GtkWidget *widget, GdkEventExpose *ose) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("Expose Main %0d,%0d %0d,%0d\n",
//ose->area.x, ose->area.y, ose->area.width, ose->area.height);
return sciThis->Expose(widget, ose);
}
gint ScintillaGTK::Expose(GtkWidget *, GdkEventExpose *ose) {
//fprintf(stderr, "Expose %0d,%0d %0d,%0d\n",
//ose->area.x, ose->area.y, ose->area.width, ose->area.height);
#if GTK_MAJOR_VERSION < 2
paintState = painting;
rcPaint.left = ose->area.x;
rcPaint.top = ose->area.y;
rcPaint.right = ose->area.x + ose->area.width;
rcPaint.bottom = ose->area.y + ose->area.height;
PRectangle rcClient = GetClientRectangle();
paintingAllText = rcPaint.Contains(rcClient);
Surface *surfaceWindow = Surface::Allocate();
if (surfaceWindow) {
surfaceWindow->Init(PWidget(wMain)->window, PWidget(wMain));
// Fill the corner between the scrollbars
if (verticalScrollBarVisible) {
if (horizontalScrollBarVisible && (wrapState == eWrapNone)) {
PRectangle rcCorner = wMain.GetClientPosition();
rcCorner.left = rcCorner.right - scrollBarWidth + 1;
rcCorner.top = rcCorner.bottom - scrollBarHeight + 1;
//fprintf(stderr, "Corner %0d,%0d %0d,%0d\n",
//rcCorner.left, rcCorner.top, rcCorner.right, rcCorner.bottom);
surfaceWindow->FillRectangle(rcCorner,
vs.styles[STYLE_LINENUMBER].back.allocated);
}
}
//Paint(surfaceWindow, rcPaint);
surfaceWindow->Release();
delete surfaceWindow;
}
if (paintState == paintAbandoned) {
// Painting area was insufficient to cover new styling or brace highlight positions
FullPaint();
}
paintState = notPainting;
#else
// For GTK+ 2, the text is painted in ExposeText
gtk_container_propagate_expose(
GTK_CONTAINER(PWidget(wMain)), PWidget(scrollbarh), ose);
gtk_container_propagate_expose(
GTK_CONTAINER(PWidget(wMain)), PWidget(scrollbarv), ose);
#endif
return FALSE;
}
void ScintillaGTK::ScrollSignal(GtkAdjustment *adj, ScintillaGTK *sciThis) {
sciThis->ScrollTo(static_cast<int>(adj->value), false);
}
void ScintillaGTK::ScrollHSignal(GtkAdjustment *adj, ScintillaGTK *sciThis) {
sciThis->HorizontalScrollTo(static_cast<int>(adj->value * 2));
}
void ScintillaGTK::SelectionReceived(GtkWidget *widget,
GtkSelectionData *selection_data, guint) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("Selection received\n");
sciThis->ReceivedSelection(selection_data);
}
void ScintillaGTK::SelectionGet(GtkWidget *widget,
GtkSelectionData *selection_data, guint info, guint) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("Selection get\n");
sciThis->GetSelection(selection_data, info, &sciThis->copyText);
}
gint ScintillaGTK::SelectionClear(GtkWidget *widget, GdkEventSelection *selection_event) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("Selection clear\n");
sciThis->UnclaimSelection(selection_event);
return gtk_selection_clear(widget, selection_event);
}
#if GTK_MAJOR_VERSION < 2
gint ScintillaGTK::SelectionNotify(GtkWidget *widget, GdkEventSelection *selection_event) {
//Platform::DebugPrintf("Selection notify\n");
return gtk_selection_notify(widget, selection_event);
}
#endif
void ScintillaGTK::DragBegin(GtkWidget *, GdkDragContext *) {
//Platform::DebugPrintf("DragBegin\n");
}
gboolean ScintillaGTK::DragMotion(GtkWidget *widget, GdkDragContext *context,
gint x, gint y, guint dragtime) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("DragMotion %d %d %x %x %x\n", x, y,
// context->actions, context->suggested_action, sciThis);
Point npt(x, y);
sciThis->inDragDrop = true;
sciThis->SetDragPosition(sciThis->PositionFromLocation(npt));
gdk_drag_status(context, context->suggested_action, dragtime);
return FALSE;
}
void ScintillaGTK::DragLeave(GtkWidget *widget, GdkDragContext * /*context*/, guint) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
sciThis->SetDragPosition(invalidPosition);
//Platform::DebugPrintf("DragLeave %x\n", sciThis);
}
void ScintillaGTK::DragEnd(GtkWidget *widget, GdkDragContext * /*context*/) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
// If drag did not result in drop here or elsewhere
if (!sciThis->dragWasDropped)
sciThis->SetEmptySelection(sciThis->posDrag);
sciThis->SetDragPosition(invalidPosition);
//Platform::DebugPrintf("DragEnd %x %d\n", sciThis, sciThis->dragWasDropped);
}
gboolean ScintillaGTK::Drop(GtkWidget *widget, GdkDragContext * /*context*/,
gint, gint, guint) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
//Platform::DebugPrintf("Drop %x\n", sciThis);
sciThis->SetDragPosition(invalidPosition);
return FALSE;
}
void ScintillaGTK::DragDataReceived(GtkWidget *widget, GdkDragContext * /*context*/,
gint, gint, GtkSelectionData *selection_data, guint /*info*/, guint) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
sciThis->ReceivedDrop(selection_data);
sciThis->SetDragPosition(invalidPosition);
}
void ScintillaGTK::DragDataGet(GtkWidget *widget, GdkDragContext *context,
GtkSelectionData *selection_data, guint info, guint) {
ScintillaGTK *sciThis = ScintillaFromWidget(widget);
sciThis->dragWasDropped = true;
if (sciThis->currentPos != sciThis->anchor) {
sciThis->GetSelection(selection_data, info, &sciThis->drag);
}
if (context->action == GDK_ACTION_MOVE) {
int selStart = sciThis->SelectionStart();
int selEnd = sciThis->SelectionEnd();
if (sciThis->posDrop > selStart) {
if (sciThis->posDrop > selEnd)
sciThis->posDrop = sciThis->posDrop - (selEnd - selStart);
else
sciThis->posDrop = selStart;
sciThis->posDrop = sciThis->pdoc->ClampPositionIntoDocument(sciThis->posDrop);
}
sciThis->ClearSelection();
}
sciThis->SetDragPosition(invalidPosition);
}
int ScintillaGTK::TimeOut(ScintillaGTK *sciThis) {
sciThis->Tick();
return 1;
}
int ScintillaGTK::IdleCallback(ScintillaGTK *sciThis) {
// Idler will be automatically stoped, if there is nothing
// to do while idle.
bool ret = sciThis->Idle();
if (ret == false) {
// FIXME: This will remove the idler from GTK, we don't want to
// remove it as it is removed automatically when this function
// returns false (although, it should be harmless).
sciThis->SetIdle(false);
}
return ret;
}
void ScintillaGTK::PopUpCB(ScintillaGTK *sciThis, guint action, GtkWidget *) {
if (action) {
sciThis->Command(action);
}
}
gint ScintillaGTK::PressCT(GtkWidget *widget, GdkEventButton *event, ScintillaGTK *sciThis) {
if (event->window != widget->window)
return FALSE;
if (event->type != GDK_BUTTON_PRESS)
return FALSE;
Point pt;
pt.x = int(event->x);
pt.y = int(event->y);
sciThis->ct.MouseClick(pt);
sciThis->CallTipClick();
#if GTK_MAJOR_VERSION >= 2
return TRUE;
#else
return FALSE;
#endif
}
gint ScintillaGTK::ExposeCT(GtkWidget *widget, GdkEventExpose * /*ose*/, CallTip *ctip) {
Surface *surfaceWindow = Surface::Allocate();
if (surfaceWindow) {
surfaceWindow->Init(widget->window, widget);
ctip->PaintCT(surfaceWindow);
surfaceWindow->Release();
delete surfaceWindow;
}
return TRUE;
}
sptr_t ScintillaGTK::DirectFunction(
ScintillaGTK *sciThis, unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
return sciThis->WndProc(iMessage, wParam, lParam);
}
sptr_t scintilla_send_message(ScintillaObject *sci, unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
ScintillaGTK *psci = reinterpret_cast<ScintillaGTK *>(sci->pscin);
return psci->WndProc(iMessage, wParam, lParam);
}
static void scintilla_class_init (ScintillaClass *klass);
static void scintilla_init (ScintillaObject *sci);
extern void Platform_Initialise();
extern void Platform_Finalise();
guint scintilla_get_type() {
static guint scintilla_type = 0;
if (!scintilla_type) {
Platform_Initialise();
static GtkTypeInfo scintilla_info = {
"Scintilla",
sizeof (ScintillaObject),
sizeof (ScintillaClass),
(GtkClassInitFunc) scintilla_class_init,
(GtkObjectInitFunc) scintilla_init,
(gpointer) NULL,
(gpointer) NULL,
0
};
scintilla_type = gtk_type_unique(gtk_container_get_type(), &scintilla_info);
}
return scintilla_type;
}
void ScintillaGTK::ClassInit(GtkObjectClass* object_class, GtkWidgetClass *widget_class) {
// Define default signal handlers for the class: Could move more
// of the signal handlers here (those that currently attached to wDraw
// in Initialise() may require coordinate translation?)
object_class->destroy = Destroy;
widget_class->size_request = SizeRequest;
widget_class->size_allocate = SizeAllocate;
widget_class->expose_event = ExposeMain;
#if GTK_MAJOR_VERSION < 2
widget_class->draw = Draw;
#endif
widget_class->motion_notify_event = Motion;
widget_class->button_press_event = Press;
widget_class->button_release_event = MouseRelease;
#if PLAT_GTK_WIN32 || (GTK_MAJOR_VERSION >= 2)
widget_class->scroll_event = ScrollEvent;
#endif
widget_class->key_press_event = KeyPress;
widget_class->key_release_event = KeyRelease;
widget_class->focus_in_event = FocusIn;
widget_class->focus_out_event = FocusOut;
widget_class->selection_received = SelectionReceived;
widget_class->selection_get = SelectionGet;
widget_class->selection_clear_event = SelectionClear;
#if GTK_MAJOR_VERSION < 2
widget_class->selection_notify_event = SelectionNotify;
#endif
widget_class->drag_data_received = DragDataReceived;
widget_class->drag_motion = DragMotion;
widget_class->drag_leave = DragLeave;
widget_class->drag_end = DragEnd;
widget_class->drag_drop = Drop;
widget_class->drag_data_get = DragDataGet;
widget_class->realize = Realize;
widget_class->unrealize = UnRealize;
widget_class->map = Map;
widget_class->unmap = UnMap;
}
#if GTK_MAJOR_VERSION < 2
#define GTK_CLASS_TYPE(c) (c->type)
#define SIG_MARSHAL gtk_marshal_NONE__INT_POINTER
#define MARSHAL_ARGUMENTS GTK_TYPE_INT, GTK_TYPE_POINTER
#else
#define SIG_MARSHAL gtk_marshal_NONE__INT_INT
#define MARSHAL_ARGUMENTS GTK_TYPE_INT, GTK_TYPE_INT
#endif
static void scintilla_class_init(ScintillaClass *klass) {
GtkObjectClass *object_class = (GtkObjectClass*) klass;
GtkWidgetClass *widget_class = (GtkWidgetClass*) klass;
parent_class = (GtkWidgetClass*) gtk_type_class(gtk_container_get_type());
scintilla_signals[COMMAND_SIGNAL] = gtk_signal_new(
"command",
GTK_RUN_LAST,
GTK_CLASS_TYPE(object_class),
GTK_SIGNAL_OFFSET(ScintillaClass, command),
SIG_MARSHAL,
GTK_TYPE_NONE,
2, MARSHAL_ARGUMENTS);
scintilla_signals[NOTIFY_SIGNAL] = gtk_signal_new(
SCINTILLA_NOTIFY,
GTK_RUN_LAST,
GTK_CLASS_TYPE(object_class),
GTK_SIGNAL_OFFSET(ScintillaClass, notify),
SIG_MARSHAL,
GTK_TYPE_NONE,
2, MARSHAL_ARGUMENTS);
#if GTK_MAJOR_VERSION < 2
gtk_object_class_add_signals(object_class,
reinterpret_cast<unsigned int *>(scintilla_signals), LAST_SIGNAL);
#endif
klass->command = NULL;
klass->notify = NULL;
ScintillaGTK::ClassInit(object_class, widget_class);
}
static void scintilla_init(ScintillaObject *sci) {
GTK_WIDGET_SET_FLAGS(sci, GTK_CAN_FOCUS);
sci->pscin = new ScintillaGTK(sci);
}
GtkWidget* scintilla_new() {
return GTK_WIDGET(gtk_type_new(scintilla_get_type()));
}
void scintilla_set_id(ScintillaObject *sci, int id) {
ScintillaGTK *psci = reinterpret_cast<ScintillaGTK *>(sci->pscin);
psci->ctrlID = id;
}
void scintilla_release_resources(void) {
Platform_Finalise();
}
|