]>
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 int len = endPos - startPos;
92 tr.lpstrText = text.GetWriteBuf(len*2);
93 tr.chrg.cpMin = startPos;
94 tr.chrg.cpMax = endPos;
95 SendMsg(%s, 0, (long)&tr);
96 text.UngetWriteBuf(len*2);
99 ('Retrieve a buffer of cells.',)),
102 'PositionFromPoint' : (0,
103 'int %s(wxPoint pt);',
105 '''int %s(wxPoint pt) {
106 return SendMsg(%s, pt.x, pt.y);''',
111 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
113 '''wxString %s(int* linePos) {
115 int len = LineLength(GetCurrentLine());
117 if (linePos) *linePos = 0;
120 // Need an extra byte because SCI_GETCURLINE writes a null to the string
121 char* buf = text.GetWriteBuf(len+1);
123 int pos = SendMsg(%s, len+1, (long)buf);
124 text.UngetWriteBuf(len);
125 if (linePos) *linePos = pos;
131 'SetUsePalette' : (None, 0,0,0),
133 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
134 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
137 '''void %s(int markerNumber, int markerSymbol,
138 const wxColour& foreground = wxNullColour,
139 const wxColour& background = wxNullColour);''',
141 '''void %s(int markerNumber, int markerSymbol,
142 const wxColour& foreground,
143 const wxColour& background) {
145 SendMsg(%s, markerNumber, markerSymbol);
147 MarkerSetForeground(markerNumber, foreground);
149 MarkerSetBackground(markerNumber, background);''',
151 ('Set the symbol used for a particular marker number,',
152 'and optionally the for and background colours.')),
154 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
155 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
156 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
157 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
158 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
159 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
160 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
161 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
163 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
164 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
165 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
166 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
167 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
168 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
170 # need to fix this to map between wx and scintilla encoding flags, leave it out for now...
171 'StyleSetCharacterSet' : (None, 0, 0, 0),
173 'AssignCmdKey' : ('CmdKeyAssign',
174 'void %s(int key, int modifiers, int cmd);',
176 '''void %s(int key, int modifiers, int cmd) {
177 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
181 'ClearCmdKey' : ('CmdKeyClear',
182 'void %s(int key, int modifiers);',
184 '''void %s(int key, int modifiers) {
185 SendMsg(%s, MAKELONG(key, modifiers));''',
189 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
192 'SetStylingEx' : ('SetStyleBytes',
193 'void %s(int length, char* styleBytes);',
195 '''void %s(int length, char* styleBytes) {
196 SendMsg(%s, length, (long)styleBytes);''',
201 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
202 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
203 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
204 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
206 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
207 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
208 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
209 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
210 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
211 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
212 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
213 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
214 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
215 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
216 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
217 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
218 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
219 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
220 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
221 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
222 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
223 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
226 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
227 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
229 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
231 'GetUsePalette' : (None, 0, 0, 0),
234 '''int %s(int minPos, int maxPos,
235 const wxString& text,
236 bool caseSensitive, bool wholeWord);''',
237 '''int %s(int minPos, int maxPos,
238 const wxString& text,
239 bool caseSensitive, bool wholeWord) {
243 flags |= caseSensitive ? SCFIND_MATCHCASE : 0;
244 flags |= wholeWord ? SCFIND_WHOLEWORD : 0;
245 ft.chrg.cpMin = minPos;
246 ft.chrg.cpMax = maxPos;
247 ft.lpstrText = (char*)text.c_str();
249 return SendMsg(%s, flags, (long)&ft);''',
253 '''int %s(bool doDraw,
257 wxDC* target, // Why does it use two? Can they be the same?
259 wxRect pageRect);''',
260 ''' int %s(bool doDraw,
264 wxDC* target, // Why does it use two? Can they be the same?
270 fr.hdcTarget = target;
271 fr.rc.top = renderRect.GetTop();
272 fr.rc.left = renderRect.GetLeft();
273 fr.rc.right = renderRect.GetRight();
274 fr.rc.bottom = renderRect.GetBottom();
275 fr.rcPage.top = pageRect.GetTop();
276 fr.rcPage.left = pageRect.GetLeft();
277 fr.rcPage.right = pageRect.GetRight();
278 fr.rcPage.bottom = pageRect.GetBottom();
279 fr.chrg.cpMin = startPos;
280 fr.chrg.cpMax = endPos;
282 return SendMsg(%s, doDraw, (long)&fr);''',
287 'wxString %s(int line);',
289 '''wxString %s(int line) {
291 int len = LineLength(line);
293 char* buf = text.GetWriteBuf(len);
295 int pos = SendMsg(%s, line, (long)buf);
296 text.UngetWriteBuf(len);
300 ('Retrieve the contents of a line.',)),
302 'SetSel' : ('SetSelection', 0, 0, 0),
303 'GetSelText' : ('GetSelectedText',
311 GetSelection(&start, &end);
312 int len = end - start;
314 char* buff = text.GetWriteBuf(len);
316 SendMsg(%s, 0, (long)buff);
317 text.UngetWriteBuf(len);
320 ('Retrieve the selected text.',)),
323 'wxString %s(int startPos, int endPos);',
325 '''wxString %s(int startPos, int endPos) {
327 int len = endPos - startPos;
329 char* buff = text.GetWriteBuf(len);
332 tr.chrg.cpMin = startPos;
333 tr.chrg.cpMax = endPos;
335 SendMsg(%s, 0, (long)&tr);
336 text.UngetWriteBuf(len);
339 ('Retrieve a range of text.',)),
341 'PointXFromPosition' : (None, 0, 0, 0),
342 'PointYFromPosition' : (None, 0, 0, 0),
344 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
345 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
346 'Null' : (None, 0, 0, 0),
353 int len = GetTextLength();
354 char* buff = text.GetWriteBuf(len+1); // leave room for the null...
356 SendMsg(%s, len+1, (long)buff);
357 text.UngetWriteBuf(len);
360 ('Retrieve all the text in the document.', )),
362 'GetDirectFunction' : (None, 0, 0, 0),
363 'GetDirectPointer' : (None, 0, 0, 0),
365 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
366 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
367 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
370 'ReplaceTarget' : (0,
371 'int %s(const wxString& text);',
374 int %s(const wxString& text) {
375 return SendMsg(%s, text.Len(), (long)text.c_str());
380 'ReplaceTargetRE' : (0,
381 'int %s(const wxString& text);',
384 int %s(const wxString& text) {
385 return SendMsg(%s, text.Len(), (long)text.c_str());
390 'SearchInTarget' : (0,
391 'int %s(const wxString& text);',
394 int %s(const wxString& text) {
395 return SendMsg(%s, text.Len(), (long)text.c_str());
402 # Remove all methods that are key commands since they can be
403 # executed with CmdKeyExecute
404 'LineDown' : (None, 0, 0, 0),
405 'LineDownExtend' : (None, 0, 0, 0),
406 'LineUp' : (None, 0, 0, 0),
407 'LineUpExtend' : (None, 0, 0, 0),
408 'CharLeft' : (None, 0, 0, 0),
409 'CharLeftExtend' : (None, 0, 0, 0),
410 'CharRight' : (None, 0, 0, 0),
411 'CharRightExtend' : (None, 0, 0, 0),
412 'WordLeft' : (None, 0, 0, 0),
413 'WordLeftExtend' : (None, 0, 0, 0),
414 'WordRight' : (None, 0, 0, 0),
415 'WordRightExtend' : (None, 0, 0, 0),
416 'Home' : (None, 0, 0, 0),
417 'HomeExtend' : (None, 0, 0, 0),
418 'LineEnd' : (None, 0, 0, 0),
419 'LineEndExtend' : (None, 0, 0, 0),
420 'DocumentStart' : (None, 0, 0, 0),
421 'DocumentStartExtend' : (None, 0, 0, 0),
422 'DocumentEnd' : (None, 0, 0, 0),
423 'DocumentEndExtend' : (None, 0, 0, 0),
424 'PageUp' : (None, 0, 0, 0),
425 'PageUpExtend' : (None, 0, 0, 0),
426 'PageDown' : (None, 0, 0, 0),
427 'PageDownExtend' : (None, 0, 0, 0),
428 'EditToggleOvertype' : (None, 0, 0, 0),
429 'Cancel' : (None, 0, 0, 0),
430 'DeleteBack' : (None, 0, 0, 0),
431 'Tab' : (None, 0, 0, 0),
432 'BackTab' : (None, 0, 0, 0),
433 'NewLine' : (None, 0, 0, 0),
434 'FormFeed' : (None, 0, 0, 0),
435 'VCHome' : (None, 0, 0, 0),
436 'VCHomeExtend' : (None, 0, 0, 0),
437 'ZoomIn' : (None, 0, 0, 0),
438 'ZoomOut' : (None, 0, 0, 0),
439 'DelWordLeft' : (None, 0, 0, 0),
440 'DelWordRight' : (None, 0, 0, 0),
441 'LineCut' : (None, 0, 0, 0),
442 'LineDelete' : (None, 0, 0, 0),
443 'LineTranspose' : (None, 0, 0, 0),
444 'LowerCase' : (None, 0, 0, 0),
445 'UpperCase' : (None, 0, 0, 0),
446 'LineScrollDown' : (None, 0, 0, 0),
447 'LineScrollUp' : (None, 0, 0, 0),
450 'GetDocPointer' : (0,
453 return (void*)SendMsg(%s);''',
456 'SetDocPointer' : (0,
457 'void %s(void* docPointer);',
458 '''void %s(void* docPointer) {
459 SendMsg(%s, 0, (long)docPointer);''',
462 'CreateDocument' : (0,
465 return (void*)SendMsg(%s);''',
468 'AddRefDocument' : (0,
469 'void %s(void* docPointer);',
470 '''void %s(void* docPointer) {
471 SendMsg(%s, (long)docPointer);''',
474 'ReleaseDocument' : (0,
475 'void %s(void* docPointer);',
476 '''void %s(void* docPointer) {
477 SendMsg(%s, (long)docPointer);''',
480 'GrabFocus' : (None, 0, 0, 0),
481 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
482 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
489 #----------------------------------------------------------------------------
491 def processIface(iface
, h_tmplt
, cpp_tmplt
, h_dest
, cpp_dest
):
497 fi
= FileInput(iface
)
500 if line
[:2] == '##' or line
== '':
505 if line
[:2] == '# ': # a doc string
506 curDocStrings
.append(line
[2:])
509 parseVal(line
[4:], values
, curDocStrings
)
512 elif op
== 'fun ' or op
== 'set ' or op
== 'get ':
513 parseFun(line
[4:], methods
, curDocStrings
, values
)
517 if string
.strip(line
[4:]) == 'Deprecated':
518 break # skip the rest of the file
524 print '***** Unknown line type: ', line
529 data
['VALUES'] = processVals(values
)
530 defs
, imps
= processMethods(methods
)
531 data
['METHOD_DEFS'] = defs
532 data
['METHOD_IMPS'] = imps
535 h_text
= open(h_tmplt
).read()
536 cpp_text
= open(cpp_tmplt
).read()
538 # do the substitutions
539 h_text
= h_text
% data
540 cpp_text
= cpp_text
% data
542 # write out destination files
543 open(h_dest
, 'w').write(h_text
)
544 open(cpp_dest
, 'w').write(cpp_text
)
548 #----------------------------------------------------------------------------
550 def processVals(values
):
552 for name
, value
, docs
in values
:
556 text
.append('// ' + x
)
557 text
.append('#define %s %s' % (name
, value
))
558 return string
.join(text
, '\n')
560 #----------------------------------------------------------------------------
562 def processMethods(methods
):
566 for retType
, name
, number
, param1
, param2
, docs
in methods
:
567 retType
= retTypeMap
.get(retType
, retType
)
568 params
= makeParamString(param1
, param2
)
570 name
, theDef
, theImp
, docs
= checkMethodOverride(name
, number
, docs
)
575 # Build the method definition for the .h file
579 defs
.append(' // ' + x
)
581 theDef
= ' %s %s(%s);' % (retType
, name
, params
)
584 # Build the method implementation string
588 imps
.append('// ' + x
)
590 theImp
= '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType
, name
, params
)
592 if retType
== 'wxColour':
593 theImp
= theImp
+ 'long c = '
594 elif retType
!= 'void':
595 theImp
= theImp
+ 'return '
596 theImp
= theImp
+ 'SendMsg(%s, %s, %s)' % (number
,
597 makeArgString(param1
),
598 makeArgString(param2
))
599 if retType
== 'bool':
600 theImp
= theImp
+ ' != 0'
601 if retType
== 'wxColour':
602 theImp
= theImp
+ ';\n return wxColourFromLong(c)'
604 theImp
= theImp
+ ';\n}'
608 return string
.join(defs
, '\n'), string
.join(imps
, '\n')
611 #----------------------------------------------------------------------------
613 def checkMethodOverride(name
, number
, docs
):
614 theDef
= theImp
= None
615 if methodOverrideMap
.has_key(name
):
616 item
= methodOverrideMap
[name
]
621 theDef
= ' ' + (item
[1] % name
)
623 theImp
= item
[2] % ('wxStyledTextCtrl::'+name
, number
) + '\n}'
627 return name
, theDef
, theImp
, docs
629 #----------------------------------------------------------------------------
631 def makeArgString(param
):
638 return '(long)%s.c_str()' % name
640 return 'wxColourAsLong(%s)' % name
644 #----------------------------------------------------------------------------
646 def makeParamString(param1
, param2
):
649 aType
= paramTypeMap
.get(param
[0], param
[0])
650 return aType
+ ' ' + param
[1]
657 st
= st
+ doOne(param2
)
661 #----------------------------------------------------------------------------
663 def parseVal(line
, values
, docs
):
664 name
, val
= string
.split(line
, '=')
666 # remove prefixes such as SCI, etc.
667 for old
, new
in valPrefixes
:
672 name
= new
+ name
[lo
:]
675 values
.append( ('wxSTC_' + name
, val
, docs
) )
677 #----------------------------------------------------------------------------
679 funregex
= re
.compile(r
'\s*([a-zA-Z0-9_]+)' # <ws>return type
680 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
682 '\(([ a-zA-Z0-9_]*),' # (param,
683 '([ a-zA-Z0-9_]*)\)') # param)
685 def parseFun(line
, methods
, docs
, values
):
686 def parseParam(param
):
687 param
= string
.strip(param
)
691 param
= tuple(string
.split(param
))
694 mo
= funregex
.match(line
)
696 print "***** Line doesn't match! : " + line
698 retType
, name
, number
, param1
, param2
= mo
.groups()
700 param1
= parseParam(param1
)
701 param2
= parseParam(param2
)
703 # Special case. For the key command functionss we want a value defined too
704 num
= string
.atoi(number
)
706 if (type(v
) == type(()) and v
[0] <= num
< v
[1]) or v
== num
:
707 parseVal('CMD_%s=%s' % (string
.upper(name
), number
), values
, ())
709 #if retType == 'void' and not param1 and not param2:
711 methods
.append( (retType
, name
, number
, param1
, param2
, tuple(docs
)) )
714 #----------------------------------------------------------------------------
718 # TODO: parse command line args to replace default input/output files???
721 processIface(IFACE
, H_TEMPLATE
, CPP_TEMPLATE
, H_DEST
, CPP_DEST
)
725 if __name__
== '__main__':
728 #----------------------------------------------------------------------------