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