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