]>
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 wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8);
72 SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
76 'void %s(const wxMemoryBuffer& data);',
78 '''void %s(const wxMemoryBuffer& data) {
79 SendMsg(%s, data.GetDataLen(), (long)data.GetData());''',
82 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
83 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
86 'wxMemoryBuffer %s(int startPos, int endPos);',
88 '''wxMemoryBuffer %s(int startPos, int endPos) {
90 if (endPos < startPos) {
95 int len = endPos - startPos;
98 tr.lpstrText = (char*)buf.GetWriteBuf(len*2+1);
99 tr.chrg.cpMin = startPos;
100 tr.chrg.cpMax = endPos;
101 len = SendMsg(%s, 0, (long)&tr);
102 buf.UngetWriteBuf(len);
105 ('Retrieve a buffer of cells.',)),
108 'PositionFromPoint' : (0,
109 'int %s(wxPoint pt);',
111 '''int %s(wxPoint pt) {
112 return SendMsg(%s, pt.x, pt.y);''',
117 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
119 '''wxString %s(int* linePos) {
120 int len = LineLength(GetCurrentLine());
122 if (linePos) *linePos = 0;
123 return wxEmptyString;
126 wxMemoryBuffer mbuf(len+1);
127 char* buf = (char*)mbuf.GetWriteBuf(len+1);
129 int pos = SendMsg(%s, len+1, (long)buf);
130 mbuf.UngetWriteBuf(len);
132 if (linePos) *linePos = pos;
133 return wxString(buf, wxConvUTF8);''',
137 'SetUsePalette' : (None, 0,0,0),
139 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
140 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
143 '''void %s(int markerNumber, int markerSymbol,
144 const wxColour& foreground = wxNullColour,
145 const wxColour& background = wxNullColour);''',
147 '''void %s(int markerNumber, int markerSymbol,
148 const wxColour& foreground,
149 const wxColour& background) {
151 SendMsg(%s, markerNumber, markerSymbol);
153 MarkerSetForeground(markerNumber, foreground);
155 MarkerSetBackground(markerNumber, background);''',
157 ('Set the symbol used for a particular marker number,',
158 'and optionally the fore and background colours.')),
160 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
161 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
162 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
163 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
164 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
165 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
166 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
167 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
169 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
170 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
171 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
172 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
173 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
174 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
176 'AssignCmdKey' : ('CmdKeyAssign',
177 'void %s(int key, int modifiers, int cmd);',
179 '''void %s(int key, int modifiers, int cmd) {
180 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
184 'ClearCmdKey' : ('CmdKeyClear',
185 'void %s(int key, int modifiers);',
187 '''void %s(int key, int modifiers) {
188 SendMsg(%s, MAKELONG(key, modifiers));''',
192 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
195 'SetStylingEx' : ('SetStyleBytes',
196 'void %s(int length, char* styleBytes);',
198 '''void %s(int length, char* styleBytes) {
199 SendMsg(%s, length, (long)styleBytes);''',
204 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
205 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
206 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
207 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
209 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
210 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
211 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
212 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
213 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
214 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
215 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
216 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
217 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
218 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
219 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
220 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
221 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
222 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
223 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
224 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
225 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
226 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
227 'AutoCSetDropRestOfWord' : ('AutoCompSetDropRestOfWord', 0,0,0),
228 'AutoCGetDropRestOfWord' : ('AutoCompGetDropRestOfWord', 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*)(const char*)text.mb_str(wxConvUTF8);
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) {
300 int len = LineLength(line);
301 if (!len) return wxEmptyString;
303 wxMemoryBuffer mbuf(len+1);
304 char* buf = (char*)mbuf.GetWriteBuf(len+1);
305 SendMsg(%s, line, (long)buf);
306 mbuf.UngetWriteBuf(len);
308 return wxString(buf, wxConvUTF8);''',
310 ('Retrieve the contents of a line.',)),
312 'SetSel' : ('SetSelection', 0, 0, 0),
313 'GetSelText' : ('GetSelectedText',
320 GetSelection(&start, &end);
321 int len = end - start;
322 if (!len) return wxEmptyString;
324 wxMemoryBuffer mbuf(len+1);
325 char* buf = (char*)mbuf.GetWriteBuf(len+1);
326 SendMsg(%s, 0, (long)buf);
327 mbuf.UngetWriteBuf(len);
329 return wxString(buf, wxConvUTF8);''',
331 ('Retrieve the selected text.',)),
334 'wxString %s(int startPos, int endPos);',
336 '''wxString %s(int startPos, int endPos) {
337 if (endPos < startPos) {
342 int len = endPos - startPos;
343 if (!len) return wxEmptyString;
344 wxMemoryBuffer mbuf(len+1);
345 char* buf = (char*)mbuf.GetWriteBuf(len);
348 tr.chrg.cpMin = startPos;
349 tr.chrg.cpMax = endPos;
350 SendMsg(%s, 0, (long)&tr);
351 mbuf.UngetWriteBuf(len);
353 return wxString(buf, wxConvUTF8);''',
355 ('Retrieve a range of text.',)),
357 'PointXFromPosition' : (None, 0, 0, 0),
358 'PointYFromPosition' : (None, 0, 0, 0),
360 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
361 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
362 'Null' : (None, 0, 0, 0),
368 int len = GetTextLength();
369 wxMemoryBuffer mbuf(len+1); // leave room for the null...
370 char* buf = (char*)mbuf.GetWriteBuf(len+1);
371 SendMsg(%s, len+1, (long)buf);
372 mbuf.UngetWriteBuf(len);
374 return wxString(buf, wxConvUTF8);''',
376 ('Retrieve all the text in the document.', )),
378 'GetDirectFunction' : (None, 0, 0, 0),
379 'GetDirectPointer' : (None, 0, 0, 0),
381 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
382 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
383 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
386 'ReplaceTarget' : (0,
387 'int %s(const wxString& text);',
390 int %s(const wxString& text) {
391 wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8);
392 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
395 'ReplaceTargetRE' : (0,
396 'int %s(const wxString& text);',
399 int %s(const wxString& text) {
400 wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8);
401 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
404 'SearchInTarget' : (0,
405 'int %s(const wxString& text);',
408 int %s(const wxString& text) {
409 wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8);
410 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
415 # Remove all methods that are key commands since they can be
416 # executed with CmdKeyExecute
417 'LineDown' : (None, 0, 0, 0),
418 'LineDownExtend' : (None, 0, 0, 0),
419 'LineUp' : (None, 0, 0, 0),
420 'LineUpExtend' : (None, 0, 0, 0),
421 'CharLeft' : (None, 0, 0, 0),
422 'CharLeftExtend' : (None, 0, 0, 0),
423 'CharRight' : (None, 0, 0, 0),
424 'CharRightExtend' : (None, 0, 0, 0),
425 'WordLeft' : (None, 0, 0, 0),
426 'WordLeftExtend' : (None, 0, 0, 0),
427 'WordRight' : (None, 0, 0, 0),
428 'WordRightExtend' : (None, 0, 0, 0),
429 'Home' : (None, 0, 0, 0),
430 'HomeExtend' : (None, 0, 0, 0),
431 'LineEnd' : (None, 0, 0, 0),
432 'LineEndExtend' : (None, 0, 0, 0),
433 'DocumentStart' : (None, 0, 0, 0),
434 'DocumentStartExtend' : (None, 0, 0, 0),
435 'DocumentEnd' : (None, 0, 0, 0),
436 'DocumentEndExtend' : (None, 0, 0, 0),
437 'PageUp' : (None, 0, 0, 0),
438 'PageUpExtend' : (None, 0, 0, 0),
439 'PageDown' : (None, 0, 0, 0),
440 'PageDownExtend' : (None, 0, 0, 0),
441 'EditToggleOvertype' : (None, 0, 0, 0),
442 'Cancel' : (None, 0, 0, 0),
443 'DeleteBack' : (None, 0, 0, 0),
444 'Tab' : (None, 0, 0, 0),
445 'BackTab' : (None, 0, 0, 0),
446 'NewLine' : (None, 0, 0, 0),
447 'FormFeed' : (None, 0, 0, 0),
448 'VCHome' : (None, 0, 0, 0),
449 'VCHomeExtend' : (None, 0, 0, 0),
450 'ZoomIn' : (None, 0, 0, 0),
451 'ZoomOut' : (None, 0, 0, 0),
452 'DelWordLeft' : (None, 0, 0, 0),
453 'DelWordRight' : (None, 0, 0, 0),
454 'LineCut' : (None, 0, 0, 0),
455 'LineDelete' : (None, 0, 0, 0),
456 'LineTranspose' : (None, 0, 0, 0),
457 'LowerCase' : (None, 0, 0, 0),
458 'UpperCase' : (None, 0, 0, 0),
459 'LineScrollDown' : (None, 0, 0, 0),
460 'LineScrollUp' : (None, 0, 0, 0),
461 'DeleteBackNotLine' : (None, 0, 0, 0),
464 'GetDocPointer' : (0,
467 return (void*)SendMsg(%s);''',
470 'SetDocPointer' : (0,
471 'void %s(void* docPointer);',
472 '''void %s(void* docPointer) {
473 SendMsg(%s, 0, (long)docPointer);''',
476 'CreateDocument' : (0,
479 return (void*)SendMsg(%s);''',
482 'AddRefDocument' : (0,
483 'void %s(void* docPointer);',
484 '''void %s(void* docPointer) {
485 SendMsg(%s, (long)docPointer);''',
488 'ReleaseDocument' : (0,
489 'void %s(void* docPointer);',
490 '''void %s(void* docPointer) {
491 SendMsg(%s, (long)docPointer);''',
495 '''void %s(int codePage) {
497 wxASSERT_MSG(codePage == wxSTC_CP_UTF8,
498 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
500 wxASSERT_MSG(codePage != wxSTC_CP_UTF8,
501 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
503 SendMsg(%s, codePage);''',
504 ("Set the code page used to interpret the bytes of the document as characters.",) ),
507 'GrabFocus' : (None, 0, 0, 0),
508 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
509 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
516 #----------------------------------------------------------------------------
518 def processIface(iface
, h_tmplt
, cpp_tmplt
, h_dest
, cpp_dest
):
524 fi
= FileInput(iface
)
527 if line
[:2] == '##' or line
== '':
532 if line
[:2] == '# ': # a doc string
533 curDocStrings
.append(line
[2:])
536 parseVal(line
[4:], values
, curDocStrings
)
539 elif op
== 'fun ' or op
== 'set ' or op
== 'get ':
540 parseFun(line
[4:], methods
, curDocStrings
, values
)
544 if string
.strip(line
[4:]) == 'Deprecated':
545 break # skip the rest of the file
551 print '***** Unknown line type: ', line
556 data
['VALUES'] = processVals(values
)
557 defs
, imps
= processMethods(methods
)
558 data
['METHOD_DEFS'] = defs
559 data
['METHOD_IMPS'] = imps
562 h_text
= open(h_tmplt
).read()
563 cpp_text
= open(cpp_tmplt
).read()
565 # do the substitutions
566 h_text
= h_text
% data
567 cpp_text
= cpp_text
% data
569 # write out destination files
570 open(h_dest
, 'w').write(h_text
)
571 open(cpp_dest
, 'w').write(cpp_text
)
575 #----------------------------------------------------------------------------
577 def processVals(values
):
579 for name
, value
, docs
in values
:
583 text
.append('// ' + x
)
584 text
.append('#define %s %s' % (name
, value
))
585 return string
.join(text
, '\n')
587 #----------------------------------------------------------------------------
589 def processMethods(methods
):
593 for retType
, name
, number
, param1
, param2
, docs
in methods
:
594 retType
= retTypeMap
.get(retType
, retType
)
595 params
= makeParamString(param1
, param2
)
597 name
, theDef
, theImp
, docs
= checkMethodOverride(name
, number
, docs
)
602 # Build the method definition for the .h file
606 defs
.append(' // ' + x
)
608 theDef
= ' %s %s(%s);' % (retType
, name
, params
)
611 # Build the method implementation string
615 imps
.append('// ' + x
)
617 theImp
= '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType
, name
, params
)
619 if retType
== 'wxColour':
620 theImp
= theImp
+ 'long c = '
621 elif retType
!= 'void':
622 theImp
= theImp
+ 'return '
623 theImp
= theImp
+ 'SendMsg(%s, %s, %s)' % (number
,
624 makeArgString(param1
),
625 makeArgString(param2
))
626 if retType
== 'bool':
627 theImp
= theImp
+ ' != 0'
628 if retType
== 'wxColour':
629 theImp
= theImp
+ ';\n return wxColourFromLong(c)'
631 theImp
= theImp
+ ';\n}'
635 return string
.join(defs
, '\n'), string
.join(imps
, '\n')
638 #----------------------------------------------------------------------------
640 def checkMethodOverride(name
, number
, docs
):
641 theDef
= theImp
= None
642 if methodOverrideMap
.has_key(name
):
643 item
= methodOverrideMap
[name
]
648 theDef
= ' ' + (item
[1] % name
)
650 theImp
= item
[2] % ('wxStyledTextCtrl::'+name
, number
) + '\n}'
654 return name
, theDef
, theImp
, docs
656 #----------------------------------------------------------------------------
658 def makeArgString(param
):
665 return '(long)(const char*)%s.mb_str(wxConvUTF8)' % name
667 return 'wxColourAsLong(%s)' % name
671 #----------------------------------------------------------------------------
673 def makeParamString(param1
, param2
):
676 aType
= paramTypeMap
.get(param
[0], param
[0])
677 return aType
+ ' ' + param
[1]
684 st
= st
+ doOne(param2
)
688 #----------------------------------------------------------------------------
690 def parseVal(line
, values
, docs
):
691 name
, val
= string
.split(line
, '=')
693 # remove prefixes such as SCI, etc.
694 for old
, new
in valPrefixes
:
699 name
= new
+ name
[lo
:]
702 values
.append( ('wxSTC_' + name
, val
, docs
) )
704 #----------------------------------------------------------------------------
706 funregex
= re
.compile(r
'\s*([a-zA-Z0-9_]+)' # <ws>return type
707 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
709 '\(([ a-zA-Z0-9_]*),' # (param,
710 '([ a-zA-Z0-9_]*)\)') # param)
712 def parseFun(line
, methods
, docs
, values
):
713 def parseParam(param
):
714 param
= string
.strip(param
)
718 param
= tuple(string
.split(param
))
721 mo
= funregex
.match(line
)
723 print "***** Line doesn't match! : " + line
725 retType
, name
, number
, param1
, param2
= mo
.groups()
727 param1
= parseParam(param1
)
728 param2
= parseParam(param2
)
730 # Special case. For the key command functionss we want a value defined too
731 num
= string
.atoi(number
)
733 if (type(v
) == type(()) and v
[0] <= num
< v
[1]) or v
== num
:
734 parseVal('CMD_%s=%s' % (string
.upper(name
), number
), values
, docs
)
736 #if retType == 'void' and not param1 and not param2:
738 methods
.append( (retType
, name
, number
, param1
, param2
, tuple(docs
)) )
741 #----------------------------------------------------------------------------
745 # TODO: parse command line args to replace default input/output files???
748 processIface(IFACE
, H_TEMPLATE
, CPP_TEMPLATE
, H_DEST
, CPP_DEST
)
752 if __name__
== '__main__':
755 #----------------------------------------------------------------------------