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