-#!/bin/env python
+#!/usr/bin/env python
#----------------------------------------------------------------------------
# Name: gen_iface.py
# Purpose: Generate stc.h and stc.cpp from the info in Scintilla.iface
CPP_TEMPLATE = os.path.abspath('./stc.cpp.in')
H_DEST = os.path.abspath('../../include/wx/stc/stc.h')
CPP_DEST = os.path.abspath('./stc.cpp')
-DOCSTR_DEST = os.path.abspath('../../../wxPython/contrib/stc/_stc_gendocs.i')
+DOCSTR_DEST = '/dev/null' #os.path.abspath('../../../wxPython/contrib/stc/_stc_gendocs.i')
# Value prefixes to convert
]
# Message function values that should have a CMD_ constant generated
-cmdValues = [ (2300, 2349),
- 2011,
+cmdValues = [ 2011,
2013,
(2176, 2180),
+ (2300, 2349),
(2390, 2393),
(2395, 2396),
2404,
(2413, 2416),
(2426, 2442),
(2450, 2455),
+ 2518,
]
'GetCharAt' :
( 0, 0,
- '''int %s(int pos) {
+ '''int %s(int pos) const {
return (unsigned char)SendMsg(%s, pos, 0);''',
0),
'GetStyleAt' :
( 0, 0,
- '''int %s(int pos) {
+ '''int %s(int pos) const {
return (unsigned char)SendMsg(%s, pos, 0);''',
0),
'PositionFromPoint' :
(0,
- 'int %s(wxPoint pt);',
+ 'int %s(wxPoint pt) const;',
- '''int %s(wxPoint pt) {
+ '''int %s(wxPoint pt) const {
return SendMsg(%s, pt.x, pt.y);''',
0),
// convert bmp to a xpm in a string
wxMemoryOutputStream strm;
wxImage img = bmp.ConvertToImage();
+ if (img.HasAlpha())
+ img.ConvertAlphaToMask();
img.SaveFile(strm, wxBITMAP_TYPE_XPM);
size_t len = strm.GetSize();
char* buff = new char[len+1];
'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
+
+ 'StyleGetFore' : ('StyleGetForeground', 0, 0, 0),
+ 'StyleGetBack' : ('StyleGetBackground', 0, 0, 0),
'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
'SetSelFore' : ('SetSelForeground', 0, 0, 0),
'SetSelBack' : ('SetSelBackground', 0, 0, 0),
'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
+ 'StyleGetFont' :
+ ('StyleGetFaceName',
+ 'wxString %s(int style);',
+ '''wxString %s(int style) {
+ long msg = %s;
+ long len = SendMsg(msg, style, 0);
+ wxMemoryBuffer mbuf(len+1);
+ char* buf = (char*)mbuf.GetWriteBuf(len+1);
+ SendMsg(msg, style, (long)buf);
+ mbuf.UngetWriteBuf(len);
+ mbuf.AppendByte(0);
+ return stc2wx(buf);''',
+ ('Get the font facename of a style',)),
'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
+ 'StyleSetCharacterSet' : (None, 0, 0, 0),
'AssignCmdKey' :
('CmdKeyAssign',
'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
+ 'IndicSetUnder': ('IndicatorSetUnder', 0, 0, 0),
+ 'IndicGetUnder': ('IndicatorGetUnder', 0, 0, 0),
'SetWhitespaceFore' : ('SetWhitespaceForeground', 0, 0, 0),
'SetWhitespaceBack' : ('SetWhitespaceBackground', 0, 0, 0),
'AutoCGetTypeSeparator' : ('AutoCompGetTypeSeparator', 0, 0, 0),
'AutoCSetTypeSeparator' : ('AutoCompSetTypeSeparator', 0, 0, 0),
'AutoCGetCurrent' : ('AutoCompGetCurrent', 0, 0, 0),
+ 'AutoCSetMaxWidth' : ('AutoCompSetMaxWidth', 0, 0, 0),
+ 'AutoCGetMaxWidth' : ('AutoCompGetMaxWidth', 0, 0, 0),
+ 'AutoCSetMaxHeight' : ('AutoCompSetMaxHeight', 0, 0, 0),
+ 'AutoCGetMaxHeight' : ('AutoCompGetMaxHeight', 0, 0, 0),
+ 'AutoCGetMaxHeight' : ('AutoCompGetMaxHeight', 0, 0, 0),
'RegisterImage' :
(0,
// convert bmp to a xpm in a string
wxMemoryOutputStream strm;
wxImage img = bmp.ConvertToImage();
+ if (img.HasAlpha())
+ img.ConvertAlphaToMask();
img.SaveFile(strm, wxBITMAP_TYPE_XPM);
size_t len = strm.GetSize();
char* buff = new char[len+1];
int startPos,
int endPos,
wxDC* draw,
- wxDC* target,
+ wxDC* target,
wxRect renderRect,
wxRect pageRect);''',
''' int %s(bool doDraw,
int startPos,
int endPos,
wxDC* draw,
- wxDC* target,
+ wxDC* target,
wxRect renderRect,
wxRect pageRect) {
RangeToFormat fr;
'GetLine' :
(0,
- 'wxString %s(int line);',
+ 'wxString %s(int line) const;',
- '''wxString %s(int line) {
+ '''wxString %s(int line) const {
int len = LineLength(line);
if (!len) return wxEmptyString;
'GetText' :
(0,
- 'wxString %s();',
+ 'wxString %s() const;',
- '''wxString %s() {
+ '''wxString %s() const {
int len = GetTextLength();
wxMemoryBuffer mbuf(len+1); // leave room for the null...
char* buf = (char*)mbuf.GetWriteBuf(len+1);
'SetHotspotActiveFore' : ('SetHotspotActiveForeground', 0, 0, 0),
'SetHotspotActiveBack' : ('SetHotspotActiveBackground', 0, 0, 0),
+ 'GetHotspotActiveFore' : ('GetHotspotActiveForeground', 0, 0, 0),
+ 'GetHotspotActiveBack' : ('GetHotspotActiveBackground', 0, 0, 0),
+ 'GetCaretLineBack' : ('GetCaretLineBackground', 0, 0, 0),
+ 'SetCaretLineBack' : ('SetCaretLineBackground', 0, 0, 0),
'ReplaceTarget' :
(0,
'TargetAsUTF8' : ( None, 0, 0, 0),
'SetLengthForEncode' : ( None, 0, 0, 0),
'EncodedFromUTF8' : ( None, 0, 0, 0),
-
+
+
+ 'GetProperty' :
+ (0,
+ 'wxString %s(const wxString& key);',
+
+ '''wxString %s(const wxString& key) {
+ int len = SendMsg(SCI_GETPROPERTY, (long)(const char*)wx2stc(key), 0);
+ if (!len) return wxEmptyString;
+
+ wxMemoryBuffer mbuf(len+1);
+ char* buf = (char*)mbuf.GetWriteBuf(len+1);
+ SendMsg(%s, (long)(const char*)wx2stc(key), (long)buf);
+ mbuf.UngetWriteBuf(len);
+ mbuf.AppendByte(0);
+ return stc2wx(buf);''',
+ ("Retrieve a 'property' value previously set with SetProperty.",)),
+
+ 'GetPropertyExpanded' :
+ (0,
+ 'wxString %s(const wxString& key);',
+
+ '''wxString %s(const wxString& key) {
+ int len = SendMsg(SCI_GETPROPERTYEXPANDED, (long)(const char*)wx2stc(key), 0);
+ if (!len) return wxEmptyString;
+
+ wxMemoryBuffer mbuf(len+1);
+ char* buf = (char*)mbuf.GetWriteBuf(len+1);
+ SendMsg(%s, (long)(const char*)wx2stc(key), (long)buf);
+ mbuf.UngetWriteBuf(len);
+ mbuf.AppendByte(0);
+ return stc2wx(buf);''',
+ ("Retrieve a 'property' value previously set with SetProperty,",
+ "with '$()' variable replacement on returned buffer.")),
+
+ 'GetPropertyInt' : (0, 0, 0,
+ ("Retrieve a 'property' value previously set with SetProperty,",
+ "interpreted as an int AFTER any '$()' variable replacement.")),
+
'GetDocPointer' :
(0,
'LoadLexerLibrary' : (None, 0,0,0),
+ 'SetPositionCache' : ('SetPositionCacheSize', 0, 0, 0),
+ 'GetPositionCache' : ('GetPositionCacheSize', 0, 0, 0),
+
'' : ('', 0, 0, 0),
}
+# all Scintilla getters are transformed into const member of wxSTC class but
+# some non-getter methods are also logically const and this set contains their
+# names (notice that it's useless to include here methods manually overridden
+# above)
+constNonGetterMethods = set((
+ 'LineFromPosition',
+ 'PositionFromLine',
+ 'LineLength',
+ 'CanRedo',
+ 'CanUndo',
+))
+
#----------------------------------------------------------------------------
def processIface(iface, h_tmplt, cpp_tmplt, h_dest, cpp_dest, docstr_dest):
curDocStrings = []
elif op == 'fun ' or op == 'set ' or op == 'get ':
- parseFun(line[4:], methods, curDocStrings, cmds)
+ parseFun(line[4:], methods, curDocStrings, cmds, op == 'get ')
curDocStrings = []
elif op == 'cat ':
imps = []
dstr = []
- for retType, name, number, param1, param2, docs in methods:
+ for retType, name, number, param1, param2, docs, is_const in methods:
retType = retTypeMap.get(retType, retType)
params = makeParamString(param1, param2)
st = 'DocStr(wxStyledTextCtrl::%s,\n' \
'"%s", "");\n' % (name, '\n'.join(docs))
dstr.append(st)
-
+
# Build the method definition for the .h file
if docs:
defs.append('')
for x in docs:
defs.append(' // ' + x)
if not theDef:
- theDef = ' %s %s(%s);' % (retType, name, params)
+ theDef = ' %s %s(%s)' % (retType, name, params)
+ if is_const:
+ theDef = theDef + ' const'
+ theDef = theDef + ';'
defs.append(theDef)
# Build the method implementation string
for x in docs:
imps.append('// ' + x)
if not theImp:
- theImp = '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType, name, params)
-
+ theImp = '%s wxStyledTextCtrl::%s(%s)' % (retType, name, params)
+ if is_const:
+ theImp = theImp + ' const'
+ theImp = theImp + '\n{\n '
if retType == 'wxColour':
theImp = theImp + 'long c = '
elif retType != 'void':
'\(([ a-zA-Z0-9_]*),' # (param,
'([ a-zA-Z0-9_]*)\)') # param)
-def parseFun(line, methods, docs, values):
+def parseFun(line, methods, docs, values, is_const):
def parseParam(param):
param = string.strip(param)
if param == '':
for v in cmdValues:
if (type(v) == type(()) and v[0] <= num <= v[1]) or v == num:
parseVal('CMD_%s=%s' % (string.upper(name), number), values, docs)
-
+
# if we are not also doing a function for CMD values, then
# just return, otherwise fall through to the append blow.
if not FUNC_FOR_CMD:
return
-
- methods.append( (retType, name, number, param1, param2, tuple(docs)) )
+
+ methods.append( (retType, name, number, param1, param2, tuple(docs),
+ is_const or name in constNonGetterMethods) )
#----------------------------------------------------------------------------
def main(args):
# TODO: parse command line args to replace default input/output files???
+ if not os.path.exists(IFACE):
+ print 'Please run this script from src/stc subdirectory.'
+ sys.exit(1)
+
# Now just do it
processIface(IFACE, H_TEMPLATE, CPP_TEMPLATE, H_DEST, CPP_DEST, DOCSTR_DEST)