]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/gen_iface.py
2 #----------------------------------------------------------------------------
4 # Purpose: Generate stc.h and stc.cpp from the info in Scintilla.iface
10 # Copyright: (c) 2000 by Total Control Software
11 # Licence: wxWindows licence
12 #----------------------------------------------------------------------------
15 import sys
, string
, re
, os
16 from fileinput
import FileInput
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 if len(sys
.argv
) > 1 and sys
.argv
[1] == '--wxpython':
25 DOCSTR_DEST
= os
.path
.abspath('../../../wxPython/src/_stc_gendocs.i')
27 DOCSTR_DEST
= '/dev/null'
30 # Value prefixes to convert
31 valPrefixes
= [('SCI_', ''),
33 ('SCN_', None), # just toss these out...
43 # Message function values that should have a CMD_ constant generated
58 # Should a funciton be also generated for the CMDs?
62 # Map some generic typenames to wx types, using return value syntax
69 # Map some generic typenames to wx types, using parameter syntax
72 'string': 'const wxString&',
73 'colour': 'const wxColour&',
77 # Map of method info that needs tweaked. Either the name needs changed, or
78 # the method definition/implementation. Tuple items are:
80 # 1. New method name. None to skip the method, 0 to leave the
82 # 2. Method definition for the .h file, 0 to leave alone
83 # 3. Method implementation for the .cpp file, 0 to leave alone.
84 # 4. tuple of Doc string lines, or 0 to leave alone.
88 'void %s(const wxString& text);',
90 '''void %s(const wxString& text) {
91 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
92 SendMsg(%s, strlen(buf), (sptr_t)(const char*)buf);''',
96 'void %s(const wxMemoryBuffer& data);',
98 '''void %s(const wxMemoryBuffer& data) {
99 SendMsg(%s, data.GetDataLen(), (sptr_t)data.GetData());''',
103 'void %s(const wxString& text);',
105 '''void %s(const wxString& text) {
106 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
107 SendMsg(%s, strlen(buf), (sptr_t)(const char*)buf);''',
110 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
111 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
115 '''int %s(int pos) const {
116 return (unsigned char)SendMsg(%s, pos, 0);''',
121 '''int %s(int pos) const {
122 return (unsigned char)SendMsg(%s, pos, 0);''',
127 'wxMemoryBuffer %s(int startPos, int endPos);',
129 '''wxMemoryBuffer %s(int startPos, int endPos) {
131 if (endPos < startPos) {
136 int len = endPos - startPos;
137 if (!len) return buf;
139 tr.lpstrText = (char*)buf.GetWriteBuf(len*2+1);
140 tr.chrg.cpMin = startPos;
141 tr.chrg.cpMax = endPos;
142 len = SendMsg(%s, 0, (sptr_t)&tr);
143 buf.UngetWriteBuf(len);
146 ('Retrieve a buffer of cells.',)),
149 'PositionFromPoint' :
151 'int %s(wxPoint pt) const;',
153 '''int %s(wxPoint pt) const {
154 return SendMsg(%s, pt.x, pt.y);''',
159 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
161 '''wxString %s(int* linePos) {
162 int len = LineLength(GetCurrentLine());
164 if (linePos) *linePos = 0;
165 return wxEmptyString;
168 wxMemoryBuffer mbuf(len+1);
169 char* buf = (char*)mbuf.GetWriteBuf(len+1);
171 int pos = SendMsg(%s, len+1, (sptr_t)buf);
172 mbuf.UngetWriteBuf(len);
174 if (linePos) *linePos = pos;
175 return stc2wx(buf);''',
179 'SetUsePalette' : (None, 0,0,0),
181 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
182 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
184 'MarkerSymbolDefined' : ('GetMarkerSymbolDefined', 0, 0, 0),
188 '''void %s(int markerNumber, int markerSymbol,
189 const wxColour& foreground = wxNullColour,
190 const wxColour& background = wxNullColour);''',
192 '''void %s(int markerNumber, int markerSymbol,
193 const wxColour& foreground,
194 const wxColour& background) {
196 SendMsg(%s, markerNumber, markerSymbol);
198 MarkerSetForeground(markerNumber, foreground);
200 MarkerSetBackground(markerNumber, background);''',
202 ('Set the symbol used for a particular marker number,',
203 'and optionally the fore and background colours.')),
206 'MarkerDefinePixmap' :
207 ('MarkerDefineBitmap',
208 '''void %s(int markerNumber, const wxBitmap& bmp);''',
209 '''void %s(int markerNumber, const wxBitmap& bmp) {
210 // convert bmp to a xpm in a string
211 wxMemoryOutputStream strm;
212 wxImage img = bmp.ConvertToImage();
214 img.ConvertAlphaToMask();
215 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
216 size_t len = strm.GetSize();
217 char* buff = new char[len+1];
218 strm.CopyTo(buff, len);
220 SendMsg(%s, markerNumber, (sptr_t)buff);
223 ('Define a marker from a bitmap',)),
226 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
227 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
228 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
229 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
230 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
231 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
232 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
233 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
237 'wxString %s(int line) const;',
239 '''wxString %s(int line) const {
241 long len = SendMsg(msg, line, 0);
243 wxMemoryBuffer mbuf(len+1);
244 char* buf = (char*)mbuf.GetWriteBuf(len+1);
245 SendMsg(msg, line, (sptr_t)buf);
246 mbuf.UngetWriteBuf(len);
248 return stc2wx(buf);''',
253 'wxString %s(int line) const;',
255 '''wxString %s(int line) const {
257 long len = SendMsg(msg, line, 0);
259 wxMemoryBuffer mbuf(len+1);
260 char* buf = (char*)mbuf.GetWriteBuf(len+1);
261 SendMsg(msg, line, (sptr_t)buf);
262 mbuf.UngetWriteBuf(len);
264 return stc2wx(buf);''',
267 'SetAdditionalSelFore' : ('SetAdditionalSelForeground', 0, 0, 0),
268 'SetAdditionalSelBack' : ('SetAdditionalSelBackground', 0, 0, 0),
269 'SetAdditionalCaretFore' : ('SetAdditionalCaretForeground', 0, 0, 0),
270 'GetAdditionalCaretFore' : ('GetAdditionalCaretForeground', 0, 0, 0),
272 'AnnotationGetText' :
274 'wxString %s(int line) const;',
276 '''wxString %s(int line) const {
278 long len = SendMsg(msg, line, 0);
280 wxMemoryBuffer mbuf(len+1);
281 char* buf = (char*)mbuf.GetWriteBuf(len+1);
282 SendMsg(msg, line, (sptr_t)buf);
283 mbuf.UngetWriteBuf(len);
285 return stc2wx(buf);''',
288 'AnnotationGetStyles' :
290 'wxString %s(int line) const;',
292 '''wxString %s(int line) const {
294 long len = SendMsg(msg, line, 0);
296 wxMemoryBuffer mbuf(len+1);
297 char* buf = (char*)mbuf.GetWriteBuf(len+1);
298 SendMsg(msg, line, (sptr_t)buf);
299 mbuf.UngetWriteBuf(len);
301 return stc2wx(buf);''',
304 'StyleGetFore' : ('StyleGetForeground', 0, 0, 0),
305 'StyleGetBack' : ('StyleGetBackground', 0, 0, 0),
306 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
307 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
308 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
309 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
310 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
313 'wxString %s(int style);',
314 '''wxString %s(int style) {
316 long len = SendMsg(msg, style, 0);
317 wxMemoryBuffer mbuf(len+1);
318 char* buf = (char*)mbuf.GetWriteBuf(len+1);
319 SendMsg(msg, style, (sptr_t)buf);
320 mbuf.UngetWriteBuf(len);
322 return stc2wx(buf);''',
323 ('Get the font facename of a style',)),
324 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
325 'StyleSetCharacterSet' : (None, 0, 0, 0),
329 'void %s(int key, int modifiers, int cmd);',
331 '''void %s(int key, int modifiers, int cmd) {
332 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
338 'void %s(int key, int modifiers);',
340 '''void %s(int key, int modifiers) {
341 SendMsg(%s, MAKELONG(key, modifiers));''',
344 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
349 'void %s(int length, char* styleBytes);',
351 '''void %s(int length, char* styleBytes) {
352 SendMsg(%s, length, (sptr_t)styleBytes);''',
356 'IndicSetAlpha' : ('IndicatorSetAlpha', 0, 0, 0),
357 'IndicGetAlpha' : ('IndicatorGetAlpha', 0, 0, 0),
358 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
359 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
360 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
361 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
362 'IndicSetUnder': ('IndicatorSetUnder', 0, 0, 0),
363 'IndicGetUnder': ('IndicatorGetUnder', 0, 0, 0),
365 'SetWhitespaceFore' : ('SetWhitespaceForeground', 0, 0, 0),
366 'SetWhitespaceBack' : ('SetWhitespaceBackground', 0, 0, 0),
368 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
369 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
370 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
371 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
372 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
373 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
374 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
375 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
376 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
377 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
378 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
379 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
380 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
381 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
382 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
383 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
384 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
385 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
386 'AutoCSetDropRestOfWord' : ('AutoCompSetDropRestOfWord', 0,0,0),
387 'AutoCGetDropRestOfWord' : ('AutoCompGetDropRestOfWord', 0,0,0),
388 'AutoCGetTypeSeparator' : ('AutoCompGetTypeSeparator', 0, 0, 0),
389 'AutoCSetTypeSeparator' : ('AutoCompSetTypeSeparator', 0, 0, 0),
390 'AutoCGetCurrent' : ('AutoCompGetCurrent', 0, 0, 0),
391 'AutoCGetCurrentText' : (None, 0, 0, 0),
392 'AutoCSetMaxWidth' : ('AutoCompSetMaxWidth', 0, 0, 0),
393 'AutoCGetMaxWidth' : ('AutoCompGetMaxWidth', 0, 0, 0),
394 'AutoCSetMaxHeight' : ('AutoCompSetMaxHeight', 0, 0, 0),
395 'AutoCGetMaxHeight' : ('AutoCompGetMaxHeight', 0, 0, 0),
396 'AutoCGetMaxHeight' : ('AutoCompGetMaxHeight', 0, 0, 0),
400 '''void %s(int type, const wxBitmap& bmp);''',
401 '''void %s(int type, const wxBitmap& bmp) {
402 // convert bmp to a xpm in a string
403 wxMemoryOutputStream strm;
404 wxImage img = bmp.ConvertToImage();
406 img.ConvertAlphaToMask();
407 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
408 size_t len = strm.GetSize();
409 char* buff = new char[len+1];
410 strm.CopyTo(buff, len);
412 SendMsg(%s, type, (sptr_t)buff);
415 ('Register an image for use in autocompletion lists.',)),
418 'ClearRegisteredImages' : (0, 0, 0,
419 ('Clear all the registered images.',)),
422 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
423 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
425 'SetVScrollBar' : ('SetUseVerticalScrollBar', 0, 0, 0),
426 'GetVScrollBar' : ('GetUseVerticalScrollBar', 0, 0, 0),
428 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
430 'GetUsePalette' : (None, 0, 0, 0),
434 '''int %s(int minPos, int maxPos, const wxString& text, int flags=0);''',
436 '''int %s(int minPos, int maxPos,
437 const wxString& text,
440 ft.chrg.cpMin = minPos;
441 ft.chrg.cpMax = maxPos;
442 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
443 ft.lpstrText = (char*)(const char*)buf;
445 return SendMsg(%s, flags, (sptr_t)&ft);''',
450 '''int %s(bool doDraw,
456 wxRect pageRect);''',
457 ''' int %s(bool doDraw,
466 if (endPos < startPos) {
472 fr.hdcTarget = target;
473 fr.rc.top = renderRect.GetTop();
474 fr.rc.left = renderRect.GetLeft();
475 fr.rc.right = renderRect.GetRight();
476 fr.rc.bottom = renderRect.GetBottom();
477 fr.rcPage.top = pageRect.GetTop();
478 fr.rcPage.left = pageRect.GetLeft();
479 fr.rcPage.right = pageRect.GetRight();
480 fr.rcPage.bottom = pageRect.GetBottom();
481 fr.chrg.cpMin = startPos;
482 fr.chrg.cpMax = endPos;
484 return SendMsg(%s, doDraw, (sptr_t)&fr);''',
490 'wxString %s(int line) const;',
492 '''wxString %s(int line) const {
493 int len = LineLength(line);
494 if (!len) return wxEmptyString;
496 wxMemoryBuffer mbuf(len+1);
497 char* buf = (char*)mbuf.GetWriteBuf(len+1);
498 SendMsg(%s, line, (sptr_t)buf);
499 mbuf.UngetWriteBuf(len);
501 return stc2wx(buf);''',
503 ('Retrieve the contents of a line.',)),
505 'SetSel' : (None, 0,0,0), #'SetSelection', 0, 0, 0),
515 GetSelection(&start, &end);
516 int len = end - start;
517 if (!len) return wxEmptyString;
519 wxMemoryBuffer mbuf(len+2);
520 char* buf = (char*)mbuf.GetWriteBuf(len+1);
521 SendMsg(%s, 0, (sptr_t)buf);
522 mbuf.UngetWriteBuf(len);
524 return stc2wx(buf);''',
526 ('Retrieve the selected text.',)),
531 'wxString %s(int startPos, int endPos);',
533 '''wxString %s(int startPos, int endPos) {
534 if (endPos < startPos) {
539 int len = endPos - startPos;
540 if (!len) return wxEmptyString;
541 wxMemoryBuffer mbuf(len+1);
542 char* buf = (char*)mbuf.GetWriteBuf(len);
545 tr.chrg.cpMin = startPos;
546 tr.chrg.cpMax = endPos;
547 SendMsg(%s, 0, (sptr_t)&tr);
548 mbuf.UngetWriteBuf(len);
550 return stc2wx(buf);''',
552 ('Retrieve a range of text.',)),
554 'PointXFromPosition' : (None, 0, 0, 0),
555 'PointYFromPosition' : (None, 0, 0, 0),
557 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
558 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
559 'Null' : (None, 0, 0, 0),
563 'wxString %s() const;',
565 '''wxString %s() const {
566 int len = GetTextLength();
567 wxMemoryBuffer mbuf(len+1); // leave room for the null...
568 char* buf = (char*)mbuf.GetWriteBuf(len+1);
569 SendMsg(%s, len+1, (sptr_t)buf);
570 mbuf.UngetWriteBuf(len);
572 return stc2wx(buf);''',
574 ('Retrieve all the text in the document.', )),
576 'GetDirectFunction' : (None, 0, 0, 0),
577 'GetDirectPointer' : (None, 0, 0, 0),
579 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
580 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
581 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
582 'CallTipSetFore' : ('CallTipSetForeground', 0, 0, 0),
583 'CallTipSetForeHlt' : ('CallTipSetForegroundHighlight', 0, 0, 0),
585 'SetHotspotActiveFore' : ('SetHotspotActiveForeground', 0, 0, 0),
586 'SetHotspotActiveBack' : ('SetHotspotActiveBackground', 0, 0, 0),
587 'GetHotspotActiveFore' : ('GetHotspotActiveForeground', 0, 0, 0),
588 'GetHotspotActiveBack' : ('GetHotspotActiveBackground', 0, 0, 0),
590 'GetCaretLineBack' : ('GetCaretLineBackground', 0, 0, 0),
591 'SetCaretLineBack' : ('SetCaretLineBackground', 0, 0, 0),
595 'int %s(const wxString& text);',
598 int %s(const wxString& text) {
599 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
600 return SendMsg(%s, strlen(buf), (sptr_t)(const char*)buf);''',
605 'int %s(const wxString& text);',
608 int %s(const wxString& text) {
609 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
610 return SendMsg(%s, strlen(buf), (sptr_t)(const char*)buf);''',
615 'int %s(const wxString& text);',
618 int %s(const wxString& text) {
619 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
620 return SendMsg(%s, strlen(buf), (sptr_t)(const char*)buf);''',
623 # not sure what to do about these yet
624 'TargetAsUTF8' : ( None, 0, 0, 0),
625 'SetLengthForEncode' : ( None, 0, 0, 0),
626 'EncodedFromUTF8' : ( None, 0, 0, 0),
631 'wxString %s(const wxString& key);',
633 '''wxString %s(const wxString& key) {
634 int len = SendMsg(SCI_GETPROPERTY, (sptr_t)(const char*)wx2stc(key), 0);
635 if (!len) return wxEmptyString;
637 wxMemoryBuffer mbuf(len+1);
638 char* buf = (char*)mbuf.GetWriteBuf(len+1);
639 SendMsg(%s, (uptr_t)(const char*)wx2stc(key), (sptr_t)buf);
640 mbuf.UngetWriteBuf(len);
642 return stc2wx(buf);''',
643 ("Retrieve a 'property' value previously set with SetProperty.",)),
645 'GetPropertyExpanded' :
647 'wxString %s(const wxString& key);',
649 '''wxString %s(const wxString& key) {
650 int len = SendMsg(SCI_GETPROPERTYEXPANDED, (uptr_t)(const char*)wx2stc(key), 0);
651 if (!len) return wxEmptyString;
653 wxMemoryBuffer mbuf(len+1);
654 char* buf = (char*)mbuf.GetWriteBuf(len+1);
655 SendMsg(%s, (uptr_t)(const char*)wx2stc(key), (sptr_t)buf);
656 mbuf.UngetWriteBuf(len);
658 return stc2wx(buf);''',
659 ("Retrieve a 'property' value previously set with SetProperty,",
660 "with '$()' variable replacement on returned buffer.")),
662 'GetPropertyInt' : (0, 0, 0,
663 ("Retrieve a 'property' value previously set with SetProperty,",
664 "interpreted as an int AFTER any '$()' variable replacement.")),
671 return (void*)SendMsg(%s);''',
676 'void %s(void* docPointer);',
677 '''void %s(void* docPointer) {
678 SendMsg(%s, 0, (sptr_t)docPointer);''',
685 return (void*)SendMsg(%s);''',
690 'void %s(void* docPointer);',
691 '''void %s(void* docPointer) {
692 SendMsg(%s, 0, (sptr_t)docPointer);''',
697 'void %s(void* docPointer);',
698 '''void %s(void* docPointer) {
699 SendMsg(%s, 0, (sptr_t)docPointer);''',
705 '''void %s(int codePage) {
707 wxASSERT_MSG(codePage == wxSTC_CP_UTF8,
708 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
710 wxASSERT_MSG(codePage != wxSTC_CP_UTF8,
711 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
713 SendMsg(%s, codePage);''',
714 ("Set the code page used to interpret the bytes of the document as characters.",) ),
717 'GrabFocus' : (None, 0, 0, 0),
719 # Rename some that would otherwise hide the wxWindow methods
720 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
721 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
722 'SetCursor' : ('SetSTCCursor', 0, 0, 0),
723 'GetCursor' : ('GetSTCCursor', 0, 0, 0),
725 'LoadLexerLibrary' : (None, 0,0,0),
727 'SetPositionCache' : ('SetPositionCacheSize', 0, 0, 0),
728 'GetPositionCache' : ('GetPositionCacheSize', 0, 0, 0),
730 'GetLexerLanguage' : (None, 0, 0, 0),
731 'SetFontQuality' : (None, 0, 0, 0),
732 'GetFontQuality' : (None, 0, 0, 0),
733 'SetSelection' : (None, 0, 0, 0),
735 'GetCharacterPointer' : (0,
737 'const char* %s() {\n'
738 ' return (const char*)SendMsg(%s, 0, 0);',
746 # all Scintilla getters are transformed into const member of wxSTC class but
747 # some non-getter methods are also logically const and this set contains their
748 # names (notice that it's useless to include here methods manually overridden
750 constNonGetterMethods
= (
759 #----------------------------------------------------------------------------
761 def processIface(iface
, h_tmplt
, cpp_tmplt
, h_dest
, cpp_dest
, docstr_dest
):
768 fi
= FileInput(iface
)
771 if line
[:2] == '##' or line
== '':
776 if line
[:2] == '# ': # a doc string
777 curDocStrings
.append(line
[2:])
780 parseVal(line
[4:], values
, curDocStrings
)
783 elif op
== 'fun ' or op
== 'set ' or op
== 'get ':
784 parseFun(line
[4:], methods
, curDocStrings
, cmds
, op
== 'get ')
788 if string
.strip(line
[4:]) == 'Deprecated':
789 break # skip the rest of the file
801 print '***** Unknown line type: ', line
806 data
['VALUES'] = processVals(values
)
807 data
['CMDS'] = processVals(cmds
)
808 defs
, imps
, docstrings
= processMethods(methods
)
809 data
['METHOD_DEFS'] = defs
810 data
['METHOD_IMPS'] = imps
813 h_text
= open(h_tmplt
).read()
814 cpp_text
= open(cpp_tmplt
).read()
816 # do the substitutions
817 h_text
= h_text
% data
818 cpp_text
= cpp_text
% data
820 # write out destination files
821 open(h_dest
, 'w').write(h_text
)
822 open(cpp_dest
, 'w').write(cpp_text
)
823 open(docstr_dest
, 'w').write(docstrings
)
827 def joinWithNewLines(values
):
828 return string
.join(values
, '\n')
830 #----------------------------------------------------------------------------
832 def processVals(values
):
834 for name
, value
, docs
in values
:
838 text
.append('// ' + x
)
839 text
.append('#define %s %s' % (name
, value
))
840 return joinWithNewLines(text
)
842 #----------------------------------------------------------------------------
844 def processMethods(methods
):
849 for retType
, name
, number
, param1
, param2
, docs
, is_const
in methods
:
850 retType
= retTypeMap
.get(retType
, retType
)
851 params
= makeParamString(param1
, param2
)
853 name
, theDef
, theImp
, docs
= checkMethodOverride(name
, number
, docs
)
859 st
= 'DocStr(wxStyledTextCtrl::%s,\n' \
860 '"%s", "");\n' % (name
, joinWithNewLines(docs
))
863 # Build the method definition for the .h file
867 defs
.append(' // ' + x
)
869 theDef
= ' %s %s(%s)' % (retType
, name
, params
)
871 theDef
= theDef
+ ' const'
872 theDef
= theDef
+ ';'
875 # Build the method implementation string
879 imps
.append('// ' + x
)
881 theImp
= '%s wxStyledTextCtrl::%s(%s)' % (retType
, name
, params
)
883 theImp
= theImp
+ ' const'
884 theImp
= theImp
+ '\n{\n '
885 if retType
== 'wxColour':
886 theImp
= theImp
+ 'long c = '
887 elif retType
!= 'void':
888 theImp
= theImp
+ 'return '
889 theImp
= theImp
+ 'SendMsg(%s, %s, %s)' % (number
,
890 makeArgString(param1
),
891 makeArgString(param2
))
892 if retType
== 'bool':
893 theImp
= theImp
+ ' != 0'
894 if retType
== 'wxColour':
895 theImp
= theImp
+ ';\n return wxColourFromLong(c)'
897 theImp
= theImp
+ ';\n}'
901 return joinWithNewLines(defs
), joinWithNewLines(imps
), joinWithNewLines(dstr
)
904 #----------------------------------------------------------------------------
906 def checkMethodOverride(name
, number
, docs
):
907 theDef
= theImp
= None
908 if methodOverrideMap
.has_key(name
):
909 item
= methodOverrideMap
[name
]
915 theDef
= ' ' + (item
[1] % name
)
917 theImp
= item
[2] % ('wxStyledTextCtrl::'+name
, number
) + '\n}'
921 print "*************", name
924 return name
, theDef
, theImp
, docs
926 #----------------------------------------------------------------------------
928 def makeArgString(param
):
935 return '(sptr_t)(const char*)wx2stc(%s)' % name
937 return 'wxColourAsLong(%s)' % name
941 #----------------------------------------------------------------------------
943 def makeParamString(param1
, param2
):
946 aType
= paramTypeMap
.get(param
[0], param
[0])
947 return aType
+ ' ' + param
[1]
954 st
= st
+ doOne(param2
)
958 #----------------------------------------------------------------------------
960 def parseVal(line
, values
, docs
):
961 name
, val
= string
.split(line
, '=')
963 # remove prefixes such as SCI, etc.
964 for old
, new
in valPrefixes
:
969 name
= new
+ name
[lo
:]
972 values
.append( ('wxSTC_' + name
, val
, docs
) )
974 #----------------------------------------------------------------------------
976 funregex
= re
.compile(r
'\s*([a-zA-Z0-9_]+)' # <ws>return type
977 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
979 '\(([ a-zA-Z0-9_]*),' # (param,
980 '([ a-zA-Z0-9_]*),*\)') # param)
982 def parseFun(line
, methods
, docs
, values
, is_const
):
983 def parseParam(param
):
984 param
= string
.strip(param
)
988 param
= tuple(string
.split(param
))
991 mo
= funregex
.match(line
)
993 print "***** Line doesn't match! : " + line
995 retType
, name
, number
, param1
, param2
= mo
.groups()
997 param1
= parseParam(param1
)
998 param2
= parseParam(param2
)
1000 # Special case. For the key command functions we want a value defined too
1001 num
= string
.atoi(number
)
1003 if (type(v
) == type(()) and v
[0] <= num
<= v
[1]) or v
== num
:
1004 parseVal('CMD_%s=%s' % (string
.upper(name
), number
), values
, docs
)
1006 # if we are not also doing a function for CMD values, then
1007 # just return, otherwise fall through to the append blow.
1008 if not FUNC_FOR_CMD
:
1011 methods
.append( (retType
, name
, number
, param1
, param2
, tuple(docs
),
1012 is_const
or name
in constNonGetterMethods
) )
1015 #----------------------------------------------------------------------------
1019 # TODO: parse command line args to replace default input/output files???
1021 if not os
.path
.exists(IFACE
):
1022 print 'Please run this script from src/stc subdirectory.'
1026 processIface(IFACE
, H_TEMPLATE
, CPP_TEMPLATE
, H_DEST
, CPP_DEST
, DOCSTR_DEST
)
1030 if __name__
== '__main__':
1033 #----------------------------------------------------------------------------