]> git.saurik.com Git - wxWidgets.git/blob - src/stc/gen_iface.py
avoid setting pango matrix when not needed
[wxWidgets.git] / src / stc / gen_iface.py
1 #!/usr/bin/env python
2 #----------------------------------------------------------------------------
3 # Name: gen_iface.py
4 # Purpose: Generate stc.h and stc.cpp from the info in Scintilla.iface
5 #
6 # Author: Robin Dunn
7 #
8 # Created: 5-Sept-2000
9 # Copyright: (c) 2000 by Total Control Software
10 # Licence: wxWindows licence
11 #----------------------------------------------------------------------------
12
13
14 import sys, string, re, os
15 from fileinput import FileInput
16
17
18 IFACE = os.path.abspath('./scintilla/include/Scintilla.iface')
19 H_TEMPLATE = os.path.abspath('./stc.h.in')
20 IH_TEMPLATE = os.path.abspath('./stc.interface.h.in')
21 CPP_TEMPLATE = os.path.abspath('./stc.cpp.in')
22 H_DEST = os.path.abspath('../../include/wx/stc/stc.h')
23 IH_DEST = os.path.abspath('../../interface/wx/stc/stc.h')
24 CPP_DEST = os.path.abspath('./stc.cpp')
25 if len(sys.argv) > 1 and sys.argv[1] == '--wxpython':
26 DOCSTR_DEST = os.path.abspath('../../../wxPython/src/_stc_gendocs.i')
27 else:
28 DOCSTR_DEST = None
29
30
31 # Value prefixes to convert
32 valPrefixes = [('SCI_', ''),
33 ('SC_', ''),
34 ('SCN_', None), # just toss these out...
35 ('SCEN_', None),
36 ('SC_EFF', None),
37 ('SCE_', ''),
38 ('SCLEX_', 'LEX_'),
39 ('SCK_', 'KEY_'),
40 ('SCFIND_', 'FIND_'),
41 ('SCWS_', 'WS_'),
42 ]
43
44 # Message function values that should have a CMD_ constant generated
45 cmdValues = [ 2011,
46 2013,
47 (2176, 2180),
48 (2300, 2349),
49 (2390, 2393),
50 (2395, 2396),
51 2404,
52 (2413, 2416),
53 (2426, 2442),
54 (2450, 2455),
55 2518,
56 (2619, 2621),
57 (2628, 2629)
58 ]
59
60
61 # Should a funciton be also generated for the CMDs?
62 FUNC_FOR_CMD = 1
63
64
65 # Map some generic typenames to wx types, using return value syntax
66 retTypeMap = {
67 'position': 'int',
68 'string': 'wxString',
69 'colour': 'wxColour',
70 }
71
72 # Map some generic typenames to wx types, using parameter syntax
73 paramTypeMap = {
74 'position': 'int',
75 'string': 'const wxString&',
76 'colour': 'const wxColour&',
77 'keymod': 'int',
78 }
79
80 # Map of method info that needs tweaked. Either the name needs changed, or
81 # the method definition/implementation. Tuple items are:
82 #
83 # 1. New method name. None to skip the method, 0 to leave the
84 # default name.
85 # 2. Method definition for the .h file, 0 to leave alone
86 # 3. Method implementation for the .cpp file, 0 to leave alone.
87 # 4. tuple of Doc string lines, or 0 to leave alone.
88 #
89 methodOverrideMap = {
90 'AddText' : (0,
91 'void %s(const wxString& text);',
92
93 '''void %s(const wxString& text) {
94 const wxWX2MBbuf buf = wx2stc(text);
95 SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
96 0),
97
98 'AddStyledText' : (0,
99 'void %s(const wxMemoryBuffer& data);',
100
101 '''void %s(const wxMemoryBuffer& data) {
102 SendMsg(%s, data.GetDataLen(), (sptr_t)data.GetData());''',
103 0),
104
105 'AppendText' : (0,
106 'void %s(const wxString& text);',
107
108 '''void %s(const wxString& text) {
109 const wxWX2MBbuf buf = wx2stc(text);
110 SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
111 0),
112
113 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
114 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
115
116 'GetCharAt' :
117 ( 0, 0,
118 '''int %s(int pos) const {
119 return (unsigned char)SendMsg(%s, pos, 0);''',
120 0),
121
122 'GetStyleAt' :
123 ( 0, 0,
124 '''int %s(int pos) const {
125 return (unsigned char)SendMsg(%s, pos, 0);''',
126 0),
127
128 'GetStyledText' :
129 (0,
130 'wxMemoryBuffer %s(int startPos, int endPos);',
131
132 '''wxMemoryBuffer %s(int startPos, int endPos) {
133 wxMemoryBuffer buf;
134 if (endPos < startPos) {
135 int temp = startPos;
136 startPos = endPos;
137 endPos = temp;
138 }
139 int len = endPos - startPos;
140 if (!len) return buf;
141 TextRange tr;
142 tr.lpstrText = (char*)buf.GetWriteBuf(len*2+1);
143 tr.chrg.cpMin = startPos;
144 tr.chrg.cpMax = endPos;
145 len = SendMsg(%s, 0, (sptr_t)&tr);
146 buf.UngetWriteBuf(len);
147 return buf;''',
148
149 ('Retrieve a buffer of cells.',)),
150
151
152 'PositionFromPoint' :
153 (0,
154 'int %s(wxPoint pt) const;',
155
156 '''int %s(wxPoint pt) const {
157 return SendMsg(%s, pt.x, pt.y);''',
158 0),
159
160 'GetCurLine' :
161 (0,
162 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
163
164 '''wxString %s(int* linePos) {
165 int len = LineLength(GetCurrentLine());
166 if (!len) {
167 if (linePos) *linePos = 0;
168 return wxEmptyString;
169 }
170
171 wxMemoryBuffer mbuf(len+1);
172 char* buf = (char*)mbuf.GetWriteBuf(len+1);
173
174 int pos = SendMsg(%s, len+1, (sptr_t)buf);
175 mbuf.UngetWriteBuf(len);
176 mbuf.AppendByte(0);
177 if (linePos) *linePos = pos;
178 return stc2wx(buf);''',
179
180 0),
181
182 'SetUsePalette' : (None, 0,0,0),
183
184 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
185 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
186 'MarkerSetBackSelected' : ('MarkerSetBackgroundSelected', 0,0,0),
187
188 'MarkerSymbolDefined' : ('GetMarkerSymbolDefined', 0, 0, 0),
189
190 'MarkerDefine' :
191 (0,
192 '''void %s(int markerNumber, int markerSymbol,
193 const wxColour& foreground = wxNullColour,
194 const wxColour& background = wxNullColour);''',
195
196 '''void %s(int markerNumber, int markerSymbol,
197 const wxColour& foreground,
198 const wxColour& background) {
199
200 SendMsg(%s, markerNumber, markerSymbol);
201 if (foreground.IsOk())
202 MarkerSetForeground(markerNumber, foreground);
203 if (background.IsOk())
204 MarkerSetBackground(markerNumber, background);''',
205
206 ('Set the symbol used for a particular marker number,',
207 'and optionally the fore and background colours.')),
208
209
210 'MarkerDefinePixmap' :
211 ('MarkerDefineBitmap',
212 '''void %s(int markerNumber, const wxBitmap& bmp);''',
213 '''void %s(int markerNumber, const wxBitmap& bmp) {
214 // convert bmp to a xpm in a string
215 wxMemoryOutputStream strm;
216 wxImage img = bmp.ConvertToImage();
217 if (img.HasAlpha())
218 img.ConvertAlphaToMask();
219 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
220 size_t len = strm.GetSize();
221 char* buff = new char[len+1];
222 strm.CopyTo(buff, len);
223 buff[len] = 0;
224 SendMsg(%s, markerNumber, (sptr_t)buff);
225 delete [] buff;
226 ''',
227 ('Define a marker from a bitmap',)),
228
229
230 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
231 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
232 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
233 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
234 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
235 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
236 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
237 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
238 'SetMarginCursorN' : ('SetMarginCursor', 0, 0, 0),
239 'GetMarginCursorN' : ('GetMarginCursor', 0, 0, 0),
240
241 'MarginGetText' :
242 (0,
243 'wxString %s(int line) const;',
244
245 '''wxString %s(int line) const {
246 long msg = %s;
247 long len = SendMsg(msg, line, 0);
248
249 wxMemoryBuffer mbuf(len+1);
250 char* buf = (char*)mbuf.GetWriteBuf(len+1);
251 SendMsg(msg, line, (sptr_t)buf);
252 mbuf.UngetWriteBuf(len);
253 mbuf.AppendByte(0);
254 return stc2wx(buf);''',
255 0),
256
257 'MarginGetStyles' :
258 (0,
259 'wxString %s(int line) const;',
260
261 '''wxString %s(int line) const {
262 long msg = %s;
263 long len = SendMsg(msg, line, 0);
264
265 wxMemoryBuffer mbuf(len+1);
266 char* buf = (char*)mbuf.GetWriteBuf(len+1);
267 SendMsg(msg, line, (sptr_t)buf);
268 mbuf.UngetWriteBuf(len);
269 mbuf.AppendByte(0);
270 return stc2wx(buf);''',
271 0),
272
273 'SetAdditionalSelFore' : ('SetAdditionalSelForeground', 0, 0, 0),
274 'SetAdditionalSelBack' : ('SetAdditionalSelBackground', 0, 0, 0),
275 'SetAdditionalCaretFore' : ('SetAdditionalCaretForeground', 0, 0, 0),
276 'GetAdditionalCaretFore' : ('GetAdditionalCaretForeground', 0, 0, 0),
277
278 'AnnotationGetText' :
279 (0,
280 'wxString %s(int line) const;',
281
282 '''wxString %s(int line) const {
283 long msg = %s;
284 long len = SendMsg(msg, line, 0);
285
286 wxMemoryBuffer mbuf(len+1);
287 char* buf = (char*)mbuf.GetWriteBuf(len+1);
288 SendMsg(msg, line, (sptr_t)buf);
289 mbuf.UngetWriteBuf(len);
290 mbuf.AppendByte(0);
291 return stc2wx(buf);''',
292 0),
293
294 'AnnotationGetStyles' :
295 (0,
296 'wxString %s(int line) const;',
297
298 '''wxString %s(int line) const {
299 long msg = %s;
300 long len = SendMsg(msg, line, 0);
301
302 wxMemoryBuffer mbuf(len+1);
303 char* buf = (char*)mbuf.GetWriteBuf(len+1);
304 SendMsg(msg, line, (sptr_t)buf);
305 mbuf.UngetWriteBuf(len);
306 mbuf.AppendByte(0);
307 return stc2wx(buf);''',
308 0),
309
310 'StyleGetFore' : ('StyleGetForeground', 0, 0, 0),
311 'StyleGetBack' : ('StyleGetBackground', 0, 0, 0),
312 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
313 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
314 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
315 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
316 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
317 'StyleGetFont' :
318 ('StyleGetFaceName',
319 'wxString %s(int style);',
320 '''wxString %s(int style) {
321 long msg = %s;
322 long len = SendMsg(msg, style, 0);
323 wxMemoryBuffer mbuf(len+1);
324 char* buf = (char*)mbuf.GetWriteBuf(len+1);
325 SendMsg(msg, style, (sptr_t)buf);
326 mbuf.UngetWriteBuf(len);
327 mbuf.AppendByte(0);
328 return stc2wx(buf);''',
329 ('Get the font facename of a style',)),
330 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
331 'StyleSetCharacterSet' : (None, 0, 0, 0),
332
333 'AssignCmdKey' :
334 ('CmdKeyAssign',
335 'void %s(int key, int modifiers, int cmd);',
336
337 '''void %s(int key, int modifiers, int cmd) {
338 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
339 0),
340
341
342 'ClearCmdKey' :
343 ('CmdKeyClear',
344 'void %s(int key, int modifiers);',
345
346 '''void %s(int key, int modifiers) {
347 SendMsg(%s, MAKELONG(key, modifiers));''',
348 0),
349
350 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
351
352
353 'SetStylingEx' :
354 ('SetStyleBytes',
355 'void %s(int length, char* styleBytes);',
356
357 '''void %s(int length, char* styleBytes) {
358 SendMsg(%s, length, (sptr_t)styleBytes);''',
359 0),
360
361
362 'IndicSetAlpha' : ('IndicatorSetAlpha', 0, 0, 0),
363 'IndicGetAlpha' : ('IndicatorGetAlpha', 0, 0, 0),
364 'IndicSetOutlineAlpha' : ('IndicatorSetOutlineAlpha', 0, 0, 0),
365 'IndicGetOutlineAlpha' : ('IndicatorGetOutlineAlpha', 0, 0, 0),
366 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
367 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
368 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
369 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
370 'IndicSetUnder': ('IndicatorSetUnder', 0, 0, 0),
371 'IndicGetUnder': ('IndicatorGetUnder', 0, 0, 0),
372
373 'SetWhitespaceFore' : ('SetWhitespaceForeground', 0, 0, 0),
374 'SetWhitespaceBack' : ('SetWhitespaceBackground', 0, 0, 0),
375
376 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
377 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
378 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
379 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
380 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
381 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
382 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
383 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
384 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
385 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
386 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
387 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
388 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
389 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
390 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
391 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
392 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
393 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
394 'AutoCSetDropRestOfWord' : ('AutoCompSetDropRestOfWord', 0,0,0),
395 'AutoCGetDropRestOfWord' : ('AutoCompGetDropRestOfWord', 0,0,0),
396 'AutoCGetTypeSeparator' : ('AutoCompGetTypeSeparator', 0, 0, 0),
397 'AutoCSetTypeSeparator' : ('AutoCompSetTypeSeparator', 0, 0, 0),
398 'AutoCGetCurrent' : ('AutoCompGetCurrent', 0, 0, 0),
399 'AutoCGetCurrentText' : (None, 0, 0, 0),
400 'AutoCSetMaxWidth' : ('AutoCompSetMaxWidth', 0, 0, 0),
401 'AutoCGetMaxWidth' : ('AutoCompGetMaxWidth', 0, 0, 0),
402 'AutoCSetMaxHeight' : ('AutoCompSetMaxHeight', 0, 0, 0),
403 'AutoCGetMaxHeight' : ('AutoCompGetMaxHeight', 0, 0, 0),
404 'AutoCGetMaxHeight' : ('AutoCompGetMaxHeight', 0, 0, 0),
405 'AutoCSetCaseInsensitiveBehaviour' : ('AutoCompSetCaseInsensitiveBehaviour', 0, 0, 0),
406 'AutoCGetCaseInsensitiveBehaviour' : ('AutoCompGetCaseInsensitiveBehaviour', 0, 0, 0),
407
408 'RegisterImage' :
409 (0,
410 '''void %s(int type, const wxBitmap& bmp);''',
411 '''void %s(int type, const wxBitmap& bmp) {
412 // convert bmp to a xpm in a string
413 wxMemoryOutputStream strm;
414 wxImage img = bmp.ConvertToImage();
415 if (img.HasAlpha())
416 img.ConvertAlphaToMask();
417 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
418 size_t len = strm.GetSize();
419 char* buff = new char[len+1];
420 strm.CopyTo(buff, len);
421 buff[len] = 0;
422 SendMsg(%s, type, (sptr_t)buff);
423 delete [] buff;
424 ''',
425 ('Register an image for use in autocompletion lists.',)),
426
427
428 'ClearRegisteredImages' : (0, 0, 0,
429 ('Clear all the registered images.',)),
430
431
432 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
433 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
434
435 'SetVScrollBar' : ('SetUseVerticalScrollBar', 0, 0, 0),
436 'GetVScrollBar' : ('GetUseVerticalScrollBar', 0, 0, 0),
437
438 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
439
440 'GetUsePalette' : (None, 0, 0, 0),
441
442 'FindText' :
443 (0,
444 '''int %s(int minPos, int maxPos, const wxString& text, int flags=0);''',
445
446 '''int %s(int minPos, int maxPos,
447 const wxString& text,
448 int flags) {
449 TextToFind ft;
450 ft.chrg.cpMin = minPos;
451 ft.chrg.cpMax = maxPos;
452 const wxWX2MBbuf buf = wx2stc(text);
453 ft.lpstrText = (char*)(const char*)buf;
454
455 return SendMsg(%s, flags, (sptr_t)&ft);''',
456 0),
457
458 'FormatRange' :
459 (0,
460 '''int %s(bool doDraw,
461 int startPos,
462 int endPos,
463 wxDC* draw,
464 wxDC* target,
465 wxRect renderRect,
466 wxRect pageRect);''',
467 ''' int %s(bool doDraw,
468 int startPos,
469 int endPos,
470 wxDC* draw,
471 wxDC* target,
472 wxRect renderRect,
473 wxRect pageRect) {
474 RangeToFormat fr;
475
476 if (endPos < startPos) {
477 int temp = startPos;
478 startPos = endPos;
479 endPos = temp;
480 }
481 fr.hdc = draw;
482 fr.hdcTarget = target;
483 fr.rc.top = renderRect.GetTop();
484 fr.rc.left = renderRect.GetLeft();
485 fr.rc.right = renderRect.GetRight();
486 fr.rc.bottom = renderRect.GetBottom();
487 fr.rcPage.top = pageRect.GetTop();
488 fr.rcPage.left = pageRect.GetLeft();
489 fr.rcPage.right = pageRect.GetRight();
490 fr.rcPage.bottom = pageRect.GetBottom();
491 fr.chrg.cpMin = startPos;
492 fr.chrg.cpMax = endPos;
493
494 return SendMsg(%s, doDraw, (sptr_t)&fr);''',
495 0),
496
497
498 'GetLine' :
499 (0,
500 'wxString %s(int line) const;',
501
502 '''wxString %s(int line) const {
503 int len = LineLength(line);
504 if (!len) return wxEmptyString;
505
506 wxMemoryBuffer mbuf(len+1);
507 char* buf = (char*)mbuf.GetWriteBuf(len+1);
508 SendMsg(%s, line, (sptr_t)buf);
509 mbuf.UngetWriteBuf(len);
510 mbuf.AppendByte(0);
511 return stc2wx(buf);''',
512
513 ('Retrieve the contents of a line.',)),
514
515 'SetSel' : (None, 0,0,0), #'SetSelection', 0, 0, 0),
516
517 'GetSelText' :
518 ('GetSelectedText',
519 'wxString %s();',
520
521 '''wxString %s() {
522 const int len = SendMsg(SCI_GETSELTEXT, 0, (sptr_t)0);
523 if (!len) return wxEmptyString;
524
525 wxMemoryBuffer mbuf(len+2);
526 char* buf = (char*)mbuf.GetWriteBuf(len+1);
527 SendMsg(%s, 0, (sptr_t)buf);
528 mbuf.UngetWriteBuf(len);
529 mbuf.AppendByte(0);
530 return stc2wx(buf);''',
531
532 ('Retrieve the selected text.',)),
533
534
535 'GetTextRange' :
536 (0,
537 'wxString %s(int startPos, int endPos);',
538
539 '''wxString %s(int startPos, int endPos) {
540 if (endPos < startPos) {
541 int temp = startPos;
542 startPos = endPos;
543 endPos = temp;
544 }
545 int len = endPos - startPos;
546 if (!len) return wxEmptyString;
547 wxMemoryBuffer mbuf(len+1);
548 char* buf = (char*)mbuf.GetWriteBuf(len);
549 TextRange tr;
550 tr.lpstrText = buf;
551 tr.chrg.cpMin = startPos;
552 tr.chrg.cpMax = endPos;
553 SendMsg(%s, 0, (sptr_t)&tr);
554 mbuf.UngetWriteBuf(len);
555 mbuf.AppendByte(0);
556 return stc2wx(buf);''',
557
558 ('Retrieve a range of text.',)),
559
560 'PointXFromPosition' : (None, 0, 0, 0),
561 'PointYFromPosition' : (None, 0, 0, 0),
562
563 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
564 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
565 'Null' : (None, 0, 0, 0),
566
567 'GetText' :
568 (0,
569 'wxString %s() const;',
570
571 '''wxString %s() const {
572 int len = GetTextLength();
573 wxMemoryBuffer mbuf(len+1); // leave room for the null...
574 char* buf = (char*)mbuf.GetWriteBuf(len+1);
575 SendMsg(%s, len+1, (sptr_t)buf);
576 mbuf.UngetWriteBuf(len);
577 mbuf.AppendByte(0);
578 return stc2wx(buf);''',
579
580 ('Retrieve all the text in the document.', )),
581
582 'GetDirectFunction' : (None, 0, 0, 0),
583 'GetDirectPointer' : (None, 0, 0, 0),
584
585 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
586 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
587 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
588 'CallTipSetFore' : ('CallTipSetForeground', 0, 0, 0),
589 'CallTipSetForeHlt' : ('CallTipSetForegroundHighlight', 0, 0, 0),
590
591 'SetHotspotActiveFore' : ('SetHotspotActiveForeground', 0, 0, 0),
592 'SetHotspotActiveBack' : ('SetHotspotActiveBackground', 0, 0, 0),
593 'GetHotspotActiveFore' : ('GetHotspotActiveForeground', 0, 0, 0),
594 'GetHotspotActiveBack' : ('GetHotspotActiveBackground', 0, 0, 0),
595
596 'GetCaretLineBack' : ('GetCaretLineBackground', 0, 0, 0),
597 'SetCaretLineBack' : ('SetCaretLineBackground', 0, 0, 0),
598
599 'ReplaceTarget' :
600 (0,
601 'int %s(const wxString& text);',
602
603 '''
604 int %s(const wxString& text) {
605 const wxWX2MBbuf buf = wx2stc(text);
606 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
607 0),
608
609 'ReplaceTargetRE' :
610 (0,
611 'int %s(const wxString& text);',
612
613 '''
614 int %s(const wxString& text) {
615 const wxWX2MBbuf buf = wx2stc(text);
616 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
617 0),
618
619 'SearchInTarget' :
620 (0,
621 'int %s(const wxString& text);',
622
623 '''
624 int %s(const wxString& text) {
625 const wxWX2MBbuf buf = wx2stc(text);
626 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
627 0),
628
629 # not sure what to do about these yet
630 'TargetAsUTF8' : ( None, 0, 0, 0),
631 'SetLengthForEncode' : ( None, 0, 0, 0),
632 'EncodedFromUTF8' : ( None, 0, 0, 0),
633
634
635 'GetProperty' :
636 (0,
637 'wxString %s(const wxString& key);',
638
639 '''wxString %s(const wxString& key) {
640 int len = SendMsg(SCI_GETPROPERTY, (sptr_t)(const char*)wx2stc(key), 0);
641 if (!len) return wxEmptyString;
642
643 wxMemoryBuffer mbuf(len+1);
644 char* buf = (char*)mbuf.GetWriteBuf(len+1);
645 SendMsg(%s, (uptr_t)(const char*)wx2stc(key), (sptr_t)buf);
646 mbuf.UngetWriteBuf(len);
647 mbuf.AppendByte(0);
648 return stc2wx(buf);''',
649 ("Retrieve a 'property' value previously set with SetProperty.",)),
650
651 'GetPropertyExpanded' :
652 (0,
653 'wxString %s(const wxString& key);',
654
655 '''wxString %s(const wxString& key) {
656 int len = SendMsg(SCI_GETPROPERTYEXPANDED, (uptr_t)(const char*)wx2stc(key), 0);
657 if (!len) return wxEmptyString;
658
659 wxMemoryBuffer mbuf(len+1);
660 char* buf = (char*)mbuf.GetWriteBuf(len+1);
661 SendMsg(%s, (uptr_t)(const char*)wx2stc(key), (sptr_t)buf);
662 mbuf.UngetWriteBuf(len);
663 mbuf.AppendByte(0);
664 return stc2wx(buf);''',
665 ("Retrieve a 'property' value previously set with SetProperty,",
666 "with '$()' variable replacement on returned buffer.")),
667
668 'GetPropertyInt' : (0, 0, 0,
669 ("Retrieve a 'property' value previously set with SetProperty,",
670 "interpreted as an int AFTER any '$()' variable replacement.")),
671
672
673 'GetDocPointer' :
674 (0,
675 'void* %s();',
676 '''void* %s() {
677 return (void*)SendMsg(%s);''',
678 0),
679
680 'SetDocPointer' :
681 (0,
682 'void %s(void* docPointer);',
683 '''void %s(void* docPointer) {
684 SendMsg(%s, 0, (sptr_t)docPointer);''',
685 0),
686
687 'CreateDocument' :
688 (0,
689 'void* %s();',
690 '''void* %s() {
691 return (void*)SendMsg(%s);''',
692 0),
693
694 'AddRefDocument' :
695 (0,
696 'void %s(void* docPointer);',
697 '''void %s(void* docPointer) {
698 SendMsg(%s, 0, (sptr_t)docPointer);''',
699 0),
700
701 'ReleaseDocument' :
702 (0,
703 'void %s(void* docPointer);',
704 '''void %s(void* docPointer) {
705 SendMsg(%s, 0, (sptr_t)docPointer);''',
706 0),
707
708 'SetCodePage' :
709 (0,
710 0,
711 '''void %s(int codePage) {
712 #if wxUSE_UNICODE
713 wxASSERT_MSG(codePage == wxSTC_CP_UTF8,
714 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
715 #else
716 wxASSERT_MSG(codePage != wxSTC_CP_UTF8,
717 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
718 #endif
719 SendMsg(%s, codePage);''',
720 ("Set the code page used to interpret the bytes of the document as characters.",) ),
721
722
723 'GrabFocus' : (None, 0, 0, 0),
724
725 # Rename some that would otherwise hide the wxWindow methods
726 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
727 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
728 'SetCursor' : ('SetSTCCursor', 0, 0, 0),
729 'GetCursor' : ('GetSTCCursor', 0, 0, 0),
730
731 'LoadLexerLibrary' : (None, 0,0,0),
732
733 'SetPositionCache' : ('SetPositionCacheSize', 0, 0, 0),
734 'GetPositionCache' : ('GetPositionCacheSize', 0, 0, 0),
735
736 'GetLexerLanguage' : (None, 0, 0, 0),
737 'SetFontQuality' : (None, 0, 0, 0),
738 'GetFontQuality' : (None, 0, 0, 0),
739 'SetSelection' : (None, 0, 0, 0),
740
741 'GetCharacterPointer' : (0,
742 'const char* %s() const;',
743 'const char* %s() const {\n'
744 ' return (const char*)SendMsg(%s, 0, 0);',
745 0),
746
747 'GetRangePointer' : (0,
748 'const char* %s(int position, int rangeLength) const;',
749 'const char* %s(int position, int rangeLength) const {\n'
750 ' return (const char*)SendMsg(%s, position, rangeLength);',
751 0),
752
753
754 'GetWordChars' :
755 (0,
756 'wxString %s() const;',
757
758 '''wxString %s() const {
759 int msg = %s;
760 int len = SendMsg(msg, 0, (sptr_t)NULL);
761 if (!len) return wxEmptyString;
762
763 wxMemoryBuffer mbuf(len+1);
764 char* buf = (char*)mbuf.GetWriteBuf(len+1);
765 SendMsg(msg, 0, (sptr_t)buf);
766 mbuf.UngetWriteBuf(len);
767 mbuf.AppendByte(0);
768 return stc2wx(buf);''',
769
770 ('Get the set of characters making up words for when moving or selecting by word.',)),
771
772 'GetTag' :
773 (0,
774 'wxString %s(int tagNumber) const;',
775
776 '''wxString %s(int tagNumber) const {
777 int msg = %s;
778 int len = SendMsg(msg, tagNumber, (sptr_t)NULL);
779 if (!len) return wxEmptyString;
780
781 wxMemoryBuffer mbuf(len+1);
782 char* buf = (char*)mbuf.GetWriteBuf(len+1);
783 SendMsg(msg, tagNumber, (sptr_t)buf);
784 mbuf.UngetWriteBuf(len);
785 mbuf.AppendByte(0);
786 return stc2wx(buf);''',
787 0),
788
789 'GetWhitespaceChars' :
790 (0,
791 'wxString %s() const;',
792
793 '''wxString %s() const {
794 int msg = %s;
795 int len = SendMsg(msg, 0, (sptr_t)NULL);
796 if (!len) return wxEmptyString;
797
798 wxMemoryBuffer mbuf(len+1);
799 char* buf = (char*)mbuf.GetWriteBuf(len+1);
800 SendMsg(msg, 0, (sptr_t)buf);
801 mbuf.UngetWriteBuf(len);
802 mbuf.AppendByte(0);
803 return stc2wx(buf);''',
804 0),
805
806
807 'GetPunctuationChars' :
808 (0,
809 'wxString %s() const;',
810
811 '''wxString %s() const {
812 int msg = %s;
813 int len = SendMsg(msg, 0, (sptr_t)NULL);
814 if (!len) return wxEmptyString;
815
816 wxMemoryBuffer mbuf(len+1);
817 char* buf = (char*)mbuf.GetWriteBuf(len+1);
818 SendMsg(msg, 0, (sptr_t)buf);
819 mbuf.UngetWriteBuf(len);
820 mbuf.AppendByte(0);
821 return stc2wx(buf);''',
822 0),
823
824
825 'PropertyNames' :
826 (0,
827 'wxString %s() const;',
828
829 '''wxString %s() const {
830 int msg = %s;
831 int len = SendMsg(msg, 0, (sptr_t)NULL);
832 if (!len) return wxEmptyString;
833
834 wxMemoryBuffer mbuf(len+1);
835 char* buf = (char*)mbuf.GetWriteBuf(len+1);
836 SendMsg(msg, 0, (sptr_t)buf);
837 mbuf.UngetWriteBuf(len);
838 mbuf.AppendByte(0);
839 return stc2wx(buf);''',
840 0),
841
842
843
844 'DescribeProperty' :
845 (0,
846 'wxString %s(const wxString& name) const;',
847
848 '''wxString %s(const wxString& name) const {
849 int msg = %s;
850 int len = SendMsg(msg, (sptr_t)(const char*)wx2stc(name), (sptr_t)NULL);
851 if (!len) return wxEmptyString;
852
853 wxMemoryBuffer mbuf(len+1);
854 char* buf = (char*)mbuf.GetWriteBuf(len+1);
855 SendMsg(msg, (sptr_t)(const char*)wx2stc(name), (sptr_t)buf);
856 mbuf.UngetWriteBuf(len);
857 mbuf.AppendByte(0);
858 return stc2wx(buf);''',
859 0),
860
861
862
863 'DescribeKeyWordSets' :
864 (0,
865 'wxString %s() const;',
866
867 '''wxString %s() const {
868 int msg = %s;
869 int len = SendMsg(msg, 0, (sptr_t)NULL);
870 if (!len) return wxEmptyString;
871
872 wxMemoryBuffer mbuf(len+1);
873 char* buf = (char*)mbuf.GetWriteBuf(len+1);
874 SendMsg(msg, 0, (sptr_t)buf);
875 mbuf.UngetWriteBuf(len);
876 mbuf.AppendByte(0);
877 return stc2wx(buf);''',
878 0),
879
880
881 'MarkerDefineRGBAImage' :
882 (0,
883 'void %s(int markerNumber, const unsigned char* pixels);',
884 '''void %s(int markerNumber, const unsigned char* pixels) {
885 SendMsg(%s, markerNumber, (sptr_t)pixels);''',
886 0),
887
888
889 'RegisterRGBAImage' :
890 (0,
891 'void %s(int type, const unsigned char* pixels);',
892 '''void %s(int type, const unsigned char* pixels) {
893 SendMsg(%s, type, (sptr_t)pixels);''',
894 0),
895
896
897 # I think these are only available on the native OSX backend, so
898 # don't add them to the wx API...
899 'FindIndicatorShow' : (None, 0,0,0),
900 'FindIndicatorFlash' : (None, 0,0,0),
901 'FindIndicatorHide' : (None, 0,0,0),
902
903 'CreateLoader' :
904 (0,
905 'void* %s(int bytes) const;',
906 """void* %s(int bytes) const {
907 return (void*)(sptr_t)SendMsg(%s, bytes); """,
908 0),
909
910 'PrivateLexerCall' :
911 (0,
912 'void* %s(int operation, void* pointer);',
913 """void* %s(int operation, void* pointer) {
914 return (void*)(sptr_t)SendMsg(%s, operation, (sptr_t)pointer); """,
915 0),
916
917 '' : ('', 0, 0, 0),
918
919 }
920
921 # all Scintilla getters are transformed into const member of wxSTC class but
922 # some non-getter methods are also logically const and this set contains their
923 # names (notice that it's useless to include here methods manually overridden
924 # above)
925 constNonGetterMethods = (
926 'LineFromPosition',
927 'PositionFromLine',
928 'LineLength',
929 'CanPaste',
930 'CanRedo',
931 'CanUndo',
932 )
933
934 #----------------------------------------------------------------------------
935
936 def processIface(iface, h_tmplt, cpp_tmplt, ih_tmplt, h_dest, cpp_dest, docstr_dest, ih_dest):
937 curDocStrings = []
938 values = []
939 methods = []
940 cmds = []
941
942 # parse iface file
943 fi = FileInput(iface)
944 for line in fi:
945 line = line[:-1]
946 if line[:2] == '##' or line == '':
947 #curDocStrings = []
948 continue
949
950 op = line[:4]
951 if line[:2] == '# ': # a doc string
952 curDocStrings.append(line[2:])
953
954 elif op == 'val ':
955 parseVal(line[4:], values, curDocStrings)
956 curDocStrings = []
957
958 elif op == 'fun ' or op == 'set ' or op == 'get ':
959 parseFun(line[4:], methods, curDocStrings, cmds, op == 'get ')
960 curDocStrings = []
961
962 elif op == 'cat ':
963 if line[4:].strip() == 'Deprecated':
964 break # skip the rest of the file
965
966 elif op == 'evt ':
967 pass
968
969 elif op == 'enu ':
970 pass
971
972 elif op == 'lex ':
973 pass
974
975 else:
976 print('***** Unknown line type: %s' % line)
977
978
979 # process templates
980 data = {}
981 data['VALUES'] = processVals(values)
982 data['CMDS'] = processVals(cmds)
983 defs, imps, docstrings, idefs = processMethods(methods)
984 data['METHOD_DEFS'] = defs
985 data['METHOD_IDEFS'] = idefs
986 data['METHOD_IMPS'] = imps
987
988 # get template text
989 h_text = open(h_tmplt).read()
990 ih_text = open(ih_tmplt).read()
991 cpp_text = open(cpp_tmplt).read()
992
993 # do the substitutions
994 h_text = h_text % data
995 cpp_text = cpp_text % data
996 ih_text = ih_text % data
997
998 # write out destination files
999 open(h_dest, 'w').write(h_text)
1000 open(cpp_dest, 'w').write(cpp_text)
1001 if docstr_dest:
1002 open(docstr_dest, 'w').write(docstrings)
1003 open(ih_dest, 'w').write(ih_text)
1004
1005
1006 def joinWithNewLines(values):
1007 return '\n'.join(values)
1008
1009 #----------------------------------------------------------------------------
1010
1011 def processVals(values):
1012 text = []
1013 for name, value, docs in values:
1014 if docs:
1015 text.append('')
1016 for x in docs:
1017 text.append('/// ' + x)
1018 text.append('#define %s %s' % (name, value))
1019 return joinWithNewLines(text)
1020
1021 #----------------------------------------------------------------------------
1022
1023 def processMethods(methods):
1024 defs = []
1025 idefs = []
1026 imps = []
1027 dstr = []
1028
1029 for retType, name, number, param1, param2, docs, is_const in methods:
1030 retType = retTypeMap.get(retType, retType)
1031 params = makeParamString(param1, param2)
1032
1033 name, theDef, theImp, docs = checkMethodOverride(name, number, docs)
1034
1035 if name is None:
1036 continue
1037
1038 # Build docstrings
1039 st = 'DocStr(wxStyledTextCtrl::%s,\n' \
1040 '"%s", "");\n' % (name, joinWithNewLines(docs))
1041 dstr.append(st)
1042
1043 # Build the method definition for the .h file
1044 if docs:
1045 defs.append('')
1046 for x in docs:
1047 defs.append(' // ' + x)
1048 if not theDef:
1049 theDef = ' %s %s(%s)' % (retType, name, params)
1050 if is_const:
1051 theDef = theDef + ' const'
1052 theDef = theDef + ';'
1053 defs.append(theDef)
1054
1055 # Build the method definition for the interface .h file
1056 if docs:
1057 idefs.append('')
1058 idefs.append(' /**')
1059 for x in docs:
1060 idefs.append(' ' + x)
1061 idefs.append(' */')
1062 if name == 'GetCurLine':
1063 idefs.append(' wxString GetCurLine(int* linePos=NULL);')
1064 else:
1065 idefs.append(theDef)
1066
1067 # Build the method implementation string
1068 if docs:
1069 imps.append('')
1070 for x in docs:
1071 imps.append('// ' + x)
1072 if not theImp:
1073 theImp = '%s wxStyledTextCtrl::%s(%s)' % (retType, name, params)
1074 if is_const:
1075 theImp = theImp + ' const'
1076 theImp = theImp + '\n{\n '
1077 if retType == 'wxColour':
1078 theImp = theImp + 'long c = '
1079 elif retType != 'void':
1080 theImp = theImp + 'return '
1081 theImp = theImp + 'SendMsg(%s, %s, %s)' % (number,
1082 makeArgString(param1),
1083 makeArgString(param2))
1084 if retType == 'bool':
1085 theImp = theImp + ' != 0'
1086 if retType == 'wxColour':
1087 theImp = theImp + ';\n return wxColourFromLong(c)'
1088
1089 theImp = theImp + ';\n}'
1090 imps.append(theImp)
1091
1092
1093 return joinWithNewLines(defs), joinWithNewLines(imps), joinWithNewLines(dstr), joinWithNewLines(idefs)
1094
1095
1096 #----------------------------------------------------------------------------
1097
1098 def checkMethodOverride(name, number, docs):
1099 theDef = theImp = None
1100 if name in methodOverrideMap:
1101 item = methodOverrideMap[name]
1102
1103 try:
1104 if item[0] != 0:
1105 name = item[0]
1106 if item[1] != 0:
1107 theDef = ' ' + (item[1] % name)
1108 if item[2] != 0:
1109 theImp = item[2] % ('wxStyledTextCtrl::'+name, number) + '\n}'
1110 if item[3] != 0:
1111 docs = item[3]
1112 except:
1113 print("************* " + name)
1114 raise
1115
1116 return name, theDef, theImp, docs
1117
1118 #----------------------------------------------------------------------------
1119
1120 def makeArgString(param):
1121 if not param:
1122 return '0'
1123
1124 typ, name = param
1125
1126 if typ == 'string':
1127 return '(sptr_t)(const char*)wx2stc(%s)' % name
1128 if typ == 'colour':
1129 return 'wxColourAsLong(%s)' % name
1130
1131 return name
1132
1133 #----------------------------------------------------------------------------
1134
1135 def makeParamString(param1, param2):
1136 def doOne(param):
1137 if param:
1138 aType = paramTypeMap.get(param[0], param[0])
1139 return aType + ' ' + param[1]
1140 else:
1141 return ''
1142
1143 st = doOne(param1)
1144 if st and param2:
1145 st = st + ', '
1146 st = st + doOne(param2)
1147 return st
1148
1149
1150 #----------------------------------------------------------------------------
1151
1152 def parseVal(line, values, docs):
1153 name, val = line.split('=')
1154
1155 # remove prefixes such as SCI, etc.
1156 for old, new in valPrefixes:
1157 lo = len(old)
1158 if name[:lo] == old:
1159 if new is None:
1160 return
1161 name = new + name[lo:]
1162
1163 # add it to the list
1164 values.append( ('wxSTC_' + name, val, docs) )
1165
1166 #----------------------------------------------------------------------------
1167
1168 funregex = re.compile(r'\s*([a-zA-Z0-9_]+)' # <ws>return type
1169 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
1170 '([0-9]+)' # number
1171 '\(([ a-zA-Z0-9_]*),' # (param,
1172 '([ a-zA-Z0-9_]*),*\)') # param)
1173
1174 def parseFun(line, methods, docs, values, is_const):
1175 def parseParam(param):
1176 param = param.strip()
1177 if param == '':
1178 param = None
1179 else:
1180 param = tuple(param.split())
1181 return param
1182
1183 mo = funregex.match(line)
1184 if mo is None:
1185 print("***** Line doesn't match! : %s" % line)
1186
1187 retType, name, number, param1, param2 = mo.groups()
1188
1189 param1 = parseParam(param1)
1190 param2 = parseParam(param2)
1191
1192 # Special case. For the key command functions we want a value defined too
1193 num = int(number)
1194 for v in cmdValues:
1195 if (type(v) == type(()) and v[0] <= num <= v[1]) or v == num:
1196 parseVal('CMD_%s=%s' % (name.upper(), number), values, docs)
1197
1198 # if we are not also doing a function for CMD values, then
1199 # just return, otherwise fall through to the append blow.
1200 if not FUNC_FOR_CMD:
1201 return
1202
1203 methods.append( (retType, name, number, param1, param2, tuple(docs),
1204 is_const or name in constNonGetterMethods) )
1205
1206
1207 #----------------------------------------------------------------------------
1208
1209
1210 def main(args):
1211 # TODO: parse command line args to replace default input/output files???
1212
1213 if not os.path.exists(IFACE):
1214 print('Please run this script from src/stc subdirectory.')
1215 sys.exit(1)
1216
1217 # Now just do it
1218 processIface(IFACE, H_TEMPLATE, CPP_TEMPLATE, IH_TEMPLATE, H_DEST, CPP_DEST, DOCSTR_DEST, IH_DEST)
1219
1220
1221
1222 if __name__ == '__main__':
1223 main(sys.argv)
1224
1225 #----------------------------------------------------------------------------
1226