]>
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 'wxString %s(int* OUTPUT=NULL);',
113 '''wxString %s(int* linePos) {
115 int len = LineLength(GetCurrentLine());
117 char* buf = text.GetWriteBuf(len);
119 int pos = SendMsg(%s, len, (long)buf);
120 text.UngetWriteBuf(len);
121 if (linePos) *linePos = pos;
127 'SetUsePalette' : (None, 0,0,0),
129 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
130 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
133 '''void %s(int markerNumber, int markerSymbol,
134 const wxColour& foreground = wxNullColour,
135 const wxColour& background = wxNullColour);''',
137 '''void %s(int markerNumber, int markerSymbol,
138 const wxColour& foreground,
139 const wxColour& background) {
141 SendMsg(%s, markerNumber, markerSymbol);
143 MarkerSetForeground(markerNumber, foreground);
145 MarkerSetBackground(markerNumber, background);''',
147 ('Set the symbol used for a particular marker number,',
148 'and optionally the for and background colours.')),
150 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
151 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
152 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
153 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
154 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
155 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
156 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
157 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
159 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
160 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
161 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
162 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
163 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
164 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
166 # need to fix this to map between wx and scintilla encoding flags, leave it out for now...
167 'StyleSetCharacterSet' : (None, 0, 0, 0),
169 'AssignCmdKey' : ('CmdKeyAssign',
170 'void %s(int key, int modifiers, int cmd);',
172 '''void %s(int key, int modifiers, int cmd) {
173 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
177 'ClearCmdKey' : ('CmdKeyClear',
178 'void %s(int key, int modifiers);',
180 '''void %s(int key, int modifiers) {
181 SendMsg(%s, MAKELONG(key, modifiers));''',
185 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
188 'SetStylingEx' : ('SetStyleBytes',
189 'void %s(int length, char* styleBytes);',
191 '''void %s(int length, char* styleBytes) {
192 SendMsg(%s, length, (long)styleBytes);''',
197 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
198 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
199 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
200 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
202 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
203 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
204 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
205 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
206 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
207 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
208 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
209 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
210 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
211 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
212 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
213 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
214 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
215 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
216 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
217 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
218 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
219 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
222 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
223 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
225 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
227 'GetUsePalette' : (None, 0, 0, 0),
230 '''int %s(int minPos, int maxPos,
231 const wxString& text,
232 bool caseSensitive, bool wholeWord);''',
233 '''int %s(int minPos, int maxPos,
234 const wxString& text,
235 bool caseSensitive, bool wholeWord) {
239 flags |= caseSensitive ? SCFIND_MATCHCASE : 0;
240 flags |= wholeWord ? SCFIND_WHOLEWORD : 0;
241 ft.chrg.cpMin = minPos;
242 ft.chrg.cpMax = maxPos;
243 ft.lpstrText = (char*)text.c_str();
245 return SendMsg(%s, flags, (long)&ft);''',
249 '''int %s(bool doDraw,
253 wxDC* target, // Why does it use two? Can they be the same?
255 wxRect pageRect);''',
256 ''' int %s(bool doDraw,
260 wxDC* target, // Why does it use two? Can they be the same?
266 fr.hdcTarget = target;
267 fr.rc.top = renderRect.GetTop();
268 fr.rc.left = renderRect.GetLeft();
269 fr.rc.right = renderRect.GetRight();
270 fr.rc.bottom = renderRect.GetBottom();
271 fr.rcPage.top = pageRect.GetTop();
272 fr.rcPage.left = pageRect.GetLeft();
273 fr.rcPage.right = pageRect.GetRight();
274 fr.rcPage.bottom = pageRect.GetBottom();
275 fr.chrg.cpMin = startPos;
276 fr.chrg.cpMax = endPos;
278 return SendMsg(%s, doDraw, (long)&fr);''',
283 'wxString %s(int line);',
285 '''wxString %s(int line) {
287 int len = LineLength(line);
289 char* buf = text.GetWriteBuf(len);
291 int pos = SendMsg(%s, line, (long)buf);
292 text.UngetWriteBuf(len);
296 ('Retrieve the contents of a line.',)),
298 'SetSel' : ('SetSelection', 0, 0, 0),
299 'GetSelText' : ('GetSelectedText',
307 GetSelection(&start, &end);
308 int len = end - start;
310 char* buff = text.GetWriteBuf(len);
312 SendMsg(%s, 0, (long)buff);
313 text.UngetWriteBuf(len);
316 ('Retrieve the selected text.',)),
319 'wxString %s(int startPos, int endPos);',
321 '''wxString %s(int startPos, int endPos) {
323 int len = endPos - startPos;
325 char* buff = text.GetWriteBuf(len);
328 tr.chrg.cpMin = startPos;
329 tr.chrg.cpMax = endPos;
331 SendMsg(%s, 0, (long)&tr);
332 text.UngetWriteBuf(len);
335 ('Retrieve a range of text.',)),
337 'PointXFromPosition' : (None, 0, 0, 0),
338 'PointYFromPosition' : (None, 0, 0, 0),
340 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
341 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
342 'Null' : (None, 0, 0, 0),
349 int len = GetTextLength()+1;
350 char* buff = text.GetWriteBuf(len);
352 SendMsg(%s, len, (long)buff);
353 text.UngetWriteBuf(len-1);
356 ('Retrieve all the text in the document.', )),
358 'GetDirectFunction' : (None, 0, 0, 0),
359 'GetDirectPointer' : (None, 0, 0, 0),
361 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
362 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
363 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
366 'ReplaceTarget' : (0,
367 'int %s(const wxString& text);',
370 int %s(const wxString& text) {
371 return SendMsg(%s, text.Len(), (long)text.c_str());
376 'ReplaceTargetRE' : (0,
377 'int %s(const wxString& text);',
380 int %s(const wxString& text) {
381 return SendMsg(%s, text.Len(), (long)text.c_str());
386 'SearchInTarget' : (0,
387 'int %s(const wxString& text);',
390 int %s(const wxString& text) {
391 return SendMsg(%s, text.Len(), (long)text.c_str());
398 # Remove all methods that are key commands since they can be
399 # executed with CmdKeyExecute
400 'LineDown' : (None, 0, 0, 0),
401 'LineDownExtend' : (None, 0, 0, 0),
402 'LineUp' : (None, 0, 0, 0),
403 'LineUpExtend' : (None, 0, 0, 0),
404 'CharLeft' : (None, 0, 0, 0),
405 'CharLeftExtend' : (None, 0, 0, 0),
406 'CharRight' : (None, 0, 0, 0),
407 'CharRightExtend' : (None, 0, 0, 0),
408 'WordLeft' : (None, 0, 0, 0),
409 'WordLeftExtend' : (None, 0, 0, 0),
410 'WordRight' : (None, 0, 0, 0),
411 'WordRightExtend' : (None, 0, 0, 0),
412 'Home' : (None, 0, 0, 0),
413 'HomeExtend' : (None, 0, 0, 0),
414 'LineEnd' : (None, 0, 0, 0),
415 'LineEndExtend' : (None, 0, 0, 0),
416 'DocumentStart' : (None, 0, 0, 0),
417 'DocumentStartExtend' : (None, 0, 0, 0),
418 'DocumentEnd' : (None, 0, 0, 0),
419 'DocumentEndExtend' : (None, 0, 0, 0),
420 'PageUp' : (None, 0, 0, 0),
421 'PageUpExtend' : (None, 0, 0, 0),
422 'PageDown' : (None, 0, 0, 0),
423 'PageDownExtend' : (None, 0, 0, 0),
424 'EditToggleOvertype' : (None, 0, 0, 0),
425 'Cancel' : (None, 0, 0, 0),
426 'DeleteBack' : (None, 0, 0, 0),
427 'Tab' : (None, 0, 0, 0),
428 'BackTab' : (None, 0, 0, 0),
429 'NewLine' : (None, 0, 0, 0),
430 'FormFeed' : (None, 0, 0, 0),
431 'VCHome' : (None, 0, 0, 0),
432 'VCHomeExtend' : (None, 0, 0, 0),
433 'ZoomIn' : (None, 0, 0, 0),
434 'ZoomOut' : (None, 0, 0, 0),
435 'DelWordLeft' : (None, 0, 0, 0),
436 'DelWordRight' : (None, 0, 0, 0),
437 'LineCut' : (None, 0, 0, 0),
438 'LineDelete' : (None, 0, 0, 0),
439 'LineTranspose' : (None, 0, 0, 0),
440 'LowerCase' : (None, 0, 0, 0),
441 'UpperCase' : (None, 0, 0, 0),
442 'LineScrollDown' : (None, 0, 0, 0),
443 'LineScrollUp' : (None, 0, 0, 0),
446 'GetDocPointer' : (0,
449 return (void*)SendMsg(%s);''',
452 'SetDocPointer' : (0,
453 'void %s(void* docPointer);',
454 '''void %s(void* docPointer) {
455 SendMsg(%s, 0, (long)docPointer);''',
458 'CreateDocument' : (0,
461 return (void*)SendMsg(%s);''',
464 'AddRefDocument' : (0,
465 'void %s(void* docPointer);',
466 '''void %s(void* docPointer) {
467 SendMsg(%s, (long)docPointer);''',
470 'ReleaseDocument' : (0,
471 'void %s(void* docPointer);',
472 '''void %s(void* docPointer) {
473 SendMsg(%s, (long)docPointer);''',
476 'GrabFocus' : (None, 0, 0, 0),
482 #----------------------------------------------------------------------------
484 def processIface(iface
, h_tmplt
, cpp_tmplt
, h_dest
, cpp_dest
):
490 fi
= FileInput(iface
)
493 if line
[:2] == '##' or line
== '':
498 if line
[:2] == '# ': # a doc string
499 curDocStrings
.append(line
[2:])
502 parseVal(line
[4:], values
, curDocStrings
)
505 elif op
== 'fun ' or op
== 'set ' or op
== 'get ':
506 parseFun(line
[4:], methods
, curDocStrings
, values
)
510 if string
.strip(line
[4:]) == 'Deprecated':
511 break # skip the rest of the file
517 print '***** Unknown line type: ', line
522 data
['VALUES'] = processVals(values
)
523 defs
, imps
= processMethods(methods
)
524 data
['METHOD_DEFS'] = defs
525 data
['METHOD_IMPS'] = imps
528 h_text
= open(h_tmplt
).read()
529 cpp_text
= open(cpp_tmplt
).read()
531 # do the substitutions
532 h_text
= h_text
% data
533 cpp_text
= cpp_text
% data
535 # write out destination files
536 open(h_dest
, 'w').write(h_text
)
537 open(cpp_dest
, 'w').write(cpp_text
)
541 #----------------------------------------------------------------------------
543 def processVals(values
):
545 for name
, value
, docs
in values
:
549 text
.append('// ' + x
)
550 text
.append('#define %s %s' % (name
, value
))
551 return string
.join(text
, '\n')
553 #----------------------------------------------------------------------------
555 def processMethods(methods
):
559 for retType
, name
, number
, param1
, param2
, docs
in methods
:
560 retType
= retTypeMap
.get(retType
, retType
)
561 params
= makeParamString(param1
, param2
)
563 name
, theDef
, theImp
, docs
= checkMethodOverride(name
, number
, docs
)
568 # Build the method definition for the .h file
572 defs
.append(' // ' + x
)
574 theDef
= ' %s %s(%s);' % (retType
, name
, params
)
577 # Build the method implementation string
581 imps
.append('// ' + x
)
583 theImp
= '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType
, name
, params
)
585 if retType
== 'wxColour':
586 theImp
= theImp
+ 'long c = '
587 elif retType
!= 'void':
588 theImp
= theImp
+ 'return '
589 theImp
= theImp
+ 'SendMsg(%s, %s, %s)' % (number
,
590 makeArgString(param1
),
591 makeArgString(param2
))
592 if retType
== 'bool':
593 theImp
= theImp
+ ' != 0'
594 if retType
== 'wxColour':
595 theImp
= theImp
+ ';\n return wxColourFromLong(c)'
597 theImp
= theImp
+ ';\n}'
601 return string
.join(defs
, '\n'), string
.join(imps
, '\n')
604 #----------------------------------------------------------------------------
606 def checkMethodOverride(name
, number
, docs
):
607 theDef
= theImp
= None
608 if methodOverrideMap
.has_key(name
):
609 item
= methodOverrideMap
[name
]
614 theDef
= ' ' + (item
[1] % name
)
616 theImp
= item
[2] % ('wxStyledTextCtrl::'+name
, number
) + '\n}'
620 return name
, theDef
, theImp
, docs
622 #----------------------------------------------------------------------------
624 def makeArgString(param
):
631 return '(long)%s.c_str()' % name
633 return 'wxColourAsLong(%s)' % name
637 #----------------------------------------------------------------------------
639 def makeParamString(param1
, param2
):
642 aType
= paramTypeMap
.get(param
[0], param
[0])
643 return aType
+ ' ' + param
[1]
650 st
= st
+ doOne(param2
)
654 #----------------------------------------------------------------------------
656 def parseVal(line
, values
, docs
):
657 name
, val
= string
.split(line
, '=')
659 # remove prefixes such as SCI, etc.
660 for old
, new
in valPrefixes
:
665 name
= new
+ name
[lo
:]
668 values
.append( ('wxSTC_' + name
, val
, docs
) )
670 #----------------------------------------------------------------------------
672 funregex
= re
.compile(r
'\s*([a-zA-Z0-9_]+)' # <ws>return type
673 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
675 '\(([ a-zA-Z0-9_]*),' # (param,
676 '([ a-zA-Z0-9_]*)\)') # param)
678 def parseFun(line
, methods
, docs
, values
):
679 def parseParam(param
):
680 param
= string
.strip(param
)
684 param
= tuple(string
.split(param
))
687 mo
= funregex
.match(line
)
689 print "***** Line doesn't match! : " + line
691 retType
, name
, number
, param1
, param2
= mo
.groups()
693 param1
= parseParam(param1
)
694 param2
= parseParam(param2
)
696 # Special case. For the key command functionss we want a value defined too
697 num
= string
.atoi(number
)
699 if (type(v
) == type(()) and v
[0] <= num
< v
[1]) or v
== num
:
700 parseVal('CMD_%s=%s' % (string
.upper(name
), number
), values
, ())
702 #if retType == 'void' and not param1 and not param2:
704 methods
.append( (retType
, name
, number
, param1
, param2
, tuple(docs
)) )
707 #----------------------------------------------------------------------------
711 # TODO: parse command line args to replace default input/output files???
714 processIface(IFACE
, H_TEMPLATE
, CPP_TEMPLATE
, H_DEST
, CPP_DEST
)
718 if __name__
== '__main__':
721 #----------------------------------------------------------------------------