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