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