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