]>
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
16 from fileinput
import FileInput
19 IFACE
= './scintilla/include/Scintilla.iface'
20 H_TEMPLATE
= './stc.h.in'
21 CPP_TEMPLATE
= './stc.cpp.in'
22 H_DEST
= '../../include/wx/stc/stc.h'
23 CPP_DEST
= './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 int len = endPos - startPos;
91 tr.lpstrText = text.GetWriteBuf(len*2+1);
92 tr.chrg.cpMin = startPos;
93 tr.chrg.cpMax = endPos;
94 SendMsg(%s, 0, (long)&tr);
95 text.UngetWriteBuf(len*2);
98 ('Retrieve a buffer of cells.',)),
101 'PositionFromPoint' : (0,
102 'int %s(wxPoint pt);',
104 '''int %s(wxPoint pt) {
105 return SendMsg(%s, pt.x, pt.y);''',
110 'wxString %s(int* OUTPUT=NULL);',
112 '''wxString %s(int* linePos) {
114 int len = LineLength(GetCurrentLine());
115 char* buf = text.GetWriteBuf(len);
117 int pos = SendMsg(%s, len, (long)buf);
118 text.UngetWriteBuf();
119 if (linePos) *linePos = pos;
125 'SetUsePalette' : (None, 0,0,0),
127 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
128 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
131 '''void %s(int markerNumber, int markerSymbol,
132 const wxColour& foreground = wxNullColour,
133 const wxColour& background = wxNullColour);''',
135 '''void %s(int markerNumber, int markerSymbol,
136 const wxColour& foreground,
137 const wxColour& background) {
139 SendMsg(%s, markerNumber, markerSymbol);
141 MarkerSetForeground(markerNumber, foreground);
143 MarkerSetBackground(markerNumber, background);''',
145 ('Set the symbol used for a particular marker number,',
146 'and optionally the for and background colours.')),
148 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
149 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
150 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
151 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
152 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
153 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
154 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
155 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
157 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
158 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
159 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
160 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
161 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
162 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
164 # need to fix this to map between wx and scintilla encoding flags, leave it out for now...
165 'StyleSetCharacterSet' : (None, 0, 0, 0),
167 'AssignCmdKey' : ('CmdKeyAssign',
168 'void %s(int key, int modifiers, int cmd);',
170 '''void %s(int key, int modifiers, int cmd) {
171 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
175 'ClearCmdKey' : ('CmdKeyClear',
176 'void %s(int key, int modifiers);',
178 '''void %s(int key, int modifiers) {
179 SendMsg(%s, MAKELONG(key, modifiers));''',
183 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
186 'SetStylingEx' : ('SetStyleBytes',
187 'void %s(int length, char* styleBytes);',
189 '''void %s(int length, char* styleBytes) {
190 SendMsg(%s, length, (long)styleBytes);''',
195 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
196 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
197 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
198 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
200 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
201 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
202 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
203 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
204 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
205 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
206 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
207 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
208 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
209 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
210 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
211 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
212 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
213 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
214 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
215 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
217 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
218 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
220 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
222 'GetUsePalette' : (None, 0, 0, 0),
225 '''int %s(int minPos, int maxPos,
226 const wxString& text,
227 bool caseSensitive, bool wholeWord);''',
228 '''int %s(int minPos, int maxPos,
229 const wxString& text,
230 bool caseSensitive, bool wholeWord) {
234 flags |= caseSensitive ? SCFIND_MATCHCASE : 0;
235 flags |= wholeWord ? SCFIND_WHOLEWORD : 0;
236 ft.chrg.cpMin = minPos;
237 ft.chrg.cpMax = maxPos;
238 ft.lpstrText = (char*)text.c_str();
240 return SendMsg(%s, flags, (long)&ft);''',
244 '''int %s(bool doDraw,
248 wxDC* target, // Why does it use two? Can they be the same?
250 wxRect pageRect);''',
251 ''' int %s(bool doDraw,
255 wxDC* target, // Why does it use two? Can they be the same?
261 fr.hdcTarget = target;
262 fr.rc.top = renderRect.GetTop();
263 fr.rc.left = renderRect.GetLeft();
264 fr.rc.right = renderRect.GetRight();
265 fr.rc.bottom = renderRect.GetBottom();
266 fr.rcPage.top = pageRect.GetTop();
267 fr.rcPage.left = pageRect.GetLeft();
268 fr.rcPage.right = pageRect.GetRight();
269 fr.rcPage.bottom = pageRect.GetBottom();
270 fr.chrg.cpMin = startPos;
271 fr.chrg.cpMax = endPos;
273 return SendMsg(%s, doDraw, (long)&fr);''',
278 'wxString %s(int line);',
280 '''wxString %s(int line) {
282 int len = LineLength(line);
283 char* buf = text.GetWriteBuf(len);
285 int pos = SendMsg(%s, line, (long)buf);
286 text.UngetWriteBuf();
290 ('Retrieve the contents of a line.',)),
292 'SetSel' : ('SetSelection', 0, 0, 0),
293 'GetSelText' : ('GetSelectedText',
301 GetSelection(&start, &end);
302 int len = end - start;
303 char* buff = text.GetWriteBuf(len+1);
305 SendMsg(%s, 0, (long)buff);
306 text.UngetWriteBuf();
309 ('Retrieve the selected text.',)),
312 'wxString %s(int startPos, int endPos);',
314 '''wxString %s(int startPos, int endPos) {
316 int len = endPos - startPos;
317 char* buff = text.GetWriteBuf(len+1);
320 tr.chrg.cpMin = startPos;
321 tr.chrg.cpMax = endPos;
323 SendMsg(%s, 0, (long)&tr);
324 text.UngetWriteBuf();
327 ('Retrieve a range of text.',)),
329 'PointXFromPosition' : (None, 0, 0, 0),
330 'PointYFromPosition' : (None, 0, 0, 0),
332 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
333 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
334 'Null' : (None, 0, 0, 0),
341 int len = GetTextLength()+1;
342 char* buff = text.GetWriteBuf(len+1);
344 SendMsg(%s, len, (long)buff);
346 text.UngetWriteBuf();
349 ('Retrieve all the text in the document.', )),
351 'GetDirectFunction' : (None, 0, 0, 0),
352 'GetDirectPointer' : (None, 0, 0, 0),
354 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
355 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
356 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
359 # Remove all methods that are key commands since they can be
360 # executed with CmdKeyExecute
361 'LineDown' : (None, 0, 0, 0),
362 'LineDownExtend' : (None, 0, 0, 0),
363 'LineUp' : (None, 0, 0, 0),
364 'LineUpExtend' : (None, 0, 0, 0),
365 'CharLeft' : (None, 0, 0, 0),
366 'CharLeftExtend' : (None, 0, 0, 0),
367 'CharRight' : (None, 0, 0, 0),
368 'CharRightExtend' : (None, 0, 0, 0),
369 'WordLeft' : (None, 0, 0, 0),
370 'WordLeftExtend' : (None, 0, 0, 0),
371 'WordRight' : (None, 0, 0, 0),
372 'WordRightExtend' : (None, 0, 0, 0),
373 'Home' : (None, 0, 0, 0),
374 'HomeExtend' : (None, 0, 0, 0),
375 'LineEnd' : (None, 0, 0, 0),
376 'LineEndExtend' : (None, 0, 0, 0),
377 'DocumentStart' : (None, 0, 0, 0),
378 'DocumentStartExtend' : (None, 0, 0, 0),
379 'DocumentEnd' : (None, 0, 0, 0),
380 'DocumentEndExtend' : (None, 0, 0, 0),
381 'PageUp' : (None, 0, 0, 0),
382 'PageUpExtend' : (None, 0, 0, 0),
383 'PageDown' : (None, 0, 0, 0),
384 'PageDownExtend' : (None, 0, 0, 0),
385 'EditToggleOvertype' : (None, 0, 0, 0),
386 'Cancel' : (None, 0, 0, 0),
387 'DeleteBack' : (None, 0, 0, 0),
388 'Tab' : (None, 0, 0, 0),
389 'BackTab' : (None, 0, 0, 0),
390 'NewLine' : (None, 0, 0, 0),
391 'FormFeed' : (None, 0, 0, 0),
392 'VCHome' : (None, 0, 0, 0),
393 'VCHomeExtend' : (None, 0, 0, 0),
394 'ZoomIn' : (None, 0, 0, 0),
395 'ZoomOut' : (None, 0, 0, 0),
396 'DelWordLeft' : (None, 0, 0, 0),
397 'DelWordRight' : (None, 0, 0, 0),
398 'LineCut' : (None, 0, 0, 0),
399 'LineDelete' : (None, 0, 0, 0),
400 'LineTranspose' : (None, 0, 0, 0),
401 'LowerCase' : (None, 0, 0, 0),
402 'UpperCase' : (None, 0, 0, 0),
403 'LineScrollDown' : (None, 0, 0, 0),
404 'LineScrollUp' : (None, 0, 0, 0),
407 'GetDocPointer' : (0,
410 return (void*)SendMsg(%s);''',
413 'SetDocPointer' : (0,
414 'void %s(void* docPointer);',
415 '''void %s(void* docPointer) {
416 SendMsg(%s, (long)docPointer);''',
419 'CreateDocument' : (0,
422 return (void*)SendMsg(%s);''',
425 'AddRefDocument' : (0,
426 'void %s(void* docPointer);',
427 '''void %s(void* docPointer) {
428 SendMsg(%s, (long)docPointer);''',
431 'ReleaseDocument' : (0,
432 'void %s(void* docPointer);',
433 '''void %s(void* docPointer) {
434 SendMsg(%s, (long)docPointer);''',
437 'GrabFocus' : (None, 0, 0, 0),
443 #----------------------------------------------------------------------------
445 def processIface(iface
, h_tmplt
, cpp_tmplt
, h_dest
, cpp_dest
):
451 fi
= FileInput(iface
)
454 if line
[:2] == '##' or line
== '':
459 if line
[:2] == '# ': # a doc string
460 curDocStrings
.append(line
[2:])
463 parseVal(line
[4:], values
, curDocStrings
)
466 elif op
== 'fun ' or op
== 'set ' or op
== 'get ':
467 parseFun(line
[4:], methods
, curDocStrings
, values
)
471 if string
.strip(line
[4:]) == 'Deprecated':
472 break # skip the rest of the file
478 print '***** Unknown line type: ', line
483 data
['VALUES'] = processVals(values
)
484 defs
, imps
= processMethods(methods
)
485 data
['METHOD_DEFS'] = defs
486 data
['METHOD_IMPS'] = imps
489 h_text
= open(h_tmplt
).read()
490 cpp_text
= open(cpp_tmplt
).read()
492 # do the substitutions
493 h_text
= h_text
% data
494 cpp_text
= cpp_text
% data
496 # write out destination files
497 open(h_dest
, 'w').write(h_text
)
498 open(cpp_dest
, 'w').write(cpp_text
)
502 #----------------------------------------------------------------------------
504 def processVals(values
):
506 for name
, value
, docs
in values
:
510 text
.append('// ' + x
)
511 text
.append('#define %s %s' % (name
, value
))
512 return string
.join(text
, '\n')
514 #----------------------------------------------------------------------------
516 def processMethods(methods
):
520 for retType
, name
, number
, param1
, param2
, docs
in methods
:
521 retType
= retTypeMap
.get(retType
, retType
)
522 params
= makeParamString(param1
, param2
)
524 name
, theDef
, theImp
, docs
= checkMethodOverride(name
, number
, docs
)
529 # Build the method definition for the .h file
533 defs
.append(' // ' + x
)
535 theDef
= ' %s %s(%s);' % (retType
, name
, params
)
538 # Build the method implementation string
542 imps
.append('// ' + x
)
544 theImp
= '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType
, name
, params
)
546 if retType
== 'wxColour':
547 theImp
= theImp
+ 'long c = '
548 elif retType
!= 'void':
549 theImp
= theImp
+ 'return '
550 theImp
= theImp
+ 'SendMsg(%s, %s, %s)' % (number
,
551 makeArgString(param1
),
552 makeArgString(param2
))
553 if retType
== 'bool':
554 theImp
= theImp
+ ' != 0'
555 if retType
== 'wxColour':
556 theImp
= theImp
+ ';\n return wxColourFromLong(c)'
558 theImp
= theImp
+ ';\n}'
562 return string
.join(defs
, '\n'), string
.join(imps
, '\n')
565 #----------------------------------------------------------------------------
567 def checkMethodOverride(name
, number
, docs
):
568 theDef
= theImp
= None
569 if methodOverrideMap
.has_key(name
):
570 item
= methodOverrideMap
[name
]
575 theDef
= ' ' + (item
[1] % name
)
577 theImp
= item
[2] % ('wxStyledTextCtrl::'+name
, number
) + '\n}'
581 return name
, theDef
, theImp
, docs
583 #----------------------------------------------------------------------------
585 def makeArgString(param
):
592 return '(long)%s.c_str()' % name
594 return 'wxColourAsLong(%s)' % name
598 #----------------------------------------------------------------------------
600 def makeParamString(param1
, param2
):
603 aType
= paramTypeMap
.get(param
[0], param
[0])
604 return aType
+ ' ' + param
[1]
611 st
= st
+ doOne(param2
)
615 #----------------------------------------------------------------------------
617 def parseVal(line
, values
, docs
):
618 name
, val
= string
.split(line
, '=')
620 # remove prefixes such as SCI, etc.
621 for old
, new
in valPrefixes
:
626 name
= new
+ name
[lo
:]
629 values
.append( ('wxSTC_' + name
, val
, docs
) )
631 #----------------------------------------------------------------------------
633 funregex
= re
.compile(r
'\s*([a-zA-Z0-9_]+)' # <ws>return type
634 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
636 '\(([ a-zA-Z0-9_]*),' # (param,
637 '([ a-zA-Z0-9_]*)\)') # param)
639 def parseFun(line
, methods
, docs
, values
):
640 def parseParam(param
):
641 param
= string
.strip(param
)
645 param
= tuple(string
.split(param
))
648 mo
= funregex
.match(line
)
650 print "***** Line doesn't match! : " + line
652 retType
, name
, number
, param1
, param2
= mo
.groups()
654 param1
= parseParam(param1
)
655 param2
= parseParam(param2
)
657 # Special case. For the key command functionss we want a value defined too
658 num
= string
.atoi(number
)
660 if (type(v
) == type(()) and v
[0] <= num
< v
[1]) or v
== num
:
661 parseVal('CMD_%s=%s' % (string
.upper(name
), number
), values
, ())
663 #if retType == 'void' and not param1 and not param2:
665 methods
.append( (retType
, name
, number
, param1
, param2
, tuple(docs
)) )
668 #----------------------------------------------------------------------------
672 # TODO: parse command line args to replace default input/output files???
675 processIface(IFACE
, H_TEMPLATE
, CPP_TEMPLATE
, H_DEST
, CPP_DEST
)
679 if __name__
== '__main__':
682 #----------------------------------------------------------------------------