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