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