]>
git.saurik.com Git - wxWidgets.git/blob - contrib/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 as well
39 cmdValues
= [ (2300, 2350), 2011, 2013, (2176, 2180) ]
42 # Map some generic typenames to wx types, using return value syntax
49 # Map some generic typenames to wx types, using parameter syntax
52 'string': 'const wxString&',
53 'colour': 'const wxColour&',
57 # Map of method info that needs tweaked. Either the name needs changed, or
58 # the method definition/implementation. Tuple items are:
60 # 1. New method name. None to skip the method, 0 to leave the
62 # 2. Method definition for the .h file, 0 to leave alone
63 # 3. Method implementation for the .cpp file, 0 to leave alone.
64 # 4. tuple of Doc string lines, or 0 to leave alone.
68 'void %s(const wxString& text);',
70 '''void %s(const wxString& text) {
71 SendMsg(%s, text.Len(), (long)text.c_str());''',
75 'void %s(const wxString& text);',
77 '''void %s(const wxString& text) {
78 SendMsg(%s, text.Len(), (long)text.c_str());''',
81 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
82 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
85 'wxString %s(int startPos, int endPos);',
87 '''wxString %s(int startPos, int endPos) {
89 if (endPos < startPos) {
94 int len = endPos - startPos;
97 tr.lpstrText = text.GetWriteBuf(len*2);
98 tr.chrg.cpMin = startPos;
99 tr.chrg.cpMax = endPos;
100 SendMsg(%s, 0, (long)&tr);
101 text.UngetWriteBuf(len*2);
104 ('Retrieve a buffer of cells.',)),
107 'PositionFromPoint' : (0,
108 'int %s(wxPoint pt);',
110 '''int %s(wxPoint pt) {
111 return SendMsg(%s, pt.x, pt.y);''',
116 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
118 '''wxString %s(int* linePos) {
120 int len = LineLength(GetCurrentLine());
122 if (linePos) *linePos = 0;
125 // Need an extra byte because SCI_GETCURLINE writes a null to the string
126 char* buf = text.GetWriteBuf(len+1);
128 int pos = SendMsg(%s, len+1, (long)buf);
129 text.UngetWriteBuf(len);
130 if (linePos) *linePos = pos;
136 'SetUsePalette' : (None, 0,0,0),
138 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
139 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
142 '''void %s(int markerNumber, int markerSymbol,
143 const wxColour& foreground = wxNullColour,
144 const wxColour& background = wxNullColour);''',
146 '''void %s(int markerNumber, int markerSymbol,
147 const wxColour& foreground,
148 const wxColour& background) {
150 SendMsg(%s, markerNumber, markerSymbol);
152 MarkerSetForeground(markerNumber, foreground);
154 MarkerSetBackground(markerNumber, background);''',
156 ('Set the symbol used for a particular marker number,',
157 'and optionally the for and background colours.')),
159 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
160 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
161 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
162 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
163 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
164 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
165 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
166 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
168 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
169 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
170 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
171 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
172 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
173 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
175 # need to fix this to map between wx and scintilla encoding flags, leave it out for now...
176 'StyleSetCharacterSet' : (None, 0, 0, 0),
178 'AssignCmdKey' : ('CmdKeyAssign',
179 'void %s(int key, int modifiers, int cmd);',
181 '''void %s(int key, int modifiers, int cmd) {
182 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
186 'ClearCmdKey' : ('CmdKeyClear',
187 'void %s(int key, int modifiers);',
189 '''void %s(int key, int modifiers) {
190 SendMsg(%s, MAKELONG(key, modifiers));''',
194 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
197 'SetStylingEx' : ('SetStyleBytes',
198 'void %s(int length, char* styleBytes);',
200 '''void %s(int length, char* styleBytes) {
201 SendMsg(%s, length, (long)styleBytes);''',
206 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
207 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
208 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
209 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
211 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
212 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
213 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
214 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
215 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
216 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
217 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
218 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
219 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
220 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
221 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
222 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
223 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
224 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
225 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
226 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
227 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
228 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
231 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
232 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
234 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
236 'GetUsePalette' : (None, 0, 0, 0),
239 '''int %s(int minPos, int maxPos,
240 const wxString& text,
241 bool caseSensitive, bool wholeWord);''',
242 '''int %s(int minPos, int maxPos,
243 const wxString& text,
244 bool caseSensitive, bool wholeWord) {
248 flags |= caseSensitive ? SCFIND_MATCHCASE : 0;
249 flags |= wholeWord ? SCFIND_WHOLEWORD : 0;
250 ft.chrg.cpMin = minPos;
251 ft.chrg.cpMax = maxPos;
252 ft.lpstrText = (char*)text.c_str();
254 return SendMsg(%s, flags, (long)&ft);''',
258 '''int %s(bool doDraw,
262 wxDC* target, // Why does it use two? Can they be the same?
264 wxRect pageRect);''',
265 ''' int %s(bool doDraw,
269 wxDC* target, // Why does it use two? Can they be the same?
274 if (endPos < startPos) {
280 fr.hdcTarget = target;
281 fr.rc.top = renderRect.GetTop();
282 fr.rc.left = renderRect.GetLeft();
283 fr.rc.right = renderRect.GetRight();
284 fr.rc.bottom = renderRect.GetBottom();
285 fr.rcPage.top = pageRect.GetTop();
286 fr.rcPage.left = pageRect.GetLeft();
287 fr.rcPage.right = pageRect.GetRight();
288 fr.rcPage.bottom = pageRect.GetBottom();
289 fr.chrg.cpMin = startPos;
290 fr.chrg.cpMax = endPos;
292 return SendMsg(%s, doDraw, (long)&fr);''',
297 'wxString %s(int line);',
299 '''wxString %s(int line) {
301 int len = LineLength(line);
303 char* buf = text.GetWriteBuf(len);
305 int pos = SendMsg(%s, line, (long)buf);
306 text.UngetWriteBuf(len);
310 ('Retrieve the contents of a line.',)),
312 'SetSel' : ('SetSelection', 0, 0, 0),
313 'GetSelText' : ('GetSelectedText',
321 GetSelection(&start, &end);
322 int len = end - start;
324 char* buff = text.GetWriteBuf(len);
326 SendMsg(%s, 0, (long)buff);
327 text.UngetWriteBuf(len);
330 ('Retrieve the selected text.',)),
333 'wxString %s(int startPos, int endPos);',
335 '''wxString %s(int startPos, int endPos) {
337 if (endPos < startPos) {
342 int len = endPos - startPos;
344 char* buff = text.GetWriteBuf(len);
347 tr.chrg.cpMin = startPos;
348 tr.chrg.cpMax = endPos;
350 SendMsg(%s, 0, (long)&tr);
351 text.UngetWriteBuf(len);
354 ('Retrieve a range of text.',)),
356 'PointXFromPosition' : (None, 0, 0, 0),
357 'PointYFromPosition' : (None, 0, 0, 0),
359 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
360 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
361 'Null' : (None, 0, 0, 0),
368 int len = GetTextLength();
369 char* buff = text.GetWriteBuf(len+1); // leave room for the null...
371 SendMsg(%s, len+1, (long)buff);
372 text.UngetWriteBuf(len);
375 ('Retrieve all the text in the document.', )),
377 'GetDirectFunction' : (None, 0, 0, 0),
378 'GetDirectPointer' : (None, 0, 0, 0),
380 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
381 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
382 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
385 'ReplaceTarget' : (0,
386 'int %s(const wxString& text);',
389 int %s(const wxString& text) {
390 return SendMsg(%s, text.Len(), (long)text.c_str());
395 'ReplaceTargetRE' : (0,
396 'int %s(const wxString& text);',
399 int %s(const wxString& text) {
400 return SendMsg(%s, text.Len(), (long)text.c_str());
405 'SearchInTarget' : (0,
406 'int %s(const wxString& text);',
409 int %s(const wxString& text) {
410 return SendMsg(%s, text.Len(), (long)text.c_str());
417 # Remove all methods that are key commands since they can be
418 # executed with CmdKeyExecute
419 'LineDown' : (None, 0, 0, 0),
420 'LineDownExtend' : (None, 0, 0, 0),
421 'LineUp' : (None, 0, 0, 0),
422 'LineUpExtend' : (None, 0, 0, 0),
423 'CharLeft' : (None, 0, 0, 0),
424 'CharLeftExtend' : (None, 0, 0, 0),
425 'CharRight' : (None, 0, 0, 0),
426 'CharRightExtend' : (None, 0, 0, 0),
427 'WordLeft' : (None, 0, 0, 0),
428 'WordLeftExtend' : (None, 0, 0, 0),
429 'WordRight' : (None, 0, 0, 0),
430 'WordRightExtend' : (None, 0, 0, 0),
431 'Home' : (None, 0, 0, 0),
432 'HomeExtend' : (None, 0, 0, 0),
433 'LineEnd' : (None, 0, 0, 0),
434 'LineEndExtend' : (None, 0, 0, 0),
435 'DocumentStart' : (None, 0, 0, 0),
436 'DocumentStartExtend' : (None, 0, 0, 0),
437 'DocumentEnd' : (None, 0, 0, 0),
438 'DocumentEndExtend' : (None, 0, 0, 0),
439 'PageUp' : (None, 0, 0, 0),
440 'PageUpExtend' : (None, 0, 0, 0),
441 'PageDown' : (None, 0, 0, 0),
442 'PageDownExtend' : (None, 0, 0, 0),
443 'EditToggleOvertype' : (None, 0, 0, 0),
444 'Cancel' : (None, 0, 0, 0),
445 'DeleteBack' : (None, 0, 0, 0),
446 'Tab' : (None, 0, 0, 0),
447 'BackTab' : (None, 0, 0, 0),
448 'NewLine' : (None, 0, 0, 0),
449 'FormFeed' : (None, 0, 0, 0),
450 'VCHome' : (None, 0, 0, 0),
451 'VCHomeExtend' : (None, 0, 0, 0),
452 'ZoomIn' : (None, 0, 0, 0),
453 'ZoomOut' : (None, 0, 0, 0),
454 'DelWordLeft' : (None, 0, 0, 0),
455 'DelWordRight' : (None, 0, 0, 0),
456 'LineCut' : (None, 0, 0, 0),
457 'LineDelete' : (None, 0, 0, 0),
458 'LineTranspose' : (None, 0, 0, 0),
459 'LowerCase' : (None, 0, 0, 0),
460 'UpperCase' : (None, 0, 0, 0),
461 'LineScrollDown' : (None, 0, 0, 0),
462 'LineScrollUp' : (None, 0, 0, 0),
465 'GetDocPointer' : (0,
468 return (void*)SendMsg(%s);''',
471 'SetDocPointer' : (0,
472 'void %s(void* docPointer);',
473 '''void %s(void* docPointer) {
474 SendMsg(%s, 0, (long)docPointer);''',
477 'CreateDocument' : (0,
480 return (void*)SendMsg(%s);''',
483 'AddRefDocument' : (0,
484 'void %s(void* docPointer);',
485 '''void %s(void* docPointer) {
486 SendMsg(%s, (long)docPointer);''',
489 'ReleaseDocument' : (0,
490 'void %s(void* docPointer);',
491 '''void %s(void* docPointer) {
492 SendMsg(%s, (long)docPointer);''',
495 'GrabFocus' : (None, 0, 0, 0),
496 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
497 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
504 #----------------------------------------------------------------------------
506 def processIface(iface
, h_tmplt
, cpp_tmplt
, h_dest
, cpp_dest
):
512 fi
= FileInput(iface
)
515 if line
[:2] == '##' or line
== '':
520 if line
[:2] == '# ': # a doc string
521 curDocStrings
.append(line
[2:])
524 parseVal(line
[4:], values
, curDocStrings
)
527 elif op
== 'fun ' or op
== 'set ' or op
== 'get ':
528 parseFun(line
[4:], methods
, curDocStrings
, values
)
532 if string
.strip(line
[4:]) == 'Deprecated':
533 break # skip the rest of the file
539 print '***** Unknown line type: ', line
544 data
['VALUES'] = processVals(values
)
545 defs
, imps
= processMethods(methods
)
546 data
['METHOD_DEFS'] = defs
547 data
['METHOD_IMPS'] = imps
550 h_text
= open(h_tmplt
).read()
551 cpp_text
= open(cpp_tmplt
).read()
553 # do the substitutions
554 h_text
= h_text
% data
555 cpp_text
= cpp_text
% data
557 # write out destination files
558 open(h_dest
, 'w').write(h_text
)
559 open(cpp_dest
, 'w').write(cpp_text
)
563 #----------------------------------------------------------------------------
565 def processVals(values
):
567 for name
, value
, docs
in values
:
571 text
.append('// ' + x
)
572 text
.append('#define %s %s' % (name
, value
))
573 return string
.join(text
, '\n')
575 #----------------------------------------------------------------------------
577 def processMethods(methods
):
581 for retType
, name
, number
, param1
, param2
, docs
in methods
:
582 retType
= retTypeMap
.get(retType
, retType
)
583 params
= makeParamString(param1
, param2
)
585 name
, theDef
, theImp
, docs
= checkMethodOverride(name
, number
, docs
)
590 # Build the method definition for the .h file
594 defs
.append(' // ' + x
)
596 theDef
= ' %s %s(%s);' % (retType
, name
, params
)
599 # Build the method implementation string
603 imps
.append('// ' + x
)
605 theImp
= '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType
, name
, params
)
607 if retType
== 'wxColour':
608 theImp
= theImp
+ 'long c = '
609 elif retType
!= 'void':
610 theImp
= theImp
+ 'return '
611 theImp
= theImp
+ 'SendMsg(%s, %s, %s)' % (number
,
612 makeArgString(param1
),
613 makeArgString(param2
))
614 if retType
== 'bool':
615 theImp
= theImp
+ ' != 0'
616 if retType
== 'wxColour':
617 theImp
= theImp
+ ';\n return wxColourFromLong(c)'
619 theImp
= theImp
+ ';\n}'
623 return string
.join(defs
, '\n'), string
.join(imps
, '\n')
626 #----------------------------------------------------------------------------
628 def checkMethodOverride(name
, number
, docs
):
629 theDef
= theImp
= None
630 if methodOverrideMap
.has_key(name
):
631 item
= methodOverrideMap
[name
]
636 theDef
= ' ' + (item
[1] % name
)
638 theImp
= item
[2] % ('wxStyledTextCtrl::'+name
, number
) + '\n}'
642 return name
, theDef
, theImp
, docs
644 #----------------------------------------------------------------------------
646 def makeArgString(param
):
653 return '(long)%s.c_str()' % name
655 return 'wxColourAsLong(%s)' % name
659 #----------------------------------------------------------------------------
661 def makeParamString(param1
, param2
):
664 aType
= paramTypeMap
.get(param
[0], param
[0])
665 return aType
+ ' ' + param
[1]
672 st
= st
+ doOne(param2
)
676 #----------------------------------------------------------------------------
678 def parseVal(line
, values
, docs
):
679 name
, val
= string
.split(line
, '=')
681 # remove prefixes such as SCI, etc.
682 for old
, new
in valPrefixes
:
687 name
= new
+ name
[lo
:]
690 values
.append( ('wxSTC_' + name
, val
, docs
) )
692 #----------------------------------------------------------------------------
694 funregex
= re
.compile(r
'\s*([a-zA-Z0-9_]+)' # <ws>return type
695 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
697 '\(([ a-zA-Z0-9_]*),' # (param,
698 '([ a-zA-Z0-9_]*)\)') # param)
700 def parseFun(line
, methods
, docs
, values
):
701 def parseParam(param
):
702 param
= string
.strip(param
)
706 param
= tuple(string
.split(param
))
709 mo
= funregex
.match(line
)
711 print "***** Line doesn't match! : " + line
713 retType
, name
, number
, param1
, param2
= mo
.groups()
715 param1
= parseParam(param1
)
716 param2
= parseParam(param2
)
718 # Special case. For the key command functionss we want a value defined too
719 num
= string
.atoi(number
)
721 if (type(v
) == type(()) and v
[0] <= num
< v
[1]) or v
== num
:
722 parseVal('CMD_%s=%s' % (string
.upper(name
), number
), values
, ())
724 #if retType == 'void' and not param1 and not param2:
726 methods
.append( (retType
, name
, number
, param1
, param2
, tuple(docs
)) )
729 #----------------------------------------------------------------------------
733 # TODO: parse command line args to replace default input/output files???
736 processIface(IFACE
, H_TEMPLATE
, CPP_TEMPLATE
, H_DEST
, CPP_DEST
)
740 if __name__
== '__main__':
743 #----------------------------------------------------------------------------