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