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