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