]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/my_typemaps.i
Fixed the code to actually work.
[wxWidgets.git] / wxPython / src / my_typemaps.i
CommitLineData
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 16
d14a1e28 17%exception {
4268f798 18 PyThreadState* __tstate = wxPyBeginAllowThreads();
d14a1e28 19 $action
4268f798 20 wxPyEndAllowThreads(__tstate);
d14a1e28 21 if (PyErr_Occurred()) SWIG_fail;
cf694132
RD
22}
23
7bf85405 24
d14a1e28
RD
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// }
7bf85405
RD
160
161
162
b639c3c5 163
d14a1e28 164//---------------------------------------------------------------------------
7bf85405
RD
165
166
d14a1e28
RD
167%typemap(in) wxString& (bool temp=false) {
168 $1 = wxString_in_helper($input);
169 if ($1 == NULL) SWIG_fail;
170 temp = true;
7bf85405
RD
171}
172
173
d14a1e28
RD
174%typemap(freearg) wxString& {
175 if (temp$argnum)
176 delete $1;
7bf85405
RD
177}
178
179
7bf85405 180
d14a1e28
RD
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
7bf85405
RD
187}
188
d14a1e28
RD
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
7bf85405
RD
195}
196
d14a1e28
RD
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
7bf85405
RD
203}
204
eec92d76 205
7bf85405 206
d14a1e28 207// //---------------------------------------------------------------------------
7bf85405 208
eec92d76 209
d14a1e28
RD
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// }
e0672e2f 220
d14a1e28
RD
221// %typemap(python, freearg) wxMemoryBuffer& {
222// if ($target)
223// delete $source;
224// }
7bf85405 225
d14a1e28
RD
226// %typemap(python, out) wxMemoryBuffer {
227// $target = PyString_FromStringAndSize((char*)$source->GetData(), $source->GetDataLen());
228// }
c8bc7bb8 229
d14a1e28
RD
230// %typemap(python, ret) wxMemoryBuffer {
231// delete $source;
232// }
185d7c3e
RD
233
234
d14a1e28
RD
235//---------------------------------------------------------------------------
236// Typemaps to convert Python sequence objects (tuples, etc.) to
237// wxSize, wxPoint, wxRealPoint, and wxRect.
7bf85405
RD
238
239
d14a1e28
RD
240%typemap(in) wxSize& (wxSize temp) {
241 $1 = &temp;
242 if ( ! wxSize_helper($input, &$1)) SWIG_fail;
7bf85405 243}
d14a1e28
RD
244%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxSize& {
245 $1 = wxPySimple_typecheck($input, wxT("wxSize"), 2);
7bf85405
RD
246}
247
248
d14a1e28
RD
249%typemap(in) wxPoint& (wxPoint temp) {
250 $1 = &temp;
251 if ( ! wxPoint_helper($input, &$1)) SWIG_fail;
7bf85405 252}
d14a1e28
RD
253%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxPoint& {
254 $1 = wxPySimple_typecheck($input, wxT("wxPoint"), 2);
10ef30eb
RD
255}
256
10ef30eb 257
d14a1e28
RD
258%typemap(in) wxRealPoint& (wxRealPoint temp) {
259 $1 = &temp;
260 if ( ! wxRealPoint_helper($input, &$1)) SWIG_fail;
10ef30eb 261}
d14a1e28
RD
262%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRealPoint& {
263 $1 = wxPySimple_typecheck($input, wxT("wxRealPoint"), 2);
10ef30eb 264}
2f90df85
RD
265
266
d14a1e28
RD
267%typemap(in) wxRect& (wxRect temp) {
268 $1 = &temp;
269 if ( ! wxRect_helper($input, &$1)) SWIG_fail;
2f90df85 270}
d14a1e28
RD
271%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRect& {
272 $1 = wxPySimple_typecheck($input, wxT("wxRect"), 4);
2f90df85
RD
273}
274
7bf85405 275
d14a1e28
RD
276%typemap(in) wxPoint2D& (wxPoint2D temp) {
277 $1 = &temp;
278 if ( ! wxPoint2D_helper($input, &$1)) SWIG_fail;
2f90df85 279}
d14a1e28
RD
280%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxPoint2D& {
281 $1 = wxPySimple_typecheck($input, wxT("wxPoint2D"), 2);
1e4a197e
RD
282}
283
d14a1e28 284
f6bcfd97
BP
285//---------------------------------------------------------------------------
286// Typemap to convert strings to wxColour. Two string formats are accepted,
de20db99 287// either a colour name, or a hex colour spec like "#RRGGBB"
f6bcfd97 288
d14a1e28
RD
289%typemap(in) wxColour& (wxColour temp) {
290 $1 = &temp;
291 if ( ! wxColour_helper($input, &$1)) SWIG_fail;
f6bcfd97 292}
d14a1e28
RD
293%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxColour& {
294 $1 = wxColour_typecheck($input);
295}
296
297
f6bcfd97 298
b37c7e1d
RD
299//---------------------------------------------------------------------------
300// Typemap for wxArrayString from Python sequence objects
301
d14a1e28
RD
302%typemap(in) wxArrayString& {
303 if (! PySequence_Check($input)) {
b37c7e1d 304 PyErr_SetString(PyExc_TypeError, "Sequence of strings expected.");
d14a1e28 305 SWIG_fail;
b37c7e1d 306 }
d14a1e28
RD
307 $1 = new wxArrayString;
308 int i, len=PySequence_Length($input);
b37c7e1d 309 for (i=0; i<len; i++) {
d14a1e28
RD
310 PyObject* item = PySequence_GetItem($input, i);
311%#if wxUSE_UNICODE
c8bc7bb8 312 PyObject* str = PyObject_Unicode(item);
d14a1e28 313%#else
b37c7e1d 314 PyObject* str = PyObject_Str(item);
d14a1e28
RD
315%#endif
316 $1->Add(Py2wxString(str));
b37c7e1d
RD
317 Py_DECREF(item);
318 Py_DECREF(str);
319 }
320}
321
d14a1e28
RD
322%typemap(freearg) wxArrayString& {
323 if ($1) delete $1;
b37c7e1d 324}
7bf85405 325
293a0a86
RD
326//---------------------------------------------------------------------------
327// Typemap for wxArrayInt from Python sequence objects
328
d14a1e28
RD
329%typemap(in) wxArrayInt& {
330 if (! PySequence_Check($input)) {
293a0a86 331 PyErr_SetString(PyExc_TypeError, "Sequence of integers expected.");
d14a1e28 332 SWIG_fail;
293a0a86 333 }
d14a1e28
RD
334 $1 = new wxArrayInt;
335 int i, len=PySequence_Length($input);
293a0a86 336 for (i=0; i<len; i++) {
d14a1e28 337 PyObject* item = PySequence_GetItem($input, i);
293a0a86 338 PyObject* number = PyNumber_Int(item);
d14a1e28 339 $1->Add(PyInt_AS_LONG(number));
293a0a86
RD
340 Py_DECREF(item);
341 Py_DECREF(number);
342 }
343}
344
d14a1e28
RD
345%typemap(freearg) wxArrayInt& {
346 if ($1) delete $1;
293a0a86
RD
347}
348
349
d14a1e28
RD
350//---------------------------------------------------------------------------
351// Typemaps to convert an array of ints to a list for return values
352%typemap(out) wxArrayInt& {
353 $result = PyList_New(0);
1e4a197e 354 size_t idx;
d14a1e28
RD
355 for (idx = 0; idx < $1->GetCount(); idx += 1) {
356 PyObject* val = PyInt_FromLong( $1->Item(idx) );
357 PyList_Append($result, val);
1e4a197e
RD
358 Py_DECREF(val);
359 }
360}
361
d14a1e28
RD
362%typemap(out) wxArrayInt {
363 $result = PyList_New(0);
1e4a197e 364 size_t idx;
d14a1e28
RD
365 for (idx = 0; idx < $1.GetCount(); idx += 1) {
366 PyObject* val = PyInt_FromLong( $1.Item(idx) );
367 PyList_Append($result, val);
1e4a197e
RD
368 Py_DECREF(val);
369 }
1e4a197e
RD
370}
371
372
7bf85405 373
d14a1e28
RD
374// Typemaps to convert an array of ints to a list for return values
375%typemap(out) wxArrayString& {
376 $result = wxArrayString2PyList_helper(*$1);
377}
7bf85405 378
d14a1e28
RD
379%typemap(out) wxArrayString {
380 $result = wxArrayString2PyList_helper($1);
7bf85405
RD
381}
382
383
d14a1e28
RD
384// //---------------------------------------------------------------------------
385// // Map T_OUTPUTs for floats to return ints.
7bf85405 386
68320e40 387
d14a1e28
RD
388// %typemap(python,ignore) float *T_OUTPUT_TOINT(float temp),
389// double *T_OUTPUT_TOINT(double temp)
390// {
391// $target = &temp;
392// }
68320e40 393
68320e40 394
d14a1e28
RD
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// }
68320e40 402
154747f5 403
d14a1e28
RD
404// %typemap(python,ignore) bool *T_OUTPUT(int temp)
405// {
406// $target = (bool*)&temp;
407// }
154747f5 408
d14a1e28
RD
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// }
154747f5 415
d14a1e28
RD
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// }
154747f5 432
d14a1e28
RD
433// %typemap(python,ignore) byte *OUTPUT = byte *T_OUTPUT;
434// %typemap(python,argout) byte *OUTPUT = byte *T_OUTPUT;
154747f5 435
1e4a197e 436
d14a1e28
RD
437// %typemap(python,ignore) wxCoord *OUTPUT = int *OUTPUT;
438// %typemap(python,argout) wxCoord *OUTPUT = int *OUTPUT;
1e4a197e
RD
439
440
9416aa89
RD
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
d14a1e28
RD
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); }
2f4e9287 488
9416aa89
RD
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
7bf85405 495//---------------------------------------------------------------------------
2f90df85 496//---------------------------------------------------------------------------
7bf85405 497
9416aa89
RD
498
499
500
501
502