]>
Commit | Line | Data |
---|---|---|
7bf85405 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: my_typemaps.i | |
3 | // Purpose: Special typemaps specifically for wxPython. | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 7/3/97 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 1998 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | ||
cf694132 | 14 | //--------------------------------------------------------------------------- |
4268f798 | 15 | // Tell SWIG to wrap all the wrappers with our thread protection |
cf694132 RD |
16 | |
17 | %except(python) { | |
4268f798 | 18 | PyThreadState* __tstate = wxPyBeginAllowThreads(); |
c8bc7bb8 | 19 | $function |
4268f798 | 20 | wxPyEndAllowThreads(__tstate); |
493f1553 | 21 | if (PyErr_Occurred()) return NULL; |
cf694132 RD |
22 | } |
23 | ||
7bf85405 | 24 | //---------------------------------------------------------------------- |
eec92d76 | 25 | // LCOUNT and choices go together. They allow a single Python list to be |
2f90df85 | 26 | // converted to an integer count and an array count items long. |
7bf85405 RD |
27 | |
28 | %typemap(python,build) int LCOUNT { | |
eec92d76 RD |
29 | if (_in_choices) { |
30 | $target = PyList_Size(_in_choices); | |
cf694132 RD |
31 | } |
32 | else { | |
33 | $target = 0; | |
34 | } | |
7bf85405 RD |
35 | } |
36 | ||
37 | ||
38 | ||
eec92d76 | 39 | %typemap(python,in) byte* choices { |
b639c3c5 RD |
40 | $target = byte_LIST_helper($source); |
41 | if ($target == NULL) { | |
42 | return NULL; | |
43 | } | |
44 | } | |
eec92d76 | 45 | %typemap(python,freearg) byte* choices { |
b639c3c5 RD |
46 | delete [] $source; |
47 | } | |
48 | ||
de9d9ed2 RD |
49 | // wxDash is a signed char |
50 | %typemap(python,in) wxDash* choices { | |
51 | $target = (wxDash*)byte_LIST_helper($source); | |
52 | if ($target == NULL) { | |
53 | return NULL; | |
54 | } | |
55 | } | |
56 | %typemap(python,freearg) wxDash* choices { | |
57 | delete [] $source; | |
58 | } | |
59 | ||
b639c3c5 | 60 | |
eec92d76 | 61 | %typemap(python,in) int* choices { |
7bf85405 RD |
62 | $target = int_LIST_helper($source); |
63 | if ($target == NULL) { | |
64 | return NULL; | |
65 | } | |
66 | } | |
eec92d76 | 67 | %typemap(python,freearg) int* choices { |
7bf85405 RD |
68 | delete [] $source; |
69 | } | |
70 | ||
71 | ||
eec92d76 | 72 | %typemap(python,in) long* choices { |
7bf85405 RD |
73 | $target = long_LIST_helper($source); |
74 | if ($target == NULL) { | |
75 | return NULL; | |
76 | } | |
77 | } | |
eec92d76 | 78 | %typemap(python,freearg) long* choices { |
7bf85405 RD |
79 | delete [] $source; |
80 | } | |
81 | ||
82 | ||
eec92d76 | 83 | %typemap(python,in) unsigned long* choices { |
7bf85405 RD |
84 | $target = (unsigned long*)long_LIST_helper($source); |
85 | if ($target == NULL) { | |
86 | return NULL; | |
87 | } | |
88 | } | |
eec92d76 | 89 | %typemap(python,freearg) unsigned long* choices { |
7bf85405 RD |
90 | delete [] $source; |
91 | } | |
92 | ||
93 | ||
eec92d76 | 94 | %typemap(python,in) char** choices { |
7bf85405 RD |
95 | $target = string_LIST_helper($source); |
96 | if ($target == NULL) { | |
97 | return NULL; | |
98 | } | |
99 | } | |
eec92d76 | 100 | %typemap(python,freearg) char** choices { |
7bf85405 RD |
101 | delete [] $source; |
102 | } | |
103 | ||
104 | ||
eec92d76 RD |
105 | %typemap(python,in) wxBitmap** choices { |
106 | $target = wxBitmap_LIST_helper($source); | |
7bf85405 RD |
107 | if ($target == NULL) { |
108 | return NULL; | |
109 | } | |
110 | } | |
eec92d76 | 111 | %typemap(python,freearg) wxBitmap** choices { |
7bf85405 RD |
112 | delete [] $source; |
113 | } | |
114 | ||
eec92d76 RD |
115 | %typemap(python,in) wxString* choices { |
116 | $target = wxString_LIST_helper($source); | |
7bf85405 RD |
117 | if ($target == NULL) { |
118 | return NULL; | |
119 | } | |
120 | } | |
eec92d76 | 121 | %typemap(python,freearg) wxString* choices { |
7bf85405 RD |
122 | delete [] $source; |
123 | } | |
124 | ||
eec92d76 RD |
125 | %typemap(python,in) wxAcceleratorEntry* choices { |
126 | $target = wxAcceleratorEntry_LIST_helper($source); | |
7bf85405 RD |
127 | if ($target == NULL) { |
128 | return NULL; | |
129 | } | |
130 | } | |
eec92d76 | 131 | %typemap(python,freearg) wxAcceleratorEntry* choices { |
7bf85405 RD |
132 | delete [] $source; |
133 | } | |
134 | ||
eec92d76 | 135 | %typemap(python,build) int PCOUNT { |
e0672e2f | 136 | $target = NPOINTS; |
eec92d76 RD |
137 | } |
138 | ||
e0672e2f RD |
139 | %typemap(python,in) wxPoint* points (int NPOINTS) { |
140 | $target = wxPoint_LIST_helper($source, &NPOINTS); | |
141 | if ($target == NULL) { | |
142 | return NULL; | |
143 | } | |
7bf85405 | 144 | } |
eec92d76 | 145 | %typemap(python,freearg) wxPoint* points { |
7bf85405 RD |
146 | delete [] $source; |
147 | } | |
148 | ||
149 | ||
eec92d76 | 150 | |
e0672e2f | 151 | |
7bf85405 RD |
152 | //--------------------------------------------------------------------------- |
153 | ||
c8bc7bb8 | 154 | |
7bf85405 | 155 | %typemap(python, in) wxString& { |
c8bc7bb8 RD |
156 | $target = wxString_in_helper($source); |
157 | if ($target == NULL) | |
185d7c3e | 158 | return NULL; |
7bf85405 | 159 | } |
185d7c3e RD |
160 | |
161 | ||
7bf85405 RD |
162 | %typemap(python, freearg) wxString& { |
163 | if ($target) | |
164 | delete $source; | |
165 | } | |
166 | ||
167 | ||
168 | ||
169 | %typemap(python, out) wxString { | |
c8bc7bb8 | 170 | #if wxUSE_UNICODE |
1e4a197e | 171 | $target = PyUnicode_FromWideChar($source->c_str(), $source->Len()); |
c8bc7bb8 | 172 | #else |
eec92d76 | 173 | $target = PyString_FromStringAndSize($source->c_str(), $source->Len()); |
c8bc7bb8 | 174 | #endif |
7bf85405 RD |
175 | } |
176 | %typemap(python, ret) wxString { | |
177 | delete $source; | |
178 | } | |
179 | ||
180 | ||
181 | %typemap(python, out) wxString* { | |
c8bc7bb8 | 182 | #if wxUSE_UNICODE |
1e4a197e | 183 | $target = PyUnicode_FromWideChar($source->c_str(), $source->Len()); |
c8bc7bb8 | 184 | #else |
eec92d76 | 185 | $target = PyString_FromStringAndSize($source->c_str(), $source->Len()); |
c8bc7bb8 | 186 | #endif |
7bf85405 RD |
187 | } |
188 | ||
189 | ||
2f90df85 | 190 | |
10ef30eb RD |
191 | //--------------------------------------------------------------------------- |
192 | ||
193 | ||
194 | %typemap(python, in) wxMemoryBuffer& { | |
195 | if (!PyString_Check($source)) { | |
196 | PyErr_SetString(PyExc_TypeError, "String buffer expected"); | |
197 | return NULL; | |
198 | } | |
199 | char* str = PyString_AS_STRING($source); | |
200 | int len = PyString_GET_SIZE($source); | |
201 | $target = new wxMemoryBuffer(len); | |
202 | memcpy($target->GetData(), str, len); | |
203 | } | |
204 | ||
205 | %typemap(python, freearg) wxMemoryBuffer& { | |
206 | if ($target) | |
207 | delete $source; | |
208 | } | |
209 | ||
210 | %typemap(python, out) wxMemoryBuffer { | |
211 | $target = PyString_FromStringAndSize((char*)$source->GetData(), $source->GetDataLen()); | |
212 | } | |
213 | ||
214 | %typemap(python, ret) wxMemoryBuffer { | |
215 | delete $source; | |
216 | } | |
2f90df85 RD |
217 | |
218 | ||
7bf85405 | 219 | //--------------------------------------------------------------------------- |
0122b7e3 | 220 | // Typemaps to convert Python sequence objects (tuples, etc.) to |
2f90df85 RD |
221 | // wxSize, wxPoint, wxRealPoint, and wxRect. |
222 | ||
223 | %typemap(python,in) wxSize& (wxSize temp) { | |
224 | $target = &temp; | |
225 | if (! wxSize_helper($source, &$target)) | |
226 | return NULL; | |
227 | } | |
228 | ||
229 | %typemap(python,in) wxPoint& (wxPoint temp) { | |
230 | $target = &temp; | |
231 | if (! wxPoint_helper($source, &$target)) | |
232 | return NULL; | |
233 | } | |
234 | ||
235 | %typemap(python,in) wxRealPoint& (wxRealPoint temp) { | |
236 | $target = &temp; | |
237 | if (! wxRealPoint_helper($source, &$target)) | |
238 | return NULL; | |
239 | } | |
7bf85405 | 240 | |
2f90df85 RD |
241 | %typemap(python,in) wxRect& (wxRect temp) { |
242 | $target = &temp; | |
243 | if (! wxRect_helper($source, &$target)) | |
244 | return NULL; | |
245 | } | |
7bf85405 | 246 | |
1e4a197e RD |
247 | %typemap(python,in) wxPoint2DDouble& (wxPoint2DDouble temp) { |
248 | $target = &temp; | |
249 | if (! wxPoint2DDouble_helper($source, &$target)) | |
250 | return NULL; | |
251 | } | |
252 | ||
f6bcfd97 BP |
253 | //--------------------------------------------------------------------------- |
254 | // Typemap to convert strings to wxColour. Two string formats are accepted, | |
de20db99 | 255 | // either a colour name, or a hex colour spec like "#RRGGBB" |
f6bcfd97 BP |
256 | |
257 | %typemap(python,in) wxColour& (wxColour temp) { | |
258 | $target = &temp; | |
259 | if (! wxColour_helper($source, &$target)) | |
260 | return NULL; | |
261 | } | |
262 | ||
b37c7e1d RD |
263 | //--------------------------------------------------------------------------- |
264 | // Typemap for wxArrayString from Python sequence objects | |
265 | ||
266 | %typemap(python,in) wxArrayString& { | |
267 | if (! PySequence_Check($source)) { | |
268 | PyErr_SetString(PyExc_TypeError, "Sequence of strings expected."); | |
269 | return NULL; | |
270 | } | |
271 | $target = new wxArrayString; | |
272 | int i, len=PySequence_Length($source); | |
273 | for (i=0; i<len; i++) { | |
274 | PyObject* item = PySequence_GetItem($source, i); | |
c8bc7bb8 RD |
275 | #if wxUSE_UNICODE |
276 | PyObject* str = PyObject_Unicode(item); | |
c8bc7bb8 | 277 | #else |
b37c7e1d | 278 | PyObject* str = PyObject_Str(item); |
c8bc7bb8 | 279 | #endif |
1e4a197e | 280 | $target->Add(Py2wxString(str)); |
b37c7e1d RD |
281 | Py_DECREF(item); |
282 | Py_DECREF(str); | |
283 | } | |
284 | } | |
285 | ||
286 | %typemap(python, freearg) wxArrayString& { | |
287 | if ($target) | |
288 | delete $source; | |
289 | } | |
7bf85405 | 290 | |
293a0a86 RD |
291 | //--------------------------------------------------------------------------- |
292 | // Typemap for wxArrayInt from Python sequence objects | |
293 | ||
294 | %typemap(python,in) wxArrayInt& { | |
295 | if (! PySequence_Check($source)) { | |
296 | PyErr_SetString(PyExc_TypeError, "Sequence of integers expected."); | |
297 | return NULL; | |
298 | } | |
299 | $target = new wxArrayInt; | |
300 | int i, len=PySequence_Length($source); | |
301 | for (i=0; i<len; i++) { | |
302 | PyObject* item = PySequence_GetItem($source, i); | |
303 | PyObject* number = PyNumber_Int(item); | |
304 | $target->Add(PyInt_AS_LONG(number)); | |
305 | Py_DECREF(item); | |
306 | Py_DECREF(number); | |
307 | } | |
308 | } | |
309 | ||
310 | %typemap(python, freearg) wxArrayInt& { | |
311 | if ($target) | |
312 | delete $source; | |
313 | } | |
314 | ||
315 | ||
1e4a197e RD |
316 | // Typemaps to convert an array of ints to a list |
317 | %typemap(python, out) wxArrayInt& { | |
318 | $target = PyList_New(0); | |
319 | size_t idx; | |
320 | for (idx = 0; idx < $source->GetCount(); idx += 1) { | |
321 | PyObject* val = PyInt_FromLong($source->Item(idx)); | |
322 | PyList_Append($target, val); | |
323 | Py_DECREF(val); | |
324 | } | |
325 | } | |
326 | ||
327 | %typemap(python, out) wxArrayInt { | |
328 | $target = PyList_New(0); | |
329 | size_t idx; | |
330 | for (idx = 0; idx < $source->GetCount(); idx += 1) { | |
331 | PyObject* val = PyInt_FromLong($source->Item(idx)); | |
332 | PyList_Append($target, val); | |
333 | Py_DECREF(val); | |
334 | } | |
335 | delete $source; | |
336 | } | |
337 | ||
338 | ||
2f90df85 | 339 | //--------------------------------------------------------------------------- |
7bf85405 RD |
340 | // Map T_OUTPUTs for floats to return ints. |
341 | ||
342 | ||
343 | %typemap(python,ignore) float *T_OUTPUT_TOINT(float temp), | |
344 | double *T_OUTPUT_TOINT(double temp) | |
345 | { | |
346 | $target = &temp; | |
347 | } | |
348 | ||
349 | ||
350 | %typemap(python,argout) float *T_OUTPUT_TOINT, | |
351 | double *T_OUTPUT_TOINT | |
352 | { | |
353 | PyObject *o; | |
354 | o = PyInt_FromLong((long) (*$source)); | |
355 | $target = t_output_helper($target, o); | |
356 | } | |
357 | ||
68320e40 RD |
358 | |
359 | %typemap(python,ignore) bool *T_OUTPUT(int temp) | |
360 | { | |
361 | $target = (bool*)&temp; | |
362 | } | |
363 | ||
364 | %typemap(python,argout) bool *T_OUTPUT | |
365 | { | |
366 | PyObject *o; | |
367 | o = PyInt_FromLong((long) (*$source)); | |
368 | $target = t_output_helper($target, o); | |
369 | } | |
370 | ||
68320e40 RD |
371 | %typemap(python,ignore) bool *OUTPUT = bool *T_OUTPUT; |
372 | %typemap(python,argout) bool *OUTPUT = bool *T_OUTPUT; | |
373 | ||
154747f5 RD |
374 | |
375 | ||
376 | %typemap(python,ignore) byte *T_OUTPUT(int temp) | |
377 | { | |
378 | $target = (byte*)&temp; | |
379 | } | |
380 | ||
381 | %typemap(python,argout) byte *T_OUTPUT | |
382 | { | |
383 | PyObject *o; | |
384 | o = PyInt_FromLong((long) (*$source)); | |
385 | $target = t_output_helper($target, o); | |
386 | } | |
387 | ||
388 | %typemap(python,ignore) byte *OUTPUT = byte *T_OUTPUT; | |
389 | %typemap(python,argout) byte *OUTPUT = byte *T_OUTPUT; | |
390 | ||
1e4a197e RD |
391 | |
392 | %typemap(python,ignore) wxCoord *OUTPUT = int *OUTPUT; | |
393 | %typemap(python,argout) wxCoord *OUTPUT = int *OUTPUT; | |
394 | ||
395 | ||
9416aa89 RD |
396 | //--------------------------------------------------------------------------- |
397 | // Typemaps to convert return values that are base class pointers | |
398 | // to the real derived type, if possible. See wxPyMake_wxObject in | |
399 | // helpers.cpp | |
400 | ||
0122b7e3 RD |
401 | %typemap(python, out) wxEvtHandler* { $target = wxPyMake_wxObject($source); } |
402 | %typemap(python, out) wxMenu* { $target = wxPyMake_wxObject($source); } | |
403 | %typemap(python, out) wxValidator* { $target = wxPyMake_wxObject($source); } | |
9416aa89 | 404 | |
1e4a197e RD |
405 | %typemap(python, out) wxApp* { $target = wxPyMake_wxObject($source); } |
406 | %typemap(python, out) wxPyApp* { $target = wxPyMake_wxObject($source); } | |
9416aa89 | 407 | %typemap(python, out) wxDC* { $target = wxPyMake_wxObject($source); } |
9416aa89 RD |
408 | %typemap(python, out) wxFSFile* { $target = wxPyMake_wxObject($source); } |
409 | %typemap(python, out) wxFileSystem* { $target = wxPyMake_wxObject($source); } | |
9416aa89 RD |
410 | %typemap(python, out) wxGridTableBase* { $target = wxPyMake_wxObject($source); } |
411 | %typemap(python, out) wxImageList* { $target = wxPyMake_wxObject($source); } | |
412 | %typemap(python, out) wxListItem* { $target = wxPyMake_wxObject($source); } | |
9416aa89 RD |
413 | %typemap(python, out) wxMenuItem* { $target = wxPyMake_wxObject($source); } |
414 | %typemap(python, out) wxMouseEvent* { $target = wxPyMake_wxObject($source); } | |
9416aa89 RD |
415 | %typemap(python, out) wxObject* { $target = wxPyMake_wxObject($source); } |
416 | %typemap(python, out) wxPyPrintout* { $target = wxPyMake_wxObject($source); } | |
0122b7e3 RD |
417 | %typemap(python, out) wxToolBarToolBase* { $target = wxPyMake_wxObject($source); } |
418 | %typemap(python, out) wxToolTip* { $target = wxPyMake_wxObject($source); } | |
419 | ||
420 | ||
7c379a20 | 421 | %typemap(python, out) wxBitmapButton* { $target = wxPyMake_wxObject($source); } |
0122b7e3 RD |
422 | %typemap(python, out) wxButton* { $target = wxPyMake_wxObject($source); } |
423 | %typemap(python, out) wxControl* { $target = wxPyMake_wxObject($source); } | |
424 | %typemap(python, out) wxFrame* { $target = wxPyMake_wxObject($source); } | |
425 | %typemap(python, out) wxGrid* { $target = wxPyMake_wxObject($source); } | |
7c379a20 | 426 | %typemap(python, out) wxListCtrl* { $target = wxPyMake_wxObject($source); } |
0122b7e3 RD |
427 | %typemap(python, out) wxMDIChildFrame* { $target = wxPyMake_wxObject($source); } |
428 | %typemap(python, out) wxMDIClientWindow* { $target = wxPyMake_wxObject($source); } | |
429 | %typemap(python, out) wxMenuBar* { $target = wxPyMake_wxObject($source); } | |
430 | %typemap(python, out) wxNotebook* { $target = wxPyMake_wxObject($source); } | |
9416aa89 RD |
431 | %typemap(python, out) wxStaticBox* { $target = wxPyMake_wxObject($source); } |
432 | %typemap(python, out) wxStatusBar* { $target = wxPyMake_wxObject($source); } | |
433 | %typemap(python, out) wxTextCtrl* { $target = wxPyMake_wxObject($source); } | |
434 | %typemap(python, out) wxToolBar* { $target = wxPyMake_wxObject($source); } | |
435 | %typemap(python, out) wxToolBarBase* { $target = wxPyMake_wxObject($source); } | |
9398120d | 436 | %typemap(python, out) wxTreeCtrl* { $target = wxPyMake_wxObject($source); } |
9416aa89 | 437 | %typemap(python, out) wxWindow* { $target = wxPyMake_wxObject($source); } |
6c5ae2d2 | 438 | %typemap(python, out) wxHtmlWindow* { $target = wxPyMake_wxObject($source); } |
1fded56b | 439 | %typemap(python, out) wxPyHtmlWindow* { $target = wxPyMake_wxObject($source); } |
6a6ff564 | 440 | %typemap(python, out) wxWizardPage* { $target = wxPyMake_wxObject($source); } |
9416aa89 | 441 | |
2f4e9287 RD |
442 | %typemap(python, out) wxSizer* { $target = wxPyMake_wxSizer($source); } |
443 | ||
9416aa89 RD |
444 | |
445 | //%typemap(python, out) wxHtmlCell* { $target = wxPyMake_wxObject($source); } | |
446 | //%typemap(python, out) wxHtmlContainerCell* { $target = wxPyMake_wxObject($source); } | |
447 | //%typemap(python, out) wxHtmlParser* { $target = wxPyMake_wxObject($source); } | |
448 | //%typemap(python, out) wxHtmlWinParser* { $target = wxPyMake_wxObject($source); } | |
449 | ||
7bf85405 | 450 | //--------------------------------------------------------------------------- |
2f90df85 | 451 | //--------------------------------------------------------------------------- |
7bf85405 | 452 | |
9416aa89 RD |
453 | |
454 | ||
455 | ||
456 | ||
457 |