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