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