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