]>
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 licence
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 IH_TEMPLATE
= os
.path
.abspath('./stc.interface.h.in')
22 CPP_TEMPLATE
= os
.path
.abspath('./stc.cpp.in')
23 H_DEST
= os
.path
.abspath('../../include/wx/stc/stc.h')
24 IH_DEST
= os
.path
.abspath('../../interface/wx/stc/stc.h')
25 CPP_DEST
= os
.path
.abspath('./stc.cpp')
26 if len(sys
.argv
) > 1 and sys
.argv
[1] == '--wxpython':
27 DOCSTR_DEST
= os
.path
.abspath('../../../wxPython/src/_stc_gendocs.i')
29 DOCSTR_DEST
= '/dev/null'
32 # Value prefixes to convert
33 valPrefixes
= [('SCI_', ''),
35 ('SCN_', None), # just toss these out...
45 # Message function values that should have a CMD_ constant generated
62 # Should a funciton be also generated for the CMDs?
66 # Map some generic typenames to wx types, using return value syntax
73 # Map some generic typenames to wx types, using parameter syntax
76 'string': 'const wxString&',
77 'colour': 'const wxColour&',
81 # Map of method info that needs tweaked. Either the name needs changed, or
82 # the method definition/implementation. Tuple items are:
84 # 1. New method name. None to skip the method, 0 to leave the
86 # 2. Method definition for the .h file, 0 to leave alone
87 # 3. Method implementation for the .cpp file, 0 to leave alone.
88 # 4. tuple of Doc string lines, or 0 to leave alone.
92 'void %s(const wxString& text);',
94 '''void %s(const wxString& text) {
95 const wxWX2MBbuf buf = wx2stc(text);
96 SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
100 'void %s(const wxMemoryBuffer& data);',
102 '''void %s(const wxMemoryBuffer& data) {
103 SendMsg(%s, data.GetDataLen(), (sptr_t)data.GetData());''',
107 'void %s(const wxString& text);',
109 '''void %s(const wxString& text) {
110 const wxWX2MBbuf buf = wx2stc(text);
111 SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
114 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
115 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
119 '''int %s(int pos) const {
120 return (unsigned char)SendMsg(%s, pos, 0);''',
125 '''int %s(int pos) const {
126 return (unsigned char)SendMsg(%s, pos, 0);''',
131 'wxMemoryBuffer %s(int startPos, int endPos);',
133 '''wxMemoryBuffer %s(int startPos, int endPos) {
135 if (endPos < startPos) {
140 int len = endPos - startPos;
141 if (!len) return buf;
143 tr.lpstrText = (char*)buf.GetWriteBuf(len*2+1);
144 tr.chrg.cpMin = startPos;
145 tr.chrg.cpMax = endPos;
146 len = SendMsg(%s, 0, (sptr_t)&tr);
147 buf.UngetWriteBuf(len);
150 ('Retrieve a buffer of cells.',)),
153 'PositionFromPoint' :
155 'int %s(wxPoint pt) const;',
157 '''int %s(wxPoint pt) const {
158 return SendMsg(%s, pt.x, pt.y);''',
163 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
165 '''wxString %s(int* linePos) {
166 int len = LineLength(GetCurrentLine());
168 if (linePos) *linePos = 0;
169 return wxEmptyString;
172 wxMemoryBuffer mbuf(len+1);
173 char* buf = (char*)mbuf.GetWriteBuf(len+1);
175 int pos = SendMsg(%s, len+1, (sptr_t)buf);
176 mbuf.UngetWriteBuf(len);
178 if (linePos) *linePos = pos;
179 return stc2wx(buf);''',
183 'SetUsePalette' : (None, 0,0,0),
185 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
186 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
187 'MarkerSetBackSelected' : ('MarkerSetBackgroundSelected', 0,0,0),
189 'MarkerSymbolDefined' : ('GetMarkerSymbolDefined', 0, 0, 0),
193 '''void %s(int markerNumber, int markerSymbol,
194 const wxColour& foreground = wxNullColour,
195 const wxColour& background = wxNullColour);''',
197 '''void %s(int markerNumber, int markerSymbol,
198 const wxColour& foreground,
199 const wxColour& background) {
201 SendMsg(%s, markerNumber, markerSymbol);
202 if (foreground.IsOk())
203 MarkerSetForeground(markerNumber, foreground);
204 if (background.IsOk())
205 MarkerSetBackground(markerNumber, background);''',
207 ('Set the symbol used for a particular marker number,',
208 'and optionally the fore and background colours.')),
211 'MarkerDefinePixmap' :
212 ('MarkerDefineBitmap',
213 '''void %s(int markerNumber, const wxBitmap& bmp);''',
214 '''void %s(int markerNumber, const wxBitmap& bmp) {
215 // convert bmp to a xpm in a string
216 wxMemoryOutputStream strm;
217 wxImage img = bmp.ConvertToImage();
219 img.ConvertAlphaToMask();
220 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
221 size_t len = strm.GetSize();
222 char* buff = new char[len+1];
223 strm.CopyTo(buff, len);
225 SendMsg(%s, markerNumber, (sptr_t)buff);
228 ('Define a marker from a bitmap',)),
231 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
232 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
233 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
234 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
235 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
236 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
237 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
238 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
239 'SetMarginCursorN' : ('SetMarginCursor', 0, 0, 0),
240 'GetMarginCursorN' : ('GetMarginCursor', 0, 0, 0),
244 'wxString %s(int line) const;',
246 '''wxString %s(int line) const {
248 long len = SendMsg(msg, line, 0);
250 wxMemoryBuffer mbuf(len+1);
251 char* buf = (char*)mbuf.GetWriteBuf(len+1);
252 SendMsg(msg, line, (sptr_t)buf);
253 mbuf.UngetWriteBuf(len);
255 return stc2wx(buf);''',
260 'wxString %s(int line) const;',
262 '''wxString %s(int line) const {
264 long len = SendMsg(msg, line, 0);
266 wxMemoryBuffer mbuf(len+1);
267 char* buf = (char*)mbuf.GetWriteBuf(len+1);
268 SendMsg(msg, line, (sptr_t)buf);
269 mbuf.UngetWriteBuf(len);
271 return stc2wx(buf);''',
274 'SetAdditionalSelFore' : ('SetAdditionalSelForeground', 0, 0, 0),
275 'SetAdditionalSelBack' : ('SetAdditionalSelBackground', 0, 0, 0),
276 'SetAdditionalCaretFore' : ('SetAdditionalCaretForeground', 0, 0, 0),
277 'GetAdditionalCaretFore' : ('GetAdditionalCaretForeground', 0, 0, 0),
279 'AnnotationGetText' :
281 'wxString %s(int line) const;',
283 '''wxString %s(int line) const {
285 long len = SendMsg(msg, line, 0);
287 wxMemoryBuffer mbuf(len+1);
288 char* buf = (char*)mbuf.GetWriteBuf(len+1);
289 SendMsg(msg, line, (sptr_t)buf);
290 mbuf.UngetWriteBuf(len);
292 return stc2wx(buf);''',
295 'AnnotationGetStyles' :
297 'wxString %s(int line) const;',
299 '''wxString %s(int line) const {
301 long len = SendMsg(msg, line, 0);
303 wxMemoryBuffer mbuf(len+1);
304 char* buf = (char*)mbuf.GetWriteBuf(len+1);
305 SendMsg(msg, line, (sptr_t)buf);
306 mbuf.UngetWriteBuf(len);
308 return stc2wx(buf);''',
311 'StyleGetFore' : ('StyleGetForeground', 0, 0, 0),
312 'StyleGetBack' : ('StyleGetBackground', 0, 0, 0),
313 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
314 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
315 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
316 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
317 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
320 'wxString %s(int style);',
321 '''wxString %s(int style) {
323 long len = SendMsg(msg, style, 0);
324 wxMemoryBuffer mbuf(len+1);
325 char* buf = (char*)mbuf.GetWriteBuf(len+1);
326 SendMsg(msg, style, (sptr_t)buf);
327 mbuf.UngetWriteBuf(len);
329 return stc2wx(buf);''',
330 ('Get the font facename of a style',)),
331 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
332 'StyleSetCharacterSet' : (None, 0, 0, 0),
336 'void %s(int key, int modifiers, int cmd);',
338 '''void %s(int key, int modifiers, int cmd) {
339 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
345 'void %s(int key, int modifiers);',
347 '''void %s(int key, int modifiers) {
348 SendMsg(%s, MAKELONG(key, modifiers));''',
351 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
356 'void %s(int length, char* styleBytes);',
358 '''void %s(int length, char* styleBytes) {
359 SendMsg(%s, length, (sptr_t)styleBytes);''',
363 'IndicSetAlpha' : ('IndicatorSetAlpha', 0, 0, 0),
364 'IndicGetAlpha' : ('IndicatorGetAlpha', 0, 0, 0),
365 'IndicSetOutlineAlpha' : ('IndicatorSetOutlineAlpha', 0, 0, 0),
366 'IndicGetOutlineAlpha' : ('IndicatorGetOutlineAlpha', 0, 0, 0),
367 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
368 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
369 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
370 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
371 'IndicSetUnder': ('IndicatorSetUnder', 0, 0, 0),
372 'IndicGetUnder': ('IndicatorGetUnder', 0, 0, 0),
374 'SetWhitespaceFore' : ('SetWhitespaceForeground', 0, 0, 0),
375 'SetWhitespaceBack' : ('SetWhitespaceBackground', 0, 0, 0),
377 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
378 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
379 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
380 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
381 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
382 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
383 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
384 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
385 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
386 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
387 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
388 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
389 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
390 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
391 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
392 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
393 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
394 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
395 'AutoCSetDropRestOfWord' : ('AutoCompSetDropRestOfWord', 0,0,0),
396 'AutoCGetDropRestOfWord' : ('AutoCompGetDropRestOfWord', 0,0,0),
397 'AutoCGetTypeSeparator' : ('AutoCompGetTypeSeparator', 0, 0, 0),
398 'AutoCSetTypeSeparator' : ('AutoCompSetTypeSeparator', 0, 0, 0),
399 'AutoCGetCurrent' : ('AutoCompGetCurrent', 0, 0, 0),
400 'AutoCGetCurrentText' : (None, 0, 0, 0),
401 'AutoCSetMaxWidth' : ('AutoCompSetMaxWidth', 0, 0, 0),
402 'AutoCGetMaxWidth' : ('AutoCompGetMaxWidth', 0, 0, 0),
403 'AutoCSetMaxHeight' : ('AutoCompSetMaxHeight', 0, 0, 0),
404 'AutoCGetMaxHeight' : ('AutoCompGetMaxHeight', 0, 0, 0),
405 'AutoCGetMaxHeight' : ('AutoCompGetMaxHeight', 0, 0, 0),
406 'AutoCSetCaseInsensitiveBehaviour' : ('AutoCompSetCaseInsensitiveBehaviour', 0, 0, 0),
407 'AutoCGetCaseInsensitiveBehaviour' : ('AutoCompGetCaseInsensitiveBehaviour', 0, 0, 0),
411 '''void %s(int type, const wxBitmap& bmp);''',
412 '''void %s(int type, const wxBitmap& bmp) {
413 // convert bmp to a xpm in a string
414 wxMemoryOutputStream strm;
415 wxImage img = bmp.ConvertToImage();
417 img.ConvertAlphaToMask();
418 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
419 size_t len = strm.GetSize();
420 char* buff = new char[len+1];
421 strm.CopyTo(buff, len);
423 SendMsg(%s, type, (sptr_t)buff);
426 ('Register an image for use in autocompletion lists.',)),
429 'ClearRegisteredImages' : (0, 0, 0,
430 ('Clear all the registered images.',)),
433 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
434 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
436 'SetVScrollBar' : ('SetUseVerticalScrollBar', 0, 0, 0),
437 'GetVScrollBar' : ('GetUseVerticalScrollBar', 0, 0, 0),
439 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
441 'GetUsePalette' : (None, 0, 0, 0),
445 '''int %s(int minPos, int maxPos, const wxString& text, int flags=0);''',
447 '''int %s(int minPos, int maxPos,
448 const wxString& text,
451 ft.chrg.cpMin = minPos;
452 ft.chrg.cpMax = maxPos;
453 const wxWX2MBbuf buf = wx2stc(text);
454 ft.lpstrText = (char*)(const char*)buf;
456 return SendMsg(%s, flags, (sptr_t)&ft);''',
461 '''int %s(bool doDraw,
467 wxRect pageRect);''',
468 ''' int %s(bool doDraw,
477 if (endPos < startPos) {
483 fr.hdcTarget = target;
484 fr.rc.top = renderRect.GetTop();
485 fr.rc.left = renderRect.GetLeft();
486 fr.rc.right = renderRect.GetRight();
487 fr.rc.bottom = renderRect.GetBottom();
488 fr.rcPage.top = pageRect.GetTop();
489 fr.rcPage.left = pageRect.GetLeft();
490 fr.rcPage.right = pageRect.GetRight();
491 fr.rcPage.bottom = pageRect.GetBottom();
492 fr.chrg.cpMin = startPos;
493 fr.chrg.cpMax = endPos;
495 return SendMsg(%s, doDraw, (sptr_t)&fr);''',
501 'wxString %s(int line) const;',
503 '''wxString %s(int line) const {
504 int len = LineLength(line);
505 if (!len) return wxEmptyString;
507 wxMemoryBuffer mbuf(len+1);
508 char* buf = (char*)mbuf.GetWriteBuf(len+1);
509 SendMsg(%s, line, (sptr_t)buf);
510 mbuf.UngetWriteBuf(len);
512 return stc2wx(buf);''',
514 ('Retrieve the contents of a line.',)),
516 'SetSel' : (None, 0,0,0), #'SetSelection', 0, 0, 0),
523 const int len = SendMsg(SCI_GETSELTEXT, 0, (sptr_t)0);
524 if (!len) return wxEmptyString;
526 wxMemoryBuffer mbuf(len+2);
527 char* buf = (char*)mbuf.GetWriteBuf(len+1);
528 SendMsg(%s, 0, (sptr_t)buf);
529 mbuf.UngetWriteBuf(len);
531 return stc2wx(buf);''',
533 ('Retrieve the selected text.',)),
538 'wxString %s(int startPos, int endPos);',
540 '''wxString %s(int startPos, int endPos) {
541 if (endPos < startPos) {
546 int len = endPos - startPos;
547 if (!len) return wxEmptyString;
548 wxMemoryBuffer mbuf(len+1);
549 char* buf = (char*)mbuf.GetWriteBuf(len);
552 tr.chrg.cpMin = startPos;
553 tr.chrg.cpMax = endPos;
554 SendMsg(%s, 0, (sptr_t)&tr);
555 mbuf.UngetWriteBuf(len);
557 return stc2wx(buf);''',
559 ('Retrieve a range of text.',)),
561 'PointXFromPosition' : (None, 0, 0, 0),
562 'PointYFromPosition' : (None, 0, 0, 0),
564 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
565 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
566 'Null' : (None, 0, 0, 0),
570 'wxString %s() const;',
572 '''wxString %s() const {
573 int len = GetTextLength();
574 wxMemoryBuffer mbuf(len+1); // leave room for the null...
575 char* buf = (char*)mbuf.GetWriteBuf(len+1);
576 SendMsg(%s, len+1, (sptr_t)buf);
577 mbuf.UngetWriteBuf(len);
579 return stc2wx(buf);''',
581 ('Retrieve all the text in the document.', )),
583 'GetDirectFunction' : (None, 0, 0, 0),
584 'GetDirectPointer' : (None, 0, 0, 0),
586 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
587 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
588 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
589 'CallTipSetFore' : ('CallTipSetForeground', 0, 0, 0),
590 'CallTipSetForeHlt' : ('CallTipSetForegroundHighlight', 0, 0, 0),
592 'SetHotspotActiveFore' : ('SetHotspotActiveForeground', 0, 0, 0),
593 'SetHotspotActiveBack' : ('SetHotspotActiveBackground', 0, 0, 0),
594 'GetHotspotActiveFore' : ('GetHotspotActiveForeground', 0, 0, 0),
595 'GetHotspotActiveBack' : ('GetHotspotActiveBackground', 0, 0, 0),
597 'GetCaretLineBack' : ('GetCaretLineBackground', 0, 0, 0),
598 'SetCaretLineBack' : ('SetCaretLineBackground', 0, 0, 0),
602 'int %s(const wxString& text);',
605 int %s(const wxString& text) {
606 const wxWX2MBbuf buf = wx2stc(text);
607 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
612 'int %s(const wxString& text);',
615 int %s(const wxString& text) {
616 const wxWX2MBbuf buf = wx2stc(text);
617 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
622 'int %s(const wxString& text);',
625 int %s(const wxString& text) {
626 const wxWX2MBbuf buf = wx2stc(text);
627 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
630 # not sure what to do about these yet
631 'TargetAsUTF8' : ( None, 0, 0, 0),
632 'SetLengthForEncode' : ( None, 0, 0, 0),
633 'EncodedFromUTF8' : ( None, 0, 0, 0),
638 'wxString %s(const wxString& key);',
640 '''wxString %s(const wxString& key) {
641 int len = SendMsg(SCI_GETPROPERTY, (sptr_t)(const char*)wx2stc(key), 0);
642 if (!len) return wxEmptyString;
644 wxMemoryBuffer mbuf(len+1);
645 char* buf = (char*)mbuf.GetWriteBuf(len+1);
646 SendMsg(%s, (uptr_t)(const char*)wx2stc(key), (sptr_t)buf);
647 mbuf.UngetWriteBuf(len);
649 return stc2wx(buf);''',
650 ("Retrieve a 'property' value previously set with SetProperty.",)),
652 'GetPropertyExpanded' :
654 'wxString %s(const wxString& key);',
656 '''wxString %s(const wxString& key) {
657 int len = SendMsg(SCI_GETPROPERTYEXPANDED, (uptr_t)(const char*)wx2stc(key), 0);
658 if (!len) return wxEmptyString;
660 wxMemoryBuffer mbuf(len+1);
661 char* buf = (char*)mbuf.GetWriteBuf(len+1);
662 SendMsg(%s, (uptr_t)(const char*)wx2stc(key), (sptr_t)buf);
663 mbuf.UngetWriteBuf(len);
665 return stc2wx(buf);''',
666 ("Retrieve a 'property' value previously set with SetProperty,",
667 "with '$()' variable replacement on returned buffer.")),
669 'GetPropertyInt' : (0, 0, 0,
670 ("Retrieve a 'property' value previously set with SetProperty,",
671 "interpreted as an int AFTER any '$()' variable replacement.")),
678 return (void*)SendMsg(%s);''',
683 'void %s(void* docPointer);',
684 '''void %s(void* docPointer) {
685 SendMsg(%s, 0, (sptr_t)docPointer);''',
692 return (void*)SendMsg(%s);''',
697 'void %s(void* docPointer);',
698 '''void %s(void* docPointer) {
699 SendMsg(%s, 0, (sptr_t)docPointer);''',
704 'void %s(void* docPointer);',
705 '''void %s(void* docPointer) {
706 SendMsg(%s, 0, (sptr_t)docPointer);''',
712 '''void %s(int codePage) {
714 wxASSERT_MSG(codePage == wxSTC_CP_UTF8,
715 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
717 wxASSERT_MSG(codePage != wxSTC_CP_UTF8,
718 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
720 SendMsg(%s, codePage);''',
721 ("Set the code page used to interpret the bytes of the document as characters.",) ),
724 'GrabFocus' : (None, 0, 0, 0),
726 # Rename some that would otherwise hide the wxWindow methods
727 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
728 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
729 'SetCursor' : ('SetSTCCursor', 0, 0, 0),
730 'GetCursor' : ('GetSTCCursor', 0, 0, 0),
732 'LoadLexerLibrary' : (None, 0,0,0),
734 'SetPositionCache' : ('SetPositionCacheSize', 0, 0, 0),
735 'GetPositionCache' : ('GetPositionCacheSize', 0, 0, 0),
737 'GetLexerLanguage' : (None, 0, 0, 0),
738 'SetFontQuality' : (None, 0, 0, 0),
739 'GetFontQuality' : (None, 0, 0, 0),
740 'SetSelection' : (None, 0, 0, 0),
742 'GetCharacterPointer' : (0,
743 'const char* %s() const;',
744 'const char* %s() const {\n'
745 ' return (const char*)SendMsg(%s, 0, 0);',
748 'GetRangePointer' : (0,
749 'const char* %s(int position, int rangeLength) const;',
750 'const char* %s(int position, int rangeLength) const {\n'
751 ' return (const char*)SendMsg(%s, position, rangeLength);',
757 'wxString %s() const;',
759 '''wxString %s() const {
761 int len = SendMsg(msg, 0, (sptr_t)NULL);
762 if (!len) return wxEmptyString;
764 wxMemoryBuffer mbuf(len+1);
765 char* buf = (char*)mbuf.GetWriteBuf(len+1);
766 SendMsg(msg, 0, (sptr_t)buf);
767 mbuf.UngetWriteBuf(len);
769 return stc2wx(buf);''',
771 ('Get the set of characters making up words for when moving or selecting by word.',)),
775 'wxString %s(int tagNumber) const;',
777 '''wxString %s(int tagNumber) const {
779 int len = SendMsg(msg, tagNumber, (sptr_t)NULL);
780 if (!len) return wxEmptyString;
782 wxMemoryBuffer mbuf(len+1);
783 char* buf = (char*)mbuf.GetWriteBuf(len+1);
784 SendMsg(msg, tagNumber, (sptr_t)buf);
785 mbuf.UngetWriteBuf(len);
787 return stc2wx(buf);''',
790 'GetWhitespaceChars' :
792 'wxString %s() const;',
794 '''wxString %s() const {
796 int len = SendMsg(msg, 0, (sptr_t)NULL);
797 if (!len) return wxEmptyString;
799 wxMemoryBuffer mbuf(len+1);
800 char* buf = (char*)mbuf.GetWriteBuf(len+1);
801 SendMsg(msg, 0, (sptr_t)buf);
802 mbuf.UngetWriteBuf(len);
804 return stc2wx(buf);''',
808 'GetPunctuationChars' :
810 'wxString %s() const;',
812 '''wxString %s() const {
814 int len = SendMsg(msg, 0, (sptr_t)NULL);
815 if (!len) return wxEmptyString;
817 wxMemoryBuffer mbuf(len+1);
818 char* buf = (char*)mbuf.GetWriteBuf(len+1);
819 SendMsg(msg, 0, (sptr_t)buf);
820 mbuf.UngetWriteBuf(len);
822 return stc2wx(buf);''',
828 'wxString %s() const;',
830 '''wxString %s() const {
832 int len = SendMsg(msg, 0, (sptr_t)NULL);
833 if (!len) return wxEmptyString;
835 wxMemoryBuffer mbuf(len+1);
836 char* buf = (char*)mbuf.GetWriteBuf(len+1);
837 SendMsg(msg, 0, (sptr_t)buf);
838 mbuf.UngetWriteBuf(len);
840 return stc2wx(buf);''',
847 'wxString %s(const wxString& name) const;',
849 '''wxString %s(const wxString& name) const {
851 int len = SendMsg(msg, (sptr_t)(const char*)wx2stc(name), (sptr_t)NULL);
852 if (!len) return wxEmptyString;
854 wxMemoryBuffer mbuf(len+1);
855 char* buf = (char*)mbuf.GetWriteBuf(len+1);
856 SendMsg(msg, (sptr_t)(const char*)wx2stc(name), (sptr_t)buf);
857 mbuf.UngetWriteBuf(len);
859 return stc2wx(buf);''',
864 'DescribeKeyWordSets' :
866 'wxString %s() const;',
868 '''wxString %s() const {
870 int len = SendMsg(msg, 0, (sptr_t)NULL);
871 if (!len) return wxEmptyString;
873 wxMemoryBuffer mbuf(len+1);
874 char* buf = (char*)mbuf.GetWriteBuf(len+1);
875 SendMsg(msg, 0, (sptr_t)buf);
876 mbuf.UngetWriteBuf(len);
878 return stc2wx(buf);''',
882 'MarkerDefineRGBAImage' :
884 'void %s(int markerNumber, const unsigned char* pixels);',
885 '''void %s(int markerNumber, const unsigned char* pixels) {
886 SendMsg(%s, markerNumber, (sptr_t)pixels);''',
890 'RegisterRGBAImage' :
892 'void %s(int type, const unsigned char* pixels);',
893 '''void %s(int type, const unsigned char* pixels) {
894 SendMsg(%s, type, (sptr_t)pixels);''',
898 # I think these are only available on the native OSX backend, so
899 # don't add them to the wx API...
900 'FindIndicatorShow' : (None, 0,0,0),
901 'FindIndicatorFlash' : (None, 0,0,0),
902 'FindIndicatorHide' : (None, 0,0,0),
906 'void* %s(int bytes) const;',
907 """void* %s(int bytes) const {
908 return (void*)(sptr_t)SendMsg(%s, bytes); """,
913 'void* %s(int operation, void* pointer);',
914 """void* %s(int operation, void* pointer) {
915 return (void*)(sptr_t)SendMsg(%s, operation, (sptr_t)pointer); """,
922 # all Scintilla getters are transformed into const member of wxSTC class but
923 # some non-getter methods are also logically const and this set contains their
924 # names (notice that it's useless to include here methods manually overridden
926 constNonGetterMethods
= (
935 #----------------------------------------------------------------------------
937 def processIface(iface
, h_tmplt
, cpp_tmplt
, ih_tmplt
, h_dest
, cpp_dest
, docstr_dest
, ih_dest
):
944 fi
= FileInput(iface
)
947 if line
[:2] == '##' or line
== '':
952 if line
[:2] == '# ': # a doc string
953 curDocStrings
.append(line
[2:])
956 parseVal(line
[4:], values
, curDocStrings
)
959 elif op
== 'fun ' or op
== 'set ' or op
== 'get ':
960 parseFun(line
[4:], methods
, curDocStrings
, cmds
, op
== 'get ')
964 if line
[4:].strip() == 'Deprecated':
965 break # skip the rest of the file
977 print('***** Unknown line type: %s' % line
)
982 data
['VALUES'] = processVals(values
)
983 data
['CMDS'] = processVals(cmds
)
984 defs
, imps
, docstrings
, idefs
= processMethods(methods
)
985 data
['METHOD_DEFS'] = defs
986 data
['METHOD_IDEFS'] = idefs
987 data
['METHOD_IMPS'] = imps
990 h_text
= open(h_tmplt
).read()
991 ih_text
= open(ih_tmplt
).read()
992 cpp_text
= open(cpp_tmplt
).read()
994 # do the substitutions
995 h_text
= h_text
% data
996 cpp_text
= cpp_text
% data
997 ih_text
= ih_text
% data
999 # write out destination files
1000 open(h_dest
, 'w').write(h_text
)
1001 open(cpp_dest
, 'w').write(cpp_text
)
1002 open(docstr_dest
, 'w').write(docstrings
)
1003 open(ih_dest
, 'w').write(ih_text
)
1006 def joinWithNewLines(values
):
1007 return '\n'.join(values
)
1009 #----------------------------------------------------------------------------
1011 def processVals(values
):
1013 for name
, value
, docs
in values
:
1017 text
.append('/// ' + x
)
1018 text
.append('#define %s %s' % (name
, value
))
1019 return joinWithNewLines(text
)
1021 #----------------------------------------------------------------------------
1023 def processMethods(methods
):
1029 for retType
, name
, number
, param1
, param2
, docs
, is_const
in methods
:
1030 retType
= retTypeMap
.get(retType
, retType
)
1031 params
= makeParamString(param1
, param2
)
1033 name
, theDef
, theImp
, docs
= checkMethodOverride(name
, number
, docs
)
1039 st
= 'DocStr(wxStyledTextCtrl::%s,\n' \
1040 '"%s", "");\n' % (name
, joinWithNewLines(docs
))
1043 # Build the method definition for the .h file
1047 defs
.append(' // ' + x
)
1049 theDef
= ' %s %s(%s)' % (retType
, name
, params
)
1051 theDef
= theDef
+ ' const'
1052 theDef
= theDef
+ ';'
1055 # Build the method definition for the interface .h file
1058 idefs
.append(' /**')
1060 idefs
.append(' ' + x
)
1062 if name
== 'GetCurLine':
1063 idefs
.append(' wxString GetCurLine(int* linePos=NULL);')
1065 idefs
.append(theDef
)
1067 # Build the method implementation string
1071 imps
.append('// ' + x
)
1073 theImp
= '%s wxStyledTextCtrl::%s(%s)' % (retType
, name
, params
)
1075 theImp
= theImp
+ ' const'
1076 theImp
= theImp
+ '\n{\n '
1077 if retType
== 'wxColour':
1078 theImp
= theImp
+ 'long c = '
1079 elif retType
!= 'void':
1080 theImp
= theImp
+ 'return '
1081 theImp
= theImp
+ 'SendMsg(%s, %s, %s)' % (number
,
1082 makeArgString(param1
),
1083 makeArgString(param2
))
1084 if retType
== 'bool':
1085 theImp
= theImp
+ ' != 0'
1086 if retType
== 'wxColour':
1087 theImp
= theImp
+ ';\n return wxColourFromLong(c)'
1089 theImp
= theImp
+ ';\n}'
1093 return joinWithNewLines(defs
), joinWithNewLines(imps
), joinWithNewLines(dstr
), joinWithNewLines(idefs
)
1096 #----------------------------------------------------------------------------
1098 def checkMethodOverride(name
, number
, docs
):
1099 theDef
= theImp
= None
1100 if name
in methodOverrideMap
:
1101 item
= methodOverrideMap
[name
]
1107 theDef
= ' ' + (item
[1] % name
)
1109 theImp
= item
[2] % ('wxStyledTextCtrl::'+name
, number
) + '\n}'
1113 print("************* " + name
)
1116 return name
, theDef
, theImp
, docs
1118 #----------------------------------------------------------------------------
1120 def makeArgString(param
):
1127 return '(sptr_t)(const char*)wx2stc(%s)' % name
1129 return 'wxColourAsLong(%s)' % name
1133 #----------------------------------------------------------------------------
1135 def makeParamString(param1
, param2
):
1138 aType
= paramTypeMap
.get(param
[0], param
[0])
1139 return aType
+ ' ' + param
[1]
1146 st
= st
+ doOne(param2
)
1150 #----------------------------------------------------------------------------
1152 def parseVal(line
, values
, docs
):
1153 name
, val
= line
.split('=')
1155 # remove prefixes such as SCI, etc.
1156 for old
, new
in valPrefixes
:
1158 if name
[:lo
] == old
:
1161 name
= new
+ name
[lo
:]
1163 # add it to the list
1164 values
.append( ('wxSTC_' + name
, val
, docs
) )
1166 #----------------------------------------------------------------------------
1168 funregex
= re
.compile(r
'\s*([a-zA-Z0-9_]+)' # <ws>return type
1169 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
1171 '\(([ a-zA-Z0-9_]*),' # (param,
1172 '([ a-zA-Z0-9_]*),*\)') # param)
1174 def parseFun(line
, methods
, docs
, values
, is_const
):
1175 def parseParam(param
):
1176 param
= param
.strip()
1180 param
= tuple(param
.split())
1183 mo
= funregex
.match(line
)
1185 print("***** Line doesn't match! : %s" % line
)
1187 retType
, name
, number
, param1
, param2
= mo
.groups()
1189 param1
= parseParam(param1
)
1190 param2
= parseParam(param2
)
1192 # Special case. For the key command functions we want a value defined too
1195 if (type(v
) == type(()) and v
[0] <= num
<= v
[1]) or v
== num
:
1196 parseVal('CMD_%s=%s' % (name
.upper(), number
), values
, docs
)
1198 # if we are not also doing a function for CMD values, then
1199 # just return, otherwise fall through to the append blow.
1200 if not FUNC_FOR_CMD
:
1203 methods
.append( (retType
, name
, number
, param1
, param2
, tuple(docs
),
1204 is_const
or name
in constNonGetterMethods
) )
1207 #----------------------------------------------------------------------------
1211 # TODO: parse command line args to replace default input/output files???
1213 if not os
.path
.exists(IFACE
):
1214 print('Please run this script from src/stc subdirectory.')
1218 processIface(IFACE
, H_TEMPLATE
, CPP_TEMPLATE
, IH_TEMPLATE
, H_DEST
, CPP_DEST
, DOCSTR_DEST
, IH_DEST
)
1222 if __name__
== '__main__':
1225 #----------------------------------------------------------------------------