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