]>
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 | ||
d14a1e28 RD |
14 | //---------------------------------------------------------------------- |
15 | // Typemaps to convert a list of items to an int (size) and an array | |
16 | ||
9f8a9f54 RD |
17 | %define MAKE_INT_ARRAY_TYPEMAPS(NAME, ARR_NAME) |
18 | %typemap(in) (int NAME, int* ARR_NAME) { | |
19 | $1 = PyList_Size($input); | |
20 | $2 = int_LIST_helper($input); | |
21 | if ($2 == NULL) SWIG_fail; | |
22 | } | |
23 | ||
24 | %typemap(freearg) (int NAME, int* ARR_NAME) { | |
25 | if ($2) delete [] $2; | |
26 | } | |
27 | %enddef | |
28 | ||
29 | MAKE_INT_ARRAY_TYPEMAPS(widths, widths_field) | |
30 | MAKE_INT_ARRAY_TYPEMAPS(styles, styles_field) | |
31 | ||
32 | ||
33 | ||
34 | // Same things for a wxString | |
d14a1e28 RD |
35 | %typemap(in) (int choices, wxString* choices_array ) { |
36 | $1 = PyList_Size($input); | |
37 | $2 = wxString_LIST_helper($input); | |
38 | if ($2 == NULL) SWIG_fail; | |
39 | } | |
40 | %typemap(freearg) (int choices, wxString* choices_array ) { | |
41 | if ($2) delete [] $2; | |
42 | } | |
43 | ||
44 | ||
9f8a9f54 | 45 | |
d14a1e28 | 46 | //--------------------------------------------------------------------------- |
dd9f7fea | 47 | // wxString typemaps |
7bf85405 RD |
48 | |
49 | ||
a72f4631 | 50 | %typemap(in) wxString& (bool temp=false) { |
d14a1e28 RD |
51 | $1 = wxString_in_helper($input); |
52 | if ($1 == NULL) SWIG_fail; | |
a72f4631 | 53 | temp = true; |
7bf85405 | 54 | } |
d14a1e28 RD |
55 | %typemap(freearg) wxString& { |
56 | if (temp$argnum) | |
57 | delete $1; | |
7bf85405 RD |
58 | } |
59 | ||
54b29c1f | 60 | %typemap(out) wxString& { |
d14a1e28 RD |
61 | %#if wxUSE_UNICODE |
62 | $result = PyUnicode_FromWideChar($1->c_str(), $1->Len()); | |
63 | %#else | |
64 | $result = PyString_FromStringAndSize($1->c_str(), $1->Len()); | |
65 | %#endif | |
7bf85405 RD |
66 | } |
67 | ||
87c2245b | 68 | |
54b29c1f RD |
69 | %apply wxString& { wxString* } |
70 | ||
71 | ||
72 | ||
73 | %typemap(out) wxString { | |
87c2245b | 74 | %#if wxUSE_UNICODE |
54b29c1f | 75 | $result = PyUnicode_FromWideChar($1.c_str(), $1.Len()); |
87c2245b | 76 | %#else |
54b29c1f | 77 | $result = PyString_FromStringAndSize($1.c_str(), $1.Len()); |
87c2245b RD |
78 | %#endif |
79 | } | |
80 | ||
dd9f7fea | 81 | %typemap(varout) wxString { |
d14a1e28 RD |
82 | %#if wxUSE_UNICODE |
83 | $result = PyUnicode_FromWideChar($1.c_str(), $1.Len()); | |
84 | %#else | |
85 | $result = PyString_FromStringAndSize($1.c_str(), $1.Len()); | |
86 | %#endif | |
7bf85405 RD |
87 | } |
88 | ||
eec92d76 | 89 | |
dd9f7fea RD |
90 | %typemap(in) wxString { |
91 | wxString* sptr = wxString_in_helper($input); | |
92 | if (sptr == NULL) SWIG_fail; | |
93 | $1 = *sptr; | |
94 | delete sptr; | |
95 | } | |
ba933fa5 RD |
96 | |
97 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxString& { | |
98 | $1 = PyString_Check($input) || PyUnicode_Check($input); | |
99 | } | |
100 | ||
6fa9e461 RD |
101 | //--------------------------------------------------------------------------- |
102 | // wxMemoryBuffer (needed for wxSTC) | |
103 | ||
a72f4631 | 104 | %typemap(in) wxMemoryBuffer& (bool temp=false) { |
6fa9e461 RD |
105 | if (!PyString_Check($input)) { |
106 | PyErr_SetString(PyExc_TypeError, "String buffer expected"); | |
107 | SWIG_fail; | |
108 | } | |
109 | char* str = PyString_AS_STRING($input); | |
110 | int len = PyString_GET_SIZE($input); | |
111 | $1 = new wxMemoryBuffer(len); | |
a72f4631 | 112 | temp = true; |
6fa9e461 | 113 | memcpy($1->GetData(), str, len); |
97d6a30b | 114 | $1->SetDataLen(len); |
6fa9e461 RD |
115 | } |
116 | ||
117 | %typemap(freearg) wxMemoryBuffer& { | |
118 | if (temp$argnum) delete $1; | |
119 | } | |
120 | ||
121 | %typemap(out) wxMemoryBuffer { | |
122 | $result = PyString_FromStringAndSize((char*)$1.GetData(), $1.GetDataLen()); | |
123 | } | |
124 | ||
125 | ||
7bf85405 | 126 | |
1110f5ce | 127 | %typemap(out) wxCharBuffer { |
334178f8 RD |
128 | if ($1.data()) |
129 | $result = PyString_FromString((char*)$1.data()); | |
130 | else | |
131 | $result = PyString_FromString(""); | |
1110f5ce RD |
132 | } |
133 | ||
134 | ||
d14a1e28 RD |
135 | //--------------------------------------------------------------------------- |
136 | // Typemaps to convert Python sequence objects (tuples, etc.) to | |
137 | // wxSize, wxPoint, wxRealPoint, and wxRect. | |
7bf85405 RD |
138 | |
139 | ||
d14a1e28 RD |
140 | %typemap(in) wxSize& (wxSize temp) { |
141 | $1 = &temp; | |
142 | if ( ! wxSize_helper($input, &$1)) SWIG_fail; | |
7bf85405 | 143 | } |
d14a1e28 RD |
144 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxSize& { |
145 | $1 = wxPySimple_typecheck($input, wxT("wxSize"), 2); | |
7bf85405 RD |
146 | } |
147 | ||
148 | ||
d14a1e28 RD |
149 | %typemap(in) wxPoint& (wxPoint temp) { |
150 | $1 = &temp; | |
151 | if ( ! wxPoint_helper($input, &$1)) SWIG_fail; | |
7bf85405 | 152 | } |
d14a1e28 RD |
153 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxPoint& { |
154 | $1 = wxPySimple_typecheck($input, wxT("wxPoint"), 2); | |
10ef30eb RD |
155 | } |
156 | ||
10ef30eb | 157 | |
d14a1e28 RD |
158 | %typemap(in) wxRealPoint& (wxRealPoint temp) { |
159 | $1 = &temp; | |
160 | if ( ! wxRealPoint_helper($input, &$1)) SWIG_fail; | |
10ef30eb | 161 | } |
d14a1e28 RD |
162 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRealPoint& { |
163 | $1 = wxPySimple_typecheck($input, wxT("wxRealPoint"), 2); | |
10ef30eb | 164 | } |
2f90df85 RD |
165 | |
166 | ||
d14a1e28 RD |
167 | %typemap(in) wxRect& (wxRect temp) { |
168 | $1 = &temp; | |
169 | if ( ! wxRect_helper($input, &$1)) SWIG_fail; | |
2f90df85 | 170 | } |
d14a1e28 RD |
171 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRect& { |
172 | $1 = wxPySimple_typecheck($input, wxT("wxRect"), 4); | |
2f90df85 RD |
173 | } |
174 | ||
7bf85405 | 175 | |
fe45b493 RD |
176 | %apply wxRect& { wxRect* }; |
177 | ||
178 | ||
179 | ||
d14a1e28 RD |
180 | %typemap(in) wxPoint2D& (wxPoint2D temp) { |
181 | $1 = &temp; | |
182 | if ( ! wxPoint2D_helper($input, &$1)) SWIG_fail; | |
2f90df85 | 183 | } |
d14a1e28 RD |
184 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxPoint2D& { |
185 | $1 = wxPySimple_typecheck($input, wxT("wxPoint2D"), 2); | |
1e4a197e RD |
186 | } |
187 | ||
d14a1e28 | 188 | |
7da662ce RD |
189 | %typemap(in) wxRect2D& (wxRect2D temp) { |
190 | $1 = &temp; | |
191 | if ( ! wxRect2D_helper($input, &$1)) SWIG_fail; | |
192 | } | |
193 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRect2D& { | |
194 | $1 = wxPySimple_typecheck($input, wxT("wxRect2D"), 4); | |
195 | } | |
196 | ||
197 | ||
f6bcfd97 BP |
198 | //--------------------------------------------------------------------------- |
199 | // Typemap to convert strings to wxColour. Two string formats are accepted, | |
de20db99 | 200 | // either a colour name, or a hex colour spec like "#RRGGBB" |
f6bcfd97 | 201 | |
d14a1e28 RD |
202 | %typemap(in) wxColour& (wxColour temp) { |
203 | $1 = &temp; | |
204 | if ( ! wxColour_helper($input, &$1)) SWIG_fail; | |
f6bcfd97 | 205 | } |
d14a1e28 RD |
206 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxColour& { |
207 | $1 = wxColour_typecheck($input); | |
208 | } | |
209 | ||
b37c7e1d RD |
210 | //--------------------------------------------------------------------------- |
211 | // Typemap for wxArrayString from Python sequence objects | |
212 | ||
a72f4631 | 213 | %typemap(in) wxArrayString& (bool temp=false) { |
d14a1e28 | 214 | if (! PySequence_Check($input)) { |
b37c7e1d | 215 | PyErr_SetString(PyExc_TypeError, "Sequence of strings expected."); |
d14a1e28 | 216 | SWIG_fail; |
b37c7e1d | 217 | } |
d14a1e28 | 218 | $1 = new wxArrayString; |
a72f4631 | 219 | temp = true; |
d14a1e28 | 220 | int i, len=PySequence_Length($input); |
b37c7e1d | 221 | for (i=0; i<len; i++) { |
d14a1e28 | 222 | PyObject* item = PySequence_GetItem($input, i); |
9899bd5b | 223 | wxString* s = wxString_in_helper(item); |
3eb1aad7 | 224 | if (PyErr_Occurred()) SWIG_fail; |
9899bd5b RD |
225 | $1->Add(*s); |
226 | delete s; | |
b37c7e1d | 227 | Py_DECREF(item); |
b37c7e1d RD |
228 | } |
229 | } | |
230 | ||
d14a1e28 | 231 | %typemap(freearg) wxArrayString& { |
c2e6d970 | 232 | if (temp$argnum) delete $1; |
b37c7e1d | 233 | } |
7bf85405 | 234 | |
293a0a86 RD |
235 | //--------------------------------------------------------------------------- |
236 | // Typemap for wxArrayInt from Python sequence objects | |
237 | ||
a72f4631 | 238 | %typemap(in) wxArrayInt& (bool temp=false) { |
d14a1e28 | 239 | if (! PySequence_Check($input)) { |
293a0a86 | 240 | PyErr_SetString(PyExc_TypeError, "Sequence of integers expected."); |
d14a1e28 | 241 | SWIG_fail; |
293a0a86 | 242 | } |
d14a1e28 | 243 | $1 = new wxArrayInt; |
a72f4631 | 244 | temp = true; |
d14a1e28 | 245 | int i, len=PySequence_Length($input); |
293a0a86 | 246 | for (i=0; i<len; i++) { |
d14a1e28 | 247 | PyObject* item = PySequence_GetItem($input, i); |
293a0a86 | 248 | PyObject* number = PyNumber_Int(item); |
ec8a7755 RD |
249 | if (!number) { |
250 | PyErr_SetString(PyExc_TypeError, "Sequence of integers expected."); | |
251 | SWIG_fail; | |
252 | } | |
d14a1e28 | 253 | $1->Add(PyInt_AS_LONG(number)); |
293a0a86 RD |
254 | Py_DECREF(item); |
255 | Py_DECREF(number); | |
256 | } | |
257 | } | |
258 | ||
d14a1e28 | 259 | %typemap(freearg) wxArrayInt& { |
c2e6d970 | 260 | if (temp$argnum) delete $1; |
293a0a86 RD |
261 | } |
262 | ||
263 | ||
d14a1e28 RD |
264 | //--------------------------------------------------------------------------- |
265 | // Typemaps to convert an array of ints to a list for return values | |
281c54cc RD |
266 | // %typemap(out) wxArrayInt& { |
267 | // $result = PyList_New(0); | |
268 | // size_t idx; | |
269 | // for (idx = 0; idx < $1->GetCount(); idx += 1) { | |
270 | // PyObject* val = PyInt_FromLong( $1->Item(idx) ); | |
271 | // PyList_Append($result, val); | |
272 | // Py_DECREF(val); | |
273 | // } | |
274 | // } | |
275 | ||
276 | // %typemap(out) wxArrayInt { | |
277 | // $result = PyList_New(0); | |
278 | // size_t idx; | |
279 | // for (idx = 0; idx < $1.GetCount(); idx += 1) { | |
280 | // PyObject* val = PyInt_FromLong( $1.Item(idx) ); | |
281 | // PyList_Append($result, val); | |
282 | // Py_DECREF(val); | |
283 | // } | |
284 | // } | |
285 | ||
d14a1e28 | 286 | %typemap(out) wxArrayInt& { |
281c54cc | 287 | $result = wxArrayInt2PyList_helper(*$1); |
1e4a197e RD |
288 | } |
289 | ||
d14a1e28 | 290 | %typemap(out) wxArrayInt { |
281c54cc RD |
291 | $result = wxArrayInt2PyList_helper($1); |
292 | } | |
293 | ||
294 | ||
295 | // convert array of doubles to a Python list | |
296 | %typemap(out) wxArrayDouble& { | |
297 | $result = wxArrayDouble2PyList_helper(*$1); | |
298 | } | |
299 | ||
300 | %typemap(out) wxArrayDouble { | |
301 | $result = wxArrayDouble2PyList_helper($1); | |
1e4a197e RD |
302 | } |
303 | ||
304 | ||
7bf85405 | 305 | |
6d450e1a | 306 | // Typemaps to convert an array of strings to a list for return values |
d14a1e28 RD |
307 | %typemap(out) wxArrayString& { |
308 | $result = wxArrayString2PyList_helper(*$1); | |
309 | } | |
7bf85405 | 310 | |
d14a1e28 RD |
311 | %typemap(out) wxArrayString { |
312 | $result = wxArrayString2PyList_helper($1); | |
7bf85405 RD |
313 | } |
314 | ||
315 | ||
e07fb96d RD |
316 | //--------------------------------------------------------------------------- |
317 | ||
da32eb53 RD |
318 | %typemap(out) bool { |
319 | $result = $1 ? Py_True : Py_False; Py_INCREF($result); | |
320 | } | |
1e4a197e | 321 | |
d19a83a5 | 322 | |
56a52e90 RD |
323 | //--------------------------------------------------------------------------- |
324 | // wxFileOffset, can be a 32-bit or a 64-bit integer | |
325 | ||
326 | %typemap(in) wxFileOffset { | |
327 | if (sizeof(wxFileOffset) > sizeof(long)) | |
328 | $1 = PyLong_AsLongLong($input); | |
329 | else | |
330 | $1 = PyInt_AsLong($input); | |
331 | } | |
332 | ||
333 | %typemap(out) wxFileOffset { | |
334 | if (sizeof(wxFileOffset) > sizeof(long)) | |
335 | $result = PyLong_FromLongLong($1); | |
336 | else | |
337 | $result = PyInt_FromLong($1); | |
338 | } | |
339 | ||
340 | ||
d19a83a5 RD |
341 | //--------------------------------------------------------------------------- |
342 | // Typemap for when GDI objects are returned by reference. This will cause a | |
343 | // copy to be made instead of returning a reference to the same instance. The | |
344 | // GDI object's internal refcounting scheme will do a copy-on-write of the | |
345 | // internal data as needed. | |
346 | ||
347 | // These too? | |
348 | //, wxRegion&, wxPalette& | |
349 | ||
350 | %typemap(out) wxBrush&, wxPen&, wxFont&, wxBitmap&, wxIcon&, wxCursor& { | |
351 | $*1_ltype* resultptr = new $*1_ltype(*$1); | |
352 | $result = SWIG_NewPointerObj((void*)(resultptr), $1_descriptor, 1); | |
353 | } | |
354 | ||
355 | ||
238ba802 RD |
356 | //--------------------------------------------------------------------------- |
357 | // Typemaps for loading a image or bitmap from an object that implements the | |
358 | // buffer interface | |
359 | ||
8c9c423b | 360 | %typemap(in) (buffer data, int DATASIZE) (Py_ssize_t temp) |
074d2e04 | 361 | { |
8c9c423b RD |
362 | if (PyObject_AsReadBuffer($input, (const void**)(&$1), &temp) == -1) SWIG_fail; |
363 | $2 = (int)temp; | |
074d2e04 | 364 | } |
238ba802 | 365 | |
8c9c423b | 366 | %typemap(in) (buffer alpha, int ALPHASIZE) (Py_ssize_t temp) |
074d2e04 RD |
367 | { |
368 | if ($input != Py_None) { | |
8c9c423b RD |
369 | if (PyObject_AsReadBuffer($input, (const void**)(&$1), &temp) == -1) SWIG_fail; |
370 | $2 = (int)temp; | |
074d2e04 RD |
371 | } |
372 | } | |
373 | ||
374 | ||
238ba802 | 375 | |
9416aa89 RD |
376 | //--------------------------------------------------------------------------- |
377 | // Typemaps to convert return values that are base class pointers | |
378 | // to the real derived type, if possible. See wxPyMake_wxObject in | |
379 | // helpers.cpp | |
380 | ||
b39c3fa0 RD |
381 | // NOTE: For those classes that also call _setOORInfo these typemaps should be |
382 | // disabled for the constructor. | |
383 | ||
214c4fbe RD |
384 | %typemap(out) wxEvtHandler* { $result = wxPyMake_wxObject($1, (bool)$owner); } |
385 | %typemap(out) wxMenu* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
386 | %typemap(out) wxValidator* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
387 | ||
388 | %typemap(out) wxApp* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
389 | %typemap(out) wxPyApp* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
390 | %typemap(out) wxDC* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
391 | %typemap(out) wxFSFile* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
392 | %typemap(out) wxFileSystem* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
3ecece7e | 393 | %typemap(out) wxImageList* { $result = wxPyMake_wxObject($1, (bool)$owner); } |
214c4fbe RD |
394 | %typemap(out) wxImage* { $result = wxPyMake_wxObject($1, (bool)$owner); } |
395 | %typemap(out) wxListItem* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
396 | %typemap(out) wxMenuItem* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
397 | %typemap(out) wxMouseEvent* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
398 | %typemap(out) wxObject* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
399 | %typemap(out) wxPyPrintout* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
400 | %typemap(out) wxToolBarToolBase* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
401 | %typemap(out) wxToolTip* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
402 | ||
403 | ||
404 | %typemap(out) wxBitmapButton* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
405 | %typemap(out) wxButton* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
406 | %typemap(out) wxControl* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
407 | %typemap(out) wxFrame* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
408 | %typemap(out) wxGrid* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
3ecece7e | 409 | %typemap(out) wxPyListCtrl* { $result = wxPyMake_wxObject($1, (bool)$owner); } |
214c4fbe RD |
410 | %typemap(out) wxMDIChildFrame* { $result = wxPyMake_wxObject($1, (bool)$owner); } |
411 | %typemap(out) wxMDIClientWindow* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
412 | %typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
413 | %typemap(out) wxNotebook* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
414 | %typemap(out) wxStaticBox* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
415 | %typemap(out) wxStatusBar* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
416 | %typemap(out) wxTextCtrl* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
417 | %typemap(out) wxToolBar* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
418 | %typemap(out) wxToolBarBase* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
214c4fbe RD |
419 | %typemap(out) wxPyTreeCtrl* { $result = wxPyMake_wxObject($1, (bool)$owner); } |
420 | %typemap(out) wxWindow* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
421 | %typemap(out) wxPyHtmlWindow* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
422 | %typemap(out) wxWizardPage* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
423 | %typemap(out) wxPyWizardPage* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
424 | %typemap(out) wxPanel* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
425 | %typemap(out) wxDialog* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
426 | %typemap(out) wxScrolledWindow* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
427 | ||
428 | %typemap(out) wxSizer* { $result = wxPyMake_wxObject($1, (bool)$owner); } | |
6d450e1a | 429 | |
9416aa89 | 430 | |
7bf85405 | 431 | //--------------------------------------------------------------------------- |
2f90df85 | 432 | //--------------------------------------------------------------------------- |
7bf85405 | 433 | |
9416aa89 RD |
434 | |
435 | ||
436 | ||
437 | ||
438 |