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