1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Special typemaps specifically for wxPython.
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
14 //----------------------------------------------------------------------
15 // Typemaps to convert a list of items to an int (size) and an array
17 %define MAKE_INT_ARRAY_TYPEMAPS(NAME, ARR_NAME)
18 %typemap(in) (int NAME, int* ARR_NAME) {
19 $1 = PyList_Size($input);
20 $2 = int_LIST_helper($input);
21 if ($2 == NULL) SWIG_fail;
24 %typemap(freearg) (int NAME, int* ARR_NAME) {
29 MAKE_INT_ARRAY_TYPEMAPS(widths, widths_field)
30 MAKE_INT_ARRAY_TYPEMAPS(styles, styles_field)
34 // Same things for a wxString
35 %typemap(in) (int choices, wxString* choices_array ) {
36 $1 = PyList_Size($input);
37 $2 = wxString_LIST_helper($input);
38 if ($2 == NULL) SWIG_fail;
40 %typemap(freearg) (int choices, wxString* choices_array ) {
46 //---------------------------------------------------------------------------
50 %typemap(in) wxString& (bool temp=false) {
51 $1 = wxString_in_helper($input);
52 if ($1 == NULL) SWIG_fail;
55 %typemap(freearg) wxString& {
60 %typemap(out) wxString& {
62 $result = PyUnicode_FromWideChar($1->c_str(), $1->Len());
64 $result = PyString_FromStringAndSize($1->c_str(), $1->Len());
69 %apply wxString& { wxString* }
73 %typemap(out) wxString {
75 $result = PyUnicode_FromWideChar($1.c_str(), $1.Len());
77 $result = PyString_FromStringAndSize($1.c_str(), $1.Len());
81 %typemap(varout) wxString {
83 $result = PyUnicode_FromWideChar($1.c_str(), $1.Len());
85 $result = PyString_FromStringAndSize($1.c_str(), $1.Len());
90 %typemap(in) wxString {
91 wxString* sptr = wxString_in_helper($input);
92 if (sptr == NULL) SWIG_fail;
97 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxString& {
98 $1 = PyString_Check($input) || PyUnicode_Check($input);
101 //---------------------------------------------------------------------------
102 // wxMemoryBuffer (needed for wxSTC)
104 %typemap(in) wxMemoryBuffer& (bool temp=false) {
105 if (!PyString_Check($input)) {
106 PyErr_SetString(PyExc_TypeError, "String buffer expected");
109 char* str = PyString_AS_STRING($input);
110 int len = PyString_GET_SIZE($input);
111 $1 = new wxMemoryBuffer(len);
113 memcpy($1->GetData(), str, len);
117 %typemap(freearg) wxMemoryBuffer& {
118 if (temp$argnum) delete $1;
121 %typemap(out) wxMemoryBuffer {
122 $result = PyString_FromStringAndSize((char*)$1.GetData(), $1.GetDataLen());
127 //---------------------------------------------------------------------------
128 // Typemaps to convert Python sequence objects (tuples, etc.) to
129 // wxSize, wxPoint, wxRealPoint, and wxRect.
132 %typemap(in) wxSize& (wxSize temp) {
134 if ( ! wxSize_helper($input, &$1)) SWIG_fail;
136 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxSize& {
137 $1 = wxPySimple_typecheck($input, wxT("wxSize"), 2);
141 %typemap(in) wxPoint& (wxPoint temp) {
143 if ( ! wxPoint_helper($input, &$1)) SWIG_fail;
145 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxPoint& {
146 $1 = wxPySimple_typecheck($input, wxT("wxPoint"), 2);
150 %typemap(in) wxRealPoint& (wxRealPoint temp) {
152 if ( ! wxRealPoint_helper($input, &$1)) SWIG_fail;
154 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRealPoint& {
155 $1 = wxPySimple_typecheck($input, wxT("wxRealPoint"), 2);
159 %typemap(in) wxRect& (wxRect temp) {
161 if ( ! wxRect_helper($input, &$1)) SWIG_fail;
163 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRect& {
164 $1 = wxPySimple_typecheck($input, wxT("wxRect"), 4);
168 %typemap(in) wxPoint2D& (wxPoint2D temp) {
170 if ( ! wxPoint2D_helper($input, &$1)) SWIG_fail;
172 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxPoint2D& {
173 $1 = wxPySimple_typecheck($input, wxT("wxPoint2D"), 2);
177 //---------------------------------------------------------------------------
178 // Typemap to convert strings to wxColour. Two string formats are accepted,
179 // either a colour name, or a hex colour spec like "#RRGGBB"
181 %typemap(in) wxColour& (wxColour temp) {
183 if ( ! wxColour_helper($input, &$1)) SWIG_fail;
185 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxColour& {
186 $1 = wxColour_typecheck($input);
191 //---------------------------------------------------------------------------
192 // Typemap for wxArrayString from Python sequence objects
194 %typemap(in) wxArrayString& (bool temp=false) {
195 if (! PySequence_Check($input)) {
196 PyErr_SetString(PyExc_TypeError, "Sequence of strings expected.");
199 $1 = new wxArrayString;
201 int i, len=PySequence_Length($input);
202 for (i=0; i<len; i++) {
203 PyObject* item = PySequence_GetItem($input, i);
205 PyObject* str = PyObject_Unicode(item);
207 PyObject* str = PyObject_Str(item);
209 if (PyErr_Occurred()) SWIG_fail;
210 $1->Add(Py2wxString(str));
216 %typemap(freearg) wxArrayString& {
217 if (temp$argnum) delete $1;
220 //---------------------------------------------------------------------------
221 // Typemap for wxArrayInt from Python sequence objects
223 %typemap(in) wxArrayInt& (bool temp=false) {
224 if (! PySequence_Check($input)) {
225 PyErr_SetString(PyExc_TypeError, "Sequence of integers expected.");
230 int i, len=PySequence_Length($input);
231 for (i=0; i<len; i++) {
232 PyObject* item = PySequence_GetItem($input, i);
233 PyObject* number = PyNumber_Int(item);
234 $1->Add(PyInt_AS_LONG(number));
240 %typemap(freearg) wxArrayInt& {
241 if (temp$argnum) delete $1;
245 //---------------------------------------------------------------------------
246 // Typemaps to convert an array of ints to a list for return values
247 %typemap(out) wxArrayInt& {
248 $result = PyList_New(0);
250 for (idx = 0; idx < $1->GetCount(); idx += 1) {
251 PyObject* val = PyInt_FromLong( $1->Item(idx) );
252 PyList_Append($result, val);
257 %typemap(out) wxArrayInt {
258 $result = PyList_New(0);
260 for (idx = 0; idx < $1.GetCount(); idx += 1) {
261 PyObject* val = PyInt_FromLong( $1.Item(idx) );
262 PyList_Append($result, val);
269 // Typemaps to convert an array of strings to a list for return values
270 %typemap(out) wxArrayString& {
271 $result = wxArrayString2PyList_helper(*$1);
274 %typemap(out) wxArrayString {
275 $result = wxArrayString2PyList_helper($1);
279 //---------------------------------------------------------------------------
282 $result = $1 ? Py_True : Py_False; Py_INCREF($result);
286 //---------------------------------------------------------------------------
287 // Typemap for when GDI objects are returned by reference. This will cause a
288 // copy to be made instead of returning a reference to the same instance. The
289 // GDI object's internal refcounting scheme will do a copy-on-write of the
290 // internal data as needed.
293 //, wxRegion&, wxPalette&
295 %typemap(out) wxBrush&, wxPen&, wxFont&, wxBitmap&, wxIcon&, wxCursor& {
296 $*1_ltype* resultptr = new $*1_ltype(*$1);
297 $result = SWIG_NewPointerObj((void*)(resultptr), $1_descriptor, 1);
301 //---------------------------------------------------------------------------
302 // Typemaps to convert return values that are base class pointers
303 // to the real derived type, if possible. See wxPyMake_wxObject in
306 // NOTE: For those classes that also call _setOORInfo these typemaps should be
307 // disabled for the constructor.
309 %typemap(out) wxEvtHandler* { $result = wxPyMake_wxObject($1, $owner); }
310 %typemap(out) wxMenu* { $result = wxPyMake_wxObject($1, $owner); }
311 %typemap(out) wxValidator* { $result = wxPyMake_wxObject($1, $owner); }
313 %typemap(out) wxApp* { $result = wxPyMake_wxObject($1, $owner); }
314 %typemap(out) wxPyApp* { $result = wxPyMake_wxObject($1, $owner); }
315 %typemap(out) wxDC* { $result = wxPyMake_wxObject($1, $owner); }
316 %typemap(out) wxFSFile* { $result = wxPyMake_wxObject($1, $owner); }
317 %typemap(out) wxFileSystem* { $result = wxPyMake_wxObject($1, $owner); }
318 %typemap(out) wxImageList* { $result = wxPyMake_wxObject($1, $owner); }
319 %typemap(out) wxListItem* { $result = wxPyMake_wxObject($1, $owner); }
320 %typemap(out) wxMenuItem* { $result = wxPyMake_wxObject($1, $owner); }
321 %typemap(out) wxMouseEvent* { $result = wxPyMake_wxObject($1, $owner); }
322 %typemap(out) wxObject* { $result = wxPyMake_wxObject($1, $owner); }
323 %typemap(out) wxPyPrintout* { $result = wxPyMake_wxObject($1, $owner); }
324 %typemap(out) wxToolBarToolBase* { $result = wxPyMake_wxObject($1, $owner); }
325 %typemap(out) wxToolTip* { $result = wxPyMake_wxObject($1, $owner); }
328 %typemap(out) wxBitmapButton* { $result = wxPyMake_wxObject($1, $owner); }
329 %typemap(out) wxButton* { $result = wxPyMake_wxObject($1, $owner); }
330 %typemap(out) wxControl* { $result = wxPyMake_wxObject($1, $owner); }
331 %typemap(out) wxFrame* { $result = wxPyMake_wxObject($1, $owner); }
332 %typemap(out) wxGrid* { $result = wxPyMake_wxObject($1, $owner); }
333 //%typemap(out) wxListCtrl* { $result = wxPyMake_wxObject($1, $owner); }
334 %typemap(out) wxMDIChildFrame* { $result = wxPyMake_wxObject($1, $owner); }
335 %typemap(out) wxMDIClientWindow* { $result = wxPyMake_wxObject($1, $owner); }
336 %typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1, $owner); }
337 %typemap(out) wxNotebook* { $result = wxPyMake_wxObject($1, $owner); }
338 %typemap(out) wxStaticBox* { $result = wxPyMake_wxObject($1, $owner); }
339 %typemap(out) wxStatusBar* { $result = wxPyMake_wxObject($1, $owner); }
340 %typemap(out) wxTextCtrl* { $result = wxPyMake_wxObject($1, $owner); }
341 %typemap(out) wxToolBar* { $result = wxPyMake_wxObject($1, $owner); }
342 %typemap(out) wxToolBarBase* { $result = wxPyMake_wxObject($1, $owner); }
343 //%typemap(out) wxTreeCtrl* { $result = wxPyMake_wxObject($1, $owner); }
344 %typemap(out) wxPyTreeCtrl* { $result = wxPyMake_wxObject($1, $owner); }
345 %typemap(out) wxWindow* { $result = wxPyMake_wxObject($1, $owner); }
346 %typemap(out) wxPyHtmlWindow* { $result = wxPyMake_wxObject($1, $owner); }
347 %typemap(out) wxWizardPage* { $result = wxPyMake_wxObject($1, $owner); }
348 %typemap(out) wxPyWizardPage* { $result = wxPyMake_wxObject($1, $owner); }
349 %typemap(out) wxPanel* { $result = wxPyMake_wxObject($1, $owner); }
350 %typemap(out) wxDialog* { $result = wxPyMake_wxObject($1, $owner); }
351 %typemap(out) wxScrolledWindow* { $result = wxPyMake_wxObject($1, $owner); }
353 %typemap(out) wxSizer* { $result = wxPyMake_wxSizer($1, $owner); }
356 //---------------------------------------------------------------------------
357 //---------------------------------------------------------------------------