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