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