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