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