]> git.saurik.com Git - wxWidgets.git/blame - src/stc/gen_iface.py
Applied patch #15540: wxRichTextTable: crashes due to an invalid focus object (dghart)
[wxWidgets.git] / src / stc / gen_iface.py
CommitLineData
3a38f8c1 1#!/usr/bin/env python
f97d84a6
RD
2#----------------------------------------------------------------------------
3# Name: gen_iface.py
4# Purpose: Generate stc.h and stc.cpp from the info in Scintilla.iface
5#
6# Author: Robin Dunn
7#
8# Created: 5-Sept-2000
f97d84a6 9# Copyright: (c) 2000 by Total Control Software
526954c5 10# Licence: wxWindows licence
f97d84a6
RD
11#----------------------------------------------------------------------------
12
13
65ec6247 14import sys, string, re, os
f97d84a6
RD
15from fileinput import FileInput
16
17
65ec6247
RD
18IFACE = os.path.abspath('./scintilla/include/Scintilla.iface')
19H_TEMPLATE = os.path.abspath('./stc.h.in')
6d7b19b0 20IH_TEMPLATE = os.path.abspath('./stc.interface.h.in')
65ec6247
RD
21CPP_TEMPLATE = os.path.abspath('./stc.cpp.in')
22H_DEST = os.path.abspath('../../include/wx/stc/stc.h')
6d7b19b0 23IH_DEST = os.path.abspath('../../interface/wx/stc/stc.h')
65ec6247 24CPP_DEST = os.path.abspath('./stc.cpp')
9e96e16f
RD
25if len(sys.argv) > 1 and sys.argv[1] == '--wxpython':
26 DOCSTR_DEST = os.path.abspath('../../../wxPython/src/_stc_gendocs.i')
27else:
cab16e6c 28 DOCSTR_DEST = None
f97d84a6
RD
29
30
31# Value prefixes to convert
32valPrefixes = [('SCI_', ''),
33 ('SC_', ''),
37d62433 34 ('SCN_', None), # just toss these out...
f97d84a6 35 ('SCEN_', None),
9e96e16f 36 ('SC_EFF', None),
f97d84a6
RD
37 ('SCE_', ''),
38 ('SCLEX_', 'LEX_'),
39 ('SCK_', 'KEY_'),
40 ('SCFIND_', 'FIND_'),
41 ('SCWS_', 'WS_'),
42]
43
c26dba42 44# Message function values that should have a CMD_ constant generated
7e0c58e9 45cmdValues = [ 2011,
2b5f62a0
VZ
46 2013,
47 (2176, 2180),
7e0c58e9 48 (2300, 2349),
2b5f62a0
VZ
49 (2390, 2393),
50 (2395, 2396),
9e730a78
RD
51 2404,
52 (2413, 2416),
8e54aaed 53 (2426, 2442),
c26dba42 54 (2450, 2455),
7e0c58e9 55 2518,
54173563
RD
56 (2619, 2621),
57 (2628, 2629)
2b5f62a0 58 ]
f97d84a6
RD
59
60
b0ad146a 61# Should a function be also generated for the CMDs?
713a0408 62FUNC_FOR_CMD = 1
c26dba42
RD
63
64
f97d84a6
RD
65# Map some generic typenames to wx types, using return value syntax
66retTypeMap = {
67 'position': 'int',
68 'string': 'wxString',
69 'colour': 'wxColour',
70 }
71
72# Map some generic typenames to wx types, using parameter syntax
73paramTypeMap = {
74 'position': 'int',
75 'string': 'const wxString&',
76 'colour': 'const wxColour&',
77 'keymod': 'int',
78}
79
80# Map of method info that needs tweaked. Either the name needs changed, or
81# the method definition/implementation. Tuple items are:
82#
83# 1. New method name. None to skip the method, 0 to leave the
84# default name.
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.
88#
89methodOverrideMap = {
90 'AddText' : (0,
91 'void %s(const wxString& text);',
92
93 '''void %s(const wxString& text) {
0bcbf72b
VZ
94 const wxWX2MBbuf buf = wx2stc(text);
95 SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
f97d84a6
RD
96 0),
97
98 'AddStyledText' : (0,
10ef30eb 99 'void %s(const wxMemoryBuffer& data);',
f97d84a6 100
10ef30eb 101 '''void %s(const wxMemoryBuffer& data) {
b796ba39 102 SendMsg(%s, data.GetDataLen(), (sptr_t)data.GetData());''',
f97d84a6
RD
103 0),
104
41a499cd
RD
105 'AppendText' : (0,
106 'void %s(const wxString& text);',
107
108 '''void %s(const wxString& text) {
0bcbf72b
VZ
109 const wxWX2MBbuf buf = wx2stc(text);
110 SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
41a499cd
RD
111 0),
112
f97d84a6
RD
113 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
114 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
115
9e730a78
RD
116 'GetCharAt' :
117 ( 0, 0,
8e0945da 118 '''int %s(int pos) const {
9e730a78
RD
119 return (unsigned char)SendMsg(%s, pos, 0);''',
120 0),
121
122 'GetStyleAt' :
123 ( 0, 0,
8e0945da 124 '''int %s(int pos) const {
9e730a78
RD
125 return (unsigned char)SendMsg(%s, pos, 0);''',
126 0),
127
128 'GetStyledText' :
129 (0,
130 'wxMemoryBuffer %s(int startPos, int endPos);',
131
132 '''wxMemoryBuffer %s(int startPos, int endPos) {
133 wxMemoryBuffer buf;
134 if (endPos < startPos) {
135 int temp = startPos;
136 startPos = endPos;
137 endPos = temp;
138 }
139 int len = endPos - startPos;
140 if (!len) return buf;
141 TextRange tr;
142 tr.lpstrText = (char*)buf.GetWriteBuf(len*2+1);
143 tr.chrg.cpMin = startPos;
144 tr.chrg.cpMax = endPos;
b796ba39 145 len = SendMsg(%s, 0, (sptr_t)&tr);
9e730a78
RD
146 buf.UngetWriteBuf(len);
147 return buf;''',
148
149 ('Retrieve a buffer of cells.',)),
150
151
152 'PositionFromPoint' :
153 (0,
2bfca191 154 'int %s(wxPoint pt) const;',
9e730a78 155
2bfca191 156 '''int %s(wxPoint pt) const {
9e730a78
RD
157 return SendMsg(%s, pt.x, pt.y);''',
158 0),
159
160 'GetCurLine' :
161 (0,
162 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
163
164 '''wxString %s(int* linePos) {
165 int len = LineLength(GetCurrentLine());
166 if (!len) {
167 if (linePos) *linePos = 0;
168 return wxEmptyString;
169 }
170
171 wxMemoryBuffer mbuf(len+1);
172 char* buf = (char*)mbuf.GetWriteBuf(len+1);
173
b796ba39 174 int pos = SendMsg(%s, len+1, (sptr_t)buf);
9e730a78
RD
175 mbuf.UngetWriteBuf(len);
176 mbuf.AppendByte(0);
177 if (linePos) *linePos = pos;
178 return stc2wx(buf);''',
179
180 0),
f97d84a6
RD
181
182 'SetUsePalette' : (None, 0,0,0),
183
184 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
185 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
54173563 186 'MarkerSetBackSelected' : ('MarkerSetBackgroundSelected', 0,0,0),
f97d84a6 187
9e96e16f
RD
188 'MarkerSymbolDefined' : ('GetMarkerSymbolDefined', 0, 0, 0),
189
9e730a78
RD
190 'MarkerDefine' :
191 (0,
192 '''void %s(int markerNumber, int markerSymbol,
193 const wxColour& foreground = wxNullColour,
194 const wxColour& background = wxNullColour);''',
195
196 '''void %s(int markerNumber, int markerSymbol,
197 const wxColour& foreground,
198 const wxColour& background) {
199
200 SendMsg(%s, markerNumber, markerSymbol);
f2b09926 201 if (foreground.IsOk())
9e730a78 202 MarkerSetForeground(markerNumber, foreground);
f2b09926 203 if (background.IsOk())
9e730a78
RD
204 MarkerSetBackground(markerNumber, background);''',
205
206 ('Set the symbol used for a particular marker number,',
207 'and optionally the fore and background colours.')),
208
209
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();
e45b3f17
RD
217 if (img.HasAlpha())
218 img.ConvertAlphaToMask();
9e730a78
RD
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);
223 buff[len] = 0;
b796ba39 224 SendMsg(%s, markerNumber, (sptr_t)buff);
9e730a78
RD
225 delete [] buff;
226 ''',
227 ('Define a marker from a bitmap',)),
f97d84a6 228
f97d84a6
RD
229
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),
54173563
RD
238 'SetMarginCursorN' : ('SetMarginCursor', 0, 0, 0),
239 'GetMarginCursorN' : ('GetMarginCursor', 0, 0, 0),
240
9e96e16f
RD
241 'MarginGetText' :
242 (0,
243 'wxString %s(int line) const;',
244
245 '''wxString %s(int line) const {
246 long msg = %s;
247 long len = SendMsg(msg, line, 0);
248
249 wxMemoryBuffer mbuf(len+1);
250 char* buf = (char*)mbuf.GetWriteBuf(len+1);
251 SendMsg(msg, line, (sptr_t)buf);
252 mbuf.UngetWriteBuf(len);
253 mbuf.AppendByte(0);
254 return stc2wx(buf);''',
255 0),
256
257 'MarginGetStyles' :
258 (0,
259 'wxString %s(int line) const;',
260
261 '''wxString %s(int line) const {
262 long msg = %s;
263 long len = SendMsg(msg, line, 0);
264
265 wxMemoryBuffer mbuf(len+1);
266 char* buf = (char*)mbuf.GetWriteBuf(len+1);
267 SendMsg(msg, line, (sptr_t)buf);
268 mbuf.UngetWriteBuf(len);
269 mbuf.AppendByte(0);
270 return stc2wx(buf);''',
271 0),
272
273 'SetAdditionalSelFore' : ('SetAdditionalSelForeground', 0, 0, 0),
274 'SetAdditionalSelBack' : ('SetAdditionalSelBackground', 0, 0, 0),
275 'SetAdditionalCaretFore' : ('SetAdditionalCaretForeground', 0, 0, 0),
276 'GetAdditionalCaretFore' : ('GetAdditionalCaretForeground', 0, 0, 0),
277
278 'AnnotationGetText' :
279 (0,
280 'wxString %s(int line) const;',
281
282 '''wxString %s(int line) const {
283 long msg = %s;
284 long len = SendMsg(msg, line, 0);
285
286 wxMemoryBuffer mbuf(len+1);
287 char* buf = (char*)mbuf.GetWriteBuf(len+1);
288 SendMsg(msg, line, (sptr_t)buf);
289 mbuf.UngetWriteBuf(len);
290 mbuf.AppendByte(0);
291 return stc2wx(buf);''',
292 0),
293
294 'AnnotationGetStyles' :
295 (0,
296 'wxString %s(int line) const;',
297
298 '''wxString %s(int line) const {
299 long msg = %s;
300 long len = SendMsg(msg, line, 0);
301
302 wxMemoryBuffer mbuf(len+1);
303 char* buf = (char*)mbuf.GetWriteBuf(len+1);
304 SendMsg(msg, line, (sptr_t)buf);
305 mbuf.UngetWriteBuf(len);
306 mbuf.AppendByte(0);
307 return stc2wx(buf);''',
308 0),
7e0c58e9
RD
309
310 'StyleGetFore' : ('StyleGetForeground', 0, 0, 0),
311 'StyleGetBack' : ('StyleGetBackground', 0, 0, 0),
f97d84a6
RD
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),
591e2d8e 317 'StyleGetFont' :
7e0c58e9
RD
318 ('StyleGetFaceName',
319 'wxString %s(int style);',
320 '''wxString %s(int style) {
321 long msg = %s;
322 long len = SendMsg(msg, style, 0);
323 wxMemoryBuffer mbuf(len+1);
324 char* buf = (char*)mbuf.GetWriteBuf(len+1);
b796ba39 325 SendMsg(msg, style, (sptr_t)buf);
7e0c58e9
RD
326 mbuf.UngetWriteBuf(len);
327 mbuf.AppendByte(0);
328 return stc2wx(buf);''',
329 ('Get the font facename of a style',)),
f97d84a6 330 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
3727c043 331 'StyleSetCharacterSet' : (None, 0, 0, 0),
591e2d8e 332
9e730a78
RD
333 'AssignCmdKey' :
334 ('CmdKeyAssign',
335 'void %s(int key, int modifiers, int cmd);',
f97d84a6 336
9e730a78
RD
337 '''void %s(int key, int modifiers, int cmd) {
338 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
339 0),
f97d84a6 340
f97d84a6 341
9e730a78
RD
342 'ClearCmdKey' :
343 ('CmdKeyClear',
344 'void %s(int key, int modifiers);',
f97d84a6 345
9e730a78
RD
346 '''void %s(int key, int modifiers) {
347 SendMsg(%s, MAKELONG(key, modifiers));''',
348 0),
f97d84a6
RD
349
350 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
351
352
9e730a78
RD
353 'SetStylingEx' :
354 ('SetStyleBytes',
355 'void %s(int length, char* styleBytes);',
f97d84a6 356
9e730a78 357 '''void %s(int length, char* styleBytes) {
b796ba39 358 SendMsg(%s, length, (sptr_t)styleBytes);''',
9e730a78 359 0),
f97d84a6
RD
360
361
9e96e16f
RD
362 'IndicSetAlpha' : ('IndicatorSetAlpha', 0, 0, 0),
363 'IndicGetAlpha' : ('IndicatorGetAlpha', 0, 0, 0),
54173563
RD
364 'IndicSetOutlineAlpha' : ('IndicatorSetOutlineAlpha', 0, 0, 0),
365 'IndicGetOutlineAlpha' : ('IndicatorGetOutlineAlpha', 0, 0, 0),
f97d84a6
RD
366 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
367 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
368 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
369 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
7e0c58e9
RD
370 'IndicSetUnder': ('IndicatorSetUnder', 0, 0, 0),
371 'IndicGetUnder': ('IndicatorGetUnder', 0, 0, 0),
591e2d8e 372
f114b858
RD
373 'SetWhitespaceFore' : ('SetWhitespaceForeground', 0, 0, 0),
374 'SetWhitespaceBack' : ('SetWhitespaceBackground', 0, 0, 0),
375
f97d84a6
RD
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),
65ec6247
RD
392 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
393 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
1a2fb4cd
RD
394 'AutoCSetDropRestOfWord' : ('AutoCompSetDropRestOfWord', 0,0,0),
395 'AutoCGetDropRestOfWord' : ('AutoCompGetDropRestOfWord', 0,0,0),
9e730a78
RD
396 'AutoCGetTypeSeparator' : ('AutoCompGetTypeSeparator', 0, 0, 0),
397 'AutoCSetTypeSeparator' : ('AutoCompSetTypeSeparator', 0, 0, 0),
8e54aaed 398 'AutoCGetCurrent' : ('AutoCompGetCurrent', 0, 0, 0),
9e96e16f 399 'AutoCGetCurrentText' : (None, 0, 0, 0),
1e9bafca
RD
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),
54173563
RD
405 'AutoCSetCaseInsensitiveBehaviour' : ('AutoCompSetCaseInsensitiveBehaviour', 0, 0, 0),
406 'AutoCGetCaseInsensitiveBehaviour' : ('AutoCompGetCaseInsensitiveBehaviour', 0, 0, 0),
591e2d8e 407
9e730a78
RD
408 'RegisterImage' :
409 (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();
e45b3f17
RD
415 if (img.HasAlpha())
416 img.ConvertAlphaToMask();
9e730a78
RD
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);
421 buff[len] = 0;
b796ba39 422 SendMsg(%s, type, (sptr_t)buff);
9e730a78
RD
423 delete [] buff;
424 ''',
425 ('Register an image for use in autocompletion lists.',)),
426
427
428 'ClearRegisteredImages' : (0, 0, 0,
429 ('Clear all the registered images.',)),
65ec6247 430
f97d84a6
RD
431
432 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
433 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
434
9e730a78
RD
435 'SetVScrollBar' : ('SetUseVerticalScrollBar', 0, 0, 0),
436 'GetVScrollBar' : ('GetUseVerticalScrollBar', 0, 0, 0),
437
f97d84a6
RD
438 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
439
440 'GetUsePalette' : (None, 0, 0, 0),
441
9e730a78
RD
442 'FindText' :
443 (0,
444 '''int %s(int minPos, int maxPos, const wxString& text, int flags=0);''',
445
446 '''int %s(int minPos, int maxPos,
447 const wxString& text,
448 int flags) {
449 TextToFind ft;
450 ft.chrg.cpMin = minPos;
451 ft.chrg.cpMax = maxPos;
0bcbf72b 452 const wxWX2MBbuf buf = wx2stc(text);
9e730a78
RD
453 ft.lpstrText = (char*)(const char*)buf;
454
b796ba39 455 return SendMsg(%s, flags, (sptr_t)&ft);''',
9e730a78
RD
456 0),
457
458 'FormatRange' :
459 (0,
460 '''int %s(bool doDraw,
461 int startPos,
462 int endPos,
463 wxDC* draw,
591e2d8e 464 wxDC* target,
9e730a78
RD
465 wxRect renderRect,
466 wxRect pageRect);''',
467 ''' int %s(bool doDraw,
468 int startPos,
469 int endPos,
470 wxDC* draw,
591e2d8e 471 wxDC* target,
9e730a78
RD
472 wxRect renderRect,
473 wxRect pageRect) {
474 RangeToFormat fr;
475
476 if (endPos < startPos) {
477 int temp = startPos;
478 startPos = endPos;
479 endPos = temp;
480 }
481 fr.hdc = draw;
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;
493
b796ba39 494 return SendMsg(%s, doDraw, (sptr_t)&fr);''',
9e730a78
RD
495 0),
496
497
498 'GetLine' :
499 (0,
2bfca191 500 'wxString %s(int line) const;',
9e730a78 501
2bfca191 502 '''wxString %s(int line) const {
9e730a78
RD
503 int len = LineLength(line);
504 if (!len) return wxEmptyString;
505
506 wxMemoryBuffer mbuf(len+1);
507 char* buf = (char*)mbuf.GetWriteBuf(len+1);
b796ba39 508 SendMsg(%s, line, (sptr_t)buf);
9e730a78
RD
509 mbuf.UngetWriteBuf(len);
510 mbuf.AppendByte(0);
511 return stc2wx(buf);''',
512
513 ('Retrieve the contents of a line.',)),
f97d84a6 514
fa70ec2b 515 'SetSel' : (None, 0,0,0), #'SetSelection', 0, 0, 0),
9e730a78
RD
516
517 'GetSelText' :
518 ('GetSelectedText',
519 'wxString %s();',
520
521 '''wxString %s() {
6094165c 522 const int len = SendMsg(SCI_GETSELTEXT, 0, (sptr_t)0);
9e730a78
RD
523 if (!len) return wxEmptyString;
524
3d7a4fe8 525 wxMemoryBuffer mbuf(len+2);
9e730a78 526 char* buf = (char*)mbuf.GetWriteBuf(len+1);
b796ba39 527 SendMsg(%s, 0, (sptr_t)buf);
9e730a78
RD
528 mbuf.UngetWriteBuf(len);
529 mbuf.AppendByte(0);
530 return stc2wx(buf);''',
531
532 ('Retrieve the selected text.',)),
533
534
535 'GetTextRange' :
536 (0,
537 'wxString %s(int startPos, int endPos);',
538
539 '''wxString %s(int startPos, int endPos) {
540 if (endPos < startPos) {
541 int temp = startPos;
542 startPos = endPos;
543 endPos = temp;
544 }
545 int len = endPos - startPos;
546 if (!len) return wxEmptyString;
547 wxMemoryBuffer mbuf(len+1);
548 char* buf = (char*)mbuf.GetWriteBuf(len);
549 TextRange tr;
550 tr.lpstrText = buf;
551 tr.chrg.cpMin = startPos;
552 tr.chrg.cpMax = endPos;
b796ba39 553 SendMsg(%s, 0, (sptr_t)&tr);
9e730a78
RD
554 mbuf.UngetWriteBuf(len);
555 mbuf.AppendByte(0);
556 return stc2wx(buf);''',
557
558 ('Retrieve a range of text.',)),
f97d84a6
RD
559
560 'PointXFromPosition' : (None, 0, 0, 0),
561 'PointYFromPosition' : (None, 0, 0, 0),
562
563 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
564 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
565 'Null' : (None, 0, 0, 0),
566
9e730a78
RD
567 'GetText' :
568 (0,
93578927 569 'wxString %s() const;',
f97d84a6 570
93578927 571 '''wxString %s() const {
9e730a78
RD
572 int len = GetTextLength();
573 wxMemoryBuffer mbuf(len+1); // leave room for the null...
574 char* buf = (char*)mbuf.GetWriteBuf(len+1);
b796ba39 575 SendMsg(%s, len+1, (sptr_t)buf);
9e730a78
RD
576 mbuf.UngetWriteBuf(len);
577 mbuf.AppendByte(0);
578 return stc2wx(buf);''',
f97d84a6 579
9e730a78 580 ('Retrieve all the text in the document.', )),
f97d84a6
RD
581
582 'GetDirectFunction' : (None, 0, 0, 0),
583 'GetDirectPointer' : (None, 0, 0, 0),
584
9e730a78
RD
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),
590
591 'SetHotspotActiveFore' : ('SetHotspotActiveForeground', 0, 0, 0),
592 'SetHotspotActiveBack' : ('SetHotspotActiveBackground', 0, 0, 0),
7e0c58e9
RD
593 'GetHotspotActiveFore' : ('GetHotspotActiveForeground', 0, 0, 0),
594 'GetHotspotActiveBack' : ('GetHotspotActiveBackground', 0, 0, 0),
591e2d8e 595
6a93571d
RD
596 'GetCaretLineBack' : ('GetCaretLineBackground', 0, 0, 0),
597 'SetCaretLineBack' : ('SetCaretLineBackground', 0, 0, 0),
9e730a78
RD
598
599 'ReplaceTarget' :
600 (0,
601 'int %s(const wxString& text);',
602
603 '''
604 int %s(const wxString& text) {
0bcbf72b
VZ
605 const wxWX2MBbuf buf = wx2stc(text);
606 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
9e730a78
RD
607 0),
608
609 'ReplaceTargetRE' :
610 (0,
611 'int %s(const wxString& text);',
612
613 '''
614 int %s(const wxString& text) {
0bcbf72b
VZ
615 const wxWX2MBbuf buf = wx2stc(text);
616 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
11a23db5
SL
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.',)),
9e730a78
RD
623
624 'SearchInTarget' :
625 (0,
626 'int %s(const wxString& text);',
627
628 '''
629 int %s(const wxString& text) {
0bcbf72b
VZ
630 const wxWX2MBbuf buf = wx2stc(text);
631 return SendMsg(%s, wx2stclen(text, buf), (sptr_t)(const char*)buf);''',
9e730a78
RD
632 0),
633
a33203cb
RD
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),
1e9bafca
RD
638
639
640 'GetProperty' :
641 (0,
642 'wxString %s(const wxString& key);',
643
644 '''wxString %s(const wxString& key) {
b796ba39 645 int len = SendMsg(SCI_GETPROPERTY, (sptr_t)(const char*)wx2stc(key), 0);
1e9bafca
RD
646 if (!len) return wxEmptyString;
647
648 wxMemoryBuffer mbuf(len+1);
649 char* buf = (char*)mbuf.GetWriteBuf(len+1);
b796ba39 650 SendMsg(%s, (uptr_t)(const char*)wx2stc(key), (sptr_t)buf);
1e9bafca
RD
651 mbuf.UngetWriteBuf(len);
652 mbuf.AppendByte(0);
653 return stc2wx(buf);''',
654 ("Retrieve a 'property' value previously set with SetProperty.",)),
655
656 'GetPropertyExpanded' :
657 (0,
658 'wxString %s(const wxString& key);',
659
660 '''wxString %s(const wxString& key) {
b796ba39 661 int len = SendMsg(SCI_GETPROPERTYEXPANDED, (uptr_t)(const char*)wx2stc(key), 0);
1e9bafca
RD
662 if (!len) return wxEmptyString;
663
664 wxMemoryBuffer mbuf(len+1);
665 char* buf = (char*)mbuf.GetWriteBuf(len+1);
b796ba39 666 SendMsg(%s, (uptr_t)(const char*)wx2stc(key), (sptr_t)buf);
1e9bafca
RD
667 mbuf.UngetWriteBuf(len);
668 mbuf.AppendByte(0);
669 return stc2wx(buf);''',
670 ("Retrieve a 'property' value previously set with SetProperty,",
671 "with '$()' variable replacement on returned buffer.")),
672
673 'GetPropertyInt' : (0, 0, 0,
674 ("Retrieve a 'property' value previously set with SetProperty,",
675 "interpreted as an int AFTER any '$()' variable replacement.")),
676
9e730a78
RD
677
678 'GetDocPointer' :
679 (0,
680 'void* %s();',
681 '''void* %s() {
682 return (void*)SendMsg(%s);''',
683 0),
684
685 'SetDocPointer' :
686 (0,
687 'void %s(void* docPointer);',
688 '''void %s(void* docPointer) {
b796ba39 689 SendMsg(%s, 0, (sptr_t)docPointer);''',
9e730a78
RD
690 0),
691
692 'CreateDocument' :
693 (0,
694 'void* %s();',
695 '''void* %s() {
696 return (void*)SendMsg(%s);''',
697 0),
698
699 'AddRefDocument' :
700 (0,
701 'void %s(void* docPointer);',
702 '''void %s(void* docPointer) {
b796ba39 703 SendMsg(%s, 0, (sptr_t)docPointer);''',
9e730a78
RD
704 0),
705
706 'ReleaseDocument' :
707 (0,
708 'void %s(void* docPointer);',
709 '''void %s(void* docPointer) {
b796ba39 710 SendMsg(%s, 0, (sptr_t)docPointer);''',
9e730a78
RD
711 0),
712
713 'SetCodePage' :
714 (0,
715 0,
716 '''void %s(int codePage) {
2b5f62a0
VZ
717#if wxUSE_UNICODE
718 wxASSERT_MSG(codePage == wxSTC_CP_UTF8,
719 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
720#else
721 wxASSERT_MSG(codePage != wxSTC_CP_UTF8,
722 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
723#endif
9e730a78
RD
724 SendMsg(%s, codePage);''',
725 ("Set the code page used to interpret the bytes of the document as characters.",) ),
2b5f62a0
VZ
726
727
728 'GrabFocus' : (None, 0, 0, 0),
88a8b04e 729
c26dba42 730 # Rename some that would otherwise hide the wxWindow methods
2b5f62a0
VZ
731 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
732 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
88a8b04e
RD
733 'SetCursor' : ('SetSTCCursor', 0, 0, 0),
734 'GetCursor' : ('GetSTCCursor', 0, 0, 0),
2b5f62a0 735
9e730a78
RD
736 'LoadLexerLibrary' : (None, 0,0,0),
737
7e0c58e9
RD
738 'SetPositionCache' : ('SetPositionCacheSize', 0, 0, 0),
739 'GetPositionCache' : ('GetPositionCacheSize', 0, 0, 0),
740
9e96e16f
RD
741 'GetLexerLanguage' : (None, 0, 0, 0),
742 'SetFontQuality' : (None, 0, 0, 0),
743 'GetFontQuality' : (None, 0, 0, 0),
744 'SetSelection' : (None, 0, 0, 0),
745
746 'GetCharacterPointer' : (0,
54173563
RD
747 'const char* %s() const;',
748 'const char* %s() const {\n'
9e96e16f
RD
749 ' return (const char*)SendMsg(%s, 0, 0);',
750 0),
751
54173563
RD
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);',
756 0),
757
9e730a78 758
9b01abb8
RD
759 'GetWordChars' :
760 (0,
761 'wxString %s() const;',
762
763 '''wxString %s() const {
764 int msg = %s;
c4bdd822 765 int len = SendMsg(msg, 0, (sptr_t)NULL);
9b01abb8
RD
766 if (!len) return wxEmptyString;
767
768 wxMemoryBuffer mbuf(len+1);
769 char* buf = (char*)mbuf.GetWriteBuf(len+1);
54173563 770 SendMsg(msg, 0, (sptr_t)buf);
9b01abb8
RD
771 mbuf.UngetWriteBuf(len);
772 mbuf.AppendByte(0);
773 return stc2wx(buf);''',
774
775 ('Get the set of characters making up words for when moving or selecting by word.',)),
776
777 'GetTag' :
778 (0,
779 'wxString %s(int tagNumber) const;',
780
781 '''wxString %s(int tagNumber) const {
782 int msg = %s;
c4bdd822 783 int len = SendMsg(msg, tagNumber, (sptr_t)NULL);
9b01abb8
RD
784 if (!len) return wxEmptyString;
785
786 wxMemoryBuffer mbuf(len+1);
787 char* buf = (char*)mbuf.GetWriteBuf(len+1);
788 SendMsg(msg, tagNumber, (sptr_t)buf);
789 mbuf.UngetWriteBuf(len);
790 mbuf.AppendByte(0);
791 return stc2wx(buf);''',
792 0),
793
794 'GetWhitespaceChars' :
795 (0,
796 'wxString %s() const;',
797
798 '''wxString %s() const {
799 int msg = %s;
c4bdd822 800 int len = SendMsg(msg, 0, (sptr_t)NULL);
9b01abb8
RD
801 if (!len) return wxEmptyString;
802
803 wxMemoryBuffer mbuf(len+1);
804 char* buf = (char*)mbuf.GetWriteBuf(len+1);
54173563 805 SendMsg(msg, 0, (sptr_t)buf);
9b01abb8
RD
806 mbuf.UngetWriteBuf(len);
807 mbuf.AppendByte(0);
808 return stc2wx(buf);''',
809 0),
810
811
812 'GetPunctuationChars' :
813 (0,
814 'wxString %s() const;',
815
816 '''wxString %s() const {
817 int msg = %s;
c4bdd822 818 int len = SendMsg(msg, 0, (sptr_t)NULL);
9b01abb8
RD
819 if (!len) return wxEmptyString;
820
821 wxMemoryBuffer mbuf(len+1);
822 char* buf = (char*)mbuf.GetWriteBuf(len+1);
54173563 823 SendMsg(msg, 0, (sptr_t)buf);
9b01abb8
RD
824 mbuf.UngetWriteBuf(len);
825 mbuf.AppendByte(0);
826 return stc2wx(buf);''',
827 0),
828
829
830 'PropertyNames' :
831 (0,
832 'wxString %s() const;',
833
834 '''wxString %s() const {
835 int msg = %s;
c4bdd822 836 int len = SendMsg(msg, 0, (sptr_t)NULL);
9b01abb8
RD
837 if (!len) return wxEmptyString;
838
839 wxMemoryBuffer mbuf(len+1);
840 char* buf = (char*)mbuf.GetWriteBuf(len+1);
54173563 841 SendMsg(msg, 0, (sptr_t)buf);
9b01abb8
RD
842 mbuf.UngetWriteBuf(len);
843 mbuf.AppendByte(0);
844 return stc2wx(buf);''',
845 0),
846
847
848
849 'DescribeProperty' :
850 (0,
851 'wxString %s(const wxString& name) const;',
852
853 '''wxString %s(const wxString& name) const {
854 int msg = %s;
c4bdd822 855 int len = SendMsg(msg, (sptr_t)(const char*)wx2stc(name), (sptr_t)NULL);
9b01abb8
RD
856 if (!len) return wxEmptyString;
857
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);
862 mbuf.AppendByte(0);
863 return stc2wx(buf);''',
864 0),
865
866
867
868 'DescribeKeyWordSets' :
869 (0,
870 'wxString %s() const;',
871
872 '''wxString %s() const {
873 int msg = %s;
c4bdd822 874 int len = SendMsg(msg, 0, (sptr_t)NULL);
9b01abb8
RD
875 if (!len) return wxEmptyString;
876
877 wxMemoryBuffer mbuf(len+1);
878 char* buf = (char*)mbuf.GetWriteBuf(len+1);
54173563 879 SendMsg(msg, 0, (sptr_t)buf);
9b01abb8
RD
880 mbuf.UngetWriteBuf(len);
881 mbuf.AppendByte(0);
882 return stc2wx(buf);''',
883 0),
54173563
RD
884
885
886 'MarkerDefineRGBAImage' :
887 (0,
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);''',
891 0),
892
893
894 'RegisterRGBAImage' :
895 (0,
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);''',
899 0),
9b01abb8
RD
900
901
54173563
RD
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),
907
908 'CreateLoader' :
909 (0,
910 'void* %s(int bytes) const;',
911 """void* %s(int bytes) const {
912 return (void*)(sptr_t)SendMsg(%s, bytes); """,
913 0),
9b01abb8 914
54173563
RD
915 'PrivateLexerCall' :
916 (0,
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); """,
920 0),
11a23db5
SL
921
922 'GetMultiPaste' :
923 (0, 0, 0,
924 ('Retrieve the effect of pasting when there are multiple selections.',)),
54173563 925
f97d84a6
RD
926 '' : ('', 0, 0, 0),
927
928 }
929
2bfca191
VZ
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
933# above)
713a0408 934constNonGetterMethods = (
2bfca191
VZ
935 'LineFromPosition',
936 'PositionFromLine',
937 'LineLength',
7d6d76d0 938 'CanPaste',
93578927
VZ
939 'CanRedo',
940 'CanUndo',
713a0408 941)
2bfca191 942
f97d84a6
RD
943#----------------------------------------------------------------------------
944
6d7b19b0 945def processIface(iface, h_tmplt, cpp_tmplt, ih_tmplt, h_dest, cpp_dest, docstr_dest, ih_dest):
f97d84a6
RD
946 curDocStrings = []
947 values = []
948 methods = []
2b5f62a0 949 cmds = []
f97d84a6
RD
950
951 # parse iface file
952 fi = FileInput(iface)
953 for line in fi:
954 line = line[:-1]
955 if line[:2] == '##' or line == '':
956 #curDocStrings = []
957 continue
958
959 op = line[:4]
960 if line[:2] == '# ': # a doc string
961 curDocStrings.append(line[2:])
962
963 elif op == 'val ':
964 parseVal(line[4:], values, curDocStrings)
965 curDocStrings = []
966
967 elif op == 'fun ' or op == 'set ' or op == 'get ':
8e0945da 968 parseFun(line[4:], methods, curDocStrings, cmds, op == 'get ')
f97d84a6
RD
969 curDocStrings = []
970
971 elif op == 'cat ':
016a3d4c 972 if line[4:].strip() == 'Deprecated':
f97d84a6
RD
973 break # skip the rest of the file
974
975 elif op == 'evt ':
976 pass
977
a834585d
RD
978 elif op == 'enu ':
979 pass
980
981 elif op == 'lex ':
982 pass
983
f97d84a6 984 else:
016a3d4c 985 print('***** Unknown line type: %s' % line)
f97d84a6
RD
986
987
988 # process templates
989 data = {}
990 data['VALUES'] = processVals(values)
2b5f62a0 991 data['CMDS'] = processVals(cmds)
6d7b19b0 992 defs, imps, docstrings, idefs = processMethods(methods)
f97d84a6 993 data['METHOD_DEFS'] = defs
6d7b19b0 994 data['METHOD_IDEFS'] = idefs
f97d84a6
RD
995 data['METHOD_IMPS'] = imps
996
997 # get template text
998 h_text = open(h_tmplt).read()
6d7b19b0 999 ih_text = open(ih_tmplt).read()
f97d84a6
RD
1000 cpp_text = open(cpp_tmplt).read()
1001
1002 # do the substitutions
1003 h_text = h_text % data
1004 cpp_text = cpp_text % data
6d7b19b0 1005 ih_text = ih_text % data
f97d84a6
RD
1006
1007 # write out destination files
1008 open(h_dest, 'w').write(h_text)
1009 open(cpp_dest, 'w').write(cpp_text)
cab16e6c
RD
1010 if docstr_dest:
1011 open(docstr_dest, 'w').write(docstrings)
6d7b19b0 1012 open(ih_dest, 'w').write(ih_text)
f97d84a6
RD
1013
1014
713a0408 1015def joinWithNewLines(values):
016a3d4c 1016 return '\n'.join(values)
713a0408 1017
f97d84a6
RD
1018#----------------------------------------------------------------------------
1019
1020def processVals(values):
1021 text = []
1022 for name, value, docs in values:
1023 if docs:
1024 text.append('')
1025 for x in docs:
6d7b19b0 1026 text.append('/// ' + x)
f97d84a6 1027 text.append('#define %s %s' % (name, value))
713a0408 1028 return joinWithNewLines(text)
f97d84a6
RD
1029
1030#----------------------------------------------------------------------------
1031
1032def processMethods(methods):
1033 defs = []
6d7b19b0 1034 idefs = []
f97d84a6 1035 imps = []
f2ccce28 1036 dstr = []
f97d84a6 1037
8e0945da 1038 for retType, name, number, param1, param2, docs, is_const in methods:
f97d84a6
RD
1039 retType = retTypeMap.get(retType, retType)
1040 params = makeParamString(param1, param2)
1041
1042 name, theDef, theImp, docs = checkMethodOverride(name, number, docs)
1043
1044 if name is None:
1045 continue
1046
f2ccce28
RD
1047 # Build docstrings
1048 st = 'DocStr(wxStyledTextCtrl::%s,\n' \
713a0408 1049 '"%s", "");\n' % (name, joinWithNewLines(docs))
f2ccce28 1050 dstr.append(st)
8e0945da 1051
f97d84a6
RD
1052 # Build the method definition for the .h file
1053 if docs:
1054 defs.append('')
1055 for x in docs:
1056 defs.append(' // ' + x)
1057 if not theDef:
8e0945da
VZ
1058 theDef = ' %s %s(%s)' % (retType, name, params)
1059 if is_const:
1060 theDef = theDef + ' const'
1061 theDef = theDef + ';'
f97d84a6
RD
1062 defs.append(theDef)
1063
6d7b19b0
RD
1064 # Build the method definition for the interface .h file
1065 if docs:
1066 idefs.append('')
1067 idefs.append(' /**')
1068 for x in docs:
1069 idefs.append(' ' + x)
1070 idefs.append(' */')
1071 if name == 'GetCurLine':
1072 idefs.append(' wxString GetCurLine(int* linePos=NULL);')
1073 else:
1074 idefs.append(theDef)
1075
f97d84a6
RD
1076 # Build the method implementation string
1077 if docs:
1078 imps.append('')
1079 for x in docs:
1080 imps.append('// ' + x)
1081 if not theImp:
8e0945da
VZ
1082 theImp = '%s wxStyledTextCtrl::%s(%s)' % (retType, name, params)
1083 if is_const:
1084 theImp = theImp + ' const'
1085 theImp = theImp + '\n{\n '
f97d84a6
RD
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)'
1097
1098 theImp = theImp + ';\n}'
1099 imps.append(theImp)
1100
1101
6d7b19b0 1102 return joinWithNewLines(defs), joinWithNewLines(imps), joinWithNewLines(dstr), joinWithNewLines(idefs)
f97d84a6
RD
1103
1104
1105#----------------------------------------------------------------------------
1106
1107def checkMethodOverride(name, number, docs):
1108 theDef = theImp = None
016a3d4c 1109 if name in methodOverrideMap:
f97d84a6
RD
1110 item = methodOverrideMap[name]
1111
c13219d6
RD
1112 try:
1113 if item[0] != 0:
1114 name = item[0]
1115 if item[1] != 0:
1116 theDef = ' ' + (item[1] % name)
1117 if item[2] != 0:
1118 theImp = item[2] % ('wxStyledTextCtrl::'+name, number) + '\n}'
1119 if item[3] != 0:
1120 docs = item[3]
1121 except:
016a3d4c 1122 print("************* " + name)
c13219d6 1123 raise
f97d84a6
RD
1124
1125 return name, theDef, theImp, docs
1126
1127#----------------------------------------------------------------------------
1128
1129def makeArgString(param):
1130 if not param:
1131 return '0'
1132
1133 typ, name = param
1134
1135 if typ == 'string':
b796ba39 1136 return '(sptr_t)(const char*)wx2stc(%s)' % name
f97d84a6
RD
1137 if typ == 'colour':
1138 return 'wxColourAsLong(%s)' % name
1139
1140 return name
1141
1142#----------------------------------------------------------------------------
1143
1144def makeParamString(param1, param2):
1145 def doOne(param):
1146 if param:
1147 aType = paramTypeMap.get(param[0], param[0])
1148 return aType + ' ' + param[1]
1149 else:
1150 return ''
1151
1152 st = doOne(param1)
1153 if st and param2:
1154 st = st + ', '
1155 st = st + doOne(param2)
1156 return st
1157
1158
1159#----------------------------------------------------------------------------
1160
1161def parseVal(line, values, docs):
016a3d4c 1162 name, val = line.split('=')
f97d84a6
RD
1163
1164 # remove prefixes such as SCI, etc.
1165 for old, new in valPrefixes:
1166 lo = len(old)
1167 if name[:lo] == old:
1168 if new is None:
1169 return
1170 name = new + name[lo:]
1171
1172 # add it to the list
1173 values.append( ('wxSTC_' + name, val, docs) )
1174
1175#----------------------------------------------------------------------------
1176
1177funregex = re.compile(r'\s*([a-zA-Z0-9_]+)' # <ws>return type
1178 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
1179 '([0-9]+)' # number
1180 '\(([ a-zA-Z0-9_]*),' # (param,
9e96e16f 1181 '([ a-zA-Z0-9_]*),*\)') # param)
f97d84a6 1182
8e0945da 1183def parseFun(line, methods, docs, values, is_const):
f97d84a6 1184 def parseParam(param):
016a3d4c 1185 param = param.strip()
f97d84a6
RD
1186 if param == '':
1187 param = None
1188 else:
016a3d4c 1189 param = tuple(param.split())
f97d84a6
RD
1190 return param
1191
1192 mo = funregex.match(line)
1193 if mo is None:
016a3d4c 1194 print("***** Line doesn't match! : %s" % line)
f97d84a6
RD
1195
1196 retType, name, number, param1, param2 = mo.groups()
1197
1198 param1 = parseParam(param1)
1199 param2 = parseParam(param2)
1200
2b5f62a0 1201 # Special case. For the key command functions we want a value defined too
016a3d4c 1202 num = int(number)
f97d84a6 1203 for v in cmdValues:
2b5f62a0 1204 if (type(v) == type(()) and v[0] <= num <= v[1]) or v == num:
016a3d4c 1205 parseVal('CMD_%s=%s' % (name.upper(), number), values, docs)
591e2d8e 1206
c26dba42
RD
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:
1210 return
591e2d8e 1211
2bfca191
VZ
1212 methods.append( (retType, name, number, param1, param2, tuple(docs),
1213 is_const or name in constNonGetterMethods) )
f97d84a6
RD
1214
1215
1216#----------------------------------------------------------------------------
1217
1218
1219def main(args):
1220 # TODO: parse command line args to replace default input/output files???
1221
591e2d8e 1222 if not os.path.exists(IFACE):
016a3d4c 1223 print('Please run this script from src/stc subdirectory.')
591e2d8e
VZ
1224 sys.exit(1)
1225
f97d84a6 1226 # Now just do it
6d7b19b0 1227 processIface(IFACE, H_TEMPLATE, CPP_TEMPLATE, IH_TEMPLATE, H_DEST, CPP_DEST, DOCSTR_DEST, IH_DEST)
f97d84a6
RD
1228
1229
1230
1231if __name__ == '__main__':
1232 main(sys.argv)
1233
1234#----------------------------------------------------------------------------
1235