]>
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')
26 # Value prefixes to convert
27 valPrefixes
= [('SCI_', ''),
29 ('SCN_', None), # just toss these out...
38 # Message function values that should have a CMD_ constant generated
39 cmdValues
= [ (2300, 2349),
52 # Should a funciton be also generated for the CMDs?
56 # Map some generic typenames to wx types, using return value syntax
63 # Map some generic typenames to wx types, using parameter syntax
66 'string': 'const wxString&',
67 'colour': 'const wxColour&',
71 # Map of method info that needs tweaked. Either the name needs changed, or
72 # the method definition/implementation. Tuple items are:
74 # 1. New method name. None to skip the method, 0 to leave the
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.
82 'void %s(const wxString& text);',
84 '''void %s(const wxString& text) {
85 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
86 SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
90 'void %s(const wxMemoryBuffer& data);',
92 '''void %s(const wxMemoryBuffer& data) {
93 SendMsg(%s, data.GetDataLen(), (long)data.GetData());''',
97 'void %s(const wxString& text);',
99 '''void %s(const wxString& text) {
100 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
101 SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
104 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
105 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
110 return (unsigned char)SendMsg(%s, pos, 0);''',
116 return (unsigned char)SendMsg(%s, pos, 0);''',
121 'wxMemoryBuffer %s(int startPos, int endPos);',
123 '''wxMemoryBuffer %s(int startPos, int endPos) {
125 if (endPos < startPos) {
130 int len = endPos - startPos;
131 if (!len) return buf;
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);
140 ('Retrieve a buffer of cells.',)),
143 'PositionFromPoint' :
145 'int %s(wxPoint pt);',
147 '''int %s(wxPoint pt) {
148 return SendMsg(%s, pt.x, pt.y);''',
153 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
155 '''wxString %s(int* linePos) {
156 int len = LineLength(GetCurrentLine());
158 if (linePos) *linePos = 0;
159 return wxEmptyString;
162 wxMemoryBuffer mbuf(len+1);
163 char* buf = (char*)mbuf.GetWriteBuf(len+1);
165 int pos = SendMsg(%s, len+1, (long)buf);
166 mbuf.UngetWriteBuf(len);
168 if (linePos) *linePos = pos;
169 return stc2wx(buf);''',
173 'SetUsePalette' : (None, 0,0,0),
175 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
176 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
180 '''void %s(int markerNumber, int markerSymbol,
181 const wxColour& foreground = wxNullColour,
182 const wxColour& background = wxNullColour);''',
184 '''void %s(int markerNumber, int markerSymbol,
185 const wxColour& foreground,
186 const wxColour& background) {
188 SendMsg(%s, markerNumber, markerSymbol);
190 MarkerSetForeground(markerNumber, foreground);
192 MarkerSetBackground(markerNumber, background);''',
194 ('Set the symbol used for a particular marker number,',
195 'and optionally the fore and background colours.')),
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);
210 SendMsg(%s, markerNumber, (long)buff);
213 ('Define a marker from a bitmap',)),
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),
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),
234 'void %s(int key, int modifiers, int cmd);',
236 '''void %s(int key, int modifiers, int cmd) {
237 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
243 'void %s(int key, int modifiers);',
245 '''void %s(int key, int modifiers) {
246 SendMsg(%s, MAKELONG(key, modifiers));''',
249 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
254 'void %s(int length, char* styleBytes);',
256 '''void %s(int length, char* styleBytes) {
257 SendMsg(%s, length, (long)styleBytes);''',
261 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
262 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
263 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
264 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
266 'SetWhitespaceFore' : ('SetWhitespaceForeground', 0, 0, 0),
267 'SetWhitespaceBack' : ('SetWhitespaceBackground', 0, 0, 0),
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),
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);
305 SendMsg(%s, type, (long)buff);
308 ('Register an image for use in autocompletion lists.',)),
311 'ClearRegisteredImages' : (0, 0, 0,
312 ('Clear all the registered images.',)),
315 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
316 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
318 'SetVScrollBar' : ('SetUseVerticalScrollBar', 0, 0, 0),
319 'GetVScrollBar' : ('GetUseVerticalScrollBar', 0, 0, 0),
321 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
323 'GetUsePalette' : (None, 0, 0, 0),
327 '''int %s(int minPos, int maxPos, const wxString& text, int flags=0);''',
329 '''int %s(int minPos, int maxPos,
330 const wxString& text,
333 ft.chrg.cpMin = minPos;
334 ft.chrg.cpMax = maxPos;
335 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
336 ft.lpstrText = (char*)(const char*)buf;
338 return SendMsg(%s, flags, (long)&ft);''',
343 '''int %s(bool doDraw,
349 wxRect pageRect);''',
350 ''' int %s(bool doDraw,
359 if (endPos < startPos) {
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;
377 return SendMsg(%s, doDraw, (long)&fr);''',
383 'wxString %s(int line);',
385 '''wxString %s(int line) {
386 int len = LineLength(line);
387 if (!len) return wxEmptyString;
389 wxMemoryBuffer mbuf(len+1);
390 char* buf = (char*)mbuf.GetWriteBuf(len+1);
391 SendMsg(%s, line, (long)buf);
392 mbuf.UngetWriteBuf(len);
394 return stc2wx(buf);''',
396 ('Retrieve the contents of a line.',)),
398 'SetSel' : ('SetSelection', 0, 0, 0),
408 GetSelection(&start, &end);
409 int len = end - start;
410 if (!len) return wxEmptyString;
412 wxMemoryBuffer mbuf(len+2);
413 char* buf = (char*)mbuf.GetWriteBuf(len+1);
414 SendMsg(%s, 0, (long)buf);
415 mbuf.UngetWriteBuf(len);
417 return stc2wx(buf);''',
419 ('Retrieve the selected text.',)),
424 'wxString %s(int startPos, int endPos);',
426 '''wxString %s(int startPos, int endPos) {
427 if (endPos < startPos) {
432 int len = endPos - startPos;
433 if (!len) return wxEmptyString;
434 wxMemoryBuffer mbuf(len+1);
435 char* buf = (char*)mbuf.GetWriteBuf(len);
438 tr.chrg.cpMin = startPos;
439 tr.chrg.cpMax = endPos;
440 SendMsg(%s, 0, (long)&tr);
441 mbuf.UngetWriteBuf(len);
443 return stc2wx(buf);''',
445 ('Retrieve a range of text.',)),
447 'PointXFromPosition' : (None, 0, 0, 0),
448 'PointYFromPosition' : (None, 0, 0, 0),
450 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
451 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
452 'Null' : (None, 0, 0, 0),
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);
465 return stc2wx(buf);''',
467 ('Retrieve all the text in the document.', )),
469 'GetDirectFunction' : (None, 0, 0, 0),
470 'GetDirectPointer' : (None, 0, 0, 0),
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),
478 'SetHotspotActiveFore' : ('SetHotspotActiveForeground', 0, 0, 0),
479 'SetHotspotActiveBack' : ('SetHotspotActiveBackground', 0, 0, 0),
484 'int %s(const wxString& text);',
487 int %s(const wxString& text) {
488 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
489 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
494 'int %s(const wxString& text);',
497 int %s(const wxString& text) {
498 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
499 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
504 'int %s(const wxString& text);',
507 int %s(const wxString& text) {
508 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
509 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
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),
522 return (void*)SendMsg(%s);''',
527 'void %s(void* docPointer);',
528 '''void %s(void* docPointer) {
529 SendMsg(%s, 0, (long)docPointer);''',
536 return (void*)SendMsg(%s);''',
541 'void %s(void* docPointer);',
542 '''void %s(void* docPointer) {
543 SendMsg(%s, 0, (long)docPointer);''',
548 'void %s(void* docPointer);',
549 '''void %s(void* docPointer) {
550 SendMsg(%s, 0, (long)docPointer);''',
556 '''void %s(int codePage) {
558 wxASSERT_MSG(codePage == wxSTC_CP_UTF8,
559 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
561 wxASSERT_MSG(codePage != wxSTC_CP_UTF8,
562 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
564 SendMsg(%s, codePage);''',
565 ("Set the code page used to interpret the bytes of the document as characters.",) ),
568 'GrabFocus' : (None, 0, 0, 0),
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),
576 'LoadLexerLibrary' : (None, 0,0,0),
583 #----------------------------------------------------------------------------
585 def processIface(iface
, h_tmplt
, cpp_tmplt
, h_dest
, cpp_dest
):
592 fi
= FileInput(iface
)
595 if line
[:2] == '##' or line
== '':
600 if line
[:2] == '# ': # a doc string
601 curDocStrings
.append(line
[2:])
604 parseVal(line
[4:], values
, curDocStrings
)
607 elif op
== 'fun ' or op
== 'set ' or op
== 'get ':
608 parseFun(line
[4:], methods
, curDocStrings
, cmds
)
612 if string
.strip(line
[4:]) == 'Deprecated':
613 break # skip the rest of the file
625 print '***** Unknown line type: ', line
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
637 h_text
= open(h_tmplt
).read()
638 cpp_text
= open(cpp_tmplt
).read()
640 # do the substitutions
641 h_text
= h_text
% data
642 cpp_text
= cpp_text
% data
644 # write out destination files
645 open(h_dest
, 'w').write(h_text
)
646 open(cpp_dest
, 'w').write(cpp_text
)
650 #----------------------------------------------------------------------------
652 def processVals(values
):
654 for name
, value
, docs
in values
:
658 text
.append('// ' + x
)
659 text
.append('#define %s %s' % (name
, value
))
660 return string
.join(text
, '\n')
662 #----------------------------------------------------------------------------
664 def processMethods(methods
):
668 for retType
, name
, number
, param1
, param2
, docs
in methods
:
669 retType
= retTypeMap
.get(retType
, retType
)
670 params
= makeParamString(param1
, param2
)
672 name
, theDef
, theImp
, docs
= checkMethodOverride(name
, number
, docs
)
677 # Build the method definition for the .h file
681 defs
.append(' // ' + x
)
683 theDef
= ' %s %s(%s);' % (retType
, name
, params
)
686 # Build the method implementation string
690 imps
.append('// ' + x
)
692 theImp
= '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType
, name
, params
)
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)'
706 theImp
= theImp
+ ';\n}'
710 return string
.join(defs
, '\n'), string
.join(imps
, '\n')
713 #----------------------------------------------------------------------------
715 def checkMethodOverride(name
, number
, docs
):
716 theDef
= theImp
= None
717 if methodOverrideMap
.has_key(name
):
718 item
= methodOverrideMap
[name
]
724 theDef
= ' ' + (item
[1] % name
)
726 theImp
= item
[2] % ('wxStyledTextCtrl::'+name
, number
) + '\n}'
730 print "*************", name
733 return name
, theDef
, theImp
, docs
735 #----------------------------------------------------------------------------
737 def makeArgString(param
):
744 return '(long)(const char*)wx2stc(%s)' % name
746 return 'wxColourAsLong(%s)' % name
750 #----------------------------------------------------------------------------
752 def makeParamString(param1
, param2
):
755 aType
= paramTypeMap
.get(param
[0], param
[0])
756 return aType
+ ' ' + param
[1]
763 st
= st
+ doOne(param2
)
767 #----------------------------------------------------------------------------
769 def parseVal(line
, values
, docs
):
770 name
, val
= string
.split(line
, '=')
772 # remove prefixes such as SCI, etc.
773 for old
, new
in valPrefixes
:
778 name
= new
+ name
[lo
:]
781 values
.append( ('wxSTC_' + name
, val
, docs
) )
783 #----------------------------------------------------------------------------
785 funregex
= re
.compile(r
'\s*([a-zA-Z0-9_]+)' # <ws>return type
786 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
788 '\(([ a-zA-Z0-9_]*),' # (param,
789 '([ a-zA-Z0-9_]*)\)') # param)
791 def parseFun(line
, methods
, docs
, values
):
792 def parseParam(param
):
793 param
= string
.strip(param
)
797 param
= tuple(string
.split(param
))
800 mo
= funregex
.match(line
)
802 print "***** Line doesn't match! : " + line
804 retType
, name
, number
, param1
, param2
= mo
.groups()
806 param1
= parseParam(param1
)
807 param2
= parseParam(param2
)
809 # Special case. For the key command functions we want a value defined too
810 num
= string
.atoi(number
)
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
)
815 # if we are not also doing a function for CMD values, then
816 # just return, otherwise fall through to the append blow.
820 methods
.append( (retType
, name
, number
, param1
, param2
, tuple(docs
)) )
823 #----------------------------------------------------------------------------
827 # TODO: parse command line args to replace default input/output files???
830 processIface(IFACE
, H_TEMPLATE
, CPP_TEMPLATE
, H_DEST
, CPP_DEST
)
834 if __name__
== '__main__':
837 #----------------------------------------------------------------------------