]>
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 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 fore 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),
229 'AutoCSetDropRestOfWord' : ('AutoCompSetDropRestOfWord', 0,0,0),
230 'AutoCGetDropRestOfWord' : ('AutoCompGetDropRestOfWord', 0,0,0),
233 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
234 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
236 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
238 'GetUsePalette' : (None, 0, 0, 0),
241 '''int %s(int minPos, int maxPos,
242 const wxString& text,
243 bool caseSensitive, bool wholeWord);''',
244 '''int %s(int minPos, int maxPos,
245 const wxString& text,
246 bool caseSensitive, bool wholeWord) {
250 flags |= caseSensitive ? SCFIND_MATCHCASE : 0;
251 flags |= wholeWord ? SCFIND_WHOLEWORD : 0;
252 ft.chrg.cpMin = minPos;
253 ft.chrg.cpMax = maxPos;
254 ft.lpstrText = (char*)text.c_str();
256 return SendMsg(%s, flags, (long)&ft);''',
260 '''int %s(bool doDraw,
264 wxDC* target, // Why does it use two? Can they be the same?
266 wxRect pageRect);''',
267 ''' int %s(bool doDraw,
271 wxDC* target, // Why does it use two? Can they be the same?
276 if (endPos < startPos) {
282 fr.hdcTarget = target;
283 fr.rc.top = renderRect.GetTop();
284 fr.rc.left = renderRect.GetLeft();
285 fr.rc.right = renderRect.GetRight();
286 fr.rc.bottom = renderRect.GetBottom();
287 fr.rcPage.top = pageRect.GetTop();
288 fr.rcPage.left = pageRect.GetLeft();
289 fr.rcPage.right = pageRect.GetRight();
290 fr.rcPage.bottom = pageRect.GetBottom();
291 fr.chrg.cpMin = startPos;
292 fr.chrg.cpMax = endPos;
294 return SendMsg(%s, doDraw, (long)&fr);''',
299 'wxString %s(int line);',
301 '''wxString %s(int line) {
303 int len = LineLength(line);
305 char* buf = text.GetWriteBuf(len);
307 int pos = SendMsg(%s, line, (long)buf);
308 text.UngetWriteBuf(len);
312 ('Retrieve the contents of a line.',)),
314 'SetSel' : ('SetSelection', 0, 0, 0),
315 'GetSelText' : ('GetSelectedText',
323 GetSelection(&start, &end);
324 int len = end - start;
326 char* buff = text.GetWriteBuf(len);
328 SendMsg(%s, 0, (long)buff);
329 text.UngetWriteBuf(len);
332 ('Retrieve the selected text.',)),
335 'wxString %s(int startPos, int endPos);',
337 '''wxString %s(int startPos, int endPos) {
339 if (endPos < startPos) {
344 int len = endPos - startPos;
346 char* buff = text.GetWriteBuf(len);
349 tr.chrg.cpMin = startPos;
350 tr.chrg.cpMax = endPos;
352 SendMsg(%s, 0, (long)&tr);
353 text.UngetWriteBuf(len);
356 ('Retrieve a range of text.',)),
358 'PointXFromPosition' : (None, 0, 0, 0),
359 'PointYFromPosition' : (None, 0, 0, 0),
361 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
362 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
363 'Null' : (None, 0, 0, 0),
370 int len = GetTextLength();
371 char* buff = text.GetWriteBuf(len+1); // leave room for the null...
373 SendMsg(%s, len+1, (long)buff);
374 text.UngetWriteBuf(len);
377 ('Retrieve all the text in the document.', )),
379 'GetDirectFunction' : (None, 0, 0, 0),
380 'GetDirectPointer' : (None, 0, 0, 0),
382 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
383 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
384 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
387 'ReplaceTarget' : (0,
388 'int %s(const wxString& text);',
391 int %s(const wxString& text) {
392 return SendMsg(%s, text.Len(), (long)text.c_str());
397 'ReplaceTargetRE' : (0,
398 'int %s(const wxString& text);',
401 int %s(const wxString& text) {
402 return SendMsg(%s, text.Len(), (long)text.c_str());
407 'SearchInTarget' : (0,
408 'int %s(const wxString& text);',
411 int %s(const wxString& text) {
412 return SendMsg(%s, text.Len(), (long)text.c_str());
419 # Remove all methods that are key commands since they can be
420 # executed with CmdKeyExecute
421 'LineDown' : (None, 0, 0, 0),
422 'LineDownExtend' : (None, 0, 0, 0),
423 'LineUp' : (None, 0, 0, 0),
424 'LineUpExtend' : (None, 0, 0, 0),
425 'CharLeft' : (None, 0, 0, 0),
426 'CharLeftExtend' : (None, 0, 0, 0),
427 'CharRight' : (None, 0, 0, 0),
428 'CharRightExtend' : (None, 0, 0, 0),
429 'WordLeft' : (None, 0, 0, 0),
430 'WordLeftExtend' : (None, 0, 0, 0),
431 'WordRight' : (None, 0, 0, 0),
432 'WordRightExtend' : (None, 0, 0, 0),
433 'Home' : (None, 0, 0, 0),
434 'HomeExtend' : (None, 0, 0, 0),
435 'LineEnd' : (None, 0, 0, 0),
436 'LineEndExtend' : (None, 0, 0, 0),
437 'DocumentStart' : (None, 0, 0, 0),
438 'DocumentStartExtend' : (None, 0, 0, 0),
439 'DocumentEnd' : (None, 0, 0, 0),
440 'DocumentEndExtend' : (None, 0, 0, 0),
441 'PageUp' : (None, 0, 0, 0),
442 'PageUpExtend' : (None, 0, 0, 0),
443 'PageDown' : (None, 0, 0, 0),
444 'PageDownExtend' : (None, 0, 0, 0),
445 'EditToggleOvertype' : (None, 0, 0, 0),
446 'Cancel' : (None, 0, 0, 0),
447 'DeleteBack' : (None, 0, 0, 0),
448 'Tab' : (None, 0, 0, 0),
449 'BackTab' : (None, 0, 0, 0),
450 'NewLine' : (None, 0, 0, 0),
451 'FormFeed' : (None, 0, 0, 0),
452 'VCHome' : (None, 0, 0, 0),
453 'VCHomeExtend' : (None, 0, 0, 0),
454 'ZoomIn' : (None, 0, 0, 0),
455 'ZoomOut' : (None, 0, 0, 0),
456 'DelWordLeft' : (None, 0, 0, 0),
457 'DelWordRight' : (None, 0, 0, 0),
458 'LineCut' : (None, 0, 0, 0),
459 'LineDelete' : (None, 0, 0, 0),
460 'LineTranspose' : (None, 0, 0, 0),
461 'LowerCase' : (None, 0, 0, 0),
462 'UpperCase' : (None, 0, 0, 0),
463 'LineScrollDown' : (None, 0, 0, 0),
464 'LineScrollUp' : (None, 0, 0, 0),
467 'GetDocPointer' : (0,
470 return (void*)SendMsg(%s);''',
473 'SetDocPointer' : (0,
474 'void %s(void* docPointer);',
475 '''void %s(void* docPointer) {
476 SendMsg(%s, 0, (long)docPointer);''',
479 'CreateDocument' : (0,
482 return (void*)SendMsg(%s);''',
485 'AddRefDocument' : (0,
486 'void %s(void* docPointer);',
487 '''void %s(void* docPointer) {
488 SendMsg(%s, (long)docPointer);''',
491 'ReleaseDocument' : (0,
492 'void %s(void* docPointer);',
493 '''void %s(void* docPointer) {
494 SendMsg(%s, (long)docPointer);''',
497 'GrabFocus' : (None, 0, 0, 0),
498 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
499 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
506 #----------------------------------------------------------------------------
508 def processIface(iface
, h_tmplt
, cpp_tmplt
, h_dest
, cpp_dest
):
514 fi
= FileInput(iface
)
517 if line
[:2] == '##' or line
== '':
522 if line
[:2] == '# ': # a doc string
523 curDocStrings
.append(line
[2:])
526 parseVal(line
[4:], values
, curDocStrings
)
529 elif op
== 'fun ' or op
== 'set ' or op
== 'get ':
530 parseFun(line
[4:], methods
, curDocStrings
, values
)
534 if string
.strip(line
[4:]) == 'Deprecated':
535 break # skip the rest of the file
541 print '***** Unknown line type: ', line
546 data
['VALUES'] = processVals(values
)
547 defs
, imps
= processMethods(methods
)
548 data
['METHOD_DEFS'] = defs
549 data
['METHOD_IMPS'] = imps
552 h_text
= open(h_tmplt
).read()
553 cpp_text
= open(cpp_tmplt
).read()
555 # do the substitutions
556 h_text
= h_text
% data
557 cpp_text
= cpp_text
% data
559 # write out destination files
560 open(h_dest
, 'w').write(h_text
)
561 open(cpp_dest
, 'w').write(cpp_text
)
565 #----------------------------------------------------------------------------
567 def processVals(values
):
569 for name
, value
, docs
in values
:
573 text
.append('// ' + x
)
574 text
.append('#define %s %s' % (name
, value
))
575 return string
.join(text
, '\n')
577 #----------------------------------------------------------------------------
579 def processMethods(methods
):
583 for retType
, name
, number
, param1
, param2
, docs
in methods
:
584 retType
= retTypeMap
.get(retType
, retType
)
585 params
= makeParamString(param1
, param2
)
587 name
, theDef
, theImp
, docs
= checkMethodOverride(name
, number
, docs
)
592 # Build the method definition for the .h file
596 defs
.append(' // ' + x
)
598 theDef
= ' %s %s(%s);' % (retType
, name
, params
)
601 # Build the method implementation string
605 imps
.append('// ' + x
)
607 theImp
= '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType
, name
, params
)
609 if retType
== 'wxColour':
610 theImp
= theImp
+ 'long c = '
611 elif retType
!= 'void':
612 theImp
= theImp
+ 'return '
613 theImp
= theImp
+ 'SendMsg(%s, %s, %s)' % (number
,
614 makeArgString(param1
),
615 makeArgString(param2
))
616 if retType
== 'bool':
617 theImp
= theImp
+ ' != 0'
618 if retType
== 'wxColour':
619 theImp
= theImp
+ ';\n return wxColourFromLong(c)'
621 theImp
= theImp
+ ';\n}'
625 return string
.join(defs
, '\n'), string
.join(imps
, '\n')
628 #----------------------------------------------------------------------------
630 def checkMethodOverride(name
, number
, docs
):
631 theDef
= theImp
= None
632 if methodOverrideMap
.has_key(name
):
633 item
= methodOverrideMap
[name
]
638 theDef
= ' ' + (item
[1] % name
)
640 theImp
= item
[2] % ('wxStyledTextCtrl::'+name
, number
) + '\n}'
644 return name
, theDef
, theImp
, docs
646 #----------------------------------------------------------------------------
648 def makeArgString(param
):
655 return '(long)%s.c_str()' % name
657 return 'wxColourAsLong(%s)' % name
661 #----------------------------------------------------------------------------
663 def makeParamString(param1
, param2
):
666 aType
= paramTypeMap
.get(param
[0], param
[0])
667 return aType
+ ' ' + param
[1]
674 st
= st
+ doOne(param2
)
678 #----------------------------------------------------------------------------
680 def parseVal(line
, values
, docs
):
681 name
, val
= string
.split(line
, '=')
683 # remove prefixes such as SCI, etc.
684 for old
, new
in valPrefixes
:
689 name
= new
+ name
[lo
:]
692 values
.append( ('wxSTC_' + name
, val
, docs
) )
694 #----------------------------------------------------------------------------
696 funregex
= re
.compile(r
'\s*([a-zA-Z0-9_]+)' # <ws>return type
697 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
699 '\(([ a-zA-Z0-9_]*),' # (param,
700 '([ a-zA-Z0-9_]*)\)') # param)
702 def parseFun(line
, methods
, docs
, values
):
703 def parseParam(param
):
704 param
= string
.strip(param
)
708 param
= tuple(string
.split(param
))
711 mo
= funregex
.match(line
)
713 print "***** Line doesn't match! : " + line
715 retType
, name
, number
, param1
, param2
= mo
.groups()
717 param1
= parseParam(param1
)
718 param2
= parseParam(param2
)
720 # Special case. For the key command functionss we want a value defined too
721 num
= string
.atoi(number
)
723 if (type(v
) == type(()) and v
[0] <= num
< v
[1]) or v
== num
:
724 parseVal('CMD_%s=%s' % (string
.upper(name
), number
), values
, ())
726 #if retType == 'void' and not param1 and not param2:
728 methods
.append( (retType
, name
, number
, param1
, param2
, tuple(docs
)) )
731 #----------------------------------------------------------------------------
735 # TODO: parse command line args to replace default input/output files???
738 processIface(IFACE
, H_TEMPLATE
, CPP_TEMPLATE
, H_DEST
, CPP_DEST
)
742 if __name__
== '__main__':
745 #----------------------------------------------------------------------------