]>
Commit | Line | Data |
---|---|---|
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 | ||
d14a1e28 | 38 | //--------------------------------------------------------------------------- |
dd9f7fea | 39 | // wxString typemaps |
7bf85405 RD |
40 | |
41 | ||
dd9f7fea | 42 | %typemap(in) wxString& (bool temp=False) { |
d14a1e28 RD |
43 | $1 = wxString_in_helper($input); |
44 | if ($1 == NULL) SWIG_fail; | |
dd9f7fea | 45 | temp = True; |
7bf85405 | 46 | } |
d14a1e28 RD |
47 | %typemap(freearg) wxString& { |
48 | if (temp$argnum) | |
49 | delete $1; | |
7bf85405 RD |
50 | } |
51 | ||
52 | ||
7bf85405 | 53 | |
d14a1e28 RD |
54 | %typemap(out) wxString { |
55 | %#if wxUSE_UNICODE | |
56 | $result = PyUnicode_FromWideChar($1.c_str(), $1.Len()); | |
57 | %#else | |
58 | $result = PyString_FromStringAndSize($1.c_str(), $1.Len()); | |
59 | %#endif | |
7bf85405 RD |
60 | } |
61 | ||
87c2245b | 62 | |
dd9f7fea | 63 | %typemap(out) wxString* { |
d14a1e28 RD |
64 | %#if wxUSE_UNICODE |
65 | $result = PyUnicode_FromWideChar($1->c_str(), $1->Len()); | |
66 | %#else | |
67 | $result = PyString_FromStringAndSize($1->c_str(), $1->Len()); | |
68 | %#endif | |
7bf85405 RD |
69 | } |
70 | ||
87c2245b RD |
71 | |
72 | %typemap(out) wxString& { | |
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 | |
78 | } | |
79 | ||
80 | ||
dd9f7fea | 81 | %typemap(varout) wxString { |
d14a1e28 RD |
82 | %#if wxUSE_UNICODE |
83 | $result = PyUnicode_FromWideChar($1.c_str(), $1.Len()); | |
84 | %#else | |
85 | $result = PyString_FromStringAndSize($1.c_str(), $1.Len()); | |
86 | %#endif | |
7bf85405 RD |
87 | } |
88 | ||
eec92d76 | 89 | |
dd9f7fea RD |
90 | %typemap(in) wxString { |
91 | wxString* sptr = wxString_in_helper($input); | |
92 | if (sptr == NULL) SWIG_fail; | |
93 | $1 = *sptr; | |
94 | delete sptr; | |
95 | } | |
96 | ||
97 | ||
7bf85405 | 98 | |
d14a1e28 RD |
99 | //--------------------------------------------------------------------------- |
100 | // Typemaps to convert Python sequence objects (tuples, etc.) to | |
101 | // wxSize, wxPoint, wxRealPoint, and wxRect. | |
7bf85405 RD |
102 | |
103 | ||
d14a1e28 RD |
104 | %typemap(in) wxSize& (wxSize temp) { |
105 | $1 = &temp; | |
106 | if ( ! wxSize_helper($input, &$1)) SWIG_fail; | |
7bf85405 | 107 | } |
d14a1e28 RD |
108 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxSize& { |
109 | $1 = wxPySimple_typecheck($input, wxT("wxSize"), 2); | |
7bf85405 RD |
110 | } |
111 | ||
112 | ||
d14a1e28 RD |
113 | %typemap(in) wxPoint& (wxPoint temp) { |
114 | $1 = &temp; | |
115 | if ( ! wxPoint_helper($input, &$1)) SWIG_fail; | |
7bf85405 | 116 | } |
d14a1e28 RD |
117 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxPoint& { |
118 | $1 = wxPySimple_typecheck($input, wxT("wxPoint"), 2); | |
10ef30eb RD |
119 | } |
120 | ||
10ef30eb | 121 | |
d14a1e28 RD |
122 | %typemap(in) wxRealPoint& (wxRealPoint temp) { |
123 | $1 = &temp; | |
124 | if ( ! wxRealPoint_helper($input, &$1)) SWIG_fail; | |
10ef30eb | 125 | } |
d14a1e28 RD |
126 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRealPoint& { |
127 | $1 = wxPySimple_typecheck($input, wxT("wxRealPoint"), 2); | |
10ef30eb | 128 | } |
2f90df85 RD |
129 | |
130 | ||
d14a1e28 RD |
131 | %typemap(in) wxRect& (wxRect temp) { |
132 | $1 = &temp; | |
133 | if ( ! wxRect_helper($input, &$1)) SWIG_fail; | |
2f90df85 | 134 | } |
d14a1e28 RD |
135 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRect& { |
136 | $1 = wxPySimple_typecheck($input, wxT("wxRect"), 4); | |
2f90df85 RD |
137 | } |
138 | ||
7bf85405 | 139 | |
d14a1e28 RD |
140 | %typemap(in) wxPoint2D& (wxPoint2D temp) { |
141 | $1 = &temp; | |
142 | if ( ! wxPoint2D_helper($input, &$1)) SWIG_fail; | |
2f90df85 | 143 | } |
d14a1e28 RD |
144 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxPoint2D& { |
145 | $1 = wxPySimple_typecheck($input, wxT("wxPoint2D"), 2); | |
1e4a197e RD |
146 | } |
147 | ||
d14a1e28 | 148 | |
f6bcfd97 BP |
149 | //--------------------------------------------------------------------------- |
150 | // Typemap to convert strings to wxColour. Two string formats are accepted, | |
de20db99 | 151 | // either a colour name, or a hex colour spec like "#RRGGBB" |
f6bcfd97 | 152 | |
d14a1e28 RD |
153 | %typemap(in) wxColour& (wxColour temp) { |
154 | $1 = &temp; | |
155 | if ( ! wxColour_helper($input, &$1)) SWIG_fail; | |
f6bcfd97 | 156 | } |
d14a1e28 RD |
157 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxColour& { |
158 | $1 = wxColour_typecheck($input); | |
159 | } | |
160 | ||
161 | ||
f6bcfd97 | 162 | |
b37c7e1d RD |
163 | //--------------------------------------------------------------------------- |
164 | // Typemap for wxArrayString from Python sequence objects | |
165 | ||
d14a1e28 RD |
166 | %typemap(in) wxArrayString& { |
167 | if (! PySequence_Check($input)) { | |
b37c7e1d | 168 | PyErr_SetString(PyExc_TypeError, "Sequence of strings expected."); |
d14a1e28 | 169 | SWIG_fail; |
b37c7e1d | 170 | } |
d14a1e28 RD |
171 | $1 = new wxArrayString; |
172 | int i, len=PySequence_Length($input); | |
b37c7e1d | 173 | for (i=0; i<len; i++) { |
d14a1e28 RD |
174 | PyObject* item = PySequence_GetItem($input, i); |
175 | %#if wxUSE_UNICODE | |
c8bc7bb8 | 176 | PyObject* str = PyObject_Unicode(item); |
d14a1e28 | 177 | %#else |
b37c7e1d | 178 | PyObject* str = PyObject_Str(item); |
d14a1e28 RD |
179 | %#endif |
180 | $1->Add(Py2wxString(str)); | |
b37c7e1d RD |
181 | Py_DECREF(item); |
182 | Py_DECREF(str); | |
183 | } | |
184 | } | |
185 | ||
d14a1e28 RD |
186 | %typemap(freearg) wxArrayString& { |
187 | if ($1) delete $1; | |
b37c7e1d | 188 | } |
7bf85405 | 189 | |
293a0a86 RD |
190 | //--------------------------------------------------------------------------- |
191 | // Typemap for wxArrayInt from Python sequence objects | |
192 | ||
d14a1e28 RD |
193 | %typemap(in) wxArrayInt& { |
194 | if (! PySequence_Check($input)) { | |
293a0a86 | 195 | PyErr_SetString(PyExc_TypeError, "Sequence of integers expected."); |
d14a1e28 | 196 | SWIG_fail; |
293a0a86 | 197 | } |
d14a1e28 RD |
198 | $1 = new wxArrayInt; |
199 | int i, len=PySequence_Length($input); | |
293a0a86 | 200 | for (i=0; i<len; i++) { |
d14a1e28 | 201 | PyObject* item = PySequence_GetItem($input, i); |
293a0a86 | 202 | PyObject* number = PyNumber_Int(item); |
d14a1e28 | 203 | $1->Add(PyInt_AS_LONG(number)); |
293a0a86 RD |
204 | Py_DECREF(item); |
205 | Py_DECREF(number); | |
206 | } | |
207 | } | |
208 | ||
d14a1e28 RD |
209 | %typemap(freearg) wxArrayInt& { |
210 | if ($1) delete $1; | |
293a0a86 RD |
211 | } |
212 | ||
213 | ||
d14a1e28 RD |
214 | //--------------------------------------------------------------------------- |
215 | // Typemaps to convert an array of ints to a list for return values | |
216 | %typemap(out) wxArrayInt& { | |
217 | $result = PyList_New(0); | |
1e4a197e | 218 | size_t idx; |
d14a1e28 RD |
219 | for (idx = 0; idx < $1->GetCount(); idx += 1) { |
220 | PyObject* val = PyInt_FromLong( $1->Item(idx) ); | |
221 | PyList_Append($result, val); | |
1e4a197e RD |
222 | Py_DECREF(val); |
223 | } | |
224 | } | |
225 | ||
d14a1e28 RD |
226 | %typemap(out) wxArrayInt { |
227 | $result = PyList_New(0); | |
1e4a197e | 228 | size_t idx; |
d14a1e28 RD |
229 | for (idx = 0; idx < $1.GetCount(); idx += 1) { |
230 | PyObject* val = PyInt_FromLong( $1.Item(idx) ); | |
231 | PyList_Append($result, val); | |
1e4a197e RD |
232 | Py_DECREF(val); |
233 | } | |
1e4a197e RD |
234 | } |
235 | ||
236 | ||
7bf85405 | 237 | |
d14a1e28 RD |
238 | // Typemaps to convert an array of ints to a list for return values |
239 | %typemap(out) wxArrayString& { | |
240 | $result = wxArrayString2PyList_helper(*$1); | |
241 | } | |
7bf85405 | 242 | |
d14a1e28 RD |
243 | %typemap(out) wxArrayString { |
244 | $result = wxArrayString2PyList_helper($1); | |
7bf85405 RD |
245 | } |
246 | ||
247 | ||
1e4a197e | 248 | |
9416aa89 RD |
249 | //--------------------------------------------------------------------------- |
250 | // Typemaps to convert return values that are base class pointers | |
251 | // to the real derived type, if possible. See wxPyMake_wxObject in | |
252 | // helpers.cpp | |
253 | ||
d14a1e28 RD |
254 | %typemap(out) wxEvtHandler* { $result = wxPyMake_wxObject($1); } |
255 | %typemap(out) wxMenu* { $result = wxPyMake_wxObject($1); } | |
256 | %typemap(out) wxValidator* { $result = wxPyMake_wxObject($1); } | |
257 | ||
258 | %typemap(out) wxApp* { $result = wxPyMake_wxObject($1); } | |
259 | %typemap(out) wxPyApp* { $result = wxPyMake_wxObject($1); } | |
260 | %typemap(out) wxDC* { $result = wxPyMake_wxObject($1); } | |
261 | %typemap(out) wxFSFile* { $result = wxPyMake_wxObject($1); } | |
262 | %typemap(out) wxFileSystem* { $result = wxPyMake_wxObject($1); } | |
263 | %typemap(out) wxGridTableBase* { $result = wxPyMake_wxObject($1); } | |
264 | %typemap(out) wxImageList* { $result = wxPyMake_wxObject($1); } | |
265 | %typemap(out) wxListItem* { $result = wxPyMake_wxObject($1); } | |
266 | %typemap(out) wxMenuItem* { $result = wxPyMake_wxObject($1); } | |
267 | %typemap(out) wxMouseEvent* { $result = wxPyMake_wxObject($1); } | |
268 | %typemap(out) wxObject* { $result = wxPyMake_wxObject($1); } | |
269 | %typemap(out) wxPyPrintout* { $result = wxPyMake_wxObject($1); } | |
270 | %typemap(out) wxToolBarToolBase* { $result = wxPyMake_wxObject($1); } | |
271 | %typemap(out) wxToolTip* { $result = wxPyMake_wxObject($1); } | |
272 | ||
273 | ||
274 | %typemap(out) wxBitmapButton* { $result = wxPyMake_wxObject($1); } | |
275 | %typemap(out) wxButton* { $result = wxPyMake_wxObject($1); } | |
276 | %typemap(out) wxControl* { $result = wxPyMake_wxObject($1); } | |
277 | %typemap(out) wxFrame* { $result = wxPyMake_wxObject($1); } | |
278 | %typemap(out) wxGrid* { $result = wxPyMake_wxObject($1); } | |
279 | %typemap(out) wxListCtrl* { $result = wxPyMake_wxObject($1); } | |
280 | %typemap(out) wxMDIChildFrame* { $result = wxPyMake_wxObject($1); } | |
281 | %typemap(out) wxMDIClientWindow* { $result = wxPyMake_wxObject($1); } | |
282 | %typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1); } | |
283 | %typemap(out) wxNotebook* { $result = wxPyMake_wxObject($1); } | |
284 | %typemap(out) wxStaticBox* { $result = wxPyMake_wxObject($1); } | |
285 | %typemap(out) wxStatusBar* { $result = wxPyMake_wxObject($1); } | |
286 | %typemap(out) wxTextCtrl* { $result = wxPyMake_wxObject($1); } | |
287 | %typemap(out) wxToolBar* { $result = wxPyMake_wxObject($1); } | |
288 | %typemap(out) wxToolBarBase* { $result = wxPyMake_wxObject($1); } | |
289 | %typemap(out) wxTreeCtrl* { $result = wxPyMake_wxObject($1); } | |
b2dc1044 | 290 | %typemap(out) wxPyTreeCtrl* { $result = wxPyMake_wxObject($1); } |
d14a1e28 RD |
291 | %typemap(out) wxWindow* { $result = wxPyMake_wxObject($1); } |
292 | %typemap(out) wxHtmlWindow* { $result = wxPyMake_wxObject($1); } | |
293 | %typemap(out) wxPyHtmlWindow* { $result = wxPyMake_wxObject($1); } | |
294 | %typemap(out) wxWizardPage* { $result = wxPyMake_wxObject($1); } | |
295 | ||
296 | %typemap(out) wxSizer* { $result = wxPyMake_wxSizer($1); } | |
2f4e9287 | 297 | |
9416aa89 RD |
298 | |
299 | //%typemap(python, out) wxHtmlCell* { $target = wxPyMake_wxObject($source); } | |
300 | //%typemap(python, out) wxHtmlContainerCell* { $target = wxPyMake_wxObject($source); } | |
301 | //%typemap(python, out) wxHtmlParser* { $target = wxPyMake_wxObject($source); } | |
302 | //%typemap(python, out) wxHtmlWinParser* { $target = wxPyMake_wxObject($source); } | |
303 | ||
7bf85405 | 304 | //--------------------------------------------------------------------------- |
2f90df85 | 305 | //--------------------------------------------------------------------------- |
7bf85405 | 306 | |
9416aa89 RD |
307 | |
308 | ||
309 | ||
310 | ||
311 |