]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/stc/gen_iface.py
Avoid an assert on wxMSW and ensure we don't use a zero delay for the
[wxWidgets.git] / contrib / src / stc / gen_iface.py
CommitLineData
f97d84a6
RD
1#!/bin/env python
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
11# Licence: wxWindows license
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')
21CPP_TEMPLATE = os.path.abspath('./stc.cpp.in')
22H_DEST = os.path.abspath('../../include/wx/stc/stc.h')
23CPP_DEST = os.path.abspath('./stc.cpp')
f2ccce28 24DOCSTR_DEST = os.path.abspath('../../../wxPython/contrib/stc/_stc_gendocs.i')
f97d84a6
RD
25
26
27# Value prefixes to convert
28valPrefixes = [('SCI_', ''),
29 ('SC_', ''),
37d62433 30 ('SCN_', None), # just toss these out...
f97d84a6
RD
31 ('SCEN_', None),
32 ('SCE_', ''),
33 ('SCLEX_', 'LEX_'),
34 ('SCK_', 'KEY_'),
35 ('SCFIND_', 'FIND_'),
36 ('SCWS_', 'WS_'),
37]
38
c26dba42 39# Message function values that should have a CMD_ constant generated
2b5f62a0
VZ
40cmdValues = [ (2300, 2349),
41 2011,
42 2013,
43 (2176, 2180),
44 (2390, 2393),
45 (2395, 2396),
9e730a78
RD
46 2404,
47 (2413, 2416),
8e54aaed 48 (2426, 2442),
c26dba42 49 (2450, 2455),
2b5f62a0 50 ]
f97d84a6
RD
51
52
c26dba42
RD
53# Should a funciton be also generated for the CMDs?
54FUNC_FOR_CMD = True
55
56
f97d84a6
RD
57# Map some generic typenames to wx types, using return value syntax
58retTypeMap = {
59 'position': 'int',
60 'string': 'wxString',
61 'colour': 'wxColour',
62 }
63
64# Map some generic typenames to wx types, using parameter syntax
65paramTypeMap = {
66 'position': 'int',
67 'string': 'const wxString&',
68 'colour': 'const wxColour&',
69 'keymod': 'int',
70}
71
72# Map of method info that needs tweaked. Either the name needs changed, or
73# the method definition/implementation. Tuple items are:
74#
75# 1. New method name. None to skip the method, 0 to leave the
76# default name.
77# 2. Method definition for the .h file, 0 to leave alone
78# 3. Method implementation for the .cpp file, 0 to leave alone.
79# 4. tuple of Doc string lines, or 0 to leave alone.
80#
81methodOverrideMap = {
82 'AddText' : (0,
83 'void %s(const wxString& text);',
84
85 '''void %s(const wxString& text) {
0c5b83b0 86 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
10ef30eb 87 SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
f97d84a6
RD
88 0),
89
90 'AddStyledText' : (0,
10ef30eb 91 'void %s(const wxMemoryBuffer& data);',
f97d84a6 92
10ef30eb
RD
93 '''void %s(const wxMemoryBuffer& data) {
94 SendMsg(%s, data.GetDataLen(), (long)data.GetData());''',
f97d84a6
RD
95 0),
96
41a499cd
RD
97 'AppendText' : (0,
98 'void %s(const wxString& text);',
99
100 '''void %s(const wxString& text) {
101 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
102 SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
103 0),
104
f97d84a6
RD
105 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
106 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
107
9e730a78
RD
108 'GetCharAt' :
109 ( 0, 0,
110 '''int %s(int pos) {
111 return (unsigned char)SendMsg(%s, pos, 0);''',
112 0),
113
114 'GetStyleAt' :
115 ( 0, 0,
116 '''int %s(int pos) {
117 return (unsigned char)SendMsg(%s, pos, 0);''',
118 0),
119
120 'GetStyledText' :
121 (0,
122 'wxMemoryBuffer %s(int startPos, int endPos);',
123
124 '''wxMemoryBuffer %s(int startPos, int endPos) {
125 wxMemoryBuffer buf;
126 if (endPos < startPos) {
127 int temp = startPos;
128 startPos = endPos;
129 endPos = temp;
130 }
131 int len = endPos - startPos;
132 if (!len) return buf;
133 TextRange tr;
134 tr.lpstrText = (char*)buf.GetWriteBuf(len*2+1);
135 tr.chrg.cpMin = startPos;
136 tr.chrg.cpMax = endPos;
137 len = SendMsg(%s, 0, (long)&tr);
138 buf.UngetWriteBuf(len);
139 return buf;''',
140
141 ('Retrieve a buffer of cells.',)),
142
143
144 'PositionFromPoint' :
145 (0,
146 'int %s(wxPoint pt);',
147
148 '''int %s(wxPoint pt) {
149 return SendMsg(%s, pt.x, pt.y);''',
150 0),
151
152 'GetCurLine' :
153 (0,
154 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
155
156 '''wxString %s(int* linePos) {
157 int len = LineLength(GetCurrentLine());
158 if (!len) {
159 if (linePos) *linePos = 0;
160 return wxEmptyString;
161 }
162
163 wxMemoryBuffer mbuf(len+1);
164 char* buf = (char*)mbuf.GetWriteBuf(len+1);
165
166 int pos = SendMsg(%s, len+1, (long)buf);
167 mbuf.UngetWriteBuf(len);
168 mbuf.AppendByte(0);
169 if (linePos) *linePos = pos;
170 return stc2wx(buf);''',
171
172 0),
f97d84a6
RD
173
174 'SetUsePalette' : (None, 0,0,0),
175
176 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
177 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
178
9e730a78
RD
179 'MarkerDefine' :
180 (0,
181 '''void %s(int markerNumber, int markerSymbol,
182 const wxColour& foreground = wxNullColour,
183 const wxColour& background = wxNullColour);''',
184
185 '''void %s(int markerNumber, int markerSymbol,
186 const wxColour& foreground,
187 const wxColour& background) {
188
189 SendMsg(%s, markerNumber, markerSymbol);
190 if (foreground.Ok())
191 MarkerSetForeground(markerNumber, foreground);
192 if (background.Ok())
193 MarkerSetBackground(markerNumber, background);''',
194
195 ('Set the symbol used for a particular marker number,',
196 'and optionally the fore and background colours.')),
197
198
199 'MarkerDefinePixmap' :
200 ('MarkerDefineBitmap',
201 '''void %s(int markerNumber, const wxBitmap& bmp);''',
202 '''void %s(int markerNumber, const wxBitmap& bmp) {
203 // convert bmp to a xpm in a string
204 wxMemoryOutputStream strm;
205 wxImage img = bmp.ConvertToImage();
206 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
207 size_t len = strm.GetSize();
208 char* buff = new char[len+1];
209 strm.CopyTo(buff, len);
210 buff[len] = 0;
211 SendMsg(%s, markerNumber, (long)buff);
212 delete [] buff;
213 ''',
214 ('Define a marker from a bitmap',)),
f97d84a6 215
f97d84a6
RD
216
217 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0),
218 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0),
219 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0),
220 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0),
221 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0),
222 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0),
223 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0),
224 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0),
225
226 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0),
227 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0),
228 'SetSelFore' : ('SetSelForeground', 0, 0, 0),
229 'SetSelBack' : ('SetSelBackground', 0, 0, 0),
230 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0),
231 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0),
3727c043
RD
232 'StyleSetCharacterSet' : (None, 0, 0, 0),
233
9e730a78
RD
234 'AssignCmdKey' :
235 ('CmdKeyAssign',
236 'void %s(int key, int modifiers, int cmd);',
f97d84a6 237
9e730a78
RD
238 '''void %s(int key, int modifiers, int cmd) {
239 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
240 0),
f97d84a6 241
f97d84a6 242
9e730a78
RD
243 'ClearCmdKey' :
244 ('CmdKeyClear',
245 'void %s(int key, int modifiers);',
f97d84a6 246
9e730a78
RD
247 '''void %s(int key, int modifiers) {
248 SendMsg(%s, MAKELONG(key, modifiers));''',
249 0),
f97d84a6
RD
250
251 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
252
253
9e730a78
RD
254 'SetStylingEx' :
255 ('SetStyleBytes',
256 'void %s(int length, char* styleBytes);',
f97d84a6 257
9e730a78
RD
258 '''void %s(int length, char* styleBytes) {
259 SendMsg(%s, length, (long)styleBytes);''',
260 0),
f97d84a6
RD
261
262
263 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0),
264 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0),
265 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0),
266 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0),
267
f114b858
RD
268 'SetWhitespaceFore' : ('SetWhitespaceForeground', 0, 0, 0),
269 'SetWhitespaceBack' : ('SetWhitespaceBackground', 0, 0, 0),
270
f97d84a6
RD
271 'AutoCShow' : ('AutoCompShow', 0, 0, 0),
272 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0),
273 'AutoCActive' : ('AutoCompActive', 0, 0, 0),
274 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0),
275 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0),
276 'AutoCStops' : ('AutoCompStops', 0, 0, 0),
277 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0),
278 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0),
279 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0),
280 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0),
281 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0),
282 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0),
283 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0),
284 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0),
285 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0),
286 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0),
65ec6247
RD
287 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
288 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
1a2fb4cd
RD
289 'AutoCSetDropRestOfWord' : ('AutoCompSetDropRestOfWord', 0,0,0),
290 'AutoCGetDropRestOfWord' : ('AutoCompGetDropRestOfWord', 0,0,0),
9e730a78
RD
291 'AutoCGetTypeSeparator' : ('AutoCompGetTypeSeparator', 0, 0, 0),
292 'AutoCSetTypeSeparator' : ('AutoCompSetTypeSeparator', 0, 0, 0),
8e54aaed 293 'AutoCGetCurrent' : ('AutoCompGetCurrent', 0, 0, 0),
9e730a78
RD
294
295 'RegisterImage' :
296 (0,
297 '''void %s(int type, const wxBitmap& bmp);''',
298 '''void %s(int type, const wxBitmap& bmp) {
299 // convert bmp to a xpm in a string
300 wxMemoryOutputStream strm;
301 wxImage img = bmp.ConvertToImage();
302 img.SaveFile(strm, wxBITMAP_TYPE_XPM);
303 size_t len = strm.GetSize();
304 char* buff = new char[len+1];
305 strm.CopyTo(buff, len);
306 buff[len] = 0;
307 SendMsg(%s, type, (long)buff);
308 delete [] buff;
309 ''',
310 ('Register an image for use in autocompletion lists.',)),
311
312
313 'ClearRegisteredImages' : (0, 0, 0,
314 ('Clear all the registered images.',)),
65ec6247 315
f97d84a6
RD
316
317 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
318 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
319
9e730a78
RD
320 'SetVScrollBar' : ('SetUseVerticalScrollBar', 0, 0, 0),
321 'GetVScrollBar' : ('GetUseVerticalScrollBar', 0, 0, 0),
322
f97d84a6
RD
323 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
324
325 'GetUsePalette' : (None, 0, 0, 0),
326
9e730a78
RD
327 'FindText' :
328 (0,
329 '''int %s(int minPos, int maxPos, const wxString& text, int flags=0);''',
330
331 '''int %s(int minPos, int maxPos,
332 const wxString& text,
333 int flags) {
334 TextToFind ft;
335 ft.chrg.cpMin = minPos;
336 ft.chrg.cpMax = maxPos;
337 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
338 ft.lpstrText = (char*)(const char*)buf;
339
340 return SendMsg(%s, flags, (long)&ft);''',
341 0),
342
343 'FormatRange' :
344 (0,
345 '''int %s(bool doDraw,
346 int startPos,
347 int endPos,
348 wxDC* draw,
8e54aaed 349 wxDC* target,
9e730a78
RD
350 wxRect renderRect,
351 wxRect pageRect);''',
352 ''' int %s(bool doDraw,
353 int startPos,
354 int endPos,
355 wxDC* draw,
8e54aaed 356 wxDC* target,
9e730a78
RD
357 wxRect renderRect,
358 wxRect pageRect) {
359 RangeToFormat fr;
360
361 if (endPos < startPos) {
362 int temp = startPos;
363 startPos = endPos;
364 endPos = temp;
365 }
366 fr.hdc = draw;
367 fr.hdcTarget = target;
368 fr.rc.top = renderRect.GetTop();
369 fr.rc.left = renderRect.GetLeft();
370 fr.rc.right = renderRect.GetRight();
371 fr.rc.bottom = renderRect.GetBottom();
372 fr.rcPage.top = pageRect.GetTop();
373 fr.rcPage.left = pageRect.GetLeft();
374 fr.rcPage.right = pageRect.GetRight();
375 fr.rcPage.bottom = pageRect.GetBottom();
376 fr.chrg.cpMin = startPos;
377 fr.chrg.cpMax = endPos;
378
379 return SendMsg(%s, doDraw, (long)&fr);''',
380 0),
381
382
383 'GetLine' :
384 (0,
385 'wxString %s(int line);',
386
387 '''wxString %s(int line) {
388 int len = LineLength(line);
389 if (!len) return wxEmptyString;
390
391 wxMemoryBuffer mbuf(len+1);
392 char* buf = (char*)mbuf.GetWriteBuf(len+1);
393 SendMsg(%s, line, (long)buf);
394 mbuf.UngetWriteBuf(len);
395 mbuf.AppendByte(0);
396 return stc2wx(buf);''',
397
398 ('Retrieve the contents of a line.',)),
f97d84a6
RD
399
400 'SetSel' : ('SetSelection', 0, 0, 0),
9e730a78
RD
401
402 'GetSelText' :
403 ('GetSelectedText',
404 'wxString %s();',
405
406 '''wxString %s() {
407 int start;
408 int end;
409
410 GetSelection(&start, &end);
411 int len = end - start;
412 if (!len) return wxEmptyString;
413
3d7a4fe8 414 wxMemoryBuffer mbuf(len+2);
9e730a78
RD
415 char* buf = (char*)mbuf.GetWriteBuf(len+1);
416 SendMsg(%s, 0, (long)buf);
417 mbuf.UngetWriteBuf(len);
418 mbuf.AppendByte(0);
419 return stc2wx(buf);''',
420
421 ('Retrieve the selected text.',)),
422
423
424 'GetTextRange' :
425 (0,
426 'wxString %s(int startPos, int endPos);',
427
428 '''wxString %s(int startPos, int endPos) {
429 if (endPos < startPos) {
430 int temp = startPos;
431 startPos = endPos;
432 endPos = temp;
433 }
434 int len = endPos - startPos;
435 if (!len) return wxEmptyString;
436 wxMemoryBuffer mbuf(len+1);
437 char* buf = (char*)mbuf.GetWriteBuf(len);
438 TextRange tr;
439 tr.lpstrText = buf;
440 tr.chrg.cpMin = startPos;
441 tr.chrg.cpMax = endPos;
442 SendMsg(%s, 0, (long)&tr);
443 mbuf.UngetWriteBuf(len);
444 mbuf.AppendByte(0);
445 return stc2wx(buf);''',
446
447 ('Retrieve a range of text.',)),
f97d84a6
RD
448
449 'PointXFromPosition' : (None, 0, 0, 0),
450 'PointYFromPosition' : (None, 0, 0, 0),
451
452 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0),
453 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0),
454 'Null' : (None, 0, 0, 0),
455
9e730a78
RD
456 'GetText' :
457 (0,
458 'wxString %s();',
f97d84a6 459
9e730a78
RD
460 '''wxString %s() {
461 int len = GetTextLength();
462 wxMemoryBuffer mbuf(len+1); // leave room for the null...
463 char* buf = (char*)mbuf.GetWriteBuf(len+1);
464 SendMsg(%s, len+1, (long)buf);
465 mbuf.UngetWriteBuf(len);
466 mbuf.AppendByte(0);
467 return stc2wx(buf);''',
f97d84a6 468
9e730a78 469 ('Retrieve all the text in the document.', )),
f97d84a6
RD
470
471 'GetDirectFunction' : (None, 0, 0, 0),
472 'GetDirectPointer' : (None, 0, 0, 0),
473
9e730a78
RD
474 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0),
475 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0),
476 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0),
477 'CallTipSetFore' : ('CallTipSetForeground', 0, 0, 0),
478 'CallTipSetForeHlt' : ('CallTipSetForegroundHighlight', 0, 0, 0),
479
480 'SetHotspotActiveFore' : ('SetHotspotActiveForeground', 0, 0, 0),
481 'SetHotspotActiveBack' : ('SetHotspotActiveBackground', 0, 0, 0),
482
483
484 'ReplaceTarget' :
485 (0,
486 'int %s(const wxString& text);',
487
488 '''
489 int %s(const wxString& text) {
490 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
491 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
492 0),
493
494 'ReplaceTargetRE' :
495 (0,
496 'int %s(const wxString& text);',
497
498 '''
499 int %s(const wxString& text) {
500 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
501 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
502 0),
503
504 'SearchInTarget' :
505 (0,
506 'int %s(const wxString& text);',
507
508 '''
509 int %s(const wxString& text) {
510 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
511 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
512 0),
513
a33203cb
RD
514 # not sure what to do about these yet
515 'TargetAsUTF8' : ( None, 0, 0, 0),
516 'SetLengthForEncode' : ( None, 0, 0, 0),
517 'EncodedFromUTF8' : ( None, 0, 0, 0),
518
9e730a78
RD
519
520 'GetDocPointer' :
521 (0,
522 'void* %s();',
523 '''void* %s() {
524 return (void*)SendMsg(%s);''',
525 0),
526
527 'SetDocPointer' :
528 (0,
529 'void %s(void* docPointer);',
530 '''void %s(void* docPointer) {
531 SendMsg(%s, 0, (long)docPointer);''',
532 0),
533
534 'CreateDocument' :
535 (0,
536 'void* %s();',
537 '''void* %s() {
538 return (void*)SendMsg(%s);''',
539 0),
540
541 'AddRefDocument' :
542 (0,
543 'void %s(void* docPointer);',
544 '''void %s(void* docPointer) {
545 SendMsg(%s, 0, (long)docPointer);''',
546 0),
547
548 'ReleaseDocument' :
549 (0,
550 'void %s(void* docPointer);',
551 '''void %s(void* docPointer) {
552 SendMsg(%s, 0, (long)docPointer);''',
553 0),
554
555 'SetCodePage' :
556 (0,
557 0,
558 '''void %s(int codePage) {
2b5f62a0
VZ
559#if wxUSE_UNICODE
560 wxASSERT_MSG(codePage == wxSTC_CP_UTF8,
561 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
562#else
563 wxASSERT_MSG(codePage != wxSTC_CP_UTF8,
564 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
565#endif
9e730a78
RD
566 SendMsg(%s, codePage);''',
567 ("Set the code page used to interpret the bytes of the document as characters.",) ),
2b5f62a0
VZ
568
569
570 'GrabFocus' : (None, 0, 0, 0),
88a8b04e 571
c26dba42 572 # Rename some that would otherwise hide the wxWindow methods
2b5f62a0
VZ
573 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
574 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
88a8b04e
RD
575 'SetCursor' : ('SetSTCCursor', 0, 0, 0),
576 'GetCursor' : ('GetSTCCursor', 0, 0, 0),
2b5f62a0 577
9e730a78
RD
578 'LoadLexerLibrary' : (None, 0,0,0),
579
580
f97d84a6
RD
581 '' : ('', 0, 0, 0),
582
583 }
584
585#----------------------------------------------------------------------------
586
f2ccce28 587def processIface(iface, h_tmplt, cpp_tmplt, h_dest, cpp_dest, docstr_dest):
f97d84a6
RD
588 curDocStrings = []
589 values = []
590 methods = []
2b5f62a0 591 cmds = []
f97d84a6
RD
592
593 # parse iface file
594 fi = FileInput(iface)
595 for line in fi:
596 line = line[:-1]
597 if line[:2] == '##' or line == '':
598 #curDocStrings = []
599 continue
600
601 op = line[:4]
602 if line[:2] == '# ': # a doc string
603 curDocStrings.append(line[2:])
604
605 elif op == 'val ':
606 parseVal(line[4:], values, curDocStrings)
607 curDocStrings = []
608
609 elif op == 'fun ' or op == 'set ' or op == 'get ':
2b5f62a0 610 parseFun(line[4:], methods, curDocStrings, cmds)
f97d84a6
RD
611 curDocStrings = []
612
613 elif op == 'cat ':
614 if string.strip(line[4:]) == 'Deprecated':
615 break # skip the rest of the file
616
617 elif op == 'evt ':
618 pass
619
a834585d
RD
620 elif op == 'enu ':
621 pass
622
623 elif op == 'lex ':
624 pass
625
f97d84a6
RD
626 else:
627 print '***** Unknown line type: ', line
628
629
630 # process templates
631 data = {}
632 data['VALUES'] = processVals(values)
2b5f62a0 633 data['CMDS'] = processVals(cmds)
f2ccce28 634 defs, imps, docstrings = processMethods(methods)
f97d84a6
RD
635 data['METHOD_DEFS'] = defs
636 data['METHOD_IMPS'] = imps
637
638 # get template text
639 h_text = open(h_tmplt).read()
640 cpp_text = open(cpp_tmplt).read()
641
642 # do the substitutions
643 h_text = h_text % data
644 cpp_text = cpp_text % data
645
646 # write out destination files
647 open(h_dest, 'w').write(h_text)
648 open(cpp_dest, 'w').write(cpp_text)
f2ccce28 649 open(docstr_dest, 'w').write(docstrings)
f97d84a6
RD
650
651
652
653#----------------------------------------------------------------------------
654
655def processVals(values):
656 text = []
657 for name, value, docs in values:
658 if docs:
659 text.append('')
660 for x in docs:
661 text.append('// ' + x)
662 text.append('#define %s %s' % (name, value))
663 return string.join(text, '\n')
664
665#----------------------------------------------------------------------------
666
667def processMethods(methods):
668 defs = []
669 imps = []
f2ccce28 670 dstr = []
f97d84a6
RD
671
672 for retType, name, number, param1, param2, docs in methods:
673 retType = retTypeMap.get(retType, retType)
674 params = makeParamString(param1, param2)
675
676 name, theDef, theImp, docs = checkMethodOverride(name, number, docs)
677
678 if name is None:
679 continue
680
f2ccce28
RD
681 # Build docstrings
682 st = 'DocStr(wxStyledTextCtrl::%s,\n' \
683 '"%s", "");\n' % (name, '\n'.join(docs))
684 dstr.append(st)
685
f97d84a6
RD
686 # Build the method definition for the .h file
687 if docs:
688 defs.append('')
689 for x in docs:
690 defs.append(' // ' + x)
691 if not theDef:
692 theDef = ' %s %s(%s);' % (retType, name, params)
693 defs.append(theDef)
694
695 # Build the method implementation string
696 if docs:
697 imps.append('')
698 for x in docs:
699 imps.append('// ' + x)
700 if not theImp:
701 theImp = '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType, name, params)
702
703 if retType == 'wxColour':
704 theImp = theImp + 'long c = '
705 elif retType != 'void':
706 theImp = theImp + 'return '
707 theImp = theImp + 'SendMsg(%s, %s, %s)' % (number,
708 makeArgString(param1),
709 makeArgString(param2))
710 if retType == 'bool':
711 theImp = theImp + ' != 0'
712 if retType == 'wxColour':
713 theImp = theImp + ';\n return wxColourFromLong(c)'
714
715 theImp = theImp + ';\n}'
716 imps.append(theImp)
717
718
f2ccce28 719 return '\n'.join(defs), '\n'.join(imps), '\n'.join(dstr)
f97d84a6
RD
720
721
722#----------------------------------------------------------------------------
723
724def checkMethodOverride(name, number, docs):
725 theDef = theImp = None
726 if methodOverrideMap.has_key(name):
727 item = methodOverrideMap[name]
728
c13219d6
RD
729 try:
730 if item[0] != 0:
731 name = item[0]
732 if item[1] != 0:
733 theDef = ' ' + (item[1] % name)
734 if item[2] != 0:
735 theImp = item[2] % ('wxStyledTextCtrl::'+name, number) + '\n}'
736 if item[3] != 0:
737 docs = item[3]
738 except:
739 print "*************", name
740 raise
f97d84a6
RD
741
742 return name, theDef, theImp, docs
743
744#----------------------------------------------------------------------------
745
746def makeArgString(param):
747 if not param:
748 return '0'
749
750 typ, name = param
751
752 if typ == 'string':
0c5b83b0 753 return '(long)(const char*)wx2stc(%s)' % name
f97d84a6
RD
754 if typ == 'colour':
755 return 'wxColourAsLong(%s)' % name
756
757 return name
758
759#----------------------------------------------------------------------------
760
761def makeParamString(param1, param2):
762 def doOne(param):
763 if param:
764 aType = paramTypeMap.get(param[0], param[0])
765 return aType + ' ' + param[1]
766 else:
767 return ''
768
769 st = doOne(param1)
770 if st and param2:
771 st = st + ', '
772 st = st + doOne(param2)
773 return st
774
775
776#----------------------------------------------------------------------------
777
778def parseVal(line, values, docs):
779 name, val = string.split(line, '=')
780
781 # remove prefixes such as SCI, etc.
782 for old, new in valPrefixes:
783 lo = len(old)
784 if name[:lo] == old:
785 if new is None:
786 return
787 name = new + name[lo:]
788
789 # add it to the list
790 values.append( ('wxSTC_' + name, val, docs) )
791
792#----------------------------------------------------------------------------
793
794funregex = re.compile(r'\s*([a-zA-Z0-9_]+)' # <ws>return type
795 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
796 '([0-9]+)' # number
797 '\(([ a-zA-Z0-9_]*),' # (param,
798 '([ a-zA-Z0-9_]*)\)') # param)
799
800def parseFun(line, methods, docs, values):
801 def parseParam(param):
802 param = string.strip(param)
803 if param == '':
804 param = None
805 else:
806 param = tuple(string.split(param))
807 return param
808
809 mo = funregex.match(line)
810 if mo is None:
811 print "***** Line doesn't match! : " + line
812
813 retType, name, number, param1, param2 = mo.groups()
814
815 param1 = parseParam(param1)
816 param2 = parseParam(param2)
817
2b5f62a0 818 # Special case. For the key command functions we want a value defined too
f97d84a6
RD
819 num = string.atoi(number)
820 for v in cmdValues:
2b5f62a0 821 if (type(v) == type(()) and v[0] <= num <= v[1]) or v == num:
10ef30eb 822 parseVal('CMD_%s=%s' % (string.upper(name), number), values, docs)
c26dba42
RD
823
824 # if we are not also doing a function for CMD values, then
825 # just return, otherwise fall through to the append blow.
826 if not FUNC_FOR_CMD:
827 return
828
f97d84a6
RD
829 methods.append( (retType, name, number, param1, param2, tuple(docs)) )
830
831
832#----------------------------------------------------------------------------
833
834
835def main(args):
836 # TODO: parse command line args to replace default input/output files???
837
838 # Now just do it
f2ccce28 839 processIface(IFACE, H_TEMPLATE, CPP_TEMPLATE, H_DEST, CPP_DEST, DOCSTR_DEST)
f97d84a6
RD
840
841
842
843if __name__ == '__main__':
844 main(sys.argv)
845
846#----------------------------------------------------------------------------
847