]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/my_typemaps.i
New SWIG runtime and commandline param
[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
d14a1e28 40//---------------------------------------------------------------------------
dd9f7fea 41// wxString typemaps
7bf85405
RD
42
43
dd9f7fea 44%typemap(in) wxString& (bool temp=False) {
d14a1e28
RD
45 $1 = wxString_in_helper($input);
46 if ($1 == NULL) SWIG_fail;
dd9f7fea 47 temp = True;
7bf85405 48}
d14a1e28
RD
49%typemap(freearg) wxString& {
50 if (temp$argnum)
51 delete $1;
7bf85405
RD
52}
53
54
7bf85405 55
d14a1e28
RD
56%typemap(out) wxString {
57%#if wxUSE_UNICODE
58 $result = PyUnicode_FromWideChar($1.c_str(), $1.Len());
59%#else
60 $result = PyString_FromStringAndSize($1.c_str(), $1.Len());
61%#endif
7bf85405
RD
62}
63
87c2245b 64
dd9f7fea 65%typemap(out) wxString* {
d14a1e28
RD
66%#if wxUSE_UNICODE
67 $result = PyUnicode_FromWideChar($1->c_str(), $1->Len());
68%#else
69 $result = PyString_FromStringAndSize($1->c_str(), $1->Len());
70%#endif
7bf85405
RD
71}
72
87c2245b
RD
73
74%typemap(out) wxString& {
75%#if wxUSE_UNICODE
76 $result = PyUnicode_FromWideChar($1->c_str(), $1->Len());
77%#else
78 $result = PyString_FromStringAndSize($1->c_str(), $1->Len());
79%#endif
80}
81
82
dd9f7fea 83%typemap(varout) wxString {
d14a1e28
RD
84%#if wxUSE_UNICODE
85 $result = PyUnicode_FromWideChar($1.c_str(), $1.Len());
86%#else
87 $result = PyString_FromStringAndSize($1.c_str(), $1.Len());
88%#endif
7bf85405
RD
89}
90
eec92d76 91
dd9f7fea
RD
92%typemap(in) wxString {
93 wxString* sptr = wxString_in_helper($input);
94 if (sptr == NULL) SWIG_fail;
95 $1 = *sptr;
96 delete sptr;
97}
98
99
7bf85405 100
d14a1e28 101// //---------------------------------------------------------------------------
7bf85405 102
eec92d76 103
d14a1e28
RD
104// %typemap(python, in) wxMemoryBuffer& {
105// if (!PyString_Check($source)) {
106// PyErr_SetString(PyExc_TypeError, "String buffer expected");
107// return NULL;
108// }
109// char* str = PyString_AS_STRING($source);
110// int len = PyString_GET_SIZE($source);
111// $target = new wxMemoryBuffer(len);
112// memcpy($target->GetData(), str, len);
113// }
e0672e2f 114
d14a1e28
RD
115// %typemap(python, freearg) wxMemoryBuffer& {
116// if ($target)
117// delete $source;
118// }
7bf85405 119
d14a1e28
RD
120// %typemap(python, out) wxMemoryBuffer {
121// $target = PyString_FromStringAndSize((char*)$source->GetData(), $source->GetDataLen());
122// }
c8bc7bb8 123
d14a1e28
RD
124// %typemap(python, ret) wxMemoryBuffer {
125// delete $source;
126// }
185d7c3e
RD
127
128
d14a1e28
RD
129//---------------------------------------------------------------------------
130// Typemaps to convert Python sequence objects (tuples, etc.) to
131// wxSize, wxPoint, wxRealPoint, and wxRect.
7bf85405
RD
132
133
d14a1e28
RD
134%typemap(in) wxSize& (wxSize temp) {
135 $1 = &temp;
136 if ( ! wxSize_helper($input, &$1)) SWIG_fail;
7bf85405 137}
d14a1e28
RD
138%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxSize& {
139 $1 = wxPySimple_typecheck($input, wxT("wxSize"), 2);
7bf85405
RD
140}
141
142
d14a1e28
RD
143%typemap(in) wxPoint& (wxPoint temp) {
144 $1 = &temp;
145 if ( ! wxPoint_helper($input, &$1)) SWIG_fail;
7bf85405 146}
d14a1e28
RD
147%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxPoint& {
148 $1 = wxPySimple_typecheck($input, wxT("wxPoint"), 2);
10ef30eb
RD
149}
150
10ef30eb 151
d14a1e28
RD
152%typemap(in) wxRealPoint& (wxRealPoint temp) {
153 $1 = &temp;
154 if ( ! wxRealPoint_helper($input, &$1)) SWIG_fail;
10ef30eb 155}
d14a1e28
RD
156%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRealPoint& {
157 $1 = wxPySimple_typecheck($input, wxT("wxRealPoint"), 2);
10ef30eb 158}
2f90df85
RD
159
160
d14a1e28
RD
161%typemap(in) wxRect& (wxRect temp) {
162 $1 = &temp;
163 if ( ! wxRect_helper($input, &$1)) SWIG_fail;
2f90df85 164}
d14a1e28
RD
165%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRect& {
166 $1 = wxPySimple_typecheck($input, wxT("wxRect"), 4);
2f90df85
RD
167}
168
7bf85405 169
d14a1e28
RD
170%typemap(in) wxPoint2D& (wxPoint2D temp) {
171 $1 = &temp;
172 if ( ! wxPoint2D_helper($input, &$1)) SWIG_fail;
2f90df85 173}
d14a1e28
RD
174%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxPoint2D& {
175 $1 = wxPySimple_typecheck($input, wxT("wxPoint2D"), 2);
1e4a197e
RD
176}
177
d14a1e28 178
f6bcfd97
BP
179//---------------------------------------------------------------------------
180// Typemap to convert strings to wxColour. Two string formats are accepted,
de20db99 181// either a colour name, or a hex colour spec like "#RRGGBB"
f6bcfd97 182
d14a1e28
RD
183%typemap(in) wxColour& (wxColour temp) {
184 $1 = &temp;
185 if ( ! wxColour_helper($input, &$1)) SWIG_fail;
f6bcfd97 186}
d14a1e28
RD
187%typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxColour& {
188 $1 = wxColour_typecheck($input);
189}
190
191
f6bcfd97 192
b37c7e1d
RD
193//---------------------------------------------------------------------------
194// Typemap for wxArrayString from Python sequence objects
195
d14a1e28
RD
196%typemap(in) wxArrayString& {
197 if (! PySequence_Check($input)) {
b37c7e1d 198 PyErr_SetString(PyExc_TypeError, "Sequence of strings expected.");
d14a1e28 199 SWIG_fail;
b37c7e1d 200 }
d14a1e28
RD
201 $1 = new wxArrayString;
202 int i, len=PySequence_Length($input);
b37c7e1d 203 for (i=0; i<len; i++) {
d14a1e28
RD
204 PyObject* item = PySequence_GetItem($input, i);
205%#if wxUSE_UNICODE
c8bc7bb8 206 PyObject* str = PyObject_Unicode(item);
d14a1e28 207%#else
b37c7e1d 208 PyObject* str = PyObject_Str(item);
d14a1e28
RD
209%#endif
210 $1->Add(Py2wxString(str));
b37c7e1d
RD
211 Py_DECREF(item);
212 Py_DECREF(str);
213 }
214}
215
d14a1e28
RD
216%typemap(freearg) wxArrayString& {
217 if ($1) delete $1;
b37c7e1d 218}
7bf85405 219
293a0a86
RD
220//---------------------------------------------------------------------------
221// Typemap for wxArrayInt from Python sequence objects
222
d14a1e28
RD
223%typemap(in) wxArrayInt& {
224 if (! PySequence_Check($input)) {
293a0a86 225 PyErr_SetString(PyExc_TypeError, "Sequence of integers expected.");
d14a1e28 226 SWIG_fail;
293a0a86 227 }
d14a1e28
RD
228 $1 = new wxArrayInt;
229 int i, len=PySequence_Length($input);
293a0a86 230 for (i=0; i<len; i++) {
d14a1e28 231 PyObject* item = PySequence_GetItem($input, i);
293a0a86 232 PyObject* number = PyNumber_Int(item);
d14a1e28 233 $1->Add(PyInt_AS_LONG(number));
293a0a86
RD
234 Py_DECREF(item);
235 Py_DECREF(number);
236 }
237}
238
d14a1e28
RD
239%typemap(freearg) wxArrayInt& {
240 if ($1) delete $1;
293a0a86
RD
241}
242
243
d14a1e28
RD
244//---------------------------------------------------------------------------
245// Typemaps to convert an array of ints to a list for return values
246%typemap(out) wxArrayInt& {
247 $result = PyList_New(0);
1e4a197e 248 size_t idx;
d14a1e28
RD
249 for (idx = 0; idx < $1->GetCount(); idx += 1) {
250 PyObject* val = PyInt_FromLong( $1->Item(idx) );
251 PyList_Append($result, val);
1e4a197e
RD
252 Py_DECREF(val);
253 }
254}
255
d14a1e28
RD
256%typemap(out) wxArrayInt {
257 $result = PyList_New(0);
1e4a197e 258 size_t idx;
d14a1e28
RD
259 for (idx = 0; idx < $1.GetCount(); idx += 1) {
260 PyObject* val = PyInt_FromLong( $1.Item(idx) );
261 PyList_Append($result, val);
1e4a197e
RD
262 Py_DECREF(val);
263 }
1e4a197e
RD
264}
265
266
7bf85405 267
d14a1e28
RD
268// Typemaps to convert an array of ints to a list for return values
269%typemap(out) wxArrayString& {
270 $result = wxArrayString2PyList_helper(*$1);
271}
7bf85405 272
d14a1e28
RD
273%typemap(out) wxArrayString {
274 $result = wxArrayString2PyList_helper($1);
7bf85405
RD
275}
276
277
d14a1e28
RD
278// //---------------------------------------------------------------------------
279// // Map T_OUTPUTs for floats to return ints.
7bf85405 280
68320e40 281
d14a1e28
RD
282// %typemap(python,ignore) float *T_OUTPUT_TOINT(float temp),
283// double *T_OUTPUT_TOINT(double temp)
284// {
285// $target = &temp;
286// }
68320e40 287
68320e40 288
d14a1e28
RD
289// %typemap(python,argout) float *T_OUTPUT_TOINT,
290// double *T_OUTPUT_TOINT
291// {
292// PyObject *o;
293// o = PyInt_FromLong((long) (*$source));
294// $target = t_output_helper($target, o);
295// }
68320e40 296
154747f5 297
d14a1e28
RD
298// %typemap(python,ignore) bool *T_OUTPUT(int temp)
299// {
300// $target = (bool*)&temp;
301// }
154747f5 302
d14a1e28
RD
303// %typemap(python,argout) bool *T_OUTPUT
304// {
305// PyObject *o;
306// o = PyInt_FromLong((long) (*$source));
307// $target = t_output_helper($target, o);
308// }
154747f5 309
d14a1e28
RD
310// %typemap(python,ignore) bool *OUTPUT = bool *T_OUTPUT;
311// %typemap(python,argout) bool *OUTPUT = bool *T_OUTPUT;
312
313
314
315// %typemap(python,ignore) byte *T_OUTPUT(int temp)
316// {
317// $target = (byte*)&temp;
318// }
319
320// %typemap(python,argout) byte *T_OUTPUT
321// {
322// PyObject *o;
323// o = PyInt_FromLong((long) (*$source));
324// $target = t_output_helper($target, o);
325// }
154747f5 326
d14a1e28
RD
327// %typemap(python,ignore) byte *OUTPUT = byte *T_OUTPUT;
328// %typemap(python,argout) byte *OUTPUT = byte *T_OUTPUT;
154747f5 329
1e4a197e 330
d14a1e28
RD
331// %typemap(python,ignore) wxCoord *OUTPUT = int *OUTPUT;
332// %typemap(python,argout) wxCoord *OUTPUT = int *OUTPUT;
1e4a197e
RD
333
334
9416aa89
RD
335//---------------------------------------------------------------------------
336// Typemaps to convert return values that are base class pointers
337// to the real derived type, if possible. See wxPyMake_wxObject in
338// helpers.cpp
339
d14a1e28
RD
340%typemap(out) wxEvtHandler* { $result = wxPyMake_wxObject($1); }
341%typemap(out) wxMenu* { $result = wxPyMake_wxObject($1); }
342%typemap(out) wxValidator* { $result = wxPyMake_wxObject($1); }
343
344%typemap(out) wxApp* { $result = wxPyMake_wxObject($1); }
345%typemap(out) wxPyApp* { $result = wxPyMake_wxObject($1); }
346%typemap(out) wxDC* { $result = wxPyMake_wxObject($1); }
347%typemap(out) wxFSFile* { $result = wxPyMake_wxObject($1); }
348%typemap(out) wxFileSystem* { $result = wxPyMake_wxObject($1); }
349%typemap(out) wxGridTableBase* { $result = wxPyMake_wxObject($1); }
350%typemap(out) wxImageList* { $result = wxPyMake_wxObject($1); }
351%typemap(out) wxListItem* { $result = wxPyMake_wxObject($1); }
352%typemap(out) wxMenuItem* { $result = wxPyMake_wxObject($1); }
353%typemap(out) wxMouseEvent* { $result = wxPyMake_wxObject($1); }
354%typemap(out) wxObject* { $result = wxPyMake_wxObject($1); }
355%typemap(out) wxPyPrintout* { $result = wxPyMake_wxObject($1); }
356%typemap(out) wxToolBarToolBase* { $result = wxPyMake_wxObject($1); }
357%typemap(out) wxToolTip* { $result = wxPyMake_wxObject($1); }
358
359
360%typemap(out) wxBitmapButton* { $result = wxPyMake_wxObject($1); }
361%typemap(out) wxButton* { $result = wxPyMake_wxObject($1); }
362%typemap(out) wxControl* { $result = wxPyMake_wxObject($1); }
363%typemap(out) wxFrame* { $result = wxPyMake_wxObject($1); }
364%typemap(out) wxGrid* { $result = wxPyMake_wxObject($1); }
365%typemap(out) wxListCtrl* { $result = wxPyMake_wxObject($1); }
366%typemap(out) wxMDIChildFrame* { $result = wxPyMake_wxObject($1); }
367%typemap(out) wxMDIClientWindow* { $result = wxPyMake_wxObject($1); }
368%typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1); }
369%typemap(out) wxNotebook* { $result = wxPyMake_wxObject($1); }
370%typemap(out) wxStaticBox* { $result = wxPyMake_wxObject($1); }
371%typemap(out) wxStatusBar* { $result = wxPyMake_wxObject($1); }
372%typemap(out) wxTextCtrl* { $result = wxPyMake_wxObject($1); }
373%typemap(out) wxToolBar* { $result = wxPyMake_wxObject($1); }
374%typemap(out) wxToolBarBase* { $result = wxPyMake_wxObject($1); }
375%typemap(out) wxTreeCtrl* { $result = wxPyMake_wxObject($1); }
376%typemap(out) wxWindow* { $result = wxPyMake_wxObject($1); }
377%typemap(out) wxHtmlWindow* { $result = wxPyMake_wxObject($1); }
378%typemap(out) wxPyHtmlWindow* { $result = wxPyMake_wxObject($1); }
379%typemap(out) wxWizardPage* { $result = wxPyMake_wxObject($1); }
380
381%typemap(out) wxSizer* { $result = wxPyMake_wxSizer($1); }
2f4e9287 382
9416aa89
RD
383
384//%typemap(python, out) wxHtmlCell* { $target = wxPyMake_wxObject($source); }
385//%typemap(python, out) wxHtmlContainerCell* { $target = wxPyMake_wxObject($source); }
386//%typemap(python, out) wxHtmlParser* { $target = wxPyMake_wxObject($source); }
387//%typemap(python, out) wxHtmlWinParser* { $target = wxPyMake_wxObject($source); }
388
7bf85405 389//---------------------------------------------------------------------------
2f90df85 390//---------------------------------------------------------------------------
7bf85405 391
9416aa89
RD
392
393
394
395
396