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