]>
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 RD |
127 | %typemap(out) wxCharBuffer { |
128 | $result = PyString_FromString((char*)$1.data()); | |
129 | } | |
130 | ||
131 | ||
d14a1e28 RD |
132 | //--------------------------------------------------------------------------- |
133 | // Typemaps to convert Python sequence objects (tuples, etc.) to | |
134 | // wxSize, wxPoint, wxRealPoint, and wxRect. | |
7bf85405 RD |
135 | |
136 | ||
d14a1e28 RD |
137 | %typemap(in) wxSize& (wxSize temp) { |
138 | $1 = &temp; | |
139 | if ( ! wxSize_helper($input, &$1)) SWIG_fail; | |
7bf85405 | 140 | } |
d14a1e28 RD |
141 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxSize& { |
142 | $1 = wxPySimple_typecheck($input, wxT("wxSize"), 2); | |
7bf85405 RD |
143 | } |
144 | ||
145 | ||
d14a1e28 RD |
146 | %typemap(in) wxPoint& (wxPoint temp) { |
147 | $1 = &temp; | |
148 | if ( ! wxPoint_helper($input, &$1)) SWIG_fail; | |
7bf85405 | 149 | } |
d14a1e28 RD |
150 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxPoint& { |
151 | $1 = wxPySimple_typecheck($input, wxT("wxPoint"), 2); | |
10ef30eb RD |
152 | } |
153 | ||
10ef30eb | 154 | |
d14a1e28 RD |
155 | %typemap(in) wxRealPoint& (wxRealPoint temp) { |
156 | $1 = &temp; | |
157 | if ( ! wxRealPoint_helper($input, &$1)) SWIG_fail; | |
10ef30eb | 158 | } |
d14a1e28 RD |
159 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRealPoint& { |
160 | $1 = wxPySimple_typecheck($input, wxT("wxRealPoint"), 2); | |
10ef30eb | 161 | } |
2f90df85 RD |
162 | |
163 | ||
d14a1e28 RD |
164 | %typemap(in) wxRect& (wxRect temp) { |
165 | $1 = &temp; | |
166 | if ( ! wxRect_helper($input, &$1)) SWIG_fail; | |
2f90df85 | 167 | } |
d14a1e28 RD |
168 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRect& { |
169 | $1 = wxPySimple_typecheck($input, wxT("wxRect"), 4); | |
2f90df85 RD |
170 | } |
171 | ||
7bf85405 | 172 | |
d14a1e28 RD |
173 | %typemap(in) wxPoint2D& (wxPoint2D temp) { |
174 | $1 = &temp; | |
175 | if ( ! wxPoint2D_helper($input, &$1)) SWIG_fail; | |
2f90df85 | 176 | } |
d14a1e28 RD |
177 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxPoint2D& { |
178 | $1 = wxPySimple_typecheck($input, wxT("wxPoint2D"), 2); | |
1e4a197e RD |
179 | } |
180 | ||
d14a1e28 | 181 | |
f6bcfd97 BP |
182 | //--------------------------------------------------------------------------- |
183 | // Typemap to convert strings to wxColour. Two string formats are accepted, | |
de20db99 | 184 | // either a colour name, or a hex colour spec like "#RRGGBB" |
f6bcfd97 | 185 | |
d14a1e28 RD |
186 | %typemap(in) wxColour& (wxColour temp) { |
187 | $1 = &temp; | |
188 | if ( ! wxColour_helper($input, &$1)) SWIG_fail; | |
f6bcfd97 | 189 | } |
d14a1e28 RD |
190 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxColour& { |
191 | $1 = wxColour_typecheck($input); | |
192 | } | |
193 | ||
194 | ||
f6bcfd97 | 195 | |
b37c7e1d RD |
196 | //--------------------------------------------------------------------------- |
197 | // Typemap for wxArrayString from Python sequence objects | |
198 | ||
a72f4631 | 199 | %typemap(in) wxArrayString& (bool temp=false) { |
d14a1e28 | 200 | if (! PySequence_Check($input)) { |
b37c7e1d | 201 | PyErr_SetString(PyExc_TypeError, "Sequence of strings expected."); |
d14a1e28 | 202 | SWIG_fail; |
b37c7e1d | 203 | } |
d14a1e28 | 204 | $1 = new wxArrayString; |
a72f4631 | 205 | temp = true; |
d14a1e28 | 206 | int i, len=PySequence_Length($input); |
b37c7e1d | 207 | for (i=0; i<len; i++) { |
d14a1e28 RD |
208 | PyObject* item = PySequence_GetItem($input, i); |
209 | %#if wxUSE_UNICODE | |
c8bc7bb8 | 210 | PyObject* str = PyObject_Unicode(item); |
d14a1e28 | 211 | %#else |
b37c7e1d | 212 | PyObject* str = PyObject_Str(item); |
d14a1e28 | 213 | %#endif |
3eb1aad7 | 214 | if (PyErr_Occurred()) SWIG_fail; |
d14a1e28 | 215 | $1->Add(Py2wxString(str)); |
b37c7e1d RD |
216 | Py_DECREF(item); |
217 | Py_DECREF(str); | |
218 | } | |
219 | } | |
220 | ||
d14a1e28 | 221 | %typemap(freearg) wxArrayString& { |
c2e6d970 | 222 | if (temp$argnum) delete $1; |
b37c7e1d | 223 | } |
7bf85405 | 224 | |
293a0a86 RD |
225 | //--------------------------------------------------------------------------- |
226 | // Typemap for wxArrayInt from Python sequence objects | |
227 | ||
a72f4631 | 228 | %typemap(in) wxArrayInt& (bool temp=false) { |
d14a1e28 | 229 | if (! PySequence_Check($input)) { |
293a0a86 | 230 | PyErr_SetString(PyExc_TypeError, "Sequence of integers expected."); |
d14a1e28 | 231 | SWIG_fail; |
293a0a86 | 232 | } |
d14a1e28 | 233 | $1 = new wxArrayInt; |
a72f4631 | 234 | temp = true; |
d14a1e28 | 235 | int i, len=PySequence_Length($input); |
293a0a86 | 236 | for (i=0; i<len; i++) { |
d14a1e28 | 237 | PyObject* item = PySequence_GetItem($input, i); |
293a0a86 | 238 | PyObject* number = PyNumber_Int(item); |
d14a1e28 | 239 | $1->Add(PyInt_AS_LONG(number)); |
293a0a86 RD |
240 | Py_DECREF(item); |
241 | Py_DECREF(number); | |
242 | } | |
243 | } | |
244 | ||
d14a1e28 | 245 | %typemap(freearg) wxArrayInt& { |
c2e6d970 | 246 | if (temp$argnum) delete $1; |
293a0a86 RD |
247 | } |
248 | ||
249 | ||
d14a1e28 RD |
250 | //--------------------------------------------------------------------------- |
251 | // Typemaps to convert an array of ints to a list for return values | |
252 | %typemap(out) wxArrayInt& { | |
253 | $result = PyList_New(0); | |
1e4a197e | 254 | size_t idx; |
d14a1e28 RD |
255 | for (idx = 0; idx < $1->GetCount(); idx += 1) { |
256 | PyObject* val = PyInt_FromLong( $1->Item(idx) ); | |
257 | PyList_Append($result, val); | |
1e4a197e RD |
258 | Py_DECREF(val); |
259 | } | |
260 | } | |
261 | ||
d14a1e28 RD |
262 | %typemap(out) wxArrayInt { |
263 | $result = PyList_New(0); | |
1e4a197e | 264 | size_t idx; |
d14a1e28 RD |
265 | for (idx = 0; idx < $1.GetCount(); idx += 1) { |
266 | PyObject* val = PyInt_FromLong( $1.Item(idx) ); | |
267 | PyList_Append($result, val); | |
1e4a197e RD |
268 | Py_DECREF(val); |
269 | } | |
1e4a197e RD |
270 | } |
271 | ||
272 | ||
7bf85405 | 273 | |
6d450e1a | 274 | // Typemaps to convert an array of strings to a list for return values |
d14a1e28 RD |
275 | %typemap(out) wxArrayString& { |
276 | $result = wxArrayString2PyList_helper(*$1); | |
277 | } | |
7bf85405 | 278 | |
d14a1e28 RD |
279 | %typemap(out) wxArrayString { |
280 | $result = wxArrayString2PyList_helper($1); | |
7bf85405 RD |
281 | } |
282 | ||
283 | ||
e07fb96d RD |
284 | //--------------------------------------------------------------------------- |
285 | ||
da32eb53 RD |
286 | %typemap(out) bool { |
287 | $result = $1 ? Py_True : Py_False; Py_INCREF($result); | |
288 | } | |
1e4a197e | 289 | |
d19a83a5 | 290 | |
56a52e90 RD |
291 | //--------------------------------------------------------------------------- |
292 | // wxFileOffset, can be a 32-bit or a 64-bit integer | |
293 | ||
294 | %typemap(in) wxFileOffset { | |
295 | if (sizeof(wxFileOffset) > sizeof(long)) | |
296 | $1 = PyLong_AsLongLong($input); | |
297 | else | |
298 | $1 = PyInt_AsLong($input); | |
299 | } | |
300 | ||
301 | %typemap(out) wxFileOffset { | |
302 | if (sizeof(wxFileOffset) > sizeof(long)) | |
303 | $result = PyLong_FromLongLong($1); | |
304 | else | |
305 | $result = PyInt_FromLong($1); | |
306 | } | |
307 | ||
308 | ||
d19a83a5 RD |
309 | //--------------------------------------------------------------------------- |
310 | // Typemap for when GDI objects are returned by reference. This will cause a | |
311 | // copy to be made instead of returning a reference to the same instance. The | |
312 | // GDI object's internal refcounting scheme will do a copy-on-write of the | |
313 | // internal data as needed. | |
314 | ||
315 | // These too? | |
316 | //, wxRegion&, wxPalette& | |
317 | ||
318 | %typemap(out) wxBrush&, wxPen&, wxFont&, wxBitmap&, wxIcon&, wxCursor& { | |
319 | $*1_ltype* resultptr = new $*1_ltype(*$1); | |
320 | $result = SWIG_NewPointerObj((void*)(resultptr), $1_descriptor, 1); | |
321 | } | |
322 | ||
323 | ||
9416aa89 RD |
324 | //--------------------------------------------------------------------------- |
325 | // Typemaps to convert return values that are base class pointers | |
326 | // to the real derived type, if possible. See wxPyMake_wxObject in | |
327 | // helpers.cpp | |
328 | ||
b39c3fa0 RD |
329 | // NOTE: For those classes that also call _setOORInfo these typemaps should be |
330 | // disabled for the constructor. | |
331 | ||
6d450e1a RD |
332 | %typemap(out) wxEvtHandler* { $result = wxPyMake_wxObject($1, $owner); } |
333 | %typemap(out) wxMenu* { $result = wxPyMake_wxObject($1, $owner); } | |
334 | %typemap(out) wxValidator* { $result = wxPyMake_wxObject($1, $owner); } | |
335 | ||
336 | %typemap(out) wxApp* { $result = wxPyMake_wxObject($1, $owner); } | |
337 | %typemap(out) wxPyApp* { $result = wxPyMake_wxObject($1, $owner); } | |
338 | %typemap(out) wxDC* { $result = wxPyMake_wxObject($1, $owner); } | |
339 | %typemap(out) wxFSFile* { $result = wxPyMake_wxObject($1, $owner); } | |
340 | %typemap(out) wxFileSystem* { $result = wxPyMake_wxObject($1, $owner); } | |
6d450e1a | 341 | %typemap(out) wxImageList* { $result = wxPyMake_wxObject($1, $owner); } |
1bad23bc | 342 | %typemap(out) wxImage* { $result = wxPyMake_wxObject($1, $owner); } |
6d450e1a RD |
343 | %typemap(out) wxListItem* { $result = wxPyMake_wxObject($1, $owner); } |
344 | %typemap(out) wxMenuItem* { $result = wxPyMake_wxObject($1, $owner); } | |
345 | %typemap(out) wxMouseEvent* { $result = wxPyMake_wxObject($1, $owner); } | |
346 | %typemap(out) wxObject* { $result = wxPyMake_wxObject($1, $owner); } | |
347 | %typemap(out) wxPyPrintout* { $result = wxPyMake_wxObject($1, $owner); } | |
348 | %typemap(out) wxToolBarToolBase* { $result = wxPyMake_wxObject($1, $owner); } | |
349 | %typemap(out) wxToolTip* { $result = wxPyMake_wxObject($1, $owner); } | |
350 | ||
351 | ||
352 | %typemap(out) wxBitmapButton* { $result = wxPyMake_wxObject($1, $owner); } | |
353 | %typemap(out) wxButton* { $result = wxPyMake_wxObject($1, $owner); } | |
354 | %typemap(out) wxControl* { $result = wxPyMake_wxObject($1, $owner); } | |
355 | %typemap(out) wxFrame* { $result = wxPyMake_wxObject($1, $owner); } | |
356 | %typemap(out) wxGrid* { $result = wxPyMake_wxObject($1, $owner); } | |
b39c3fa0 | 357 | //%typemap(out) wxListCtrl* { $result = wxPyMake_wxObject($1, $owner); } |
6d450e1a RD |
358 | %typemap(out) wxMDIChildFrame* { $result = wxPyMake_wxObject($1, $owner); } |
359 | %typemap(out) wxMDIClientWindow* { $result = wxPyMake_wxObject($1, $owner); } | |
360 | %typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1, $owner); } | |
361 | %typemap(out) wxNotebook* { $result = wxPyMake_wxObject($1, $owner); } | |
362 | %typemap(out) wxStaticBox* { $result = wxPyMake_wxObject($1, $owner); } | |
363 | %typemap(out) wxStatusBar* { $result = wxPyMake_wxObject($1, $owner); } | |
364 | %typemap(out) wxTextCtrl* { $result = wxPyMake_wxObject($1, $owner); } | |
365 | %typemap(out) wxToolBar* { $result = wxPyMake_wxObject($1, $owner); } | |
366 | %typemap(out) wxToolBarBase* { $result = wxPyMake_wxObject($1, $owner); } | |
b39c3fa0 | 367 | //%typemap(out) wxTreeCtrl* { $result = wxPyMake_wxObject($1, $owner); } |
6d450e1a RD |
368 | %typemap(out) wxPyTreeCtrl* { $result = wxPyMake_wxObject($1, $owner); } |
369 | %typemap(out) wxWindow* { $result = wxPyMake_wxObject($1, $owner); } | |
6d450e1a RD |
370 | %typemap(out) wxPyHtmlWindow* { $result = wxPyMake_wxObject($1, $owner); } |
371 | %typemap(out) wxWizardPage* { $result = wxPyMake_wxObject($1, $owner); } | |
b39c3fa0 | 372 | %typemap(out) wxPyWizardPage* { $result = wxPyMake_wxObject($1, $owner); } |
6d450e1a RD |
373 | %typemap(out) wxPanel* { $result = wxPyMake_wxObject($1, $owner); } |
374 | %typemap(out) wxDialog* { $result = wxPyMake_wxObject($1, $owner); } | |
375 | %typemap(out) wxScrolledWindow* { $result = wxPyMake_wxObject($1, $owner); } | |
376 | ||
377 | %typemap(out) wxSizer* { $result = wxPyMake_wxSizer($1, $owner); } | |
378 | ||
9416aa89 | 379 | |
7bf85405 | 380 | //--------------------------------------------------------------------------- |
2f90df85 | 381 | //--------------------------------------------------------------------------- |
7bf85405 | 382 | |
9416aa89 RD |
383 | |
384 | ||
385 | ||
386 | ||
387 |