]>
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 license
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 DOCSTR_DEST
= os
.path
.abspath('../../../wxPython/contrib/stc/_stc_gendocs.i')
27 # Value prefixes to convert
28 valPrefixes
= [('SCI_', ''),
30 ('SCN_', None), # just toss these out...
39 # Message function values that should have a CMD_ constant generated
40 cmdValues
= [ (2300, 2349),
53 # Should a funciton be also generated for the CMDs?
57 # Map some generic typenames to wx types, using return value syntax
64 # Map some generic typenames to wx types, using parameter syntax
67 'string': 'const wxString&',
68 'colour': 'const wxColour&',
72 # Map of method info that needs tweaked. Either the name needs changed, or
73 # the method definition/implementation. Tuple items are:
75 # 1. New method name. None to skip the method, 0 to leave the
77 # 2. Method definition for the .h file, 0 to leave alone
78 # 3. Method implementation for the .cpp file, 0 to leave alone.
79 # 4. tuple of Doc string lines, or 0 to leave alone.
83 'void %s(const wxString& text);',
85 '''void %s(const wxString& text) {
86 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
87 SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
91 'void %s(const wxMemoryBuffer& data);',
93 '''void %s(const wxMemoryBuffer& data) {
94 SendMsg(%s, data.GetDataLen(), (long)data.GetData());''',
98 'void %s(const wxString& text);',
100 '''void %s(const wxString& text) {
101 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
102 SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
105 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
106 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
111 return (unsigned char)SendMsg(%s, pos, 0);''',
117 return (unsigned char)SendMsg(%s, pos, 0);''',
122 'wxMemoryBuffer %s(int startPos, int endPos);',
124 '''wxMemoryBuffer %s(int startPos, int endPos) {
126 if (endPos < startPos) {
131 int len = endPos - startPos;
132 if (!len) return buf;
134 tr.lpstrText = (char*)buf.GetWriteBuf(len*2+1);
135 tr.chrg.cpMin = startPos;
136 tr.chrg.cpMax = endPos;
137 len = SendMsg(%s, 0, (long)&tr);
138 buf.UngetWriteBuf(len);
141 ('Retrieve a buffer of cells.',)),
144 'PositionFromPoint' :
146 'int %s(wxPoint pt);',
148 '''int %s(wxPoint pt) {
149 return SendMsg(%s, pt.x, pt.y);''',
154 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
156 '''wxString %s(int* linePos) {
157 int len = LineLength(GetCurrentLine());
159 if (linePos) *linePos = 0;
160 return wxEmptyString;
163 wxMemoryBuffer mbuf(len+1);
164 char* buf = (char*)mbuf.GetWriteBuf(len+1);
166 int pos = SendMsg(%s, len+1, (long)buf);
167 mbuf.UngetWriteBuf(len);
169 if (linePos) *linePos = pos;
170 return stc2wx(buf);''',
174 'SetUsePalette' : (None, 0,0,0),
176 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
177 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
181 '''void %s(int markerNumber, int markerSymbol,
182 const wxColour& foreground = wxNullColour,
183 const wxColour& background = wxNullColour);''',
185 '''void %s(int markerNumber, int markerSymbol,
186 const wxColour& foreground,
187 const wxColour& background) {
189 SendMsg(%s, markerNumber, markerSymbol);
191 MarkerSetForeground(markerNumber, foreground);
193 MarkerSetBackground(markerNumber, background);''',
195 ('Set the symbol used for a particular marker number,',
196 'and optionally the fore and background colours.')),
199 'MarkerDefinePixmap' :
200 ('MarkerDefineBitmap',
201 '''void %s(int markerNumber, const wxBitmap& bmp);''',
202 '''void %s(int markerNumber, const wxBitmap& bmp) {
203 // convert bmp to a xpm in a string
204 wxMemoryOutputStream strm;
205 wxImage img = bmp.ConvertToImage();
206 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
207 size_t len = strm.GetSize();
208 char* buff = new char[len+1];
209 strm.CopyTo(buff, len);
211 SendMsg(%s, markerNumber, (long)buff);
214 ('Define a marker from a bitmap',)),
217 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
218 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
219 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
220 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
221 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
222 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
223 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
224 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
226 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
227 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
228 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
229 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
230 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
231 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
232 'StyleSetCharacterSet' : (None, 0, 0, 0),
236 'void %s(int key, int modifiers, int cmd);',
238 '''void %s(int key, int modifiers, int cmd) {
239 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
245 'void %s(int key, int modifiers);',
247 '''void %s(int key, int modifiers) {
248 SendMsg(%s, MAKELONG(key, modifiers));''',
251 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
256 'void %s(int length, char* styleBytes);',
258 '''void %s(int length, char* styleBytes) {
259 SendMsg(%s, length, (long)styleBytes);''',
263 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
264 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
265 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
266 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
268 'SetWhitespaceFore' : ('SetWhitespaceForeground', 0, 0, 0),
269 'SetWhitespaceBack' : ('SetWhitespaceBackground', 0, 0, 0),
271 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
272 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
273 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
274 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
275 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
276 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
277 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
278 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
279 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
280 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
281 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
282 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
283 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
284 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
285 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
286 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
287 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
288 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
289 'AutoCSetDropRestOfWord' : ('AutoCompSetDropRestOfWord', 0,0,0),
290 'AutoCGetDropRestOfWord' : ('AutoCompGetDropRestOfWord', 0,0,0),
291 'AutoCGetTypeSeparator' : ('AutoCompGetTypeSeparator', 0, 0, 0),
292 'AutoCSetTypeSeparator' : ('AutoCompSetTypeSeparator', 0, 0, 0),
293 'AutoCGetCurrent' : ('AutoCompGetCurrent', 0, 0, 0),
297 '''void %s(int type, const wxBitmap& bmp);''',
298 '''void %s(int type, const wxBitmap& bmp) {
299 // convert bmp to a xpm in a string
300 wxMemoryOutputStream strm;
301 wxImage img = bmp.ConvertToImage();
302 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
303 size_t len = strm.GetSize();
304 char* buff = new char[len+1];
305 strm.CopyTo(buff, len);
307 SendMsg(%s, type, (long)buff);
310 ('Register an image for use in autocompletion lists.',)),
313 'ClearRegisteredImages' : (0, 0, 0,
314 ('Clear all the registered images.',)),
317 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
318 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
320 'SetVScrollBar' : ('SetUseVerticalScrollBar', 0, 0, 0),
321 'GetVScrollBar' : ('GetUseVerticalScrollBar', 0, 0, 0),
323 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
325 'GetUsePalette' : (None, 0, 0, 0),
329 '''int %s(int minPos, int maxPos, const wxString& text, int flags=0);''',
331 '''int %s(int minPos, int maxPos,
332 const wxString& text,
335 ft.chrg.cpMin = minPos;
336 ft.chrg.cpMax = maxPos;
337 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
338 ft.lpstrText = (char*)(const char*)buf;
340 return SendMsg(%s, flags, (long)&ft);''',
345 '''int %s(bool doDraw,
351 wxRect pageRect);''',
352 ''' int %s(bool doDraw,
361 if (endPos < startPos) {
367 fr.hdcTarget = target;
368 fr.rc.top = renderRect.GetTop();
369 fr.rc.left = renderRect.GetLeft();
370 fr.rc.right = renderRect.GetRight();
371 fr.rc.bottom = renderRect.GetBottom();
372 fr.rcPage.top = pageRect.GetTop();
373 fr.rcPage.left = pageRect.GetLeft();
374 fr.rcPage.right = pageRect.GetRight();
375 fr.rcPage.bottom = pageRect.GetBottom();
376 fr.chrg.cpMin = startPos;
377 fr.chrg.cpMax = endPos;
379 return SendMsg(%s, doDraw, (long)&fr);''',
385 'wxString %s(int line);',
387 '''wxString %s(int line) {
388 int len = LineLength(line);
389 if (!len) return wxEmptyString;
391 wxMemoryBuffer mbuf(len+1);
392 char* buf = (char*)mbuf.GetWriteBuf(len+1);
393 SendMsg(%s, line, (long)buf);
394 mbuf.UngetWriteBuf(len);
396 return stc2wx(buf);''',
398 ('Retrieve the contents of a line.',)),
400 'SetSel' : ('SetSelection', 0, 0, 0),
410 GetSelection(&start, &end);
411 int len = end - start;
412 if (!len) return wxEmptyString;
414 wxMemoryBuffer mbuf(len+2);
415 char* buf = (char*)mbuf.GetWriteBuf(len+1);
416 SendMsg(%s, 0, (long)buf);
417 mbuf.UngetWriteBuf(len);
419 return stc2wx(buf);''',
421 ('Retrieve the selected text.',)),
426 'wxString %s(int startPos, int endPos);',
428 '''wxString %s(int startPos, int endPos) {
429 if (endPos < startPos) {
434 int len = endPos - startPos;
435 if (!len) return wxEmptyString;
436 wxMemoryBuffer mbuf(len+1);
437 char* buf = (char*)mbuf.GetWriteBuf(len);
440 tr.chrg.cpMin = startPos;
441 tr.chrg.cpMax = endPos;
442 SendMsg(%s, 0, (long)&tr);
443 mbuf.UngetWriteBuf(len);
445 return stc2wx(buf);''',
447 ('Retrieve a range of text.',)),
449 'PointXFromPosition' : (None, 0, 0, 0),
450 'PointYFromPosition' : (None, 0, 0, 0),
452 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
453 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
454 'Null' : (None, 0, 0, 0),
461 int len = GetTextLength();
462 wxMemoryBuffer mbuf(len+1); // leave room for the null...
463 char* buf = (char*)mbuf.GetWriteBuf(len+1);
464 SendMsg(%s, len+1, (long)buf);
465 mbuf.UngetWriteBuf(len);
467 return stc2wx(buf);''',
469 ('Retrieve all the text in the document.', )),
471 'GetDirectFunction' : (None, 0, 0, 0),
472 'GetDirectPointer' : (None, 0, 0, 0),
474 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
475 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
476 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
477 'CallTipSetFore' : ('CallTipSetForeground', 0, 0, 0),
478 'CallTipSetForeHlt' : ('CallTipSetForegroundHighlight', 0, 0, 0),
480 'SetHotspotActiveFore' : ('SetHotspotActiveForeground', 0, 0, 0),
481 'SetHotspotActiveBack' : ('SetHotspotActiveBackground', 0, 0, 0),
486 'int %s(const wxString& text);',
489 int %s(const wxString& text) {
490 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
491 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
496 'int %s(const wxString& text);',
499 int %s(const wxString& text) {
500 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
501 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
506 'int %s(const wxString& text);',
509 int %s(const wxString& text) {
510 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
511 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
514 # not sure what to do about these yet
515 'TargetAsUTF8' : ( None, 0, 0, 0),
516 'SetLengthForEncode' : ( None, 0, 0, 0),
517 'EncodedFromUTF8' : ( None, 0, 0, 0),
524 return (void*)SendMsg(%s);''',
529 'void %s(void* docPointer);',
530 '''void %s(void* docPointer) {
531 SendMsg(%s, 0, (long)docPointer);''',
538 return (void*)SendMsg(%s);''',
543 'void %s(void* docPointer);',
544 '''void %s(void* docPointer) {
545 SendMsg(%s, 0, (long)docPointer);''',
550 'void %s(void* docPointer);',
551 '''void %s(void* docPointer) {
552 SendMsg(%s, 0, (long)docPointer);''',
558 '''void %s(int codePage) {
560 wxASSERT_MSG(codePage == wxSTC_CP_UTF8,
561 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
563 wxASSERT_MSG(codePage != wxSTC_CP_UTF8,
564 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
566 SendMsg(%s, codePage);''',
567 ("Set the code page used to interpret the bytes of the document as characters.",) ),
570 'GrabFocus' : (None, 0, 0, 0),
572 # Rename some that would otherwise hide the wxWindow methods
573 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
574 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
575 'SetCursor' : ('SetSTCCursor', 0, 0, 0),
576 'GetCursor' : ('GetSTCCursor', 0, 0, 0),
578 'LoadLexerLibrary' : (None, 0,0,0),
585 #----------------------------------------------------------------------------
587 def processIface(iface
, h_tmplt
, cpp_tmplt
, h_dest
, cpp_dest
, docstr_dest
):
594 fi
= FileInput(iface
)
597 if line
[:2] == '##' or line
== '':
602 if line
[:2] == '# ': # a doc string
603 curDocStrings
.append(line
[2:])
606 parseVal(line
[4:], values
, curDocStrings
)
609 elif op
== 'fun ' or op
== 'set ' or op
== 'get ':
610 parseFun(line
[4:], methods
, curDocStrings
, cmds
)
614 if string
.strip(line
[4:]) == 'Deprecated':
615 break # skip the rest of the file
627 print '***** Unknown line type: ', line
632 data
['VALUES'] = processVals(values
)
633 data
['CMDS'] = processVals(cmds
)
634 defs
, imps
, docstrings
= processMethods(methods
)
635 data
['METHOD_DEFS'] = defs
636 data
['METHOD_IMPS'] = imps
639 h_text
= open(h_tmplt
).read()
640 cpp_text
= open(cpp_tmplt
).read()
642 # do the substitutions
643 h_text
= h_text
% data
644 cpp_text
= cpp_text
% data
646 # write out destination files
647 open(h_dest
, 'w').write(h_text
)
648 open(cpp_dest
, 'w').write(cpp_text
)
649 open(docstr_dest
, 'w').write(docstrings
)
653 #----------------------------------------------------------------------------
655 def processVals(values
):
657 for name
, value
, docs
in values
:
661 text
.append('// ' + x
)
662 text
.append('#define %s %s' % (name
, value
))
663 return string
.join(text
, '\n')
665 #----------------------------------------------------------------------------
667 def processMethods(methods
):
672 for retType
, name
, number
, param1
, param2
, docs
in methods
:
673 retType
= retTypeMap
.get(retType
, retType
)
674 params
= makeParamString(param1
, param2
)
676 name
, theDef
, theImp
, docs
= checkMethodOverride(name
, number
, docs
)
682 st
= 'DocStr(wxStyledTextCtrl::%s,\n' \
683 '"%s", "");\n' % (name
, '\n'.join(docs
))
686 # Build the method definition for the .h file
690 defs
.append(' // ' + x
)
692 theDef
= ' %s %s(%s);' % (retType
, name
, params
)
695 # Build the method implementation string
699 imps
.append('// ' + x
)
701 theImp
= '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType
, name
, params
)
703 if retType
== 'wxColour':
704 theImp
= theImp
+ 'long c = '
705 elif retType
!= 'void':
706 theImp
= theImp
+ 'return '
707 theImp
= theImp
+ 'SendMsg(%s, %s, %s)' % (number
,
708 makeArgString(param1
),
709 makeArgString(param2
))
710 if retType
== 'bool':
711 theImp
= theImp
+ ' != 0'
712 if retType
== 'wxColour':
713 theImp
= theImp
+ ';\n return wxColourFromLong(c)'
715 theImp
= theImp
+ ';\n}'
719 return '\n'.join(defs
), '\n'.join(imps
), '\n'.join(dstr
)
722 #----------------------------------------------------------------------------
724 def checkMethodOverride(name
, number
, docs
):
725 theDef
= theImp
= None
726 if methodOverrideMap
.has_key(name
):
727 item
= methodOverrideMap
[name
]
733 theDef
= ' ' + (item
[1] % name
)
735 theImp
= item
[2] % ('wxStyledTextCtrl::'+name
, number
) + '\n}'
739 print "*************", name
742 return name
, theDef
, theImp
, docs
744 #----------------------------------------------------------------------------
746 def makeArgString(param
):
753 return '(long)(const char*)wx2stc(%s)' % name
755 return 'wxColourAsLong(%s)' % name
759 #----------------------------------------------------------------------------
761 def makeParamString(param1
, param2
):
764 aType
= paramTypeMap
.get(param
[0], param
[0])
765 return aType
+ ' ' + param
[1]
772 st
= st
+ doOne(param2
)
776 #----------------------------------------------------------------------------
778 def parseVal(line
, values
, docs
):
779 name
, val
= string
.split(line
, '=')
781 # remove prefixes such as SCI, etc.
782 for old
, new
in valPrefixes
:
787 name
= new
+ name
[lo
:]
790 values
.append( ('wxSTC_' + name
, val
, docs
) )
792 #----------------------------------------------------------------------------
794 funregex
= re
.compile(r
'\s*([a-zA-Z0-9_]+)' # <ws>return type
795 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
797 '\(([ a-zA-Z0-9_]*),' # (param,
798 '([ a-zA-Z0-9_]*)\)') # param)
800 def parseFun(line
, methods
, docs
, values
):
801 def parseParam(param
):
802 param
= string
.strip(param
)
806 param
= tuple(string
.split(param
))
809 mo
= funregex
.match(line
)
811 print "***** Line doesn't match! : " + line
813 retType
, name
, number
, param1
, param2
= mo
.groups()
815 param1
= parseParam(param1
)
816 param2
= parseParam(param2
)
818 # Special case. For the key command functions we want a value defined too
819 num
= string
.atoi(number
)
821 if (type(v
) == type(()) and v
[0] <= num
<= v
[1]) or v
== num
:
822 parseVal('CMD_%s=%s' % (string
.upper(name
), number
), values
, docs
)
824 # if we are not also doing a function for CMD values, then
825 # just return, otherwise fall through to the append blow.
829 methods
.append( (retType
, name
, number
, param1
, param2
, tuple(docs
)) )
832 #----------------------------------------------------------------------------
836 # TODO: parse command line args to replace default input/output files???
839 processIface(IFACE
, H_TEMPLATE
, CPP_TEMPLATE
, H_DEST
, CPP_DEST
, DOCSTR_DEST
)
843 if __name__
== '__main__':
846 #----------------------------------------------------------------------------