1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Special typemaps specifically for wxPython.
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
14 //---------------------------------------------------------------------------
15 // Tell SWIG to wrap all the wrappers with our thread protection
18 PyThreadState* __tstate = wxPyBeginAllowThreads();
20 wxPyEndAllowThreads(__tstate);
21 if (PyErr_Occurred()) SWIG_fail;
25 //----------------------------------------------------------------------
26 // Typemaps to convert a list of items to an int (size) and an array
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;
33 %typemap(freearg) (int choices, wxString* choices_array ) {
38 //---------------------------------------------------------------------------
42 %typemap(in) wxString& (bool temp=False) {
43 $1 = wxString_in_helper($input);
44 if ($1 == NULL) SWIG_fail;
47 %typemap(freearg) wxString& {
52 %typemap(out) wxString& {
54 $result = PyUnicode_FromWideChar($1->c_str(), $1->Len());
56 $result = PyString_FromStringAndSize($1->c_str(), $1->Len());
61 %apply wxString& { wxString* }
65 %typemap(out) wxString {
67 $result = PyUnicode_FromWideChar($1.c_str(), $1.Len());
69 $result = PyString_FromStringAndSize($1.c_str(), $1.Len());
73 %typemap(varout) wxString {
75 $result = PyUnicode_FromWideChar($1.c_str(), $1.Len());
77 $result = PyString_FromStringAndSize($1.c_str(), $1.Len());
82 %typemap(in) wxString {
83 wxString* sptr = wxString_in_helper($input);
84 if (sptr == NULL) SWIG_fail;
89 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxString& {
90 $1 = PyString_Check($input) || PyUnicode_Check($input);
93 //---------------------------------------------------------------------------
94 // wxMemoryBuffer (needed for wxSTC)
96 %typemap(in) wxMemoryBuffer& (bool temp=False) {
97 if (!PyString_Check($input)) {
98 PyErr_SetString(PyExc_TypeError, "String buffer expected");
101 char* str = PyString_AS_STRING($input);
102 int len = PyString_GET_SIZE($input);
103 $1 = new wxMemoryBuffer(len);
105 memcpy($1->GetData(), str, len);
108 %typemap(freearg) wxMemoryBuffer& {
109 if (temp$argnum) delete $1;
112 %typemap(out) wxMemoryBuffer {
113 $result = PyString_FromStringAndSize((char*)$1.GetData(), $1.GetDataLen());
118 //---------------------------------------------------------------------------
119 // Typemaps to convert Python sequence objects (tuples, etc.) to
120 // wxSize, wxPoint, wxRealPoint, and wxRect.
123 %typemap(in) wxSize& (wxSize temp) {
125 if ( ! wxSize_helper($input, &$1)) SWIG_fail;
127 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxSize& {
128 $1 = wxPySimple_typecheck($input, wxT("wxSize"), 2);
132 %typemap(in) wxPoint& (wxPoint temp) {
134 if ( ! wxPoint_helper($input, &$1)) SWIG_fail;
136 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxPoint& {
137 $1 = wxPySimple_typecheck($input, wxT("wxPoint"), 2);
141 %typemap(in) wxRealPoint& (wxRealPoint temp) {
143 if ( ! wxRealPoint_helper($input, &$1)) SWIG_fail;
145 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRealPoint& {
146 $1 = wxPySimple_typecheck($input, wxT("wxRealPoint"), 2);
150 %typemap(in) wxRect& (wxRect temp) {
152 if ( ! wxRect_helper($input, &$1)) SWIG_fail;
154 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRect& {
155 $1 = wxPySimple_typecheck($input, wxT("wxRect"), 4);
159 %typemap(in) wxPoint2D& (wxPoint2D temp) {
161 if ( ! wxPoint2D_helper($input, &$1)) SWIG_fail;
163 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxPoint2D& {
164 $1 = wxPySimple_typecheck($input, wxT("wxPoint2D"), 2);
168 //---------------------------------------------------------------------------
169 // Typemap to convert strings to wxColour. Two string formats are accepted,
170 // either a colour name, or a hex colour spec like "#RRGGBB"
172 %typemap(in) wxColour& (wxColour temp) {
174 if ( ! wxColour_helper($input, &$1)) SWIG_fail;
176 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxColour& {
177 $1 = wxColour_typecheck($input);
182 //---------------------------------------------------------------------------
183 // Typemap for wxArrayString from Python sequence objects
185 %typemap(in) wxArrayString& (bool temp=False) {
186 if (! PySequence_Check($input)) {
187 PyErr_SetString(PyExc_TypeError, "Sequence of strings expected.");
190 $1 = new wxArrayString;
192 int i, len=PySequence_Length($input);
193 for (i=0; i<len; i++) {
194 PyObject* item = PySequence_GetItem($input, i);
196 PyObject* str = PyObject_Unicode(item);
198 PyObject* str = PyObject_Str(item);
200 $1->Add(Py2wxString(str));
206 %typemap(freearg) wxArrayString& {
207 if (temp$argnum) delete $1;
210 //---------------------------------------------------------------------------
211 // Typemap for wxArrayInt from Python sequence objects
213 %typemap(in) wxArrayInt& (bool temp=False) {
214 if (! PySequence_Check($input)) {
215 PyErr_SetString(PyExc_TypeError, "Sequence of integers expected.");
220 int i, len=PySequence_Length($input);
221 for (i=0; i<len; i++) {
222 PyObject* item = PySequence_GetItem($input, i);
223 PyObject* number = PyNumber_Int(item);
224 $1->Add(PyInt_AS_LONG(number));
230 %typemap(freearg) wxArrayInt& {
231 if (temp$argnum) delete $1;
235 //---------------------------------------------------------------------------
236 // Typemaps to convert an array of ints to a list for return values
237 %typemap(out) wxArrayInt& {
238 $result = PyList_New(0);
240 for (idx = 0; idx < $1->GetCount(); idx += 1) {
241 PyObject* val = PyInt_FromLong( $1->Item(idx) );
242 PyList_Append($result, val);
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);
259 // Typemaps to convert an array of ints to a list for return values
260 %typemap(out) wxArrayString& {
261 $result = wxArrayString2PyList_helper(*$1);
264 %typemap(out) wxArrayString {
265 $result = wxArrayString2PyList_helper($1);
269 //---------------------------------------------------------------------------
271 %typemap(out) bool "$result = $1 ? Py_True : Py_False; Py_INCREF($result);"
275 //---------------------------------------------------------------------------
276 // Typemap for when GDI objects are returned by reference. This will cause a
277 // copy to be made instead of returning a reference to the same instance. The
278 // GDI object's internal refcounting scheme will do a copy-on-write of the
279 // internal data as needed.
282 //, wxRegion&, wxPalette&
284 %typemap(out) wxBrush&, wxPen&, wxFont&, wxBitmap&, wxIcon&, wxCursor& {
285 $*1_ltype* resultptr = new $*1_ltype(*$1);
286 $result = SWIG_NewPointerObj((void*)(resultptr), $1_descriptor, 1);
290 //---------------------------------------------------------------------------
291 // Typemaps to convert return values that are base class pointers
292 // to the real derived type, if possible. See wxPyMake_wxObject in
295 %typemap(out) wxEvtHandler* { $result = wxPyMake_wxObject($1); }
296 %typemap(out) wxMenu* { $result = wxPyMake_wxObject($1); }
297 %typemap(out) wxValidator* { $result = wxPyMake_wxObject($1); }
299 %typemap(out) wxApp* { $result = wxPyMake_wxObject($1); }
300 %typemap(out) wxPyApp* { $result = wxPyMake_wxObject($1); }
301 %typemap(out) wxDC* { $result = wxPyMake_wxObject($1); }
302 %typemap(out) wxFSFile* { $result = wxPyMake_wxObject($1); }
303 %typemap(out) wxFileSystem* { $result = wxPyMake_wxObject($1); }
304 %typemap(out) wxGridTableBase* { $result = wxPyMake_wxObject($1); }
305 %typemap(out) wxImageList* { $result = wxPyMake_wxObject($1); }
306 %typemap(out) wxListItem* { $result = wxPyMake_wxObject($1); }
307 %typemap(out) wxMenuItem* { $result = wxPyMake_wxObject($1); }
308 %typemap(out) wxMouseEvent* { $result = wxPyMake_wxObject($1); }
309 %typemap(out) wxObject* { $result = wxPyMake_wxObject($1); }
310 %typemap(out) wxPyPrintout* { $result = wxPyMake_wxObject($1); }
311 %typemap(out) wxToolBarToolBase* { $result = wxPyMake_wxObject($1); }
312 %typemap(out) wxToolTip* { $result = wxPyMake_wxObject($1); }
315 %typemap(out) wxBitmapButton* { $result = wxPyMake_wxObject($1); }
316 %typemap(out) wxButton* { $result = wxPyMake_wxObject($1); }
317 %typemap(out) wxControl* { $result = wxPyMake_wxObject($1); }
318 %typemap(out) wxFrame* { $result = wxPyMake_wxObject($1); }
319 %typemap(out) wxGrid* { $result = wxPyMake_wxObject($1); }
320 %typemap(out) wxListCtrl* { $result = wxPyMake_wxObject($1); }
321 %typemap(out) wxMDIChildFrame* { $result = wxPyMake_wxObject($1); }
322 %typemap(out) wxMDIClientWindow* { $result = wxPyMake_wxObject($1); }
323 %typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1); }
324 %typemap(out) wxNotebook* { $result = wxPyMake_wxObject($1); }
325 %typemap(out) wxStaticBox* { $result = wxPyMake_wxObject($1); }
326 %typemap(out) wxStatusBar* { $result = wxPyMake_wxObject($1); }
327 %typemap(out) wxTextCtrl* { $result = wxPyMake_wxObject($1); }
328 %typemap(out) wxToolBar* { $result = wxPyMake_wxObject($1); }
329 %typemap(out) wxToolBarBase* { $result = wxPyMake_wxObject($1); }
330 %typemap(out) wxTreeCtrl* { $result = wxPyMake_wxObject($1); }
331 %typemap(out) wxPyTreeCtrl* { $result = wxPyMake_wxObject($1); }
332 %typemap(out) wxWindow* { $result = wxPyMake_wxObject($1); }
333 %typemap(out) wxHtmlWindow* { $result = wxPyMake_wxObject($1); }
334 %typemap(out) wxPyHtmlWindow* { $result = wxPyMake_wxObject($1); }
335 %typemap(out) wxWizardPage* { $result = wxPyMake_wxObject($1); }
337 %typemap(out) wxSizer* { $result = wxPyMake_wxSizer($1); }
340 //%typemap(python, out) wxHtmlCell* { $target = wxPyMake_wxObject($source); }
341 //%typemap(python, out) wxHtmlContainerCell* { $target = wxPyMake_wxObject($source); }
342 //%typemap(python, out) wxHtmlParser* { $target = wxPyMake_wxObject($source); }
343 //%typemap(python, out) wxHtmlWinParser* { $target = wxPyMake_wxObject($source); }
345 //---------------------------------------------------------------------------
346 //---------------------------------------------------------------------------