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