]>
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
9 # Copyright: (c) 2000 by Total Control Software
10 # Licence: wxWindows licence
11 #----------------------------------------------------------------------------
14 import sys
, string
, re
, os
15 from fileinput
import FileInput
18 IFACE
= os
.path
.abspath('./scintilla/include/Scintilla.iface')
19 H_TEMPLATE
= os
.path
.abspath('./stc.h.in')
20 IH_TEMPLATE
= os
.path
.abspath('./stc.interface.h.in')
21 CPP_TEMPLATE
= os
.path
.abspath('./stc.cpp.in')
22 H_DEST
= os
.path
.abspath('../../include/wx/stc/stc.h')
23 IH_DEST
= os
.path
.abspath('../../interface/wx/stc/stc.h')
24 CPP_DEST
= os
.path
.abspath('./stc.cpp')
25 if len(sys
.argv
) > 1 and sys
.argv
[1] == '--wxpython':
26 DOCSTR_DEST
= os
.path
.abspath('../../../wxPython/src/_stc_gendocs.i')
31 # Value prefixes to convert
32 valPrefixes
= [('SCI_', ''),
34 ('SCN_', None), # just toss these out...
44 # Message function values that should have a CMD_ constant generated
61 # Should a function be also generated for the CMDs?
65 # Map some generic typenames to wx types, using return value syntax
72 # Map some generic typenames to wx types, using parameter syntax
75 'string': 'const wxString&',
76 'colour': 'const wxColour&',
80 # Map of method info that needs tweaked. Either the name needs changed, or
81 # the method definition/implementation. Tuple items are:
83 # 1. New method name. None to skip the method, 0 to leave the
85 # 2. Method definition for the .h file, 0 to leave alone
86 # 3. Method implementation for the .cpp file, 0 to leave alone.
87 # 4. tuple of Doc string lines, or 0 to leave alone.
91 'void %s(const wxString& text);',
93 '''void %s(const wxString& text) {
94 const wxWX2MBbuf buf = wx2stc(text);
95 SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
99 'void %s(const wxMemoryBuffer& data);',
101 '''void %s(const wxMemoryBuffer& data) {
102 SendMsg(%s, data.GetDataLen(), (sptr_t)data.GetData());''',
106 'void %s(const wxString& text);',
108 '''void %s(const wxString& text) {
109 const wxWX2MBbuf buf = wx2stc(text);
110 SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
113 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
114 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
118 '''int %s(int pos) const {
119 return (unsigned char)SendMsg(%s, pos, 0);''',
124 '''int %s(int pos) const {
125 return (unsigned char)SendMsg(%s, pos, 0);''',
130 'wxMemoryBuffer %s(int startPos, int endPos);',
132 '''wxMemoryBuffer %s(int startPos, int endPos) {
134 if (endPos < startPos) {
139 int len = endPos - startPos;
140 if (!len) return buf;
142 tr.lpstrText = (char*)buf.GetWriteBuf(len*2+1);
143 tr.chrg.cpMin = startPos;
144 tr.chrg.cpMax = endPos;
145 len = SendMsg(%s, 0, (sptr_t)&tr);
146 buf.UngetWriteBuf(len);
149 ('Retrieve a buffer of cells.',)),
152 'PositionFromPoint' :
154 'int %s(wxPoint pt) const;',
156 '''int %s(wxPoint pt) const {
157 return SendMsg(%s, pt.x, pt.y);''',
162 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
164 '''wxString %s(int* linePos) {
165 int len = LineLength(GetCurrentLine());
167 if (linePos) *linePos = 0;
168 return wxEmptyString;
171 wxMemoryBuffer mbuf(len+1);
172 char* buf = (char*)mbuf.GetWriteBuf(len+1);
174 int pos = SendMsg(%s, len+1, (sptr_t)buf);
175 mbuf.UngetWriteBuf(len);
177 if (linePos) *linePos = pos;
178 return stc2wx(buf);''',
182 'SetUsePalette' : (None, 0,0,0),
184 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
185 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
186 'MarkerSetBackSelected' : ('MarkerSetBackgroundSelected', 0,0,0),
188 'MarkerSymbolDefined' : ('GetMarkerSymbolDefined', 0, 0, 0),
192 '''void %s(int markerNumber, int markerSymbol,
193 const wxColour& foreground = wxNullColour,
194 const wxColour& background = wxNullColour);''',
196 '''void %s(int markerNumber, int markerSymbol,
197 const wxColour& foreground,
198 const wxColour& background) {
200 SendMsg(%s, markerNumber, markerSymbol);
201 if (foreground.IsOk())
202 MarkerSetForeground(markerNumber, foreground);
203 if (background.IsOk())
204 MarkerSetBackground(markerNumber, background);''',
206 ('Set the symbol used for a particular marker number,',
207 'and optionally the fore and background colours.')),
210 'MarkerDefinePixmap' :
211 ('MarkerDefineBitmap',
212 '''void %s(int markerNumber, const wxBitmap& bmp);''',
213 '''void %s(int markerNumber, const wxBitmap& bmp) {
214 // convert bmp to a xpm in a string
215 wxMemoryOutputStream strm;
216 wxImage img = bmp.ConvertToImage();
218 img.ConvertAlphaToMask();
219 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
220 size_t len = strm.GetSize();
221 char* buff = new char[len+1];
222 strm.CopyTo(buff, len);
224 SendMsg(%s, markerNumber, (sptr_t)buff);
227 ('Define a marker from a bitmap',)),
230 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
231 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
232 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
233 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
234 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
235 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
236 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
237 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
238 'SetMarginCursorN' : ('SetMarginCursor', 0, 0, 0),
239 'GetMarginCursorN' : ('GetMarginCursor', 0, 0, 0),
243 'wxString %s(int line) const;',
245 '''wxString %s(int line) const {
247 long len = SendMsg(msg, line, 0);
249 wxMemoryBuffer mbuf(len+1);
250 char* buf = (char*)mbuf.GetWriteBuf(len+1);
251 SendMsg(msg, line, (sptr_t)buf);
252 mbuf.UngetWriteBuf(len);
254 return stc2wx(buf);''',
259 'wxString %s(int line) const;',
261 '''wxString %s(int line) const {
263 long len = SendMsg(msg, line, 0);
265 wxMemoryBuffer mbuf(len+1);
266 char* buf = (char*)mbuf.GetWriteBuf(len+1);
267 SendMsg(msg, line, (sptr_t)buf);
268 mbuf.UngetWriteBuf(len);
270 return stc2wx(buf);''',
273 'SetAdditionalSelFore' : ('SetAdditionalSelForeground', 0, 0, 0),
274 'SetAdditionalSelBack' : ('SetAdditionalSelBackground', 0, 0, 0),
275 'SetAdditionalCaretFore' : ('SetAdditionalCaretForeground', 0, 0, 0),
276 'GetAdditionalCaretFore' : ('GetAdditionalCaretForeground', 0, 0, 0),
278 'AnnotationGetText' :
280 'wxString %s(int line) const;',
282 '''wxString %s(int line) const {
284 long len = SendMsg(msg, line, 0);
286 wxMemoryBuffer mbuf(len+1);
287 char* buf = (char*)mbuf.GetWriteBuf(len+1);
288 SendMsg(msg, line, (sptr_t)buf);
289 mbuf.UngetWriteBuf(len);
291 return stc2wx(buf);''',
294 'AnnotationGetStyles' :
296 'wxString %s(int line) const;',
298 '''wxString %s(int line) const {
300 long len = SendMsg(msg, line, 0);
302 wxMemoryBuffer mbuf(len+1);
303 char* buf = (char*)mbuf.GetWriteBuf(len+1);
304 SendMsg(msg, line, (sptr_t)buf);
305 mbuf.UngetWriteBuf(len);
307 return stc2wx(buf);''',
310 'StyleGetFore' : ('StyleGetForeground', 0, 0, 0),
311 'StyleGetBack' : ('StyleGetBackground', 0, 0, 0),
312 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
313 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
314 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
315 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
316 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
319 'wxString %s(int style);',
320 '''wxString %s(int style) {
322 long len = SendMsg(msg, style, 0);
323 wxMemoryBuffer mbuf(len+1);
324 char* buf = (char*)mbuf.GetWriteBuf(len+1);
325 SendMsg(msg, style, (sptr_t)buf);
326 mbuf.UngetWriteBuf(len);
328 return stc2wx(buf);''',
329 ('Get the font facename of a style',)),
330 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
331 'StyleSetCharacterSet' : (None, 0, 0, 0),
335 'void %s(int key, int modifiers, int cmd);',
337 '''void %s(int key, int modifiers, int cmd) {
338 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
344 'void %s(int key, int modifiers);',
346 '''void %s(int key, int modifiers) {
347 SendMsg(%s, MAKELONG(key, modifiers));''',
350 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
355 'void %s(int length, char* styleBytes);',
357 '''void %s(int length, char* styleBytes) {
358 SendMsg(%s, length, (sptr_t)styleBytes);''',
362 'IndicSetAlpha' : ('IndicatorSetAlpha', 0, 0, 0),
363 'IndicGetAlpha' : ('IndicatorGetAlpha', 0, 0, 0),
364 'IndicSetOutlineAlpha' : ('IndicatorSetOutlineAlpha', 0, 0, 0),
365 'IndicGetOutlineAlpha' : ('IndicatorGetOutlineAlpha', 0, 0, 0),
366 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
367 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
368 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
369 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
370 'IndicSetUnder': ('IndicatorSetUnder', 0, 0, 0),
371 'IndicGetUnder': ('IndicatorGetUnder', 0, 0, 0),
373 'SetWhitespaceFore' : ('SetWhitespaceForeground', 0, 0, 0),
374 'SetWhitespaceBack' : ('SetWhitespaceBackground', 0, 0, 0),
376 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
377 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
378 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
379 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
380 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
381 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
382 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
383 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
384 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
385 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
386 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
387 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
388 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
389 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
390 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
391 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
392 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
393 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
394 'AutoCSetDropRestOfWord' : ('AutoCompSetDropRestOfWord', 0,0,0),
395 'AutoCGetDropRestOfWord' : ('AutoCompGetDropRestOfWord', 0,0,0),
396 'AutoCGetTypeSeparator' : ('AutoCompGetTypeSeparator', 0, 0, 0),
397 'AutoCSetTypeSeparator' : ('AutoCompSetTypeSeparator', 0, 0, 0),
398 'AutoCGetCurrent' : ('AutoCompGetCurrent', 0, 0, 0),
399 'AutoCGetCurrentText' : (None, 0, 0, 0),
400 'AutoCSetMaxWidth' : ('AutoCompSetMaxWidth', 0, 0, 0),
401 'AutoCGetMaxWidth' : ('AutoCompGetMaxWidth', 0, 0, 0),
402 'AutoCSetMaxHeight' : ('AutoCompSetMaxHeight', 0, 0, 0),
403 'AutoCGetMaxHeight' : ('AutoCompGetMaxHeight', 0, 0, 0),
404 'AutoCGetMaxHeight' : ('AutoCompGetMaxHeight', 0, 0, 0),
405 'AutoCSetCaseInsensitiveBehaviour' : ('AutoCompSetCaseInsensitiveBehaviour', 0, 0, 0),
406 'AutoCGetCaseInsensitiveBehaviour' : ('AutoCompGetCaseInsensitiveBehaviour', 0, 0, 0),
410 '''void %s(int type, const wxBitmap& bmp);''',
411 '''void %s(int type, const wxBitmap& bmp) {
412 // convert bmp to a xpm in a string
413 wxMemoryOutputStream strm;
414 wxImage img = bmp.ConvertToImage();
416 img.ConvertAlphaToMask();
417 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
418 size_t len = strm.GetSize();
419 char* buff = new char[len+1];
420 strm.CopyTo(buff, len);
422 SendMsg(%s, type, (sptr_t)buff);
425 ('Register an image for use in autocompletion lists.',)),
428 'ClearRegisteredImages' : (0, 0, 0,
429 ('Clear all the registered images.',)),
432 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
433 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
435 'SetVScrollBar' : ('SetUseVerticalScrollBar', 0, 0, 0),
436 'GetVScrollBar' : ('GetUseVerticalScrollBar', 0, 0, 0),
438 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
440 'GetUsePalette' : (None, 0, 0, 0),
444 '''int %s(int minPos, int maxPos, const wxString& text, int flags=0);''',
446 '''int %s(int minPos, int maxPos,
447 const wxString& text,
450 ft.chrg.cpMin = minPos;
451 ft.chrg.cpMax = maxPos;
452 const wxWX2MBbuf buf = wx2stc(text);
453 ft.lpstrText = (char*)(const char*)buf;
455 return SendMsg(%s, flags, (sptr_t)&ft);''',
460 '''int %s(bool doDraw,
466 wxRect pageRect);''',
467 ''' int %s(bool doDraw,
476 if (endPos < startPos) {
482 fr.hdcTarget = target;
483 fr.rc.top = renderRect.GetTop();
484 fr.rc.left = renderRect.GetLeft();
485 fr.rc.right = renderRect.GetRight();
486 fr.rc.bottom = renderRect.GetBottom();
487 fr.rcPage.top = pageRect.GetTop();
488 fr.rcPage.left = pageRect.GetLeft();
489 fr.rcPage.right = pageRect.GetRight();
490 fr.rcPage.bottom = pageRect.GetBottom();
491 fr.chrg.cpMin = startPos;
492 fr.chrg.cpMax = endPos;
494 return SendMsg(%s, doDraw, (sptr_t)&fr);''',
500 'wxString %s(int line) const;',
502 '''wxString %s(int line) const {
503 int len = LineLength(line);
504 if (!len) return wxEmptyString;
506 wxMemoryBuffer mbuf(len+1);
507 char* buf = (char*)mbuf.GetWriteBuf(len+1);
508 SendMsg(%s, line, (sptr_t)buf);
509 mbuf.UngetWriteBuf(len);
511 return stc2wx(buf);''',
513 ('Retrieve the contents of a line.',)),
515 'SetSel' : (None, 0,0,0), #'SetSelection', 0, 0, 0),
522 const int len = SendMsg(SCI_GETSELTEXT, 0, (sptr_t)0);
523 if (!len) return wxEmptyString;
525 wxMemoryBuffer mbuf(len+2);
526 char* buf = (char*)mbuf.GetWriteBuf(len+1);
527 SendMsg(%s, 0, (sptr_t)buf);
528 mbuf.UngetWriteBuf(len);
530 return stc2wx(buf);''',
532 ('Retrieve the selected text.',)),
537 'wxString %s(int startPos, int endPos);',
539 '''wxString %s(int startPos, int endPos) {
540 if (endPos < startPos) {
545 int len = endPos - startPos;
546 if (!len) return wxEmptyString;
547 wxMemoryBuffer mbuf(len+1);
548 char* buf = (char*)mbuf.GetWriteBuf(len);
551 tr.chrg.cpMin = startPos;
552 tr.chrg.cpMax = endPos;
553 SendMsg(%s, 0, (sptr_t)&tr);
554 mbuf.UngetWriteBuf(len);
556 return stc2wx(buf);''',
558 ('Retrieve a range of text.',)),
560 'PointXFromPosition' : (None, 0, 0, 0),
561 'PointYFromPosition' : (None, 0, 0, 0),
563 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
564 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
565 'Null' : (None, 0, 0, 0),
569 'wxString %s() const;',
571 '''wxString %s() const {
572 int len = GetTextLength();
573 wxMemoryBuffer mbuf(len+1); // leave room for the null...
574 char* buf = (char*)mbuf.GetWriteBuf(len+1);
575 SendMsg(%s, len+1, (sptr_t)buf);
576 mbuf.UngetWriteBuf(len);
578 return stc2wx(buf);''',
580 ('Retrieve all the text in the document.', )),
582 'GetDirectFunction' : (None, 0, 0, 0),
583 'GetDirectPointer' : (None, 0, 0, 0),
585 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
586 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
587 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
588 'CallTipSetFore' : ('CallTipSetForeground', 0, 0, 0),
589 'CallTipSetForeHlt' : ('CallTipSetForegroundHighlight', 0, 0, 0),
591 'SetHotspotActiveFore' : ('SetHotspotActiveForeground', 0, 0, 0),
592 'SetHotspotActiveBack' : ('SetHotspotActiveBackground', 0, 0, 0),
593 'GetHotspotActiveFore' : ('GetHotspotActiveForeground', 0, 0, 0),
594 'GetHotspotActiveBack' : ('GetHotspotActiveBackground', 0, 0, 0),
596 'GetCaretLineBack' : ('GetCaretLineBackground', 0, 0, 0),
597 'SetCaretLineBack' : ('SetCaretLineBackground', 0, 0, 0),
601 'int %s(const wxString& text);',
604 int %s(const wxString& text) {
605 const wxWX2MBbuf buf = wx2stc(text);
606 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
611 'int %s(const wxString& text);',
614 int %s(const wxString& text) {
615 const wxWX2MBbuf buf = wx2stc(text);
616 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
617 ('Replace the target text with the argument text after \\\d processing.',
618 'Text is counted so it can contain NULs.',
619 'Looks for \\\d where d is between 1 and 9 and replaces these with the strings',
620 'matched in the last search operation which were surrounded by \( and \).',
621 'Returns the length of the replacement text including any change',
622 'caused by processing the \\\d patterns.',)),
626 'int %s(const wxString& text);',
629 int %s(const wxString& text) {
630 const wxWX2MBbuf buf = wx2stc(text);
631 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
634 # not sure what to do about these yet
635 'TargetAsUTF8' : ( None, 0, 0, 0),
636 'SetLengthForEncode' : ( None, 0, 0, 0),
637 'EncodedFromUTF8' : ( None, 0, 0, 0),
642 'wxString %s(const wxString& key);',
644 '''wxString %s(const wxString& key) {
645 int len = SendMsg(SCI_GETPROPERTY, (sptr_t)(const char*)wx2stc(key), 0);
646 if (!len) return wxEmptyString;
648 wxMemoryBuffer mbuf(len+1);
649 char* buf = (char*)mbuf.GetWriteBuf(len+1);
650 SendMsg(%s, (uptr_t)(const char*)wx2stc(key), (sptr_t)buf);
651 mbuf.UngetWriteBuf(len);
653 return stc2wx(buf);''',
654 ("Retrieve a 'property' value previously set with SetProperty.",)),
656 'GetPropertyExpanded' :
658 'wxString %s(const wxString& key);',
660 '''wxString %s(const wxString& key) {
661 int len = SendMsg(SCI_GETPROPERTYEXPANDED, (uptr_t)(const char*)wx2stc(key), 0);
662 if (!len) return wxEmptyString;
664 wxMemoryBuffer mbuf(len+1);
665 char* buf = (char*)mbuf.GetWriteBuf(len+1);
666 SendMsg(%s, (uptr_t)(const char*)wx2stc(key), (sptr_t)buf);
667 mbuf.UngetWriteBuf(len);
669 return stc2wx(buf);''',
670 ("Retrieve a 'property' value previously set with SetProperty,",
671 "with '$()' variable replacement on returned buffer.")),
673 'GetPropertyInt' : (0, 0, 0,
674 ("Retrieve a 'property' value previously set with SetProperty,",
675 "interpreted as an int AFTER any '$()' variable replacement.")),
682 return (void*)SendMsg(%s);''',
687 'void %s(void* docPointer);',
688 '''void %s(void* docPointer) {
689 SendMsg(%s, 0, (sptr_t)docPointer);''',
696 return (void*)SendMsg(%s);''',
701 'void %s(void* docPointer);',
702 '''void %s(void* docPointer) {
703 SendMsg(%s, 0, (sptr_t)docPointer);''',
708 'void %s(void* docPointer);',
709 '''void %s(void* docPointer) {
710 SendMsg(%s, 0, (sptr_t)docPointer);''',
716 '''void %s(int codePage) {
718 wxASSERT_MSG(codePage == wxSTC_CP_UTF8,
719 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
721 wxASSERT_MSG(codePage != wxSTC_CP_UTF8,
722 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
724 SendMsg(%s, codePage);''',
725 ("Set the code page used to interpret the bytes of the document as characters.",) ),
728 'GrabFocus' : (None, 0, 0, 0),
730 # Rename some that would otherwise hide the wxWindow methods
731 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
732 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
733 'SetCursor' : ('SetSTCCursor', 0, 0, 0),
734 'GetCursor' : ('GetSTCCursor', 0, 0, 0),
736 'LoadLexerLibrary' : (None, 0,0,0),
738 'SetPositionCache' : ('SetPositionCacheSize', 0, 0, 0),
739 'GetPositionCache' : ('GetPositionCacheSize', 0, 0, 0),
741 'GetLexerLanguage' : (None, 0, 0, 0),
742 'SetFontQuality' : (None, 0, 0, 0),
743 'GetFontQuality' : (None, 0, 0, 0),
744 'SetSelection' : (None, 0, 0, 0),
746 'GetCharacterPointer' : (0,
747 'const char* %s() const;',
748 'const char* %s() const {\n'
749 ' return (const char*)SendMsg(%s, 0, 0);',
752 'GetRangePointer' : (0,
753 'const char* %s(int position, int rangeLength) const;',
754 'const char* %s(int position, int rangeLength) const {\n'
755 ' return (const char*)SendMsg(%s, position, rangeLength);',
761 'wxString %s() const;',
763 '''wxString %s() const {
765 int len = SendMsg(msg, 0, (sptr_t)NULL);
766 if (!len) return wxEmptyString;
768 wxMemoryBuffer mbuf(len+1);
769 char* buf = (char*)mbuf.GetWriteBuf(len+1);
770 SendMsg(msg, 0, (sptr_t)buf);
771 mbuf.UngetWriteBuf(len);
773 return stc2wx(buf);''',
775 ('Get the set of characters making up words for when moving or selecting by word.',)),
779 'wxString %s(int tagNumber) const;',
781 '''wxString %s(int tagNumber) const {
783 int len = SendMsg(msg, tagNumber, (sptr_t)NULL);
784 if (!len) return wxEmptyString;
786 wxMemoryBuffer mbuf(len+1);
787 char* buf = (char*)mbuf.GetWriteBuf(len+1);
788 SendMsg(msg, tagNumber, (sptr_t)buf);
789 mbuf.UngetWriteBuf(len);
791 return stc2wx(buf);''',
794 'GetWhitespaceChars' :
796 'wxString %s() const;',
798 '''wxString %s() const {
800 int len = SendMsg(msg, 0, (sptr_t)NULL);
801 if (!len) return wxEmptyString;
803 wxMemoryBuffer mbuf(len+1);
804 char* buf = (char*)mbuf.GetWriteBuf(len+1);
805 SendMsg(msg, 0, (sptr_t)buf);
806 mbuf.UngetWriteBuf(len);
808 return stc2wx(buf);''',
812 'GetPunctuationChars' :
814 'wxString %s() const;',
816 '''wxString %s() const {
818 int len = SendMsg(msg, 0, (sptr_t)NULL);
819 if (!len) return wxEmptyString;
821 wxMemoryBuffer mbuf(len+1);
822 char* buf = (char*)mbuf.GetWriteBuf(len+1);
823 SendMsg(msg, 0, (sptr_t)buf);
824 mbuf.UngetWriteBuf(len);
826 return stc2wx(buf);''',
832 'wxString %s() const;',
834 '''wxString %s() const {
836 int len = SendMsg(msg, 0, (sptr_t)NULL);
837 if (!len) return wxEmptyString;
839 wxMemoryBuffer mbuf(len+1);
840 char* buf = (char*)mbuf.GetWriteBuf(len+1);
841 SendMsg(msg, 0, (sptr_t)buf);
842 mbuf.UngetWriteBuf(len);
844 return stc2wx(buf);''',
851 'wxString %s(const wxString& name) const;',
853 '''wxString %s(const wxString& name) const {
855 int len = SendMsg(msg, (sptr_t)(const char*)wx2stc(name), (sptr_t)NULL);
856 if (!len) return wxEmptyString;
858 wxMemoryBuffer mbuf(len+1);
859 char* buf = (char*)mbuf.GetWriteBuf(len+1);
860 SendMsg(msg, (sptr_t)(const char*)wx2stc(name), (sptr_t)buf);
861 mbuf.UngetWriteBuf(len);
863 return stc2wx(buf);''',
868 'DescribeKeyWordSets' :
870 'wxString %s() const;',
872 '''wxString %s() const {
874 int len = SendMsg(msg, 0, (sptr_t)NULL);
875 if (!len) return wxEmptyString;
877 wxMemoryBuffer mbuf(len+1);
878 char* buf = (char*)mbuf.GetWriteBuf(len+1);
879 SendMsg(msg, 0, (sptr_t)buf);
880 mbuf.UngetWriteBuf(len);
882 return stc2wx(buf);''',
886 'MarkerDefineRGBAImage' :
888 'void %s(int markerNumber, const unsigned char* pixels);',
889 '''void %s(int markerNumber, const unsigned char* pixels) {
890 SendMsg(%s, markerNumber, (sptr_t)pixels);''',
894 'RegisterRGBAImage' :
896 'void %s(int type, const unsigned char* pixels);',
897 '''void %s(int type, const unsigned char* pixels) {
898 SendMsg(%s, type, (sptr_t)pixels);''',
902 # I think these are only available on the native OSX backend, so
903 # don't add them to the wx API...
904 'FindIndicatorShow' : (None, 0,0,0),
905 'FindIndicatorFlash' : (None, 0,0,0),
906 'FindIndicatorHide' : (None, 0,0,0),
910 'void* %s(int bytes) const;',
911 """void* %s(int bytes) const {
912 return (void*)(sptr_t)SendMsg(%s, bytes); """,
917 'void* %s(int operation, void* pointer);',
918 """void* %s(int operation, void* pointer) {
919 return (void*)(sptr_t)SendMsg(%s, operation, (sptr_t)pointer); """,
924 ('Retrieve the effect of pasting when there are multiple selections.',)),
930 # all Scintilla getters are transformed into const member of wxSTC class but
931 # some non-getter methods are also logically const and this set contains their
932 # names (notice that it's useless to include here methods manually overridden
934 constNonGetterMethods
= (
943 #----------------------------------------------------------------------------
945 def processIface(iface
, h_tmplt
, cpp_tmplt
, ih_tmplt
, h_dest
, cpp_dest
, docstr_dest
, ih_dest
):
952 fi
= FileInput(iface
)
955 if line
[:2] == '##' or line
== '':
960 if line
[:2] == '# ': # a doc string
961 curDocStrings
.append(line
[2:])
964 parseVal(line
[4:], values
, curDocStrings
)
967 elif op
== 'fun ' or op
== 'set ' or op
== 'get ':
968 parseFun(line
[4:], methods
, curDocStrings
, cmds
, op
== 'get ')
972 if line
[4:].strip() == 'Deprecated':
973 break # skip the rest of the file
985 print('***** Unknown line type: %s' % line
)
990 data
['VALUES'] = processVals(values
)
991 data
['CMDS'] = processVals(cmds
)
992 defs
, imps
, docstrings
, idefs
= processMethods(methods
)
993 data
['METHOD_DEFS'] = defs
994 data
['METHOD_IDEFS'] = idefs
995 data
['METHOD_IMPS'] = imps
998 h_text
= open(h_tmplt
).read()
999 ih_text
= open(ih_tmplt
).read()
1000 cpp_text
= open(cpp_tmplt
).read()
1002 # do the substitutions
1003 h_text
= h_text
% data
1004 cpp_text
= cpp_text
% data
1005 ih_text
= ih_text
% data
1007 # write out destination files
1008 open(h_dest
, 'w').write(h_text
)
1009 open(cpp_dest
, 'w').write(cpp_text
)
1011 open(docstr_dest
, 'w').write(docstrings
)
1012 open(ih_dest
, 'w').write(ih_text
)
1015 def joinWithNewLines(values
):
1016 return '\n'.join(values
)
1018 #----------------------------------------------------------------------------
1020 def processVals(values
):
1022 for name
, value
, docs
in values
:
1026 text
.append('/// ' + x
)
1027 text
.append('#define %s %s' % (name
, value
))
1028 return joinWithNewLines(text
)
1030 #----------------------------------------------------------------------------
1032 def processMethods(methods
):
1038 for retType
, name
, number
, param1
, param2
, docs
, is_const
in methods
:
1039 retType
= retTypeMap
.get(retType
, retType
)
1040 params
= makeParamString(param1
, param2
)
1042 name
, theDef
, theImp
, docs
= checkMethodOverride(name
, number
, docs
)
1048 st
= 'DocStr(wxStyledTextCtrl::%s,\n' \
1049 '"%s", "");\n' % (name
, joinWithNewLines(docs
))
1052 # Build the method definition for the .h file
1056 defs
.append(' // ' + x
)
1058 theDef
= ' %s %s(%s)' % (retType
, name
, params
)
1060 theDef
= theDef
+ ' const'
1061 theDef
= theDef
+ ';'
1064 # Build the method definition for the interface .h file
1067 idefs
.append(' /**')
1069 idefs
.append(' ' + x
)
1071 if name
== 'GetCurLine':
1072 idefs
.append(' wxString GetCurLine(int* linePos=NULL);')
1074 idefs
.append(theDef
)
1076 # Build the method implementation string
1080 imps
.append('// ' + x
)
1082 theImp
= '%s wxStyledTextCtrl::%s(%s)' % (retType
, name
, params
)
1084 theImp
= theImp
+ ' const'
1085 theImp
= theImp
+ '\n{\n '
1086 if retType
== 'wxColour':
1087 theImp
= theImp
+ 'long c = '
1088 elif retType
!= 'void':
1089 theImp
= theImp
+ 'return '
1090 theImp
= theImp
+ 'SendMsg(%s, %s, %s)' % (number
,
1091 makeArgString(param1
),
1092 makeArgString(param2
))
1093 if retType
== 'bool':
1094 theImp
= theImp
+ ' != 0'
1095 if retType
== 'wxColour':
1096 theImp
= theImp
+ ';\n return wxColourFromLong(c)'
1098 theImp
= theImp
+ ';\n}'
1102 return joinWithNewLines(defs
), joinWithNewLines(imps
), joinWithNewLines(dstr
), joinWithNewLines(idefs
)
1105 #----------------------------------------------------------------------------
1107 def checkMethodOverride(name
, number
, docs
):
1108 theDef
= theImp
= None
1109 if name
in methodOverrideMap
:
1110 item
= methodOverrideMap
[name
]
1116 theDef
= ' ' + (item
[1] % name
)
1118 theImp
= item
[2] % ('wxStyledTextCtrl::'+name
, number
) + '\n}'
1122 print("************* " + name
)
1125 return name
, theDef
, theImp
, docs
1127 #----------------------------------------------------------------------------
1129 def makeArgString(param
):
1136 return '(sptr_t)(const char*)wx2stc(%s)' % name
1138 return 'wxColourAsLong(%s)' % name
1142 #----------------------------------------------------------------------------
1144 def makeParamString(param1
, param2
):
1147 aType
= paramTypeMap
.get(param
[0], param
[0])
1148 return aType
+ ' ' + param
[1]
1155 st
= st
+ doOne(param2
)
1159 #----------------------------------------------------------------------------
1161 def parseVal(line
, values
, docs
):
1162 name
, val
= line
.split('=')
1164 # remove prefixes such as SCI, etc.
1165 for old
, new
in valPrefixes
:
1167 if name
[:lo
] == old
:
1170 name
= new
+ name
[lo
:]
1172 # add it to the list
1173 values
.append( ('wxSTC_' + name
, val
, docs
) )
1175 #----------------------------------------------------------------------------
1177 funregex
= re
.compile(r
'\s*([a-zA-Z0-9_]+)' # <ws>return type
1178 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
1180 '\(([ a-zA-Z0-9_]*),' # (param,
1181 '([ a-zA-Z0-9_]*),*\)') # param)
1183 def parseFun(line
, methods
, docs
, values
, is_const
):
1184 def parseParam(param
):
1185 param
= param
.strip()
1189 param
= tuple(param
.split())
1192 mo
= funregex
.match(line
)
1194 print("***** Line doesn't match! : %s" % line
)
1196 retType
, name
, number
, param1
, param2
= mo
.groups()
1198 param1
= parseParam(param1
)
1199 param2
= parseParam(param2
)
1201 # Special case. For the key command functions we want a value defined too
1204 if (type(v
) == type(()) and v
[0] <= num
<= v
[1]) or v
== num
:
1205 parseVal('CMD_%s=%s' % (name
.upper(), number
), values
, docs
)
1207 # if we are not also doing a function for CMD values, then
1208 # just return, otherwise fall through to the append blow.
1209 if not FUNC_FOR_CMD
:
1212 methods
.append( (retType
, name
, number
, param1
, param2
, tuple(docs
),
1213 is_const
or name
in constNonGetterMethods
) )
1216 #----------------------------------------------------------------------------
1220 # TODO: parse command line args to replace default input/output files???
1222 if not os
.path
.exists(IFACE
):
1223 print('Please run this script from src/stc subdirectory.')
1227 processIface(IFACE
, H_TEMPLATE
, CPP_TEMPLATE
, IH_TEMPLATE
, H_DEST
, CPP_DEST
, DOCSTR_DEST
, IH_DEST
)
1231 if __name__
== '__main__':
1234 #----------------------------------------------------------------------------