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