]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/my_typemaps.i
XPMHAND.H dependency removed
[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
RD
14//---------------------------------------------------------------------------
15// Tell SWIG to wrap all the wrappers with Python's thread macros
16
17%except(python) {
18 wxPy_BEGIN_ALLOW_THREADS;
19 $function
20 wxPy_END_ALLOW_THREADS;
21}
22
7bf85405 23//----------------------------------------------------------------------
eec92d76 24// LCOUNT and choices go together. They allow a single Python list to be
2f90df85 25// converted to an integer count and an array count items long.
7bf85405
RD
26
27%typemap(python,build) int LCOUNT {
eec92d76
RD
28 if (_in_choices) {
29 $target = PyList_Size(_in_choices);
cf694132
RD
30 }
31 else {
32 $target = 0;
33 }
7bf85405
RD
34}
35
36
37
eec92d76 38%typemap(python,in) byte* choices {
b639c3c5
RD
39 $target = byte_LIST_helper($source);
40 if ($target == NULL) {
41 return NULL;
42 }
43}
eec92d76 44%typemap(python,freearg) byte* choices {
b639c3c5
RD
45 delete [] $source;
46}
47
de9d9ed2
RD
48// wxDash is a signed char
49%typemap(python,in) wxDash* choices {
50 $target = (wxDash*)byte_LIST_helper($source);
51 if ($target == NULL) {
52 return NULL;
53 }
54}
55%typemap(python,freearg) wxDash* choices {
56 delete [] $source;
57}
58
b639c3c5 59
eec92d76 60%typemap(python,in) int* choices {
7bf85405
RD
61 $target = int_LIST_helper($source);
62 if ($target == NULL) {
63 return NULL;
64 }
65}
eec92d76 66%typemap(python,freearg) int* choices {
7bf85405
RD
67 delete [] $source;
68}
69
70
eec92d76 71%typemap(python,in) long* choices {
7bf85405
RD
72 $target = long_LIST_helper($source);
73 if ($target == NULL) {
74 return NULL;
75 }
76}
eec92d76 77%typemap(python,freearg) long* choices {
7bf85405
RD
78 delete [] $source;
79}
80
81
eec92d76 82%typemap(python,in) unsigned long* choices {
7bf85405
RD
83 $target = (unsigned long*)long_LIST_helper($source);
84 if ($target == NULL) {
85 return NULL;
86 }
87}
eec92d76 88%typemap(python,freearg) unsigned long* choices {
7bf85405
RD
89 delete [] $source;
90}
91
92
eec92d76 93%typemap(python,in) char** choices {
7bf85405
RD
94 $target = string_LIST_helper($source);
95 if ($target == NULL) {
96 return NULL;
97 }
98}
eec92d76 99%typemap(python,freearg) char** choices {
7bf85405
RD
100 delete [] $source;
101}
102
103
eec92d76
RD
104%typemap(python,in) wxBitmap** choices {
105 $target = wxBitmap_LIST_helper($source);
7bf85405
RD
106 if ($target == NULL) {
107 return NULL;
108 }
109}
eec92d76 110%typemap(python,freearg) wxBitmap** choices {
7bf85405
RD
111 delete [] $source;
112}
113
eec92d76
RD
114%typemap(python,in) wxString* choices {
115 $target = wxString_LIST_helper($source);
7bf85405
RD
116 if ($target == NULL) {
117 return NULL;
118 }
119}
eec92d76 120%typemap(python,freearg) wxString* choices {
7bf85405
RD
121 delete [] $source;
122}
123
eec92d76
RD
124%typemap(python,in) wxAcceleratorEntry* choices {
125 $target = wxAcceleratorEntry_LIST_helper($source);
7bf85405
RD
126 if ($target == NULL) {
127 return NULL;
128 }
129}
eec92d76 130%typemap(python,freearg) wxAcceleratorEntry* choices {
7bf85405
RD
131 delete [] $source;
132}
133
eec92d76 134%typemap(python,build) int PCOUNT {
e0672e2f 135 $target = NPOINTS;
eec92d76
RD
136}
137
e0672e2f
RD
138%typemap(python,in) wxPoint* points (int NPOINTS) {
139 $target = wxPoint_LIST_helper($source, &NPOINTS);
140 if ($target == NULL) {
141 return NULL;
142 }
7bf85405 143}
eec92d76 144%typemap(python,freearg) wxPoint* points {
7bf85405
RD
145 delete [] $source;
146}
147
148
eec92d76 149
e0672e2f 150
7bf85405
RD
151//---------------------------------------------------------------------------
152
153%{
7a446686
RD
154#if PYTHON_API_VERSION >= 1009
155 static char* wxStringErrorMsg = "String or Unicode type required";
156#else
157 static char* wxStringErrorMsg = "string type is required for parameter";
158#endif
7bf85405
RD
159%}
160
185d7c3e
RD
161// TODO: Which works best???
162
163// Implementation #1
164// %typemap(python, in) wxString& (PyObject* temp, int tmpDoDecRef) {
165// temp = $source;
166// tmpDoDecRef = 0;
167// #if PYTHON_API_VERSION >= 1009
168// if (PyUnicode_Check(temp) {
169// temp = PyUnicode_AsUTF8String(temp);
170// if (! temp) {
171// PyErr_SetString(PyExc_TypeError, "Unicode encoding to UTF8 failed.");
172// return NULL;
173// }
174// tmpDoDecRef = 1;
175// #endif
176// if (!PyString_Check(temp)) {
177// PyErr_SetString(PyExc_TypeError, wxStringErrorMsg);
178// return NULL;
179// }
180// $target = new wxString(PyString_AsString(temp), PyString_Size(temp));
181// #if PYTHON_API_VERESION >= 1009
182// if (tmpDoDecRef) Py_DECREF(temp);
183// #endif
184// }
185
186
187// Implementation #2
7bf85405 188%typemap(python, in) wxString& {
185d7c3e
RD
189#if PYTHON_API_VERSION >= 1009
190 char* tmpPtr; int tmpSize;
191 if (!PyString_Check($source) && !PyUnicode_Check($source)) {
7a446686 192 PyErr_SetString(PyExc_TypeError, wxStringErrorMsg);
185d7c3e
RD
193 return NULL;
194 }
195 if (PyString_AsStringAndSize($source, &tmpPtr, &tmpSize) == -1)
196 return NULL;
197 $target = new wxString(tmpPtr, tmpSize);
198#else
7bf85405
RD
199 if (!PyString_Check($source)) {
200 PyErr_SetString(PyExc_TypeError, wxStringErrorMsg);
201 return NULL;
202 }
185d7c3e
RD
203 $target = new wxString(PyString_AS_STRING($source), PyString_GET_SIZE($source));
204#endif
7bf85405 205}
185d7c3e
RD
206
207
208
209
7bf85405
RD
210%typemap(python, freearg) wxString& {
211 if ($target)
212 delete $source;
213}
214
215
216
217%typemap(python, out) wxString {
eec92d76 218 $target = PyString_FromStringAndSize($source->c_str(), $source->Len());
7bf85405
RD
219}
220%typemap(python, ret) wxString {
221 delete $source;
222}
223
224
225%typemap(python, out) wxString* {
eec92d76 226 $target = PyString_FromStringAndSize($source->c_str(), $source->Len());
7bf85405
RD
227}
228
229
2f90df85
RD
230
231
232
7bf85405 233//---------------------------------------------------------------------------
2f90df85
RD
234// Typemaps to convert Python sequence objects (2-tuples, etc.) to
235// wxSize, wxPoint, wxRealPoint, and wxRect.
236
237%typemap(python,in) wxSize& (wxSize temp) {
238 $target = &temp;
239 if (! wxSize_helper($source, &$target))
240 return NULL;
241}
242
243%typemap(python,in) wxPoint& (wxPoint temp) {
244 $target = &temp;
245 if (! wxPoint_helper($source, &$target))
246 return NULL;
247}
248
249%typemap(python,in) wxRealPoint& (wxRealPoint temp) {
250 $target = &temp;
251 if (! wxRealPoint_helper($source, &$target))
252 return NULL;
253}
7bf85405 254
2f90df85
RD
255%typemap(python,in) wxRect& (wxRect temp) {
256 $target = &temp;
257 if (! wxRect_helper($source, &$target))
258 return NULL;
259}
7bf85405 260
f6bcfd97
BP
261//---------------------------------------------------------------------------
262// Typemap to convert strings to wxColour. Two string formats are accepted,
de20db99 263// either a colour name, or a hex colour spec like "#RRGGBB"
f6bcfd97
BP
264
265%typemap(python,in) wxColour& (wxColour temp) {
266 $target = &temp;
267 if (! wxColour_helper($source, &$target))
268 return NULL;
269}
270
7bf85405 271
2f90df85 272//---------------------------------------------------------------------------
7bf85405
RD
273// Map T_OUTPUTs for floats to return ints.
274
275
276%typemap(python,ignore) float *T_OUTPUT_TOINT(float temp),
277 double *T_OUTPUT_TOINT(double temp)
278{
279 $target = &temp;
280}
281
282
283%typemap(python,argout) float *T_OUTPUT_TOINT,
284 double *T_OUTPUT_TOINT
285{
286 PyObject *o;
287 o = PyInt_FromLong((long) (*$source));
288 $target = t_output_helper($target, o);
289}
290
9416aa89
RD
291//---------------------------------------------------------------------------
292// Typemaps to convert return values that are base class pointers
293// to the real derived type, if possible. See wxPyMake_wxObject in
294// helpers.cpp
295
296
297%typemap(python, out) wxButton* { $target = wxPyMake_wxObject($source); }
298%typemap(python, out) wxControl* { $target = wxPyMake_wxObject($source); }
299%typemap(python, out) wxDC* { $target = wxPyMake_wxObject($source); }
300%typemap(python, out) wxEvtHandler* { $target = wxPyMake_wxObject($source); }
301%typemap(python, out) wxFSFile* { $target = wxPyMake_wxObject($source); }
302%typemap(python, out) wxFileSystem* { $target = wxPyMake_wxObject($source); }
303%typemap(python, out) wxFrame* { $target = wxPyMake_wxObject($source); }
304%typemap(python, out) wxGrid* { $target = wxPyMake_wxObject($source); }
305%typemap(python, out) wxGridTableBase* { $target = wxPyMake_wxObject($source); }
306%typemap(python, out) wxImageList* { $target = wxPyMake_wxObject($source); }
307%typemap(python, out) wxListItem* { $target = wxPyMake_wxObject($source); }
308%typemap(python, out) wxMDIChildFrame* { $target = wxPyMake_wxObject($source); }
309%typemap(python, out) wxMDIClientWindow* { $target = wxPyMake_wxObject($source); }
310%typemap(python, out) wxMenu* { $target = wxPyMake_wxObject($source); }
311%typemap(python, out) wxMenuBar* { $target = wxPyMake_wxObject($source); }
312%typemap(python, out) wxMenuItem* { $target = wxPyMake_wxObject($source); }
313%typemap(python, out) wxMouseEvent* { $target = wxPyMake_wxObject($source); }
314%typemap(python, out) wxNotebook* { $target = wxPyMake_wxObject($source); }
315%typemap(python, out) wxObject* { $target = wxPyMake_wxObject($source); }
316%typemap(python, out) wxPyPrintout* { $target = wxPyMake_wxObject($source); }
317%typemap(python, out) wxSizer* { $target = wxPyMake_wxObject($source); }
318%typemap(python, out) wxSizer* { $target = wxPyMake_wxObject($source); }
319%typemap(python, out) wxStaticBox* { $target = wxPyMake_wxObject($source); }
320%typemap(python, out) wxStatusBar* { $target = wxPyMake_wxObject($source); }
321%typemap(python, out) wxTextCtrl* { $target = wxPyMake_wxObject($source); }
322%typemap(python, out) wxToolBar* { $target = wxPyMake_wxObject($source); }
323%typemap(python, out) wxToolBarBase* { $target = wxPyMake_wxObject($source); }
324%typemap(python, out) wxToolBarToolBase* { $target = wxPyMake_wxObject($source); }
325%typemap(python, out) wxToolTip* { $target = wxPyMake_wxObject($source); }
326%typemap(python, out) wxValidator* { $target = wxPyMake_wxObject($source); }
327%typemap(python, out) wxWindow* { $target = wxPyMake_wxObject($source); }
328
329
330//%typemap(python, out) wxHtmlCell* { $target = wxPyMake_wxObject($source); }
331//%typemap(python, out) wxHtmlContainerCell* { $target = wxPyMake_wxObject($source); }
332//%typemap(python, out) wxHtmlParser* { $target = wxPyMake_wxObject($source); }
333//%typemap(python, out) wxHtmlWinParser* { $target = wxPyMake_wxObject($source); }
334
7bf85405 335//---------------------------------------------------------------------------
2f90df85 336//---------------------------------------------------------------------------
7bf85405 337
9416aa89
RD
338
339
340
341
342