Add docstrings for wxSTC methods
[wxWidgets.git] / src / stc / gen_iface.py
1 #!/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 license
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 DOCSTR_DEST = os.path.abspath('../../../wxPython/contrib/stc/_stc_gendocs.i')
25
26
27 # Value prefixes to convert
28 valPrefixes = [('SCI_', ''),
29 ('SC_', ''),
30 ('SCN_', None), # just toss these out...
31 ('SCEN_', None),
32 ('SCE_', ''),
33 ('SCLEX_', 'LEX_'),
34 ('SCK_', 'KEY_'),
35 ('SCFIND_', 'FIND_'),
36 ('SCWS_', 'WS_'),
37 ]
38
39 # Message function values that should have a CMD_ constant generated
40 cmdValues = [ (2300, 2349),
41 2011,
42 2013,
43 (2176, 2180),
44 (2390, 2393),
45 (2395, 2396),
46 2404,
47 (2413, 2416),
48 (2426, 2442),
49 (2450, 2455),
50 ]
51
52
53 # Should a funciton be also generated for the CMDs?
54 FUNC_FOR_CMD = True
55
56
57 # Map some generic typenames to wx types, using return value syntax
58 retTypeMap = {
59 'position': 'int',
60 'string': 'wxString',
61 'colour': 'wxColour',
62 }
63
64 # Map some generic typenames to wx types, using parameter syntax
65 paramTypeMap = {
66 'position': 'int',
67 'string': 'const wxString&',
68 'colour': 'const wxColour&',
69 'keymod': 'int',
70 }
71
72 # Map of method info that needs tweaked. Either the name needs changed, or
73 # the method definition/implementation. Tuple items are:
74 #
75 # 1. New method name. None to skip the method, 0 to leave the
76 # default name.
77 # 2. Method definition for the .h file, 0 to leave alone
78 # 3. Method implementation for the .cpp file, 0 to leave alone.
79 # 4. tuple of Doc string lines, or 0 to leave alone.
80 #
81 methodOverrideMap = {
82 'AddText' : (0,
83 'void %s(const wxString& text);',
84
85 '''void %s(const wxString& text) {
86 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
87 SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
88 0),
89
90 'AddStyledText' : (0,
91 'void %s(const wxMemoryBuffer& data);',
92
93 '''void %s(const wxMemoryBuffer& data) {
94 SendMsg(%s, data.GetDataLen(), (long)data.GetData());''',
95 0),
96
97 'AppendText' : (0,
98 'void %s(const wxString& text);',
99
100 '''void %s(const wxString& text) {
101 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
102 SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
103 0),
104
105 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
106 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
107
108 'GetCharAt' :
109 ( 0, 0,
110 '''int %s(int pos) {
111 return (unsigned char)SendMsg(%s, pos, 0);''',
112 0),
113
114 'GetStyleAt' :
115 ( 0, 0,
116 '''int %s(int pos) {
117 return (unsigned char)SendMsg(%s, pos, 0);''',
118 0),
119
120 'GetStyledText' :
121 (0,
122 'wxMemoryBuffer %s(int startPos, int endPos);',
123
124 '''wxMemoryBuffer %s(int startPos, int endPos) {
125 wxMemoryBuffer buf;
126 if (endPos < startPos) {
127 int temp = startPos;
128 startPos = endPos;
129 endPos = temp;
130 }
131 int len = endPos - startPos;
132 if (!len) return buf;
133 TextRange tr;
134 tr.lpstrText = (char*)buf.GetWriteBuf(len*2+1);
135 tr.chrg.cpMin = startPos;
136 tr.chrg.cpMax = endPos;
137 len = SendMsg(%s, 0, (long)&tr);
138 buf.UngetWriteBuf(len);
139 return buf;''',
140
141 ('Retrieve a buffer of cells.',)),
142
143
144 'PositionFromPoint' :
145 (0,
146 'int %s(wxPoint pt);',
147
148 '''int %s(wxPoint pt) {
149 return SendMsg(%s, pt.x, pt.y);''',
150 0),
151
152 'GetCurLine' :
153 (0,
154 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
155
156 '''wxString %s(int* linePos) {
157 int len = LineLength(GetCurrentLine());
158 if (!len) {
159 if (linePos) *linePos = 0;
160 return wxEmptyString;
161 }
162
163 wxMemoryBuffer mbuf(len+1);
164 char* buf = (char*)mbuf.GetWriteBuf(len+1);
165
166 int pos = SendMsg(%s, len+1, (long)buf);
167 mbuf.UngetWriteBuf(len);
168 mbuf.AppendByte(0);
169 if (linePos) *linePos = pos;
170 return stc2wx(buf);''',
171
172 0),
173
174 'SetUsePalette' : (None, 0,0,0),
175
176 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
177 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
178
179 'MarkerDefine' :
180 (0,
181 '''void %s(int markerNumber, int markerSymbol,
182 const wxColour& foreground = wxNullColour,
183 const wxColour& background = wxNullColour);''',
184
185 '''void %s(int markerNumber, int markerSymbol,
186 const wxColour& foreground,
187 const wxColour& background) {
188
189 SendMsg(%s, markerNumber, markerSymbol);
190 if (foreground.Ok())
191 MarkerSetForeground(markerNumber, foreground);
192 if (background.Ok())
193 MarkerSetBackground(markerNumber, background);''',
194
195 ('Set the symbol used for a particular marker number,',
196 'and optionally the fore and background colours.')),
197
198
199 'MarkerDefinePixmap' :
200 ('MarkerDefineBitmap',
201 '''void %s(int markerNumber, const wxBitmap& bmp);''',
202 '''void %s(int markerNumber, const wxBitmap& bmp) {
203 // convert bmp to a xpm in a string
204 wxMemoryOutputStream strm;
205 wxImage img = bmp.ConvertToImage();
206 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
207 size_t len = strm.GetSize();
208 char* buff = new char[len+1];
209 strm.CopyTo(buff, len);
210 buff[len] = 0;
211 SendMsg(%s, markerNumber, (long)buff);
212 delete [] buff;
213 ''',
214 ('Define a marker from a bitmap',)),
215
216
217 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
218 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
219 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
220 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
221 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
222 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
223 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
224 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
225
226 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
227 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
228 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
229 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
230 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
231 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
232
233 'AssignCmdKey' :
234 ('CmdKeyAssign',
235 'void %s(int key, int modifiers, int cmd);',
236
237 '''void %s(int key, int modifiers, int cmd) {
238 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
239 0),
240
241
242 'ClearCmdKey' :
243 ('CmdKeyClear',
244 'void %s(int key, int modifiers);',
245
246 '''void %s(int key, int modifiers) {
247 SendMsg(%s, MAKELONG(key, modifiers));''',
248 0),
249
250 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
251
252
253 'SetStylingEx' :
254 ('SetStyleBytes',
255 'void %s(int length, char* styleBytes);',
256
257 '''void %s(int length, char* styleBytes) {
258 SendMsg(%s, length, (long)styleBytes);''',
259 0),
260
261
262 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
263 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
264 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
265 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
266
267 'SetWhitespaceFore' : ('SetWhitespaceForeground', 0, 0, 0),
268 'SetWhitespaceBack' : ('SetWhitespaceBackground', 0, 0, 0),
269
270 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
271 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
272 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
273 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
274 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
275 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
276 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
277 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
278 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
279 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
280 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
281 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
282 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
283 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
284 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
285 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
286 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
287 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
288 'AutoCSetDropRestOfWord' : ('AutoCompSetDropRestOfWord', 0,0,0),
289 'AutoCGetDropRestOfWord' : ('AutoCompGetDropRestOfWord', 0,0,0),
290 'AutoCGetTypeSeparator' : ('AutoCompGetTypeSeparator', 0, 0, 0),
291 'AutoCSetTypeSeparator' : ('AutoCompSetTypeSeparator', 0, 0, 0),
292 'AutoCGetCurrent' : ('AutoCompGetCurrent', 0, 0, 0),
293
294 'RegisterImage' :
295 (0,
296 '''void %s(int type, const wxBitmap& bmp);''',
297 '''void %s(int type, const wxBitmap& bmp) {
298 // convert bmp to a xpm in a string
299 wxMemoryOutputStream strm;
300 wxImage img = bmp.ConvertToImage();
301 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
302 size_t len = strm.GetSize();
303 char* buff = new char[len+1];
304 strm.CopyTo(buff, len);
305 buff[len] = 0;
306 SendMsg(%s, type, (long)buff);
307 delete [] buff;
308 ''',
309 ('Register an image for use in autocompletion lists.',)),
310
311
312 'ClearRegisteredImages' : (0, 0, 0,
313 ('Clear all the registered images.',)),
314
315
316 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
317 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
318
319 'SetVScrollBar' : ('SetUseVerticalScrollBar', 0, 0, 0),
320 'GetVScrollBar' : ('GetUseVerticalScrollBar', 0, 0, 0),
321
322 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
323
324 'GetUsePalette' : (None, 0, 0, 0),
325
326 'FindText' :
327 (0,
328 '''int %s(int minPos, int maxPos, const wxString& text, int flags=0);''',
329
330 '''int %s(int minPos, int maxPos,
331 const wxString& text,
332 int flags) {
333 TextToFind ft;
334 ft.chrg.cpMin = minPos;
335 ft.chrg.cpMax = maxPos;
336 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
337 ft.lpstrText = (char*)(const char*)buf;
338
339 return SendMsg(%s, flags, (long)&ft);''',
340 0),
341
342 'FormatRange' :
343 (0,
344 '''int %s(bool doDraw,
345 int startPos,
346 int endPos,
347 wxDC* draw,
348 wxDC* target,
349 wxRect renderRect,
350 wxRect pageRect);''',
351 ''' int %s(bool doDraw,
352 int startPos,
353 int endPos,
354 wxDC* draw,
355 wxDC* target,
356 wxRect renderRect,
357 wxRect pageRect) {
358 RangeToFormat fr;
359
360 if (endPos < startPos) {
361 int temp = startPos;
362 startPos = endPos;
363 endPos = temp;
364 }
365 fr.hdc = draw;
366 fr.hdcTarget = target;
367 fr.rc.top = renderRect.GetTop();
368 fr.rc.left = renderRect.GetLeft();
369 fr.rc.right = renderRect.GetRight();
370 fr.rc.bottom = renderRect.GetBottom();
371 fr.rcPage.top = pageRect.GetTop();
372 fr.rcPage.left = pageRect.GetLeft();
373 fr.rcPage.right = pageRect.GetRight();
374 fr.rcPage.bottom = pageRect.GetBottom();
375 fr.chrg.cpMin = startPos;
376 fr.chrg.cpMax = endPos;
377
378 return SendMsg(%s, doDraw, (long)&fr);''',
379 0),
380
381
382 'GetLine' :
383 (0,
384 'wxString %s(int line);',
385
386 '''wxString %s(int line) {
387 int len = LineLength(line);
388 if (!len) return wxEmptyString;
389
390 wxMemoryBuffer mbuf(len+1);
391 char* buf = (char*)mbuf.GetWriteBuf(len+1);
392 SendMsg(%s, line, (long)buf);
393 mbuf.UngetWriteBuf(len);
394 mbuf.AppendByte(0);
395 return stc2wx(buf);''',
396
397 ('Retrieve the contents of a line.',)),
398
399 'SetSel' : ('SetSelection', 0, 0, 0),
400
401 'GetSelText' :
402 ('GetSelectedText',
403 'wxString %s();',
404
405 '''wxString %s() {
406 int start;
407 int end;
408
409 GetSelection(&start, &end);
410 int len = end - start;
411 if (!len) return wxEmptyString;
412
413 wxMemoryBuffer mbuf(len+2);
414 char* buf = (char*)mbuf.GetWriteBuf(len+1);
415 SendMsg(%s, 0, (long)buf);
416 mbuf.UngetWriteBuf(len);
417 mbuf.AppendByte(0);
418 return stc2wx(buf);''',
419
420 ('Retrieve the selected text.',)),
421
422
423 'GetTextRange' :
424 (0,
425 'wxString %s(int startPos, int endPos);',
426
427 '''wxString %s(int startPos, int endPos) {
428 if (endPos < startPos) {
429 int temp = startPos;
430 startPos = endPos;
431 endPos = temp;
432 }
433 int len = endPos - startPos;
434 if (!len) return wxEmptyString;
435 wxMemoryBuffer mbuf(len+1);
436 char* buf = (char*)mbuf.GetWriteBuf(len);
437 TextRange tr;
438 tr.lpstrText = buf;
439 tr.chrg.cpMin = startPos;
440 tr.chrg.cpMax = endPos;
441 SendMsg(%s, 0, (long)&tr);
442 mbuf.UngetWriteBuf(len);
443 mbuf.AppendByte(0);
444 return stc2wx(buf);''',
445
446 ('Retrieve a range of text.',)),
447
448 'PointXFromPosition' : (None, 0, 0, 0),
449 'PointYFromPosition' : (None, 0, 0, 0),
450
451 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
452 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
453 'Null' : (None, 0, 0, 0),
454
455 'GetText' :
456 (0,
457 'wxString %s();',
458
459 '''wxString %s() {
460 int len = GetTextLength();
461 wxMemoryBuffer mbuf(len+1); // leave room for the null...
462 char* buf = (char*)mbuf.GetWriteBuf(len+1);
463 SendMsg(%s, len+1, (long)buf);
464 mbuf.UngetWriteBuf(len);
465 mbuf.AppendByte(0);
466 return stc2wx(buf);''',
467
468 ('Retrieve all the text in the document.', )),
469
470 'GetDirectFunction' : (None, 0, 0, 0),
471 'GetDirectPointer' : (None, 0, 0, 0),
472
473 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
474 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
475 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
476 'CallTipSetFore' : ('CallTipSetForeground', 0, 0, 0),
477 'CallTipSetForeHlt' : ('CallTipSetForegroundHighlight', 0, 0, 0),
478
479 'SetHotspotActiveFore' : ('SetHotspotActiveForeground', 0, 0, 0),
480 'SetHotspotActiveBack' : ('SetHotspotActiveBackground', 0, 0, 0),
481
482
483 'ReplaceTarget' :
484 (0,
485 'int %s(const wxString& text);',
486
487 '''
488 int %s(const wxString& text) {
489 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
490 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
491 0),
492
493 'ReplaceTargetRE' :
494 (0,
495 'int %s(const wxString& text);',
496
497 '''
498 int %s(const wxString& text) {
499 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
500 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
501 0),
502
503 'SearchInTarget' :
504 (0,
505 'int %s(const wxString& text);',
506
507 '''
508 int %s(const wxString& text) {
509 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
510 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
511 0),
512
513 # not sure what to do about these yet
514 'TargetAsUTF8' : ( None, 0, 0, 0),
515 'SetLengthForEncode' : ( None, 0, 0, 0),
516 'EncodedFromUTF8' : ( None, 0, 0, 0),
517
518
519 'GetDocPointer' :
520 (0,
521 'void* %s();',
522 '''void* %s() {
523 return (void*)SendMsg(%s);''',
524 0),
525
526 'SetDocPointer' :
527 (0,
528 'void %s(void* docPointer);',
529 '''void %s(void* docPointer) {
530 SendMsg(%s, 0, (long)docPointer);''',
531 0),
532
533 'CreateDocument' :
534 (0,
535 'void* %s();',
536 '''void* %s() {
537 return (void*)SendMsg(%s);''',
538 0),
539
540 'AddRefDocument' :
541 (0,
542 'void %s(void* docPointer);',
543 '''void %s(void* docPointer) {
544 SendMsg(%s, 0, (long)docPointer);''',
545 0),
546
547 'ReleaseDocument' :
548 (0,
549 'void %s(void* docPointer);',
550 '''void %s(void* docPointer) {
551 SendMsg(%s, 0, (long)docPointer);''',
552 0),
553
554 'SetCodePage' :
555 (0,
556 0,
557 '''void %s(int codePage) {
558 #if wxUSE_UNICODE
559 wxASSERT_MSG(codePage == wxSTC_CP_UTF8,
560 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
561 #else
562 wxASSERT_MSG(codePage != wxSTC_CP_UTF8,
563 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
564 #endif
565 SendMsg(%s, codePage);''',
566 ("Set the code page used to interpret the bytes of the document as characters.",) ),
567
568
569 'GrabFocus' : (None, 0, 0, 0),
570
571 # Rename some that would otherwise hide the wxWindow methods
572 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
573 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
574 'SetCursor' : ('SetSTCCursor', 0, 0, 0),
575 'GetCursor' : ('GetSTCCursor', 0, 0, 0),
576
577 'LoadLexerLibrary' : (None, 0,0,0),
578
579
580 '' : ('', 0, 0, 0),
581
582 }
583
584 #----------------------------------------------------------------------------
585
586 def processIface(iface, h_tmplt, cpp_tmplt, h_dest, cpp_dest, docstr_dest):
587 curDocStrings = []
588 values = []
589 methods = []
590 cmds = []
591
592 # parse iface file
593 fi = FileInput(iface)
594 for line in fi:
595 line = line[:-1]
596 if line[:2] == '##' or line == '':
597 #curDocStrings = []
598 continue
599
600 op = line[:4]
601 if line[:2] == '# ': # a doc string
602 curDocStrings.append(line[2:])
603
604 elif op == 'val ':
605 parseVal(line[4:], values, curDocStrings)
606 curDocStrings = []
607
608 elif op == 'fun ' or op == 'set ' or op == 'get ':
609 parseFun(line[4:], methods, curDocStrings, cmds)
610 curDocStrings = []
611
612 elif op == 'cat ':
613 if string.strip(line[4:]) == 'Deprecated':
614 break # skip the rest of the file
615
616 elif op == 'evt ':
617 pass
618
619 elif op == 'enu ':
620 pass
621
622 elif op == 'lex ':
623 pass
624
625 else:
626 print '***** Unknown line type: ', line
627
628
629 # process templates
630 data = {}
631 data['VALUES'] = processVals(values)
632 data['CMDS'] = processVals(cmds)
633 defs, imps, docstrings = processMethods(methods)
634 data['METHOD_DEFS'] = defs
635 data['METHOD_IMPS'] = imps
636
637 # get template text
638 h_text = open(h_tmplt).read()
639 cpp_text = open(cpp_tmplt).read()
640
641 # do the substitutions
642 h_text = h_text % data
643 cpp_text = cpp_text % data
644
645 # write out destination files
646 open(h_dest, 'w').write(h_text)
647 open(cpp_dest, 'w').write(cpp_text)
648 open(docstr_dest, 'w').write(docstrings)
649
650
651
652 #----------------------------------------------------------------------------
653
654 def processVals(values):
655 text = []
656 for name, value, docs in values:
657 if docs:
658 text.append('')
659 for x in docs:
660 text.append('// ' + x)
661 text.append('#define %s %s' % (name, value))
662 return string.join(text, '\n')
663
664 #----------------------------------------------------------------------------
665
666 def processMethods(methods):
667 defs = []
668 imps = []
669 dstr = []
670
671 for retType, name, number, param1, param2, docs in methods:
672 retType = retTypeMap.get(retType, retType)
673 params = makeParamString(param1, param2)
674
675 name, theDef, theImp, docs = checkMethodOverride(name, number, docs)
676
677 if name is None:
678 continue
679
680 # Build docstrings
681 st = 'DocStr(wxStyledTextCtrl::%s,\n' \
682 '"%s", "");\n' % (name, '\n'.join(docs))
683 dstr.append(st)
684
685 # Build the method definition for the .h file
686 if docs:
687 defs.append('')
688 for x in docs:
689 defs.append(' // ' + x)
690 if not theDef:
691 theDef = ' %s %s(%s);' % (retType, name, params)
692 defs.append(theDef)
693
694 # Build the method implementation string
695 if docs:
696 imps.append('')
697 for x in docs:
698 imps.append('// ' + x)
699 if not theImp:
700 theImp = '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType, name, params)
701
702 if retType == 'wxColour':
703 theImp = theImp + 'long c = '
704 elif retType != 'void':
705 theImp = theImp + 'return '
706 theImp = theImp + 'SendMsg(%s, %s, %s)' % (number,
707 makeArgString(param1),
708 makeArgString(param2))
709 if retType == 'bool':
710 theImp = theImp + ' != 0'
711 if retType == 'wxColour':
712 theImp = theImp + ';\n return wxColourFromLong(c)'
713
714 theImp = theImp + ';\n}'
715 imps.append(theImp)
716
717
718 return '\n'.join(defs), '\n'.join(imps), '\n'.join(dstr)
719
720
721 #----------------------------------------------------------------------------
722
723 def checkMethodOverride(name, number, docs):
724 theDef = theImp = None
725 if methodOverrideMap.has_key(name):
726 item = methodOverrideMap[name]
727
728 try:
729 if item[0] != 0:
730 name = item[0]
731 if item[1] != 0:
732 theDef = ' ' + (item[1] % name)
733 if item[2] != 0:
734 theImp = item[2] % ('wxStyledTextCtrl::'+name, number) + '\n}'
735 if item[3] != 0:
736 docs = item[3]
737 except:
738 print "*************", name
739 raise
740
741 return name, theDef, theImp, docs
742
743 #----------------------------------------------------------------------------
744
745 def makeArgString(param):
746 if not param:
747 return '0'
748
749 typ, name = param
750
751 if typ == 'string':
752 return '(long)(const char*)wx2stc(%s)' % name
753 if typ == 'colour':
754 return 'wxColourAsLong(%s)' % name
755
756 return name
757
758 #----------------------------------------------------------------------------
759
760 def makeParamString(param1, param2):
761 def doOne(param):
762 if param:
763 aType = paramTypeMap.get(param[0], param[0])
764 return aType + ' ' + param[1]
765 else:
766 return ''
767
768 st = doOne(param1)
769 if st and param2:
770 st = st + ', '
771 st = st + doOne(param2)
772 return st
773
774
775 #----------------------------------------------------------------------------
776
777 def parseVal(line, values, docs):
778 name, val = string.split(line, '=')
779
780 # remove prefixes such as SCI, etc.
781 for old, new in valPrefixes:
782 lo = len(old)
783 if name[:lo] == old:
784 if new is None:
785 return
786 name = new + name[lo:]
787
788 # add it to the list
789 values.append( ('wxSTC_' + name, val, docs) )
790
791 #----------------------------------------------------------------------------
792
793 funregex = re.compile(r'\s*([a-zA-Z0-9_]+)' # <ws>return type
794 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
795 '([0-9]+)' # number
796 '\(([ a-zA-Z0-9_]*),' # (param,
797 '([ a-zA-Z0-9_]*)\)') # param)
798
799 def parseFun(line, methods, docs, values):
800 def parseParam(param):
801 param = string.strip(param)
802 if param == '':
803 param = None
804 else:
805 param = tuple(string.split(param))
806 return param
807
808 mo = funregex.match(line)
809 if mo is None:
810 print "***** Line doesn't match! : " + line
811
812 retType, name, number, param1, param2 = mo.groups()
813
814 param1 = parseParam(param1)
815 param2 = parseParam(param2)
816
817 # Special case. For the key command functions we want a value defined too
818 num = string.atoi(number)
819 for v in cmdValues:
820 if (type(v) == type(()) and v[0] <= num <= v[1]) or v == num:
821 parseVal('CMD_%s=%s' % (string.upper(name), number), values, docs)
822
823 # if we are not also doing a function for CMD values, then
824 # just return, otherwise fall through to the append blow.
825 if not FUNC_FOR_CMD:
826 return
827
828 methods.append( (retType, name, number, param1, param2, tuple(docs)) )
829
830
831 #----------------------------------------------------------------------------
832
833
834 def main(args):
835 # TODO: parse command line args to replace default input/output files???
836
837 # Now just do it
838 processIface(IFACE, H_TEMPLATE, CPP_TEMPLATE, H_DEST, CPP_DEST, DOCSTR_DEST)
839
840
841
842 if __name__ == '__main__':
843 main(sys.argv)
844
845 #----------------------------------------------------------------------------
846