]>
git.saurik.com Git - wxWidgets.git/blob - contrib/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, 2349),
48 # Map some generic typenames to wx types, using return value syntax
55 # Map some generic typenames to wx types, using parameter syntax
58 'string': 'const wxString&',
59 'colour': 'const wxColour&',
63 # Map of method info that needs tweaked. Either the name needs changed, or
64 # the method definition/implementation. Tuple items are:
66 # 1. New method name. None to skip the method, 0 to leave the
68 # 2. Method definition for the .h file, 0 to leave alone
69 # 3. Method implementation for the .cpp file, 0 to leave alone.
70 # 4. tuple of Doc string lines, or 0 to leave alone.
74 'void %s(const wxString& text);',
76 '''void %s(const wxString& text) {
77 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
78 SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
82 'void %s(const wxMemoryBuffer& data);',
84 '''void %s(const wxMemoryBuffer& data) {
85 SendMsg(%s, data.GetDataLen(), (long)data.GetData());''',
88 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
89 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
93 return (unsigned char)SendMsg(%s, pos, 0);''',
96 'GetStyleAt' : ( 0, 0,
98 return (unsigned char)SendMsg(%s, pos, 0);''',
101 'GetStyledText' : (0,
102 'wxMemoryBuffer %s(int startPos, int endPos);',
104 '''wxMemoryBuffer %s(int startPos, int endPos) {
106 if (endPos < startPos) {
111 int len = endPos - startPos;
112 if (!len) return buf;
114 tr.lpstrText = (char*)buf.GetWriteBuf(len*2+1);
115 tr.chrg.cpMin = startPos;
116 tr.chrg.cpMax = endPos;
117 len = SendMsg(%s, 0, (long)&tr);
118 buf.UngetWriteBuf(len);
121 ('Retrieve a buffer of cells.',)),
124 'PositionFromPoint' : (0,
125 'int %s(wxPoint pt);',
127 '''int %s(wxPoint pt) {
128 return SendMsg(%s, pt.x, pt.y);''',
133 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
135 '''wxString %s(int* linePos) {
136 int len = LineLength(GetCurrentLine());
138 if (linePos) *linePos = 0;
139 return wxEmptyString;
142 wxMemoryBuffer mbuf(len+1);
143 char* buf = (char*)mbuf.GetWriteBuf(len+1);
145 int pos = SendMsg(%s, len+1, (long)buf);
146 mbuf.UngetWriteBuf(len);
148 if (linePos) *linePos = pos;
149 return stc2wx(buf);''',
153 'SetUsePalette' : (None, 0,0,0),
155 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
156 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
159 '''void %s(int markerNumber, int markerSymbol,
160 const wxColour& foreground = wxNullColour,
161 const wxColour& background = wxNullColour);''',
163 '''void %s(int markerNumber, int markerSymbol,
164 const wxColour& foreground,
165 const wxColour& background) {
167 SendMsg(%s, markerNumber, markerSymbol);
169 MarkerSetForeground(markerNumber, foreground);
171 MarkerSetBackground(markerNumber, background);''',
173 ('Set the symbol used for a particular marker number,',
174 'and optionally the fore and background colours.')),
176 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
177 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
178 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
179 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
180 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
181 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
182 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
183 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
185 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
186 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
187 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
188 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
189 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
190 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
192 'AssignCmdKey' : ('CmdKeyAssign',
193 'void %s(int key, int modifiers, int cmd);',
195 '''void %s(int key, int modifiers, int cmd) {
196 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
200 'ClearCmdKey' : ('CmdKeyClear',
201 'void %s(int key, int modifiers);',
203 '''void %s(int key, int modifiers) {
204 SendMsg(%s, MAKELONG(key, modifiers));''',
208 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
211 'SetStylingEx' : ('SetStyleBytes',
212 'void %s(int length, char* styleBytes);',
214 '''void %s(int length, char* styleBytes) {
215 SendMsg(%s, length, (long)styleBytes);''',
220 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
221 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
222 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
223 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
225 'SetWhitespaceFore' : ('SetWhitespaceForeground', 0, 0, 0),
226 'SetWhitespaceBack' : ('SetWhitespaceBackground', 0, 0, 0),
228 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
229 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
230 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
231 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
232 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
233 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
234 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
235 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
236 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
237 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
238 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
239 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
240 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
241 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
242 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
243 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
244 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
245 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
246 'AutoCSetDropRestOfWord' : ('AutoCompSetDropRestOfWord', 0,0,0),
247 'AutoCGetDropRestOfWord' : ('AutoCompGetDropRestOfWord', 0,0,0),
250 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
251 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
253 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
255 'GetUsePalette' : (None, 0, 0, 0),
258 '''int %s(int minPos, int maxPos, const wxString& text, int flags=0);''',
260 '''int %s(int minPos, int maxPos,
261 const wxString& text,
264 ft.chrg.cpMin = minPos;
265 ft.chrg.cpMax = maxPos;
266 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
267 ft.lpstrText = (char*)(const char*)buf;
269 return SendMsg(%s, flags, (long)&ft);''',
273 '''int %s(bool doDraw,
277 wxDC* target, // Why does it use two? Can they be the same?
279 wxRect pageRect);''',
280 ''' int %s(bool doDraw,
284 wxDC* target, // Why does it use two? Can they be the same?
289 if (endPos < startPos) {
295 fr.hdcTarget = target;
296 fr.rc.top = renderRect.GetTop();
297 fr.rc.left = renderRect.GetLeft();
298 fr.rc.right = renderRect.GetRight();
299 fr.rc.bottom = renderRect.GetBottom();
300 fr.rcPage.top = pageRect.GetTop();
301 fr.rcPage.left = pageRect.GetLeft();
302 fr.rcPage.right = pageRect.GetRight();
303 fr.rcPage.bottom = pageRect.GetBottom();
304 fr.chrg.cpMin = startPos;
305 fr.chrg.cpMax = endPos;
307 return SendMsg(%s, doDraw, (long)&fr);''',
312 'wxString %s(int line);',
314 '''wxString %s(int line) {
315 int len = LineLength(line);
316 if (!len) return wxEmptyString;
318 wxMemoryBuffer mbuf(len+1);
319 char* buf = (char*)mbuf.GetWriteBuf(len+1);
320 SendMsg(%s, line, (long)buf);
321 mbuf.UngetWriteBuf(len);
323 return stc2wx(buf);''',
325 ('Retrieve the contents of a line.',)),
327 'SetSel' : ('SetSelection', 0, 0, 0),
328 'GetSelText' : ('GetSelectedText',
335 GetSelection(&start, &end);
336 int len = end - start;
337 if (!len) return wxEmptyString;
339 wxMemoryBuffer mbuf(len+1);
340 char* buf = (char*)mbuf.GetWriteBuf(len+1);
341 SendMsg(%s, 0, (long)buf);
342 mbuf.UngetWriteBuf(len);
344 return stc2wx(buf);''',
346 ('Retrieve the selected text.',)),
349 'wxString %s(int startPos, int endPos);',
351 '''wxString %s(int startPos, int endPos) {
352 if (endPos < startPos) {
357 int len = endPos - startPos;
358 if (!len) return wxEmptyString;
359 wxMemoryBuffer mbuf(len+1);
360 char* buf = (char*)mbuf.GetWriteBuf(len);
363 tr.chrg.cpMin = startPos;
364 tr.chrg.cpMax = endPos;
365 SendMsg(%s, 0, (long)&tr);
366 mbuf.UngetWriteBuf(len);
368 return stc2wx(buf);''',
370 ('Retrieve a range of text.',)),
372 'PointXFromPosition' : (None, 0, 0, 0),
373 'PointYFromPosition' : (None, 0, 0, 0),
375 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
376 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
377 'Null' : (None, 0, 0, 0),
383 int len = GetTextLength();
384 wxMemoryBuffer mbuf(len+1); // leave room for the null...
385 char* buf = (char*)mbuf.GetWriteBuf(len+1);
386 SendMsg(%s, len+1, (long)buf);
387 mbuf.UngetWriteBuf(len);
389 return stc2wx(buf);''',
391 ('Retrieve all the text in the document.', )),
393 'GetDirectFunction' : (None, 0, 0, 0),
394 'GetDirectPointer' : (None, 0, 0, 0),
396 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
397 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
398 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
401 'ReplaceTarget' : (0,
402 'int %s(const wxString& text);',
405 int %s(const wxString& text) {
406 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
407 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
410 'ReplaceTargetRE' : (0,
411 'int %s(const wxString& text);',
414 int %s(const wxString& text) {
415 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
416 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
419 'SearchInTarget' : (0,
420 'int %s(const wxString& text);',
423 int %s(const wxString& text) {
424 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
425 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
429 'GetDocPointer' : (0,
432 return (void*)SendMsg(%s);''',
435 'SetDocPointer' : (0,
436 'void %s(void* docPointer);',
437 '''void %s(void* docPointer) {
438 SendMsg(%s, 0, (long)docPointer);''',
441 'CreateDocument' : (0,
444 return (void*)SendMsg(%s);''',
447 'AddRefDocument' : (0,
448 'void %s(void* docPointer);',
449 '''void %s(void* docPointer) {
450 SendMsg(%s, 0, (long)docPointer);''',
453 'ReleaseDocument' : (0,
454 'void %s(void* docPointer);',
455 '''void %s(void* docPointer) {
456 SendMsg(%s, 0, (long)docPointer);''',
460 '''void %s(int codePage) {
462 wxASSERT_MSG(codePage == wxSTC_CP_UTF8,
463 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
465 wxASSERT_MSG(codePage != wxSTC_CP_UTF8,
466 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
468 SendMsg(%s, codePage);''',
469 ("Set the code page used to interpret the bytes of the document as characters.",) ),
472 'GrabFocus' : (None, 0, 0, 0),
473 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
474 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
478 # Remove all methods that are key commands since they can be
479 # executed with CmdKeyExecute
480 'LineDown' : (None, 0, 0, 0),
481 'LineDownExtend' : (None, 0, 0, 0),
482 'LineUp' : (None, 0, 0, 0),
483 'LineUpExtend' : (None, 0, 0, 0),
484 'CharLeft' : (None, 0, 0, 0),
485 'CharLeftExtend' : (None, 0, 0, 0),
486 'CharRight' : (None, 0, 0, 0),
487 'CharRightExtend' : (None, 0, 0, 0),
488 'WordLeft' : (None, 0, 0, 0),
489 'WordLeftExtend' : (None, 0, 0, 0),
490 'WordRight' : (None, 0, 0, 0),
491 'WordRightExtend' : (None, 0, 0, 0),
492 'Home' : (None, 0, 0, 0),
493 'HomeExtend' : (None, 0, 0, 0),
494 'LineEnd' : (None, 0, 0, 0),
495 'LineEndExtend' : (None, 0, 0, 0),
496 'DocumentStart' : (None, 0, 0, 0),
497 'DocumentStartExtend' : (None, 0, 0, 0),
498 'DocumentEnd' : (None, 0, 0, 0),
499 'DocumentEndExtend' : (None, 0, 0, 0),
500 'PageUp' : (None, 0, 0, 0),
501 'PageUpExtend' : (None, 0, 0, 0),
502 'PageDown' : (None, 0, 0, 0),
503 'PageDownExtend' : (None, 0, 0, 0),
504 'EditToggleOvertype' : (None, 0, 0, 0),
505 'Cancel' : (None, 0, 0, 0),
506 'DeleteBack' : (None, 0, 0, 0),
507 'Tab' : (None, 0, 0, 0),
508 'BackTab' : (None, 0, 0, 0),
509 'NewLine' : (None, 0, 0, 0),
510 'FormFeed' : (None, 0, 0, 0),
511 'VCHome' : (None, 0, 0, 0),
512 'VCHomeExtend' : (None, 0, 0, 0),
513 'ZoomIn' : (None, 0, 0, 0),
514 'ZoomOut' : (None, 0, 0, 0),
515 'DelWordLeft' : (None, 0, 0, 0),
516 'DelWordRight' : (None, 0, 0, 0),
517 'LineCut' : (None, 0, 0, 0),
518 'LineDelete' : (None, 0, 0, 0),
519 'LineTranspose' : (None, 0, 0, 0),
520 'LowerCase' : (None, 0, 0, 0),
521 'UpperCase' : (None, 0, 0, 0),
522 'LineScrollDown' : (None, 0, 0, 0),
523 'LineScrollUp' : (None, 0, 0, 0),
524 'DeleteBackNotLine' : (None, 0, 0, 0),
533 #----------------------------------------------------------------------------
535 def processIface(iface
, h_tmplt
, cpp_tmplt
, h_dest
, cpp_dest
):
542 fi
= FileInput(iface
)
545 if line
[:2] == '##' or line
== '':
550 if line
[:2] == '# ': # a doc string
551 curDocStrings
.append(line
[2:])
554 parseVal(line
[4:], values
, curDocStrings
)
557 elif op
== 'fun ' or op
== 'set ' or op
== 'get ':
558 parseFun(line
[4:], methods
, curDocStrings
, cmds
)
562 if string
.strip(line
[4:]) == 'Deprecated':
563 break # skip the rest of the file
575 print '***** Unknown line type: ', line
580 data
['VALUES'] = processVals(values
)
581 data
['CMDS'] = processVals(cmds
)
582 defs
, imps
= processMethods(methods
)
583 data
['METHOD_DEFS'] = defs
584 data
['METHOD_IMPS'] = imps
587 h_text
= open(h_tmplt
).read()
588 cpp_text
= open(cpp_tmplt
).read()
590 # do the substitutions
591 h_text
= h_text
% data
592 cpp_text
= cpp_text
% data
594 # write out destination files
595 open(h_dest
, 'w').write(h_text
)
596 open(cpp_dest
, 'w').write(cpp_text
)
600 #----------------------------------------------------------------------------
602 def processVals(values
):
604 for name
, value
, docs
in values
:
608 text
.append('// ' + x
)
609 text
.append('#define %s %s' % (name
, value
))
610 return string
.join(text
, '\n')
612 #----------------------------------------------------------------------------
614 def processMethods(methods
):
618 for retType
, name
, number
, param1
, param2
, docs
in methods
:
619 retType
= retTypeMap
.get(retType
, retType
)
620 params
= makeParamString(param1
, param2
)
622 name
, theDef
, theImp
, docs
= checkMethodOverride(name
, number
, docs
)
627 # Build the method definition for the .h file
631 defs
.append(' // ' + x
)
633 theDef
= ' %s %s(%s);' % (retType
, name
, params
)
636 # Build the method implementation string
640 imps
.append('// ' + x
)
642 theImp
= '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType
, name
, params
)
644 if retType
== 'wxColour':
645 theImp
= theImp
+ 'long c = '
646 elif retType
!= 'void':
647 theImp
= theImp
+ 'return '
648 theImp
= theImp
+ 'SendMsg(%s, %s, %s)' % (number
,
649 makeArgString(param1
),
650 makeArgString(param2
))
651 if retType
== 'bool':
652 theImp
= theImp
+ ' != 0'
653 if retType
== 'wxColour':
654 theImp
= theImp
+ ';\n return wxColourFromLong(c)'
656 theImp
= theImp
+ ';\n}'
660 return string
.join(defs
, '\n'), string
.join(imps
, '\n')
663 #----------------------------------------------------------------------------
665 def checkMethodOverride(name
, number
, docs
):
666 theDef
= theImp
= None
667 if methodOverrideMap
.has_key(name
):
668 item
= methodOverrideMap
[name
]
674 theDef
= ' ' + (item
[1] % name
)
676 theImp
= item
[2] % ('wxStyledTextCtrl::'+name
, number
) + '\n}'
680 print "*************", name
683 return name
, theDef
, theImp
, docs
685 #----------------------------------------------------------------------------
687 def makeArgString(param
):
694 return '(long)(const char*)wx2stc(%s)' % name
696 return 'wxColourAsLong(%s)' % name
700 #----------------------------------------------------------------------------
702 def makeParamString(param1
, param2
):
705 aType
= paramTypeMap
.get(param
[0], param
[0])
706 return aType
+ ' ' + param
[1]
713 st
= st
+ doOne(param2
)
717 #----------------------------------------------------------------------------
719 def parseVal(line
, values
, docs
):
720 name
, val
= string
.split(line
, '=')
722 # remove prefixes such as SCI, etc.
723 for old
, new
in valPrefixes
:
728 name
= new
+ name
[lo
:]
731 values
.append( ('wxSTC_' + name
, val
, docs
) )
733 #----------------------------------------------------------------------------
735 funregex
= re
.compile(r
'\s*([a-zA-Z0-9_]+)' # <ws>return type
736 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
738 '\(([ a-zA-Z0-9_]*),' # (param,
739 '([ a-zA-Z0-9_]*)\)') # param)
741 def parseFun(line
, methods
, docs
, values
):
742 def parseParam(param
):
743 param
= string
.strip(param
)
747 param
= tuple(string
.split(param
))
750 mo
= funregex
.match(line
)
752 print "***** Line doesn't match! : " + line
754 retType
, name
, number
, param1
, param2
= mo
.groups()
756 param1
= parseParam(param1
)
757 param2
= parseParam(param2
)
759 # Special case. For the key command functions we want a value defined too
760 num
= string
.atoi(number
)
762 if (type(v
) == type(()) and v
[0] <= num
<= v
[1]) or v
== num
:
763 parseVal('CMD_%s=%s' % (string
.upper(name
), number
), values
, docs
)
765 #if retType == 'void' and not param1 and not param2:
767 methods
.append( (retType
, name
, number
, param1
, param2
, tuple(docs
)) )
770 #----------------------------------------------------------------------------
774 # TODO: parse command line args to replace default input/output files???
777 processIface(IFACE
, H_TEMPLATE
, CPP_TEMPLATE
, H_DEST
, CPP_DEST
)
781 if __name__
== '__main__':
784 #----------------------------------------------------------------------------