]> git.saurik.com Git - wxWidgets.git/blob - src/stc/gen_iface.py
Adjusted filelist.txt and wxUniv.dsp to use generic
[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 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
258 ft.lpstrText = (char*)(const char*)buf;
259
260 return SendMsg(%s, flags, (long)&ft);''',
261 0),
262
263 'FormatRange' : (0,
264 '''int %s(bool doDraw,
265 int startPos,
266 int endPos,
267 wxDC* draw,
268 wxDC* target, // Why does it use two? Can they be the same?
269 wxRect renderRect,
270 wxRect pageRect);''',
271 ''' int %s(bool doDraw,
272 int startPos,
273 int endPos,
274 wxDC* draw,
275 wxDC* target, // Why does it use two? Can they be the same?
276 wxRect renderRect,
277 wxRect pageRect) {
278 RangeToFormat fr;
279
280 if (endPos < startPos) {
281 int temp = startPos;
282 startPos = endPos;
283 endPos = temp;
284 }
285 fr.hdc = draw;
286 fr.hdcTarget = target;
287 fr.rc.top = renderRect.GetTop();
288 fr.rc.left = renderRect.GetLeft();
289 fr.rc.right = renderRect.GetRight();
290 fr.rc.bottom = renderRect.GetBottom();
291 fr.rcPage.top = pageRect.GetTop();
292 fr.rcPage.left = pageRect.GetLeft();
293 fr.rcPage.right = pageRect.GetRight();
294 fr.rcPage.bottom = pageRect.GetBottom();
295 fr.chrg.cpMin = startPos;
296 fr.chrg.cpMax = endPos;
297
298 return SendMsg(%s, doDraw, (long)&fr);''',
299 0),
300
301
302 'GetLine' : (0,
303 'wxString %s(int line);',
304
305 '''wxString %s(int line) {
306 int len = LineLength(line);
307 if (!len) return wxEmptyString;
308
309 wxMemoryBuffer mbuf(len+1);
310 char* buf = (char*)mbuf.GetWriteBuf(len+1);
311 SendMsg(%s, line, (long)buf);
312 mbuf.UngetWriteBuf(len);
313 mbuf.AppendByte(0);
314 return stc2wx(buf);''',
315
316 ('Retrieve the contents of a line.',)),
317
318 'SetSel' : ('SetSelection', 0, 0, 0),
319 'GetSelText' : ('GetSelectedText',
320 'wxString %s();',
321
322 '''wxString %s() {
323 int start;
324 int end;
325
326 GetSelection(&start, &end);
327 int len = end - start;
328 if (!len) return wxEmptyString;
329
330 wxMemoryBuffer mbuf(len+1);
331 char* buf = (char*)mbuf.GetWriteBuf(len+1);
332 SendMsg(%s, 0, (long)buf);
333 mbuf.UngetWriteBuf(len);
334 mbuf.AppendByte(0);
335 return stc2wx(buf);''',
336
337 ('Retrieve the selected text.',)),
338
339 'GetTextRange' : (0,
340 'wxString %s(int startPos, int endPos);',
341
342 '''wxString %s(int startPos, int endPos) {
343 if (endPos < startPos) {
344 int temp = startPos;
345 startPos = endPos;
346 endPos = temp;
347 }
348 int len = endPos - startPos;
349 if (!len) return wxEmptyString;
350 wxMemoryBuffer mbuf(len+1);
351 char* buf = (char*)mbuf.GetWriteBuf(len);
352 TextRange tr;
353 tr.lpstrText = buf;
354 tr.chrg.cpMin = startPos;
355 tr.chrg.cpMax = endPos;
356 SendMsg(%s, 0, (long)&tr);
357 mbuf.UngetWriteBuf(len);
358 mbuf.AppendByte(0);
359 return stc2wx(buf);''',
360
361 ('Retrieve a range of text.',)),
362
363 'PointXFromPosition' : (None, 0, 0, 0),
364 'PointYFromPosition' : (None, 0, 0, 0),
365
366 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
367 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
368 'Null' : (None, 0, 0, 0),
369
370 'GetText' : (0,
371 'wxString %s();',
372
373 '''wxString %s() {
374 int len = GetTextLength();
375 wxMemoryBuffer mbuf(len+1); // leave room for the null...
376 char* buf = (char*)mbuf.GetWriteBuf(len+1);
377 SendMsg(%s, len+1, (long)buf);
378 mbuf.UngetWriteBuf(len);
379 mbuf.AppendByte(0);
380 return stc2wx(buf);''',
381
382 ('Retrieve all the text in the document.', )),
383
384 'GetDirectFunction' : (None, 0, 0, 0),
385 'GetDirectPointer' : (None, 0, 0, 0),
386
387 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
388 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
389 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
390
391
392 'ReplaceTarget' : (0,
393 'int %s(const wxString& text);',
394
395 '''
396 int %s(const wxString& text) {
397 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
398 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
399 0),
400
401 'ReplaceTargetRE' : (0,
402 'int %s(const wxString& text);',
403
404 '''
405 int %s(const wxString& text) {
406 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
407 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
408 0),
409
410 'SearchInTarget' : (0,
411 'int %s(const wxString& text);',
412
413 '''
414 int %s(const wxString& text) {
415 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
416 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
417 0),
418
419
420
421 # Remove all methods that are key commands since they can be
422 # executed with CmdKeyExecute
423 'LineDown' : (None, 0, 0, 0),
424 'LineDownExtend' : (None, 0, 0, 0),
425 'LineUp' : (None, 0, 0, 0),
426 'LineUpExtend' : (None, 0, 0, 0),
427 'CharLeft' : (None, 0, 0, 0),
428 'CharLeftExtend' : (None, 0, 0, 0),
429 'CharRight' : (None, 0, 0, 0),
430 'CharRightExtend' : (None, 0, 0, 0),
431 'WordLeft' : (None, 0, 0, 0),
432 'WordLeftExtend' : (None, 0, 0, 0),
433 'WordRight' : (None, 0, 0, 0),
434 'WordRightExtend' : (None, 0, 0, 0),
435 'Home' : (None, 0, 0, 0),
436 'HomeExtend' : (None, 0, 0, 0),
437 'LineEnd' : (None, 0, 0, 0),
438 'LineEndExtend' : (None, 0, 0, 0),
439 'DocumentStart' : (None, 0, 0, 0),
440 'DocumentStartExtend' : (None, 0, 0, 0),
441 'DocumentEnd' : (None, 0, 0, 0),
442 'DocumentEndExtend' : (None, 0, 0, 0),
443 'PageUp' : (None, 0, 0, 0),
444 'PageUpExtend' : (None, 0, 0, 0),
445 'PageDown' : (None, 0, 0, 0),
446 'PageDownExtend' : (None, 0, 0, 0),
447 'EditToggleOvertype' : (None, 0, 0, 0),
448 'Cancel' : (None, 0, 0, 0),
449 'DeleteBack' : (None, 0, 0, 0),
450 'Tab' : (None, 0, 0, 0),
451 'BackTab' : (None, 0, 0, 0),
452 'NewLine' : (None, 0, 0, 0),
453 'FormFeed' : (None, 0, 0, 0),
454 'VCHome' : (None, 0, 0, 0),
455 'VCHomeExtend' : (None, 0, 0, 0),
456 'ZoomIn' : (None, 0, 0, 0),
457 'ZoomOut' : (None, 0, 0, 0),
458 'DelWordLeft' : (None, 0, 0, 0),
459 'DelWordRight' : (None, 0, 0, 0),
460 'LineCut' : (None, 0, 0, 0),
461 'LineDelete' : (None, 0, 0, 0),
462 'LineTranspose' : (None, 0, 0, 0),
463 'LowerCase' : (None, 0, 0, 0),
464 'UpperCase' : (None, 0, 0, 0),
465 'LineScrollDown' : (None, 0, 0, 0),
466 'LineScrollUp' : (None, 0, 0, 0),
467 'DeleteBackNotLine' : (None, 0, 0, 0),
468
469
470 'GetDocPointer' : (0,
471 'void* %s();',
472 '''void* %s() {
473 return (void*)SendMsg(%s);''',
474 0),
475
476 'SetDocPointer' : (0,
477 'void %s(void* docPointer);',
478 '''void %s(void* docPointer) {
479 SendMsg(%s, 0, (long)docPointer);''',
480 0),
481
482 'CreateDocument' : (0,
483 'void* %s();',
484 '''void* %s() {
485 return (void*)SendMsg(%s);''',
486 0),
487
488 'AddRefDocument' : (0,
489 'void %s(void* docPointer);',
490 '''void %s(void* docPointer) {
491 SendMsg(%s, 0, (long)docPointer);''',
492 0),
493
494 'ReleaseDocument' : (0,
495 'void %s(void* docPointer);',
496 '''void %s(void* docPointer) {
497 SendMsg(%s, 0, (long)docPointer);''',
498 0),
499 'SetCodePage' : (0,
500 0,
501 '''void %s(int codePage) {
502 #if wxUSE_UNICODE
503 wxASSERT_MSG(codePage == wxSTC_CP_UTF8,
504 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
505 #else
506 wxASSERT_MSG(codePage != wxSTC_CP_UTF8,
507 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
508 #endif
509 SendMsg(%s, codePage);''',
510 ("Set the code page used to interpret the bytes of the document as characters.",) ),
511
512
513 'GrabFocus' : (None, 0, 0, 0),
514 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
515 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
516
517
518 '' : ('', 0, 0, 0),
519
520 }
521
522 #----------------------------------------------------------------------------
523
524 def processIface(iface, h_tmplt, cpp_tmplt, h_dest, cpp_dest):
525 curDocStrings = []
526 values = []
527 methods = []
528
529 # parse iface file
530 fi = FileInput(iface)
531 for line in fi:
532 line = line[:-1]
533 if line[:2] == '##' or line == '':
534 #curDocStrings = []
535 continue
536
537 op = line[:4]
538 if line[:2] == '# ': # a doc string
539 curDocStrings.append(line[2:])
540
541 elif op == 'val ':
542 parseVal(line[4:], values, curDocStrings)
543 curDocStrings = []
544
545 elif op == 'fun ' or op == 'set ' or op == 'get ':
546 parseFun(line[4:], methods, curDocStrings, values)
547 curDocStrings = []
548
549 elif op == 'cat ':
550 if string.strip(line[4:]) == 'Deprecated':
551 break # skip the rest of the file
552
553 elif op == 'evt ':
554 pass
555
556 elif op == 'enu ':
557 pass
558
559 elif op == 'lex ':
560 pass
561
562 else:
563 print '***** Unknown line type: ', line
564
565
566 # process templates
567 data = {}
568 data['VALUES'] = processVals(values)
569 defs, imps = processMethods(methods)
570 data['METHOD_DEFS'] = defs
571 data['METHOD_IMPS'] = imps
572
573 # get template text
574 h_text = open(h_tmplt).read()
575 cpp_text = open(cpp_tmplt).read()
576
577 # do the substitutions
578 h_text = h_text % data
579 cpp_text = cpp_text % data
580
581 # write out destination files
582 open(h_dest, 'w').write(h_text)
583 open(cpp_dest, 'w').write(cpp_text)
584
585
586
587 #----------------------------------------------------------------------------
588
589 def processVals(values):
590 text = []
591 for name, value, docs in values:
592 if docs:
593 text.append('')
594 for x in docs:
595 text.append('// ' + x)
596 text.append('#define %s %s' % (name, value))
597 return string.join(text, '\n')
598
599 #----------------------------------------------------------------------------
600
601 def processMethods(methods):
602 defs = []
603 imps = []
604
605 for retType, name, number, param1, param2, docs in methods:
606 retType = retTypeMap.get(retType, retType)
607 params = makeParamString(param1, param2)
608
609 name, theDef, theImp, docs = checkMethodOverride(name, number, docs)
610
611 if name is None:
612 continue
613
614 # Build the method definition for the .h file
615 if docs:
616 defs.append('')
617 for x in docs:
618 defs.append(' // ' + x)
619 if not theDef:
620 theDef = ' %s %s(%s);' % (retType, name, params)
621 defs.append(theDef)
622
623 # Build the method implementation string
624 if docs:
625 imps.append('')
626 for x in docs:
627 imps.append('// ' + x)
628 if not theImp:
629 theImp = '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType, name, params)
630
631 if retType == 'wxColour':
632 theImp = theImp + 'long c = '
633 elif retType != 'void':
634 theImp = theImp + 'return '
635 theImp = theImp + 'SendMsg(%s, %s, %s)' % (number,
636 makeArgString(param1),
637 makeArgString(param2))
638 if retType == 'bool':
639 theImp = theImp + ' != 0'
640 if retType == 'wxColour':
641 theImp = theImp + ';\n return wxColourFromLong(c)'
642
643 theImp = theImp + ';\n}'
644 imps.append(theImp)
645
646
647 return string.join(defs, '\n'), string.join(imps, '\n')
648
649
650 #----------------------------------------------------------------------------
651
652 def checkMethodOverride(name, number, docs):
653 theDef = theImp = None
654 if methodOverrideMap.has_key(name):
655 item = methodOverrideMap[name]
656
657 try:
658 if item[0] != 0:
659 name = item[0]
660 if item[1] != 0:
661 theDef = ' ' + (item[1] % name)
662 if item[2] != 0:
663 theImp = item[2] % ('wxStyledTextCtrl::'+name, number) + '\n}'
664 if item[3] != 0:
665 docs = item[3]
666 except:
667 print "*************", name
668 raise
669
670 return name, theDef, theImp, docs
671
672 #----------------------------------------------------------------------------
673
674 def makeArgString(param):
675 if not param:
676 return '0'
677
678 typ, name = param
679
680 if typ == 'string':
681 return '(long)(const char*)wx2stc(%s)' % name
682 if typ == 'colour':
683 return 'wxColourAsLong(%s)' % name
684
685 return name
686
687 #----------------------------------------------------------------------------
688
689 def makeParamString(param1, param2):
690 def doOne(param):
691 if param:
692 aType = paramTypeMap.get(param[0], param[0])
693 return aType + ' ' + param[1]
694 else:
695 return ''
696
697 st = doOne(param1)
698 if st and param2:
699 st = st + ', '
700 st = st + doOne(param2)
701 return st
702
703
704 #----------------------------------------------------------------------------
705
706 def parseVal(line, values, docs):
707 name, val = string.split(line, '=')
708
709 # remove prefixes such as SCI, etc.
710 for old, new in valPrefixes:
711 lo = len(old)
712 if name[:lo] == old:
713 if new is None:
714 return
715 name = new + name[lo:]
716
717 # add it to the list
718 values.append( ('wxSTC_' + name, val, docs) )
719
720 #----------------------------------------------------------------------------
721
722 funregex = re.compile(r'\s*([a-zA-Z0-9_]+)' # <ws>return type
723 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
724 '([0-9]+)' # number
725 '\(([ a-zA-Z0-9_]*),' # (param,
726 '([ a-zA-Z0-9_]*)\)') # param)
727
728 def parseFun(line, methods, docs, values):
729 def parseParam(param):
730 param = string.strip(param)
731 if param == '':
732 param = None
733 else:
734 param = tuple(string.split(param))
735 return param
736
737 mo = funregex.match(line)
738 if mo is None:
739 print "***** Line doesn't match! : " + line
740
741 retType, name, number, param1, param2 = mo.groups()
742
743 param1 = parseParam(param1)
744 param2 = parseParam(param2)
745
746 # Special case. For the key command functionss we want a value defined too
747 num = string.atoi(number)
748 for v in cmdValues:
749 if (type(v) == type(()) and v[0] <= num < v[1]) or v == num:
750 parseVal('CMD_%s=%s' % (string.upper(name), number), values, docs)
751
752 #if retType == 'void' and not param1 and not param2:
753
754 methods.append( (retType, name, number, param1, param2, tuple(docs)) )
755
756
757 #----------------------------------------------------------------------------
758
759
760 def main(args):
761 # TODO: parse command line args to replace default input/output files???
762
763 # Now just do it
764 processIface(IFACE, H_TEMPLATE, CPP_TEMPLATE, H_DEST, CPP_DEST)
765
766
767
768 if __name__ == '__main__':
769 main(sys.argv)
770
771 #----------------------------------------------------------------------------
772