]>
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 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')
24 if len(sys
.argv
) > 1 and sys
.argv
[1] == '--wxpython':
25 DOCSTR_DEST
= os
.path
.abspath('../../../wxPython/src/_stc_gendocs.i')
27 DOCSTR_DEST
= '/dev/null'
30 # Value prefixes to convert
31 valPrefixes
= [('SCI_', ''),
33 ('SCN_', None), # just toss these out...
43 # Message function values that should have a CMD_ constant generated
60 # Should a funciton be also generated for the CMDs?
64 # Map some generic typenames to wx types, using return value syntax
71 # Map some generic typenames to wx types, using parameter syntax
74 'string': 'const wxString&',
75 'colour': 'const wxColour&',
79 # Map of method info that needs tweaked. Either the name needs changed, or
80 # the method definition/implementation. Tuple items are:
82 # 1. New method name. None to skip the method, 0 to leave the
84 # 2. Method definition for the .h file, 0 to leave alone
85 # 3. Method implementation for the .cpp file, 0 to leave alone.
86 # 4. tuple of Doc string lines, or 0 to leave alone.
90 'void %s(const wxString& text);',
92 '''void %s(const wxString& text) {
93 const wxWX2MBbuf buf = wx2stc(text);
94 SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
98 'void %s(const wxMemoryBuffer& data);',
100 '''void %s(const wxMemoryBuffer& data) {
101 SendMsg(%s, data.GetDataLen(), (sptr_t)data.GetData());''',
105 'void %s(const wxString& text);',
107 '''void %s(const wxString& text) {
108 const wxWX2MBbuf buf = wx2stc(text);
109 SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
112 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
113 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
117 '''int %s(int pos) const {
118 return (unsigned char)SendMsg(%s, pos, 0);''',
123 '''int %s(int pos) const {
124 return (unsigned char)SendMsg(%s, pos, 0);''',
129 'wxMemoryBuffer %s(int startPos, int endPos);',
131 '''wxMemoryBuffer %s(int startPos, int endPos) {
133 if (endPos < startPos) {
138 int len = endPos - startPos;
139 if (!len) return buf;
141 tr.lpstrText = (char*)buf.GetWriteBuf(len*2+1);
142 tr.chrg.cpMin = startPos;
143 tr.chrg.cpMax = endPos;
144 len = SendMsg(%s, 0, (sptr_t)&tr);
145 buf.UngetWriteBuf(len);
148 ('Retrieve a buffer of cells.',)),
151 'PositionFromPoint' :
153 'int %s(wxPoint pt) const;',
155 '''int %s(wxPoint pt) const {
156 return SendMsg(%s, pt.x, pt.y);''',
161 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
163 '''wxString %s(int* linePos) {
164 int len = LineLength(GetCurrentLine());
166 if (linePos) *linePos = 0;
167 return wxEmptyString;
170 wxMemoryBuffer mbuf(len+1);
171 char* buf = (char*)mbuf.GetWriteBuf(len+1);
173 int pos = SendMsg(%s, len+1, (sptr_t)buf);
174 mbuf.UngetWriteBuf(len);
176 if (linePos) *linePos = pos;
177 return stc2wx(buf);''',
181 'SetUsePalette' : (None, 0,0,0),
183 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
184 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
185 'MarkerSetBackSelected' : ('MarkerSetBackgroundSelected', 0,0,0),
187 'MarkerSymbolDefined' : ('GetMarkerSymbolDefined', 0, 0, 0),
191 '''void %s(int markerNumber, int markerSymbol,
192 const wxColour& foreground = wxNullColour,
193 const wxColour& background = wxNullColour);''',
195 '''void %s(int markerNumber, int markerSymbol,
196 const wxColour& foreground,
197 const wxColour& background) {
199 SendMsg(%s, markerNumber, markerSymbol);
200 if (foreground.IsOk())
201 MarkerSetForeground(markerNumber, foreground);
202 if (background.IsOk())
203 MarkerSetBackground(markerNumber, background);''',
205 ('Set the symbol used for a particular marker number,',
206 'and optionally the fore and background colours.')),
209 'MarkerDefinePixmap' :
210 ('MarkerDefineBitmap',
211 '''void %s(int markerNumber, const wxBitmap& bmp);''',
212 '''void %s(int markerNumber, const wxBitmap& bmp) {
213 // convert bmp to a xpm in a string
214 wxMemoryOutputStream strm;
215 wxImage img = bmp.ConvertToImage();
217 img.ConvertAlphaToMask();
218 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
219 size_t len = strm.GetSize();
220 char* buff = new char[len+1];
221 strm.CopyTo(buff, len);
223 SendMsg(%s, markerNumber, (sptr_t)buff);
226 ('Define a marker from a bitmap',)),
229 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
230 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
231 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
232 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
233 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
234 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
235 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
236 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
237 'SetMarginCursorN' : ('SetMarginCursor', 0, 0, 0),
238 'GetMarginCursorN' : ('GetMarginCursor', 0, 0, 0),
242 'wxString %s(int line) const;',
244 '''wxString %s(int line) const {
246 long len = SendMsg(msg, line, 0);
248 wxMemoryBuffer mbuf(len+1);
249 char* buf = (char*)mbuf.GetWriteBuf(len+1);
250 SendMsg(msg, line, (sptr_t)buf);
251 mbuf.UngetWriteBuf(len);
253 return stc2wx(buf);''',
258 'wxString %s(int line) const;',
260 '''wxString %s(int line) const {
262 long len = SendMsg(msg, line, 0);
264 wxMemoryBuffer mbuf(len+1);
265 char* buf = (char*)mbuf.GetWriteBuf(len+1);
266 SendMsg(msg, line, (sptr_t)buf);
267 mbuf.UngetWriteBuf(len);
269 return stc2wx(buf);''',
272 'SetAdditionalSelFore' : ('SetAdditionalSelForeground', 0, 0, 0),
273 'SetAdditionalSelBack' : ('SetAdditionalSelBackground', 0, 0, 0),
274 'SetAdditionalCaretFore' : ('SetAdditionalCaretForeground', 0, 0, 0),
275 'GetAdditionalCaretFore' : ('GetAdditionalCaretForeground', 0, 0, 0),
277 'AnnotationGetText' :
279 'wxString %s(int line) const;',
281 '''wxString %s(int line) const {
283 long len = SendMsg(msg, line, 0);
285 wxMemoryBuffer mbuf(len+1);
286 char* buf = (char*)mbuf.GetWriteBuf(len+1);
287 SendMsg(msg, line, (sptr_t)buf);
288 mbuf.UngetWriteBuf(len);
290 return stc2wx(buf);''',
293 'AnnotationGetStyles' :
295 'wxString %s(int line) const;',
297 '''wxString %s(int line) const {
299 long len = SendMsg(msg, line, 0);
301 wxMemoryBuffer mbuf(len+1);
302 char* buf = (char*)mbuf.GetWriteBuf(len+1);
303 SendMsg(msg, line, (sptr_t)buf);
304 mbuf.UngetWriteBuf(len);
306 return stc2wx(buf);''',
309 'StyleGetFore' : ('StyleGetForeground', 0, 0, 0),
310 'StyleGetBack' : ('StyleGetBackground', 0, 0, 0),
311 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
312 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
313 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
314 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
315 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
318 'wxString %s(int style);',
319 '''wxString %s(int style) {
321 long len = SendMsg(msg, style, 0);
322 wxMemoryBuffer mbuf(len+1);
323 char* buf = (char*)mbuf.GetWriteBuf(len+1);
324 SendMsg(msg, style, (sptr_t)buf);
325 mbuf.UngetWriteBuf(len);
327 return stc2wx(buf);''',
328 ('Get the font facename of a style',)),
329 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
330 'StyleSetCharacterSet' : (None, 0, 0, 0),
334 'void %s(int key, int modifiers, int cmd);',
336 '''void %s(int key, int modifiers, int cmd) {
337 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
343 'void %s(int key, int modifiers);',
345 '''void %s(int key, int modifiers) {
346 SendMsg(%s, MAKELONG(key, modifiers));''',
349 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
354 'void %s(int length, char* styleBytes);',
356 '''void %s(int length, char* styleBytes) {
357 SendMsg(%s, length, (sptr_t)styleBytes);''',
361 'IndicSetAlpha' : ('IndicatorSetAlpha', 0, 0, 0),
362 'IndicGetAlpha' : ('IndicatorGetAlpha', 0, 0, 0),
363 'IndicSetOutlineAlpha' : ('IndicatorSetOutlineAlpha', 0, 0, 0),
364 'IndicGetOutlineAlpha' : ('IndicatorGetOutlineAlpha', 0, 0, 0),
365 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
366 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
367 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
368 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
369 'IndicSetUnder': ('IndicatorSetUnder', 0, 0, 0),
370 'IndicGetUnder': ('IndicatorGetUnder', 0, 0, 0),
372 'SetWhitespaceFore' : ('SetWhitespaceForeground', 0, 0, 0),
373 'SetWhitespaceBack' : ('SetWhitespaceBackground', 0, 0, 0),
375 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
376 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
377 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
378 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
379 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
380 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
381 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
382 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
383 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
384 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
385 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
386 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
387 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
388 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
389 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
390 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
391 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
392 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
393 'AutoCSetDropRestOfWord' : ('AutoCompSetDropRestOfWord', 0,0,0),
394 'AutoCGetDropRestOfWord' : ('AutoCompGetDropRestOfWord', 0,0,0),
395 'AutoCGetTypeSeparator' : ('AutoCompGetTypeSeparator', 0, 0, 0),
396 'AutoCSetTypeSeparator' : ('AutoCompSetTypeSeparator', 0, 0, 0),
397 'AutoCGetCurrent' : ('AutoCompGetCurrent', 0, 0, 0),
398 'AutoCGetCurrentText' : (None, 0, 0, 0),
399 'AutoCSetMaxWidth' : ('AutoCompSetMaxWidth', 0, 0, 0),
400 'AutoCGetMaxWidth' : ('AutoCompGetMaxWidth', 0, 0, 0),
401 'AutoCSetMaxHeight' : ('AutoCompSetMaxHeight', 0, 0, 0),
402 'AutoCGetMaxHeight' : ('AutoCompGetMaxHeight', 0, 0, 0),
403 'AutoCGetMaxHeight' : ('AutoCompGetMaxHeight', 0, 0, 0),
404 'AutoCSetCaseInsensitiveBehaviour' : ('AutoCompSetCaseInsensitiveBehaviour', 0, 0, 0),
405 'AutoCGetCaseInsensitiveBehaviour' : ('AutoCompGetCaseInsensitiveBehaviour', 0, 0, 0),
409 '''void %s(int type, const wxBitmap& bmp);''',
410 '''void %s(int type, const wxBitmap& bmp) {
411 // convert bmp to a xpm in a string
412 wxMemoryOutputStream strm;
413 wxImage img = bmp.ConvertToImage();
415 img.ConvertAlphaToMask();
416 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
417 size_t len = strm.GetSize();
418 char* buff = new char[len+1];
419 strm.CopyTo(buff, len);
421 SendMsg(%s, type, (sptr_t)buff);
424 ('Register an image for use in autocompletion lists.',)),
427 'ClearRegisteredImages' : (0, 0, 0,
428 ('Clear all the registered images.',)),
431 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
432 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
434 'SetVScrollBar' : ('SetUseVerticalScrollBar', 0, 0, 0),
435 'GetVScrollBar' : ('GetUseVerticalScrollBar', 0, 0, 0),
437 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
439 'GetUsePalette' : (None, 0, 0, 0),
443 '''int %s(int minPos, int maxPos, const wxString& text, int flags=0);''',
445 '''int %s(int minPos, int maxPos,
446 const wxString& text,
449 ft.chrg.cpMin = minPos;
450 ft.chrg.cpMax = maxPos;
451 const wxWX2MBbuf buf = wx2stc(text);
452 ft.lpstrText = (char*)(const char*)buf;
454 return SendMsg(%s, flags, (sptr_t)&ft);''',
459 '''int %s(bool doDraw,
465 wxRect pageRect);''',
466 ''' int %s(bool doDraw,
475 if (endPos < startPos) {
481 fr.hdcTarget = target;
482 fr.rc.top = renderRect.GetTop();
483 fr.rc.left = renderRect.GetLeft();
484 fr.rc.right = renderRect.GetRight();
485 fr.rc.bottom = renderRect.GetBottom();
486 fr.rcPage.top = pageRect.GetTop();
487 fr.rcPage.left = pageRect.GetLeft();
488 fr.rcPage.right = pageRect.GetRight();
489 fr.rcPage.bottom = pageRect.GetBottom();
490 fr.chrg.cpMin = startPos;
491 fr.chrg.cpMax = endPos;
493 return SendMsg(%s, doDraw, (sptr_t)&fr);''',
499 'wxString %s(int line) const;',
501 '''wxString %s(int line) const {
502 int len = LineLength(line);
503 if (!len) return wxEmptyString;
505 wxMemoryBuffer mbuf(len+1);
506 char* buf = (char*)mbuf.GetWriteBuf(len+1);
507 SendMsg(%s, line, (sptr_t)buf);
508 mbuf.UngetWriteBuf(len);
510 return stc2wx(buf);''',
512 ('Retrieve the contents of a line.',)),
514 'SetSel' : (None, 0,0,0), #'SetSelection', 0, 0, 0),
521 const int len = SendMsg(SCI_GETSELTEXT, 0, (sptr_t)0);
522 if (!len) return wxEmptyString;
524 wxMemoryBuffer mbuf(len+2);
525 char* buf = (char*)mbuf.GetWriteBuf(len+1);
526 SendMsg(%s, 0, (sptr_t)buf);
527 mbuf.UngetWriteBuf(len);
529 return stc2wx(buf);''',
531 ('Retrieve the selected text.',)),
536 'wxString %s(int startPos, int endPos);',
538 '''wxString %s(int startPos, int endPos) {
539 if (endPos < startPos) {
544 int len = endPos - startPos;
545 if (!len) return wxEmptyString;
546 wxMemoryBuffer mbuf(len+1);
547 char* buf = (char*)mbuf.GetWriteBuf(len);
550 tr.chrg.cpMin = startPos;
551 tr.chrg.cpMax = endPos;
552 SendMsg(%s, 0, (sptr_t)&tr);
553 mbuf.UngetWriteBuf(len);
555 return stc2wx(buf);''',
557 ('Retrieve a range of text.',)),
559 'PointXFromPosition' : (None, 0, 0, 0),
560 'PointYFromPosition' : (None, 0, 0, 0),
562 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
563 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
564 'Null' : (None, 0, 0, 0),
568 'wxString %s() const;',
570 '''wxString %s() const {
571 int len = GetTextLength();
572 wxMemoryBuffer mbuf(len+1); // leave room for the null...
573 char* buf = (char*)mbuf.GetWriteBuf(len+1);
574 SendMsg(%s, len+1, (sptr_t)buf);
575 mbuf.UngetWriteBuf(len);
577 return stc2wx(buf);''',
579 ('Retrieve all the text in the document.', )),
581 'GetDirectFunction' : (None, 0, 0, 0),
582 'GetDirectPointer' : (None, 0, 0, 0),
584 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
585 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
586 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
587 'CallTipSetFore' : ('CallTipSetForeground', 0, 0, 0),
588 'CallTipSetForeHlt' : ('CallTipSetForegroundHighlight', 0, 0, 0),
590 'SetHotspotActiveFore' : ('SetHotspotActiveForeground', 0, 0, 0),
591 'SetHotspotActiveBack' : ('SetHotspotActiveBackground', 0, 0, 0),
592 'GetHotspotActiveFore' : ('GetHotspotActiveForeground', 0, 0, 0),
593 'GetHotspotActiveBack' : ('GetHotspotActiveBackground', 0, 0, 0),
595 'GetCaretLineBack' : ('GetCaretLineBackground', 0, 0, 0),
596 'SetCaretLineBack' : ('SetCaretLineBackground', 0, 0, 0),
600 'int %s(const wxString& text);',
603 int %s(const wxString& text) {
604 const wxWX2MBbuf buf = wx2stc(text);
605 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
610 'int %s(const wxString& text);',
613 int %s(const wxString& text) {
614 const wxWX2MBbuf buf = wx2stc(text);
615 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
620 'int %s(const wxString& text);',
623 int %s(const wxString& text) {
624 const wxWX2MBbuf buf = wx2stc(text);
625 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
628 # not sure what to do about these yet
629 'TargetAsUTF8' : ( None, 0, 0, 0),
630 'SetLengthForEncode' : ( None, 0, 0, 0),
631 'EncodedFromUTF8' : ( None, 0, 0, 0),
636 'wxString %s(const wxString& key);',
638 '''wxString %s(const wxString& key) {
639 int len = SendMsg(SCI_GETPROPERTY, (sptr_t)(const char*)wx2stc(key), 0);
640 if (!len) return wxEmptyString;
642 wxMemoryBuffer mbuf(len+1);
643 char* buf = (char*)mbuf.GetWriteBuf(len+1);
644 SendMsg(%s, (uptr_t)(const char*)wx2stc(key), (sptr_t)buf);
645 mbuf.UngetWriteBuf(len);
647 return stc2wx(buf);''',
648 ("Retrieve a 'property' value previously set with SetProperty.",)),
650 'GetPropertyExpanded' :
652 'wxString %s(const wxString& key);',
654 '''wxString %s(const wxString& key) {
655 int len = SendMsg(SCI_GETPROPERTYEXPANDED, (uptr_t)(const char*)wx2stc(key), 0);
656 if (!len) return wxEmptyString;
658 wxMemoryBuffer mbuf(len+1);
659 char* buf = (char*)mbuf.GetWriteBuf(len+1);
660 SendMsg(%s, (uptr_t)(const char*)wx2stc(key), (sptr_t)buf);
661 mbuf.UngetWriteBuf(len);
663 return stc2wx(buf);''',
664 ("Retrieve a 'property' value previously set with SetProperty,",
665 "with '$()' variable replacement on returned buffer.")),
667 'GetPropertyInt' : (0, 0, 0,
668 ("Retrieve a 'property' value previously set with SetProperty,",
669 "interpreted as an int AFTER any '$()' variable replacement.")),
676 return (void*)SendMsg(%s);''',
681 'void %s(void* docPointer);',
682 '''void %s(void* docPointer) {
683 SendMsg(%s, 0, (sptr_t)docPointer);''',
690 return (void*)SendMsg(%s);''',
695 'void %s(void* docPointer);',
696 '''void %s(void* docPointer) {
697 SendMsg(%s, 0, (sptr_t)docPointer);''',
702 'void %s(void* docPointer);',
703 '''void %s(void* docPointer) {
704 SendMsg(%s, 0, (sptr_t)docPointer);''',
710 '''void %s(int codePage) {
712 wxASSERT_MSG(codePage == wxSTC_CP_UTF8,
713 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
715 wxASSERT_MSG(codePage != wxSTC_CP_UTF8,
716 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
718 SendMsg(%s, codePage);''',
719 ("Set the code page used to interpret the bytes of the document as characters.",) ),
722 'GrabFocus' : (None, 0, 0, 0),
724 # Rename some that would otherwise hide the wxWindow methods
725 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
726 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
727 'SetCursor' : ('SetSTCCursor', 0, 0, 0),
728 'GetCursor' : ('GetSTCCursor', 0, 0, 0),
730 'LoadLexerLibrary' : (None, 0,0,0),
732 'SetPositionCache' : ('SetPositionCacheSize', 0, 0, 0),
733 'GetPositionCache' : ('GetPositionCacheSize', 0, 0, 0),
735 'GetLexerLanguage' : (None, 0, 0, 0),
736 'SetFontQuality' : (None, 0, 0, 0),
737 'GetFontQuality' : (None, 0, 0, 0),
738 'SetSelection' : (None, 0, 0, 0),
740 'GetCharacterPointer' : (0,
741 'const char* %s() const;',
742 'const char* %s() const {\n'
743 ' return (const char*)SendMsg(%s, 0, 0);',
746 'GetRangePointer' : (0,
747 'const char* %s(int position, int rangeLength) const;',
748 'const char* %s(int position, int rangeLength) const {\n'
749 ' return (const char*)SendMsg(%s, position, rangeLength);',
755 'wxString %s() const;',
757 '''wxString %s() const {
759 int len = SendMsg(msg, 0, NULL);
760 if (!len) return wxEmptyString;
762 wxMemoryBuffer mbuf(len+1);
763 char* buf = (char*)mbuf.GetWriteBuf(len+1);
764 SendMsg(msg, 0, (sptr_t)buf);
765 mbuf.UngetWriteBuf(len);
767 return stc2wx(buf);''',
769 ('Get the set of characters making up words for when moving or selecting by word.',)),
773 'wxString %s(int tagNumber) const;',
775 '''wxString %s(int tagNumber) const {
777 int len = SendMsg(msg, tagNumber, NULL);
778 if (!len) return wxEmptyString;
780 wxMemoryBuffer mbuf(len+1);
781 char* buf = (char*)mbuf.GetWriteBuf(len+1);
782 SendMsg(msg, tagNumber, (sptr_t)buf);
783 mbuf.UngetWriteBuf(len);
785 return stc2wx(buf);''',
788 'GetWhitespaceChars' :
790 'wxString %s() const;',
792 '''wxString %s() const {
794 int len = SendMsg(msg, 0, NULL);
795 if (!len) return wxEmptyString;
797 wxMemoryBuffer mbuf(len+1);
798 char* buf = (char*)mbuf.GetWriteBuf(len+1);
799 SendMsg(msg, 0, (sptr_t)buf);
800 mbuf.UngetWriteBuf(len);
802 return stc2wx(buf);''',
806 'GetPunctuationChars' :
808 'wxString %s() const;',
810 '''wxString %s() const {
812 int len = SendMsg(msg, 0, NULL);
813 if (!len) return wxEmptyString;
815 wxMemoryBuffer mbuf(len+1);
816 char* buf = (char*)mbuf.GetWriteBuf(len+1);
817 SendMsg(msg, 0, (sptr_t)buf);
818 mbuf.UngetWriteBuf(len);
820 return stc2wx(buf);''',
826 'wxString %s() const;',
828 '''wxString %s() const {
830 int len = SendMsg(msg, 0, NULL);
831 if (!len) return wxEmptyString;
833 wxMemoryBuffer mbuf(len+1);
834 char* buf = (char*)mbuf.GetWriteBuf(len+1);
835 SendMsg(msg, 0, (sptr_t)buf);
836 mbuf.UngetWriteBuf(len);
838 return stc2wx(buf);''',
845 'wxString %s(const wxString& name) const;',
847 '''wxString %s(const wxString& name) const {
849 int len = SendMsg(msg, (sptr_t)(const char*)wx2stc(name), NULL);
850 if (!len) return wxEmptyString;
852 wxMemoryBuffer mbuf(len+1);
853 char* buf = (char*)mbuf.GetWriteBuf(len+1);
854 SendMsg(msg, (sptr_t)(const char*)wx2stc(name), (sptr_t)buf);
855 mbuf.UngetWriteBuf(len);
857 return stc2wx(buf);''',
862 'DescribeKeyWordSets' :
864 'wxString %s() const;',
866 '''wxString %s() const {
868 int len = SendMsg(msg, 0, NULL);
869 if (!len) return wxEmptyString;
871 wxMemoryBuffer mbuf(len+1);
872 char* buf = (char*)mbuf.GetWriteBuf(len+1);
873 SendMsg(msg, 0, (sptr_t)buf);
874 mbuf.UngetWriteBuf(len);
876 return stc2wx(buf);''',
880 'MarkerDefineRGBAImage' :
882 'void %s(int markerNumber, const unsigned char* pixels);',
883 '''void %s(int markerNumber, const unsigned char* pixels) {
884 SendMsg(%s, markerNumber, (sptr_t)pixels);''',
888 'RegisterRGBAImage' :
890 'void %s(int type, const unsigned char* pixels);',
891 '''void %s(int type, const unsigned char* pixels) {
892 SendMsg(%s, type, (sptr_t)pixels);''',
896 # I think these are only available on the native OSX backend, so
897 # don't add them to the wx API...
898 'FindIndicatorShow' : (None, 0,0,0),
899 'FindIndicatorFlash' : (None, 0,0,0),
900 'FindIndicatorHide' : (None, 0,0,0),
904 'void* %s(int bytes) const;',
905 """void* %s(int bytes) const {
906 return (void*)(sptr_t)SendMsg(%s, bytes); """,
911 'void* %s(int operation, void* pointer);',
912 """void* %s(int operation, void* pointer) {
913 return (void*)(sptr_t)SendMsg(%s, operation, (sptr_t)pointer); """,
920 # all Scintilla getters are transformed into const member of wxSTC class but
921 # some non-getter methods are also logically const and this set contains their
922 # names (notice that it's useless to include here methods manually overridden
924 constNonGetterMethods
= (
933 #----------------------------------------------------------------------------
935 def processIface(iface
, h_tmplt
, cpp_tmplt
, h_dest
, cpp_dest
, docstr_dest
):
942 fi
= FileInput(iface
)
945 if line
[:2] == '##' or line
== '':
950 if line
[:2] == '# ': # a doc string
951 curDocStrings
.append(line
[2:])
954 parseVal(line
[4:], values
, curDocStrings
)
957 elif op
== 'fun ' or op
== 'set ' or op
== 'get ':
958 parseFun(line
[4:], methods
, curDocStrings
, cmds
, op
== 'get ')
962 if line
[4:].strip() == 'Deprecated':
963 break # skip the rest of the file
975 print('***** Unknown line type: %s' % line
)
980 data
['VALUES'] = processVals(values
)
981 data
['CMDS'] = processVals(cmds
)
982 defs
, imps
, docstrings
= processMethods(methods
)
983 data
['METHOD_DEFS'] = defs
984 data
['METHOD_IMPS'] = imps
987 h_text
= open(h_tmplt
).read()
988 cpp_text
= open(cpp_tmplt
).read()
990 # do the substitutions
991 h_text
= h_text
% data
992 cpp_text
= cpp_text
% data
994 # write out destination files
995 open(h_dest
, 'w').write(h_text
)
996 open(cpp_dest
, 'w').write(cpp_text
)
997 open(docstr_dest
, 'w').write(docstrings
)
1001 def joinWithNewLines(values
):
1002 return '\n'.join(values
)
1004 #----------------------------------------------------------------------------
1006 def processVals(values
):
1008 for name
, value
, docs
in values
:
1012 text
.append('// ' + x
)
1013 text
.append('#define %s %s' % (name
, value
))
1014 return joinWithNewLines(text
)
1016 #----------------------------------------------------------------------------
1018 def processMethods(methods
):
1023 for retType
, name
, number
, param1
, param2
, docs
, is_const
in methods
:
1024 retType
= retTypeMap
.get(retType
, retType
)
1025 params
= makeParamString(param1
, param2
)
1027 name
, theDef
, theImp
, docs
= checkMethodOverride(name
, number
, docs
)
1033 st
= 'DocStr(wxStyledTextCtrl::%s,\n' \
1034 '"%s", "");\n' % (name
, joinWithNewLines(docs
))
1037 # Build the method definition for the .h file
1041 defs
.append(' // ' + x
)
1043 theDef
= ' %s %s(%s)' % (retType
, name
, params
)
1045 theDef
= theDef
+ ' const'
1046 theDef
= theDef
+ ';'
1049 # Build the method implementation string
1053 imps
.append('// ' + x
)
1055 theImp
= '%s wxStyledTextCtrl::%s(%s)' % (retType
, name
, params
)
1057 theImp
= theImp
+ ' const'
1058 theImp
= theImp
+ '\n{\n '
1059 if retType
== 'wxColour':
1060 theImp
= theImp
+ 'long c = '
1061 elif retType
!= 'void':
1062 theImp
= theImp
+ 'return '
1063 theImp
= theImp
+ 'SendMsg(%s, %s, %s)' % (number
,
1064 makeArgString(param1
),
1065 makeArgString(param2
))
1066 if retType
== 'bool':
1067 theImp
= theImp
+ ' != 0'
1068 if retType
== 'wxColour':
1069 theImp
= theImp
+ ';\n return wxColourFromLong(c)'
1071 theImp
= theImp
+ ';\n}'
1075 return joinWithNewLines(defs
), joinWithNewLines(imps
), joinWithNewLines(dstr
)
1078 #----------------------------------------------------------------------------
1080 def checkMethodOverride(name
, number
, docs
):
1081 theDef
= theImp
= None
1082 if name
in methodOverrideMap
:
1083 item
= methodOverrideMap
[name
]
1089 theDef
= ' ' + (item
[1] % name
)
1091 theImp
= item
[2] % ('wxStyledTextCtrl::'+name
, number
) + '\n}'
1095 print("************* " + name
)
1098 return name
, theDef
, theImp
, docs
1100 #----------------------------------------------------------------------------
1102 def makeArgString(param
):
1109 return '(sptr_t)(const char*)wx2stc(%s)' % name
1111 return 'wxColourAsLong(%s)' % name
1115 #----------------------------------------------------------------------------
1117 def makeParamString(param1
, param2
):
1120 aType
= paramTypeMap
.get(param
[0], param
[0])
1121 return aType
+ ' ' + param
[1]
1128 st
= st
+ doOne(param2
)
1132 #----------------------------------------------------------------------------
1134 def parseVal(line
, values
, docs
):
1135 name
, val
= line
.split('=')
1137 # remove prefixes such as SCI, etc.
1138 for old
, new
in valPrefixes
:
1140 if name
[:lo
] == old
:
1143 name
= new
+ name
[lo
:]
1145 # add it to the list
1146 values
.append( ('wxSTC_' + name
, val
, docs
) )
1148 #----------------------------------------------------------------------------
1150 funregex
= re
.compile(r
'\s*([a-zA-Z0-9_]+)' # <ws>return type
1151 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
1153 '\(([ a-zA-Z0-9_]*),' # (param,
1154 '([ a-zA-Z0-9_]*),*\)') # param)
1156 def parseFun(line
, methods
, docs
, values
, is_const
):
1157 def parseParam(param
):
1158 param
= param
.strip()
1162 param
= tuple(param
.split())
1165 mo
= funregex
.match(line
)
1167 print("***** Line doesn't match! : %s" % line
)
1169 retType
, name
, number
, param1
, param2
= mo
.groups()
1171 param1
= parseParam(param1
)
1172 param2
= parseParam(param2
)
1174 # Special case. For the key command functions we want a value defined too
1177 if (type(v
) == type(()) and v
[0] <= num
<= v
[1]) or v
== num
:
1178 parseVal('CMD_%s=%s' % (name
.upper(), number
), values
, docs
)
1180 # if we are not also doing a function for CMD values, then
1181 # just return, otherwise fall through to the append blow.
1182 if not FUNC_FOR_CMD
:
1185 methods
.append( (retType
, name
, number
, param1
, param2
, tuple(docs
),
1186 is_const
or name
in constNonGetterMethods
) )
1189 #----------------------------------------------------------------------------
1193 # TODO: parse command line args to replace default input/output files???
1195 if not os
.path
.exists(IFACE
):
1196 print('Please run this script from src/stc subdirectory.')
1200 processIface(IFACE
, H_TEMPLATE
, CPP_TEMPLATE
, H_DEST
, CPP_DEST
, DOCSTR_DEST
)
1204 if __name__
== '__main__':
1207 #----------------------------------------------------------------------------