]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/gen_iface.py
[ 1491948 ] Fix for a minor GUI bug in wxEditableListBox.
[wxWidgets.git] / contrib / 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 DOCSTR_DEST = os.path.abspath('../../../wxPython/contrib/stc/_stc_gendocs.i')
25
26
27 # Value prefixes to convert
28 valPrefixes = [('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
40 cmdValues = [ (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?
54 FUNC_FOR_CMD = True
55
56
57 # Map some generic typenames to wx types, using return value syntax
58 retTypeMap = {
59 'position': 'int',
60 'string': 'wxString',
61 'colour': 'wxColour',
62 }
63
64 # Map some generic typenames to wx types, using parameter syntax
65 paramTypeMap = {
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 #
81 methodOverrideMap = {
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
493 'ReplaceTarget' :
494 (0,
495 'int %s(const wxString& text);',
496
497 '''
498 int %s(const wxString& text) {
499 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
500 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
501 0),
502
503 'ReplaceTargetRE' :
504 (0,
505 'int %s(const wxString& text);',
506
507 '''
508 int %s(const wxString& text) {
509 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
510 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
511 0),
512
513 'SearchInTarget' :
514 (0,
515 'int %s(const wxString& text);',
516
517 '''
518 int %s(const wxString& text) {
519 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
520 return SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
521 0),
522
523 # not sure what to do about these yet
524 'TargetAsUTF8' : ( None, 0, 0, 0),
525 'SetLengthForEncode' : ( None, 0, 0, 0),
526 'EncodedFromUTF8' : ( None, 0, 0, 0),
527
528
529 'GetProperty' :
530 (0,
531 'wxString %s(const wxString& key);',
532
533 '''wxString %s(const wxString& key) {
534 int len = SendMsg(SCI_GETPROPERTY, (long)(const char*)wx2stc(key), (long)NULL);
535 if (!len) return wxEmptyString;
536
537 wxMemoryBuffer mbuf(len+1);
538 char* buf = (char*)mbuf.GetWriteBuf(len+1);
539 SendMsg(%s, (long)(const char*)wx2stc(key), (long)buf);
540 mbuf.UngetWriteBuf(len);
541 mbuf.AppendByte(0);
542 return stc2wx(buf);''',
543 ("Retrieve a 'property' value previously set with SetProperty.",)),
544
545 'GetPropertyExpanded' :
546 (0,
547 'wxString %s(const wxString& key);',
548
549 '''wxString %s(const wxString& key) {
550 int len = SendMsg(SCI_GETPROPERTYEXPANDED, (long)(const char*)wx2stc(key), (long)NULL);
551 if (!len) return wxEmptyString;
552
553 wxMemoryBuffer mbuf(len+1);
554 char* buf = (char*)mbuf.GetWriteBuf(len+1);
555 SendMsg(%s, (long)(const char*)wx2stc(key), (long)buf);
556 mbuf.UngetWriteBuf(len);
557 mbuf.AppendByte(0);
558 return stc2wx(buf);''',
559 ("Retrieve a 'property' value previously set with SetProperty,",
560 "with '$()' variable replacement on returned buffer.")),
561
562 'GetPropertyInt' : (0, 0, 0,
563 ("Retrieve a 'property' value previously set with SetProperty,",
564 "interpreted as an int AFTER any '$()' variable replacement.")),
565
566
567 'GetDocPointer' :
568 (0,
569 'void* %s();',
570 '''void* %s() {
571 return (void*)SendMsg(%s);''',
572 0),
573
574 'SetDocPointer' :
575 (0,
576 'void %s(void* docPointer);',
577 '''void %s(void* docPointer) {
578 SendMsg(%s, 0, (long)docPointer);''',
579 0),
580
581 'CreateDocument' :
582 (0,
583 'void* %s();',
584 '''void* %s() {
585 return (void*)SendMsg(%s);''',
586 0),
587
588 'AddRefDocument' :
589 (0,
590 'void %s(void* docPointer);',
591 '''void %s(void* docPointer) {
592 SendMsg(%s, 0, (long)docPointer);''',
593 0),
594
595 'ReleaseDocument' :
596 (0,
597 'void %s(void* docPointer);',
598 '''void %s(void* docPointer) {
599 SendMsg(%s, 0, (long)docPointer);''',
600 0),
601
602 'SetCodePage' :
603 (0,
604 0,
605 '''void %s(int codePage) {
606 #if wxUSE_UNICODE
607 wxASSERT_MSG(codePage == wxSTC_CP_UTF8,
608 wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on."));
609 #else
610 wxASSERT_MSG(codePage != wxSTC_CP_UTF8,
611 wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off."));
612 #endif
613 SendMsg(%s, codePage);''',
614 ("Set the code page used to interpret the bytes of the document as characters.",) ),
615
616
617 'GrabFocus' : (None, 0, 0, 0),
618
619 # Rename some that would otherwise hide the wxWindow methods
620 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
621 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
622 'SetCursor' : ('SetSTCCursor', 0, 0, 0),
623 'GetCursor' : ('GetSTCCursor', 0, 0, 0),
624
625 'LoadLexerLibrary' : (None, 0,0,0),
626
627
628 '' : ('', 0, 0, 0),
629
630 }
631
632 #----------------------------------------------------------------------------
633
634 def processIface(iface, h_tmplt, cpp_tmplt, h_dest, cpp_dest, docstr_dest):
635 curDocStrings = []
636 values = []
637 methods = []
638 cmds = []
639
640 # parse iface file
641 fi = FileInput(iface)
642 for line in fi:
643 line = line[:-1]
644 if line[:2] == '##' or line == '':
645 #curDocStrings = []
646 continue
647
648 op = line[:4]
649 if line[:2] == '# ': # a doc string
650 curDocStrings.append(line[2:])
651
652 elif op == 'val ':
653 parseVal(line[4:], values, curDocStrings)
654 curDocStrings = []
655
656 elif op == 'fun ' or op == 'set ' or op == 'get ':
657 parseFun(line[4:], methods, curDocStrings, cmds)
658 curDocStrings = []
659
660 elif op == 'cat ':
661 if string.strip(line[4:]) == 'Deprecated':
662 break # skip the rest of the file
663
664 elif op == 'evt ':
665 pass
666
667 elif op == 'enu ':
668 pass
669
670 elif op == 'lex ':
671 pass
672
673 else:
674 print '***** Unknown line type: ', line
675
676
677 # process templates
678 data = {}
679 data['VALUES'] = processVals(values)
680 data['CMDS'] = processVals(cmds)
681 defs, imps, docstrings = processMethods(methods)
682 data['METHOD_DEFS'] = defs
683 data['METHOD_IMPS'] = imps
684
685 # get template text
686 h_text = open(h_tmplt).read()
687 cpp_text = open(cpp_tmplt).read()
688
689 # do the substitutions
690 h_text = h_text % data
691 cpp_text = cpp_text % data
692
693 # write out destination files
694 open(h_dest, 'w').write(h_text)
695 open(cpp_dest, 'w').write(cpp_text)
696 open(docstr_dest, 'w').write(docstrings)
697
698
699
700 #----------------------------------------------------------------------------
701
702 def processVals(values):
703 text = []
704 for name, value, docs in values:
705 if docs:
706 text.append('')
707 for x in docs:
708 text.append('// ' + x)
709 text.append('#define %s %s' % (name, value))
710 return string.join(text, '\n')
711
712 #----------------------------------------------------------------------------
713
714 def processMethods(methods):
715 defs = []
716 imps = []
717 dstr = []
718
719 for retType, name, number, param1, param2, docs in methods:
720 retType = retTypeMap.get(retType, retType)
721 params = makeParamString(param1, param2)
722
723 name, theDef, theImp, docs = checkMethodOverride(name, number, docs)
724
725 if name is None:
726 continue
727
728 # Build docstrings
729 st = 'DocStr(wxStyledTextCtrl::%s,\n' \
730 '"%s", "");\n' % (name, '\n'.join(docs))
731 dstr.append(st)
732
733 # Build the method definition for the .h file
734 if docs:
735 defs.append('')
736 for x in docs:
737 defs.append(' // ' + x)
738 if not theDef:
739 theDef = ' %s %s(%s);' % (retType, name, params)
740 defs.append(theDef)
741
742 # Build the method implementation string
743 if docs:
744 imps.append('')
745 for x in docs:
746 imps.append('// ' + x)
747 if not theImp:
748 theImp = '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType, name, params)
749
750 if retType == 'wxColour':
751 theImp = theImp + 'long c = '
752 elif retType != 'void':
753 theImp = theImp + 'return '
754 theImp = theImp + 'SendMsg(%s, %s, %s)' % (number,
755 makeArgString(param1),
756 makeArgString(param2))
757 if retType == 'bool':
758 theImp = theImp + ' != 0'
759 if retType == 'wxColour':
760 theImp = theImp + ';\n return wxColourFromLong(c)'
761
762 theImp = theImp + ';\n}'
763 imps.append(theImp)
764
765
766 return '\n'.join(defs), '\n'.join(imps), '\n'.join(dstr)
767
768
769 #----------------------------------------------------------------------------
770
771 def checkMethodOverride(name, number, docs):
772 theDef = theImp = None
773 if methodOverrideMap.has_key(name):
774 item = methodOverrideMap[name]
775
776 try:
777 if item[0] != 0:
778 name = item[0]
779 if item[1] != 0:
780 theDef = ' ' + (item[1] % name)
781 if item[2] != 0:
782 theImp = item[2] % ('wxStyledTextCtrl::'+name, number) + '\n}'
783 if item[3] != 0:
784 docs = item[3]
785 except:
786 print "*************", name
787 raise
788
789 return name, theDef, theImp, docs
790
791 #----------------------------------------------------------------------------
792
793 def makeArgString(param):
794 if not param:
795 return '0'
796
797 typ, name = param
798
799 if typ == 'string':
800 return '(long)(const char*)wx2stc(%s)' % name
801 if typ == 'colour':
802 return 'wxColourAsLong(%s)' % name
803
804 return name
805
806 #----------------------------------------------------------------------------
807
808 def makeParamString(param1, param2):
809 def doOne(param):
810 if param:
811 aType = paramTypeMap.get(param[0], param[0])
812 return aType + ' ' + param[1]
813 else:
814 return ''
815
816 st = doOne(param1)
817 if st and param2:
818 st = st + ', '
819 st = st + doOne(param2)
820 return st
821
822
823 #----------------------------------------------------------------------------
824
825 def parseVal(line, values, docs):
826 name, val = string.split(line, '=')
827
828 # remove prefixes such as SCI, etc.
829 for old, new in valPrefixes:
830 lo = len(old)
831 if name[:lo] == old:
832 if new is None:
833 return
834 name = new + name[lo:]
835
836 # add it to the list
837 values.append( ('wxSTC_' + name, val, docs) )
838
839 #----------------------------------------------------------------------------
840
841 funregex = re.compile(r'\s*([a-zA-Z0-9_]+)' # <ws>return type
842 '\s+([a-zA-Z0-9_]+)=' # <ws>name=
843 '([0-9]+)' # number
844 '\(([ a-zA-Z0-9_]*),' # (param,
845 '([ a-zA-Z0-9_]*)\)') # param)
846
847 def parseFun(line, methods, docs, values):
848 def parseParam(param):
849 param = string.strip(param)
850 if param == '':
851 param = None
852 else:
853 param = tuple(string.split(param))
854 return param
855
856 mo = funregex.match(line)
857 if mo is None:
858 print "***** Line doesn't match! : " + line
859
860 retType, name, number, param1, param2 = mo.groups()
861
862 param1 = parseParam(param1)
863 param2 = parseParam(param2)
864
865 # Special case. For the key command functions we want a value defined too
866 num = string.atoi(number)
867 for v in cmdValues:
868 if (type(v) == type(()) and v[0] <= num <= v[1]) or v == num:
869 parseVal('CMD_%s=%s' % (string.upper(name), number), values, docs)
870
871 # if we are not also doing a function for CMD values, then
872 # just return, otherwise fall through to the append blow.
873 if not FUNC_FOR_CMD:
874 return
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, DOCSTR_DEST)
887
888
889
890 if __name__ == '__main__':
891 main(sys.argv)
892
893 #----------------------------------------------------------------------------
894