]> git.saurik.com Git - wxWidgets.git/blame - contrib/src/stc/gen_iface.py
reSWIGged
[wxWidgets.git] / contrib / src / stc / gen_iface.py
CommitLineData
f97d84a6
RD
1#!/bin/env python
2#----------------------------------------------------------------------------
3# Name: gen_iface.py
4# Purpose: Generate stc.h and stc.cpp from the info in Scintilla.iface
5#
6# Author: Robin Dunn
7#
8# Created: 5-Sept-2000
9# RCS-ID: $Id$
10# Copyright: (c) 2000 by Total Control Software
11# Licence: wxWindows license
12#----------------------------------------------------------------------------
13
14
65ec6247 15import sys, string, re, os
f97d84a6
RD
16from fileinput import FileInput
17
18
65ec6247
RD
19IFACE = os.path.abspath('./scintilla/include/Scintilla.iface')
20H_TEMPLATE = os.path.abspath('./stc.h.in')
21CPP_TEMPLATE = os.path.abspath('./stc.cpp.in')
22H_DEST = os.path.abspath('../../include/wx/stc/stc.h')
23CPP_DEST = os.path.abspath('./stc.cpp')
f2ccce28 24DOCSTR_DEST = os.path.abspath('../../../wxPython/contrib/stc/_stc_gendocs.i')
f97d84a6
RD
25
26
27# Value prefixes to convert
28valPrefixes = [('SCI_', ''),
29 ('SC_', ''),
37d62433 30 ('SCN_', None), # just toss these out...
f97d84a6
RD
31 ('SCEN_', None),
32 ('SCE_', ''),
33 ('SCLEX_', 'LEX_'),
34 ('SCK_', 'KEY_'),
35 ('SCFIND_', 'FIND_'),
36 ('SCWS_', 'WS_'),
37]
38
c26dba42 39# Message function values that should have a CMD_ constant generated
2b5f62a0
VZ
40cmdValues = [ (2300, 2349),
41 2011,
42 2013,
43 (2176, 2180),
44 (2390, 2393),
45 (2395, 2396),
9e730a78
RD
46 2404,
47 (2413, 2416),
8e54aaed 48 (2426, 2442),
c26dba42 49 (2450, 2455),
2b5f62a0 50 ]
f97d84a6
RD
51
52
c26dba42
RD
53# Should a funciton be also generated for the CMDs?
54FUNC_FOR_CMD = True
55
56
f97d84a6
RD
57# Map some generic typenames to wx types, using return value syntax
58retTypeMap = {
59 'position': 'int',
60 'string': 'wxString',
61 'colour': 'wxColour',
62 }
63
64# Map some generic typenames to wx types, using parameter syntax
65paramTypeMap = {
66 'position': 'int',
67 'string': 'const wxString&',
68 'colour': 'const wxColour&',
69 'keymod': 'int',
70}
71
72# Map of method info that needs tweaked. Either the name needs changed, or
73# the method definition/implementation. Tuple items are:
74#
75# 1. New method name. None to skip the method, 0 to leave the
76# default name.
77# 2. Method definition for the .h file, 0 to leave alone
78# 3. Method implementation for the .cpp file, 0 to leave alone.
79# 4. tuple of Doc string lines, or 0 to leave alone.
80#
81methodOverrideMap = {
82 'AddText' : (0,
83 'void %s(const wxString& text);',
84
85 '''void %s(const wxString& text) {
0c5b83b0 86 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
10ef30eb 87 SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
f97d84a6
RD
88 0),
89
90 'AddStyledText' : (0,
10ef30eb 91 'void %s(const wxMemoryBuffer& data);',
f97d84a6 92
10ef30eb
RD
93 '''void %s(const wxMemoryBuffer& data) {
94 SendMsg(%s, data.GetDataLen(), (long)data.GetData());''',
f97d84a6
RD
95 0),
96
41a499cd
RD
97 'AppendText' : (0,
98 'void %s(const wxString& text);',
99
100 '''void %s(const wxString& text) {
101 wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
102 SendMsg(%s, strlen(buf), (long)(const char*)buf);''',
103 0),
104
f97d84a6
RD
105 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0),
106 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0),
107
9e730a78
RD
108 'GetCharAt' :
109 ( 0, 0,
110 '''int %s(int pos) {
111 return (unsigned char)SendMsg(%s, pos, 0);''',
112 0),
113
114 'GetStyleAt' :
115 ( 0, 0,
116 '''int %s(int pos) {
117 return (unsigned char)SendMsg(%s, pos, 0);''',
118 0),
119
120 'GetStyledText' :
121 (0,
122 'wxMemoryBuffer %s(int startPos, int endPos);',
123
124 '''wxMemoryBuffer %s(int startPos, int endPos) {
125 wxMemoryBuffer buf;
126 if (endPos < startPos) {
127 int temp = startPos;
128 startPos = endPos;
129 endPos = temp;
130 }
131 int len = endPos - startPos;
132 if (!len) return buf;
133 TextRange tr;
134 tr.lpstrText = (char*)buf.GetWriteBuf(len*2+1);
135 tr.chrg.cpMin = startPos;
136 tr.chrg.cpMax = endPos;
137 len = SendMsg(%s, 0, (long)&tr);
138 buf.UngetWriteBuf(len);
139 return buf;''',
140
141 ('Retrieve a buffer of cells.',)),
142
143
144 'PositionFromPoint' :
145 (0,
146 'int %s(wxPoint pt);',
147
148 '''int %s(wxPoint pt) {
149 return SendMsg(%s, pt.x, pt.y);''',
150 0),
151
152 'GetCurLine' :
153 (0,
154 '#ifdef SWIG\n wxString %s(int* OUTPUT);\n#else\n wxString GetCurLine(int* linePos=NULL);\n#endif',
155
156 '''wxString %s(int* linePos) {
157 int len = LineLength(GetCurrentLine());
158 if (!len) {
159 if (linePos) *linePos = 0;
160 return wxEmptyString;
161 }
162
163 wxMemoryBuffer mbuf(len+1);
164 char* buf = (char*)mbuf.GetWriteBuf(len+1);
165
166 int pos = SendMsg(%s, len+1, (long)buf);
167 mbuf.UngetWriteBuf(len);
168 mbuf.AppendByte(0);
169 if (linePos) *linePos = pos;
170 return stc2wx(buf);''',
171
172 0),
f97d84a6
RD
173
174 'SetUsePalette' : (None, 0,0,0),
175
176 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0),
177 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0),
178
9e730a78
RD
179 'MarkerDefine' :
180 (0,
181 '''void %s(int markerNumber, int markerSymbol,
182 const wxColour& foreground = wxNullColour,
183 const wxColour& background = wxNullColour);''',
184
185 '''void %s(int markerNumber, int markerSymbol,
186 const wxColour& foreground,
187 const wxColour& background) {
188
189 SendMsg(%s, markerNumber, markerSymbol);
190 if (foreground.Ok())
191 MarkerSetForeground(markerNumber, foreground);
192 if (background.Ok())
193 MarkerSetBackground(markerNumber, background);''',
194
195 ('Set the symbol used for a particular marker number,',
196 'and optionally the fore and background colours.')),
197
198
199 'MarkerDefinePixmap' :
200 ('MarkerDefineBitmap',
201 '''void %s(int markerNumber, const wxBitmap& bmp);''',
202 '''void %s(int markerNumber, const wxBitmap& bmp) {
203 // convert bmp to a xpm in a string
204 wxMemoryOutputStream strm;
205 wxImage img = bmp.ConvertToImage();
e45b3f17
RD
206 if (img.HasAlpha())
207 img.ConvertAlphaToMask();
9e730a78
RD
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',)),
f97d84a6 217
f97d84a6
RD
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),
3727c043
RD
234 'StyleSetCharacterSet' : (None, 0, 0, 0),
235
9e730a78
RD
236 'AssignCmdKey' :
237 ('CmdKeyAssign',
238 'void %s(int key, int modifiers, int cmd);',
f97d84a6 239
9e730a78
RD
240 '''void %s(int key, int modifiers, int cmd) {
241 SendMsg(%s, MAKELONG(key, modifiers), cmd);''',
242 0),
f97d84a6 243
f97d84a6 244
9e730a78
RD
245 'ClearCmdKey' :
246 ('CmdKeyClear',
247 'void %s(int key, int modifiers);',
f97d84a6 248
9e730a78
RD
249 '''void %s(int key, int modifiers) {
250 SendMsg(%s, MAKELONG(key, modifiers));''',
251 0),
f97d84a6
RD
252
253 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0),
254
255
9e730a78
RD
256 'SetStylingEx' :
257 ('SetStyleBytes',
258 'void %s(int length, char* styleBytes);',
f97d84a6 259
9e730a78
RD
260 '''void %s(int length, char* styleBytes) {
261 SendMsg(%s, length, (long)styleBytes);''',
262 0),
f97d84a6
RD
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
f114b858
RD
270 'SetWhitespaceFore' : ('SetWhitespaceForeground', 0, 0, 0),
271 'SetWhitespaceBack' : ('SetWhitespaceBackground', 0, 0, 0),
272
f97d84a6
RD
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),
65ec6247
RD
289 'AutoCSetAutoHide' : ('AutoCompSetAutoHide', 0, 0, 0),
290 'AutoCGetAutoHide' : ('AutoCompGetAutoHide', 0, 0, 0),
1a2fb4cd
RD
291 'AutoCSetDropRestOfWord' : ('AutoCompSetDropRestOfWord', 0,0,0),
292 'AutoCGetDropRestOfWord' : ('AutoCompGetDropRestOfWord', 0,0,0),
9e730a78
RD
293 'AutoCGetTypeSeparator' : ('AutoCompGetTypeSeparator', 0, 0, 0),
294 'AutoCSetTypeSeparator' : ('AutoCompSetTypeSeparator', 0, 0, 0),
8e54aaed 295 'AutoCGetCurrent' : ('AutoCompGetCurrent', 0, 0, 0),
1e9bafca
RD
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
9e730a78
RD
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();
e45b3f17
RD
309 if (img.HasAlpha())
310 img.ConvertAlphaToMask();
9e730a78
RD
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.',)),
65ec6247 324
f97d84a6
RD
325
326 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0),
327 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0),
328
9e730a78
RD
329 'SetVScrollBar' : ('SetUseVerticalScrollBar', 0, 0, 0),
330 'GetVScrollBar' : ('GetUseVerticalScrollBar', 0, 0, 0),
331
f97d84a6
RD
332 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0),
333
334 'GetUsePalette' : (None, 0, 0, 0),
335
9e730a78
RD
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,
8e54aaed 358 wxDC* target,
9e730a78
RD
359 wxRect renderRect,
360 wxRect pageRect);''',
361 ''' int %s(bool doDraw,
362 int startPos,
363 int endPos,
364 wxDC* draw,
8e54aaed 365 wxDC* target,
9e730a78
RD
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.',)),
f97d84a6
RD
408
409 'SetSel' : ('SetSelection', 0, 0, 0),
9e730a78
RD
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
3d7a4fe8 423 wxMemoryBuffer mbuf(len+2);
9e730a78
RD
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.',)),
f97d84a6
RD
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
9e730a78
RD
465 'GetText' :
466 (0,
467 'wxString %s();',
f97d84a6 468
9e730a78
RD
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);''',
f97d84a6 477
9e730a78 478 ('Retrieve all the text in the document.', )),
f97d84a6
RD
479
480 'GetDirectFunction' : (None, 0, 0, 0),
481 'GetDirectPointer' : (None, 0, 0, 0),
482
9e730a78
RD
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
a33203cb
RD
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),
1e9bafca
RD
527
528
529 'GetProperty' :
530 (0,
531 'wxString %s(const wxString& key);',
532
533 '''wxString %s(const wxString& key) {
cd2e8564 534 int len = SendMsg(SCI_GETPROPERTY, (long)(const char*)wx2stc(key), (long)NULL);
1e9bafca
RD
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) {
cd2e8564 550 int len = SendMsg(SCI_GETPROPERTYEXPANDED, (long)(const char*)wx2stc(key), (long)NULL);
1e9bafca
RD
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
9e730a78
RD
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) {
2b5f62a0
VZ
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
9e730a78
RD
613 SendMsg(%s, codePage);''',
614 ("Set the code page used to interpret the bytes of the document as characters.",) ),
2b5f62a0
VZ
615
616
617 'GrabFocus' : (None, 0, 0, 0),
88a8b04e 618
c26dba42 619 # Rename some that would otherwise hide the wxWindow methods
2b5f62a0
VZ
620 'SetFocus' : ('SetSTCFocus', 0, 0, 0),
621 'GetFocus' : ('GetSTCFocus', 0, 0, 0),
88a8b04e
RD
622 'SetCursor' : ('SetSTCCursor', 0, 0, 0),
623 'GetCursor' : ('GetSTCCursor', 0, 0, 0),
2b5f62a0 624
9e730a78
RD
625 'LoadLexerLibrary' : (None, 0,0,0),
626
627
f97d84a6
RD
628 '' : ('', 0, 0, 0),
629
630 }
631
632#----------------------------------------------------------------------------
633
f2ccce28 634def processIface(iface, h_tmplt, cpp_tmplt, h_dest, cpp_dest, docstr_dest):
f97d84a6
RD
635 curDocStrings = []
636 values = []
637 methods = []
2b5f62a0 638 cmds = []
f97d84a6
RD
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 ':
2b5f62a0 657 parseFun(line[4:], methods, curDocStrings, cmds)
f97d84a6
RD
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
a834585d
RD
667 elif op == 'enu ':
668 pass
669
670 elif op == 'lex ':
671 pass
672
f97d84a6
RD
673 else:
674 print '***** Unknown line type: ', line
675
676
677 # process templates
678 data = {}
679 data['VALUES'] = processVals(values)
2b5f62a0 680 data['CMDS'] = processVals(cmds)
f2ccce28 681 defs, imps, docstrings = processMethods(methods)
f97d84a6
RD
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)
f2ccce28 696 open(docstr_dest, 'w').write(docstrings)
f97d84a6
RD
697
698
699
700#----------------------------------------------------------------------------
701
702def 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
714def processMethods(methods):
715 defs = []
716 imps = []
f2ccce28 717 dstr = []
f97d84a6
RD
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
f2ccce28
RD
728 # Build docstrings
729 st = 'DocStr(wxStyledTextCtrl::%s,\n' \
730 '"%s", "");\n' % (name, '\n'.join(docs))
731 dstr.append(st)
732
f97d84a6
RD
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
f2ccce28 766 return '\n'.join(defs), '\n'.join(imps), '\n'.join(dstr)
f97d84a6
RD
767
768
769#----------------------------------------------------------------------------
770
771def checkMethodOverride(name, number, docs):
772 theDef = theImp = None
773 if methodOverrideMap.has_key(name):
774 item = methodOverrideMap[name]
775
c13219d6
RD
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
f97d84a6
RD
788
789 return name, theDef, theImp, docs
790
791#----------------------------------------------------------------------------
792
793def makeArgString(param):
794 if not param:
795 return '0'
796
797 typ, name = param
798
799 if typ == 'string':
0c5b83b0 800 return '(long)(const char*)wx2stc(%s)' % name
f97d84a6
RD
801 if typ == 'colour':
802 return 'wxColourAsLong(%s)' % name
803
804 return name
805
806#----------------------------------------------------------------------------
807
808def 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
825def 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
841funregex = 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
847def 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
2b5f62a0 865 # Special case. For the key command functions we want a value defined too
f97d84a6
RD
866 num = string.atoi(number)
867 for v in cmdValues:
2b5f62a0 868 if (type(v) == type(()) and v[0] <= num <= v[1]) or v == num:
10ef30eb 869 parseVal('CMD_%s=%s' % (string.upper(name), number), values, docs)
c26dba42
RD
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
f97d84a6
RD
876 methods.append( (retType, name, number, param1, param2, tuple(docs)) )
877
878
879#----------------------------------------------------------------------------
880
881
882def main(args):
883 # TODO: parse command line args to replace default input/output files???
884
885 # Now just do it
f2ccce28 886 processIface(IFACE, H_TEMPLATE, CPP_TEMPLATE, H_DEST, CPP_DEST, DOCSTR_DEST)
f97d84a6
RD
887
888
889
890if __name__ == '__main__':
891 main(sys.argv)
892
893#----------------------------------------------------------------------------
894