]>
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());''',
96 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
97 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
102 return (unsigned char)SendMsg(%s, pos, 0);''',
108 return (unsigned char)SendMsg(%s, pos, 0);''',
113 'wxMemoryBuffer %s(int startPos, int endPos);',
115 '''wxMemoryBuffer %s(int startPos, int endPos) {
117 if (endPos < startPos) {
122 int len = endPos - startPos;
123 if (!len) return buf;
125 tr.lpstrText = (char*)buf.GetWriteBuf(len*2+1);
126 tr.chrg.cpMin = startPos;
127 tr.chrg.cpMax = endPos;
128 len = SendMsg(%s, 0, (long)&tr);
129 buf.UngetWriteBuf(len);
132 ('Retrieve a buffer of cells.',)),
135 'PositionFromPoint' :
137 'int %s(wxPoint pt);',
139 '''int %s(wxPoint pt) {
140 return SendMsg(%s, pt.x, pt.y);''',
145 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
147 '''wxString %s(int* linePos) {
148 int len = LineLength(GetCurrentLine());
150 if (linePos) *linePos = 0;
151 return wxEmptyString;
154 wxMemoryBuffer mbuf(len+1);
155 char* buf = (char*)mbuf.GetWriteBuf(len+1);
157 int pos = SendMsg(%s, len+1, (long)buf);
158 mbuf.UngetWriteBuf(len);
160 if (linePos) *linePos = pos;
161 return stc2wx(buf);''',
165 'SetUsePalette' : (None, 0,0,0),
167 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
168 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
172 '''void %s(int markerNumber, int markerSymbol,
173 const wxColour& foreground = wxNullColour,
174 const wxColour& background = wxNullColour);''',
176 '''void %s(int markerNumber, int markerSymbol,
177 const wxColour& foreground,
178 const wxColour& background) {
180 SendMsg(%s, markerNumber, markerSymbol);
182 MarkerSetForeground(markerNumber, foreground);
184 MarkerSetBackground(markerNumber, background);''',
186 ('Set the symbol used for a particular marker number,',
187 'and optionally the fore and background colours.')),
190 'MarkerDefinePixmap' :
191 ('MarkerDefineBitmap',
192 '''void %s(int markerNumber, const wxBitmap& bmp);''',
193 '''void %s(int markerNumber, const wxBitmap& bmp) {
194 // convert bmp to a xpm in a string
195 wxMemoryOutputStream strm;
196 wxImage img = bmp.ConvertToImage();
197 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
198 size_t len = strm.GetSize();
199 char* buff = new char[len+1];
200 strm.CopyTo(buff, len);
202 SendMsg(%s, markerNumber, (long)buff);
205 ('Define a marker from a bitmap',)),
208 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
209 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
210 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
211 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
212 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
213 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
214 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
215 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
217 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
218 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
219 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
220 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
221 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
222 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
226 'void %s(int key, int modifiers, int cmd);',
228 '''void %s(int key, int modifiers, int cmd) {
229 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
235 'void %s(int key, int modifiers);',
237 '''void %s(int key, int modifiers) {
238 SendMsg(%s, MAKELONG(key, modifiers));''',
241 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
246 'void %s(int length, char* styleBytes);',
248 '''void %s(int length, char* styleBytes) {
249 SendMsg(%s, length, (long)styleBytes);''',
253 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
254 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
255 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
256 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
258 'SetWhitespaceFore' : ('SetWhitespaceForeground', 0, 0, 0),
259 'SetWhitespaceBack' : ('SetWhitespaceBackground', 0, 0, 0),
261 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
262 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
263 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
264 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
265 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
266 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
267 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
268 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
269 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
270 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
271 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
272 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
273 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
274 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
275 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
276 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
277 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
278 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
279 'AutoCSetDropRestOfWord' : ('AutoCompSetDropRestOfWord', 0,0,0),
280 'AutoCGetDropRestOfWord' : ('AutoCompGetDropRestOfWord', 0,0,0),
281 'AutoCGetTypeSeparator' : ('AutoCompGetTypeSeparator', 0, 0, 0),
282 'AutoCSetTypeSeparator' : ('AutoCompSetTypeSeparator', 0, 0, 0),
283 'AutoCGetCurrent' : ('AutoCompGetCurrent', 0, 0, 0),
287 '''void %s(int type, const wxBitmap& bmp);''',
288 '''void %s(int type, const wxBitmap& bmp) {
289 // convert bmp to a xpm in a string
290 wxMemoryOutputStream strm;
291 wxImage img = bmp.ConvertToImage();
292 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
293 size_t len = strm.GetSize();
294 char* buff = new char[len+1];
295 strm.CopyTo(buff, len);
297 SendMsg(%s, type, (long)buff);
300 ('Register an image for use in autocompletion lists.',)),
303 'ClearRegisteredImages' : (0, 0, 0,
304 ('Clear all the registered images.',)),
307 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
308 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
310 'SetVScrollBar' : ('SetUseVerticalScrollBar', 0, 0, 0),
311 'GetVScrollBar' : ('GetUseVerticalScrollBar', 0, 0, 0),
313 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
315 'GetUsePalette' : (None, 0, 0, 0),
319 '''int %s(int minPos, int maxPos, const wxString& text, int flags=0);''',
321 '''int %s(int minPos, int maxPos,
322 const wxString& text,
325 ft.chrg.cpMin = minPos;
326 ft.chrg.cpMax = maxPos;
327 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
328 ft.lpstrText = (char*)(const char*)buf;
330 return SendMsg(%s, flags, (long)&ft);''',
335 '''int %s(bool doDraw,
341 wxRect pageRect);''',
342 ''' int %s(bool doDraw,
351 if (endPos < startPos) {
357 fr.hdcTarget = target;
358 fr.rc.top = renderRect.GetTop();
359 fr.rc.left = renderRect.GetLeft();
360 fr.rc.right = renderRect.GetRight();
361 fr.rc.bottom = renderRect.GetBottom();
362 fr.rcPage.top = pageRect.GetTop();
363 fr.rcPage.left = pageRect.GetLeft();
364 fr.rcPage.right = pageRect.GetRight();
365 fr.rcPage.bottom = pageRect.GetBottom();
366 fr.chrg.cpMin = startPos;
367 fr.chrg.cpMax = endPos;
369 return SendMsg(%s, doDraw, (long)&fr);''',
375 'wxString %s(int line);',
377 '''wxString %s(int line) {
378 int len = LineLength(line);
379 if (!len) return wxEmptyString;
381 wxMemoryBuffer mbuf(len+1);
382 char* buf = (char*)mbuf.GetWriteBuf(len+1);
383 SendMsg(%s, line, (long)buf);
384 mbuf.UngetWriteBuf(len);
386 return stc2wx(buf);''',
388 ('Retrieve the contents of a line.',)),
390 'SetSel' : ('SetSelection', 0, 0, 0),
400 GetSelection(&start, &end);
401 int len = end - start;
402 if (!len) return wxEmptyString;
404 wxMemoryBuffer mbuf(len+2);
405 char* buf = (char*)mbuf.GetWriteBuf(len+1);
406 SendMsg(%s, 0, (long)buf);
407 mbuf.UngetWriteBuf(len);
409 return stc2wx(buf);''',
411 ('Retrieve the selected text.',)),
416 'wxString %s(int startPos, int endPos);',
418 '''wxString %s(int startPos, int endPos) {
419 if (endPos < startPos) {
424 int len = endPos - startPos;
425 if (!len) return wxEmptyString;
426 wxMemoryBuffer mbuf(len+1);
427 char* buf = (char*)mbuf.GetWriteBuf(len);
430 tr.chrg.cpMin = startPos;
431 tr.chrg.cpMax = endPos;
432 SendMsg(%s, 0, (long)&tr);
433 mbuf.UngetWriteBuf(len);
435 return stc2wx(buf);''',
437 ('Retrieve a range of text.',)),
439 'PointXFromPosition' : (None, 0, 0, 0),
440 'PointYFromPosition' : (None, 0, 0, 0),
442 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
443 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
444 'Null' : (None, 0, 0, 0),
451 int len = GetTextLength();
452 wxMemoryBuffer mbuf(len+1); // leave room for the null...
453 char* buf = (char*)mbuf.GetWriteBuf(len+1);
454 SendMsg(%s, len+1, (long)buf);
455 mbuf.UngetWriteBuf(len);
457 return stc2wx(buf);''',
459 ('Retrieve all the text in the document.', )),
461 'GetDirectFunction' : (None, 0, 0, 0),
462 'GetDirectPointer' : (None, 0, 0, 0),
464 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
465 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
466 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
467 'CallTipSetFore' : ('CallTipSetForeground', 0, 0, 0),
468 'CallTipSetForeHlt' : ('CallTipSetForegroundHighlight', 0, 0, 0),
470 'SetHotspotActiveFore' : ('SetHotspotActiveForeground', 0, 0, 0),
471 'SetHotspotActiveBack' : ('SetHotspotActiveBackground', 0, 0, 0),
476 'int %s(const wxString& text);',
479 int %s(const wxString& text) {
480 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
481 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
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);''',
504 # not sure what to do about these yet
505 'TargetAsUTF8' : ( None, 0, 0, 0),
506 'SetLengthForEncode' : ( None, 0, 0, 0),
507 'EncodedFromUTF8' : ( None, 0, 0, 0),
514 return (void*)SendMsg(%s);''',
519 'void %s(void* docPointer);',
520 '''void %s(void* docPointer) {
521 SendMsg(%s, 0, (long)docPointer);''',
528 return (void*)SendMsg(%s);''',
533 'void %s(void* docPointer);',
534 '''void %s(void* docPointer) {
535 SendMsg(%s, 0, (long)docPointer);''',
540 'void %s(void* docPointer);',
541 '''void %s(void* docPointer) {
542 SendMsg(%s, 0, (long)docPointer);''',
548 '''void %s(int codePage) {
550 wxASSERT_MSG(codePage == wxSTC_CP_UTF8,
551 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
553 wxASSERT_MSG(codePage != wxSTC_CP_UTF8,
554 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
556 SendMsg(%s, codePage);''',
557 ("Set the code page used to interpret the bytes of the document as characters.",) ),
560 'GrabFocus' : (None, 0, 0, 0),
562 # Rename some that would otherwise hide the wxWindow methods
563 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
564 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
565 'SetCursor' : ('SetSTCCursor', 0, 0, 0),
566 'GetCursor' : ('GetSTCCursor', 0, 0, 0),
568 'LoadLexerLibrary' : (None, 0,0,0),
575 #----------------------------------------------------------------------------
577 def processIface(iface
, h_tmplt
, cpp_tmplt
, h_dest
, cpp_dest
):
584 fi
= FileInput(iface
)
587 if line
[:2] == '##' or line
== '':
592 if line
[:2] == '# ': # a doc string
593 curDocStrings
.append(line
[2:])
596 parseVal(line
[4:], values
, curDocStrings
)
599 elif op
== 'fun ' or op
== 'set ' or op
== 'get ':
600 parseFun(line
[4:], methods
, curDocStrings
, cmds
)
604 if string
.strip(line
[4:]) == 'Deprecated':
605 break # skip the rest of the file
617 print '***** Unknown line type: ', line
622 data
['VALUES'] = processVals(values
)
623 data
['CMDS'] = processVals(cmds
)
624 defs
, imps
= processMethods(methods
)
625 data
['METHOD_DEFS'] = defs
626 data
['METHOD_IMPS'] = imps
629 h_text
= open(h_tmplt
).read()
630 cpp_text
= open(cpp_tmplt
).read()
632 # do the substitutions
633 h_text
= h_text
% data
634 cpp_text
= cpp_text
% data
636 # write out destination files
637 open(h_dest
, 'w').write(h_text
)
638 open(cpp_dest
, 'w').write(cpp_text
)
642 #----------------------------------------------------------------------------
644 def processVals(values
):
646 for name
, value
, docs
in values
:
650 text
.append('// ' + x
)
651 text
.append('#define %s %s' % (name
, value
))
652 return string
.join(text
, '\n')
654 #----------------------------------------------------------------------------
656 def processMethods(methods
):
660 for retType
, name
, number
, param1
, param2
, docs
in methods
:
661 retType
= retTypeMap
.get(retType
, retType
)
662 params
= makeParamString(param1
, param2
)
664 name
, theDef
, theImp
, docs
= checkMethodOverride(name
, number
, docs
)
669 # Build the method definition for the .h file
673 defs
.append(' // ' + x
)
675 theDef
= ' %s %s(%s);' % (retType
, name
, params
)
678 # Build the method implementation string
682 imps
.append('// ' + x
)
684 theImp
= '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType
, name
, params
)
686 if retType
== 'wxColour':
687 theImp
= theImp
+ 'long c = '
688 elif retType
!= 'void':
689 theImp
= theImp
+ 'return '
690 theImp
= theImp
+ 'SendMsg(%s, %s, %s)' % (number
,
691 makeArgString(param1
),
692 makeArgString(param2
))
693 if retType
== 'bool':
694 theImp
= theImp
+ ' != 0'
695 if retType
== 'wxColour':
696 theImp
= theImp
+ ';\n return wxColourFromLong(c)'
698 theImp
= theImp
+ ';\n}'
702 return string
.join(defs
, '\n'), string
.join(imps
, '\n')
705 #----------------------------------------------------------------------------
707 def checkMethodOverride(name
, number
, docs
):
708 theDef
= theImp
= None
709 if methodOverrideMap
.has_key(name
):
710 item
= methodOverrideMap
[name
]
716 theDef
= ' ' + (item
[1] % name
)
718 theImp
= item
[2] % ('wxStyledTextCtrl::'+name
, number
) + '\n}'
722 print "*************", name
725 return name
, theDef
, theImp
, docs
727 #----------------------------------------------------------------------------
729 def makeArgString(param
):
736 return '(long)(const char*)wx2stc(%s)' % name
738 return 'wxColourAsLong(%s)' % name
742 #----------------------------------------------------------------------------
744 def makeParamString(param1
, param2
):
747 aType
= paramTypeMap
.get(param
[0], param
[0])
748 return aType
+ ' ' + param
[1]
755 st
= st
+ doOne(param2
)
759 #----------------------------------------------------------------------------
761 def parseVal(line
, values
, docs
):
762 name
, val
= string
.split(line
, '=')
764 # remove prefixes such as SCI, etc.
765 for old
, new
in valPrefixes
:
770 name
= new
+ name
[lo
:]
773 values
.append( ('wxSTC_' + name
, val
, docs
) )
775 #----------------------------------------------------------------------------
777 funregex
= re
.compile(r
'\s*([a-zA-Z0-9_]+)' # <ws>return type
778 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
780 '\(([ a-zA-Z0-9_]*),' # (param,
781 '([ a-zA-Z0-9_]*)\)') # param)
783 def parseFun(line
, methods
, docs
, values
):
784 def parseParam(param
):
785 param
= string
.strip(param
)
789 param
= tuple(string
.split(param
))
792 mo
= funregex
.match(line
)
794 print "***** Line doesn't match! : " + line
796 retType
, name
, number
, param1
, param2
= mo
.groups()
798 param1
= parseParam(param1
)
799 param2
= parseParam(param2
)
801 # Special case. For the key command functions we want a value defined too
802 num
= string
.atoi(number
)
804 if (type(v
) == type(()) and v
[0] <= num
<= v
[1]) or v
== num
:
805 parseVal('CMD_%s=%s' % (string
.upper(name
), number
), values
, docs
)
807 # if we are not also doing a function for CMD values, then
808 # just return, otherwise fall through to the append blow.
812 methods
.append( (retType
, name
, number
, param1
, param2
, tuple(docs
)) )
815 #----------------------------------------------------------------------------
819 # TODO: parse command line args to replace default input/output files???
822 processIface(IFACE
, H_TEMPLATE
, CPP_TEMPLATE
, H_DEST
, CPP_DEST
)
826 if __name__
== '__main__':
829 #----------------------------------------------------------------------------