]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/src/my_typemaps.i
Some minor updates, fixes, etc.
[wxWidgets.git] / utils / 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
RD
14//---------------------------------------------------------------------------
15// Tell SWIG to wrap all the wrappers with Python's thread macros
16
17%except(python) {
18 wxPy_BEGIN_ALLOW_THREADS;
19 $function
20 wxPy_END_ALLOW_THREADS;
21}
22
7bf85405 23//----------------------------------------------------------------------
eec92d76 24// LCOUNT and choices go together. They allow a single Python list to be
2f90df85 25// converted to an integer count and an array count items long.
7bf85405
RD
26
27%typemap(python,build) int LCOUNT {
eec92d76
RD
28 if (_in_choices) {
29 $target = PyList_Size(_in_choices);
cf694132
RD
30 }
31 else {
32 $target = 0;
33 }
7bf85405
RD
34}
35
36
37
eec92d76 38%typemap(python,in) byte* choices {
b639c3c5
RD
39 $target = byte_LIST_helper($source);
40 if ($target == NULL) {
41 return NULL;
42 }
43}
eec92d76 44%typemap(python,freearg) byte* choices {
b639c3c5
RD
45 delete [] $source;
46}
47
48
eec92d76 49%typemap(python,in) int* choices {
7bf85405
RD
50 $target = int_LIST_helper($source);
51 if ($target == NULL) {
52 return NULL;
53 }
54}
eec92d76 55%typemap(python,freearg) int* choices {
7bf85405
RD
56 delete [] $source;
57}
58
59
eec92d76 60%typemap(python,in) long* choices {
7bf85405
RD
61 $target = long_LIST_helper($source);
62 if ($target == NULL) {
63 return NULL;
64 }
65}
eec92d76 66%typemap(python,freearg) long* choices {
7bf85405
RD
67 delete [] $source;
68}
69
70
eec92d76 71%typemap(python,in) unsigned long* choices {
7bf85405
RD
72 $target = (unsigned long*)long_LIST_helper($source);
73 if ($target == NULL) {
74 return NULL;
75 }
76}
eec92d76 77%typemap(python,freearg) unsigned long* choices {
7bf85405
RD
78 delete [] $source;
79}
80
81
5bff6bb8 82#ifdef __WXMSW__
eec92d76
RD
83%typemap(python,in) wxDash* choices = unsigned long* choices;
84%typemap(python,freearg) wxDash* choices = unsigned long* choices;
5bff6bb8 85#else
eec92d76
RD
86%typemap(python,in) wxDash* choices = byte* choices;
87%typemap(python,freearg) wxDash* choices = byte* choices;
5bff6bb8 88#endif
7bf85405
RD
89
90
eec92d76 91%typemap(python,in) char** choices {
7bf85405
RD
92 $target = string_LIST_helper($source);
93 if ($target == NULL) {
94 return NULL;
95 }
96}
eec92d76 97%typemap(python,freearg) char** choices {
7bf85405
RD
98 delete [] $source;
99}
100
101
eec92d76
RD
102%typemap(python,in) wxBitmap** choices {
103 $target = wxBitmap_LIST_helper($source);
7bf85405
RD
104 if ($target == NULL) {
105 return NULL;
106 }
107}
eec92d76 108%typemap(python,freearg) wxBitmap** choices {
7bf85405
RD
109 delete [] $source;
110}
111
eec92d76
RD
112%typemap(python,in) wxString* choices {
113 $target = wxString_LIST_helper($source);
7bf85405
RD
114 if ($target == NULL) {
115 return NULL;
116 }
117}
eec92d76 118%typemap(python,freearg) wxString* choices {
7bf85405
RD
119 delete [] $source;
120}
121
eec92d76
RD
122%typemap(python,in) wxAcceleratorEntry* choices {
123 $target = wxAcceleratorEntry_LIST_helper($source);
7bf85405
RD
124 if ($target == NULL) {
125 return NULL;
126 }
127}
eec92d76 128%typemap(python,freearg) wxAcceleratorEntry* choices {
7bf85405
RD
129 delete [] $source;
130}
131
eec92d76
RD
132
133
134
135
136%typemap(python,build) int PCOUNT {
137 if (_in_points) {
138 $target = PyList_Size(_in_points);
139 }
140 else {
141 $target = 0;
142 }
143}
144
145%typemap(python,in) wxPoint* points {
146 $target = wxPoint_LIST_helper($source);
7bf85405
RD
147 if ($target == NULL) {
148 return NULL;
149 }
150}
eec92d76 151%typemap(python,freearg) wxPoint* points {
7bf85405
RD
152 delete [] $source;
153}
154
155
eec92d76 156
7bf85405
RD
157//---------------------------------------------------------------------------
158
159%{
160static char* wxStringErrorMsg = "string type is required for parameter";
161%}
162
163%typemap(python, in) wxString& {
164 if (!PyString_Check($source)) {
165 PyErr_SetString(PyExc_TypeError, wxStringErrorMsg);
166 return NULL;
167 }
cf694132 168 $target = new wxString(PyString_AsString($source), PyString_Size($source));
7bf85405
RD
169}
170%typemap(python, freearg) wxString& {
171 if ($target)
172 delete $source;
173}
174
175
176
177%typemap(python, out) wxString {
eec92d76 178 $target = PyString_FromStringAndSize($source->c_str(), $source->Len());
7bf85405
RD
179}
180%typemap(python, ret) wxString {
181 delete $source;
182}
183
184
185%typemap(python, out) wxString* {
eec92d76 186 $target = PyString_FromStringAndSize($source->c_str(), $source->Len());
7bf85405
RD
187}
188
189
2f90df85
RD
190
191
192
7bf85405 193//---------------------------------------------------------------------------
2f90df85
RD
194// Typemaps to convert Python sequence objects (2-tuples, etc.) to
195// wxSize, wxPoint, wxRealPoint, and wxRect.
196
197%typemap(python,in) wxSize& (wxSize temp) {
198 $target = &temp;
199 if (! wxSize_helper($source, &$target))
200 return NULL;
201}
202
203%typemap(python,in) wxPoint& (wxPoint temp) {
204 $target = &temp;
205 if (! wxPoint_helper($source, &$target))
206 return NULL;
207}
208
209%typemap(python,in) wxRealPoint& (wxRealPoint temp) {
210 $target = &temp;
211 if (! wxRealPoint_helper($source, &$target))
212 return NULL;
213}
7bf85405 214
2f90df85
RD
215%typemap(python,in) wxRect& (wxRect temp) {
216 $target = &temp;
217 if (! wxRect_helper($source, &$target))
218 return NULL;
219}
7bf85405
RD
220
221
2f90df85 222//---------------------------------------------------------------------------
7bf85405
RD
223// Map T_OUTPUTs for floats to return ints.
224
225
226%typemap(python,ignore) float *T_OUTPUT_TOINT(float temp),
227 double *T_OUTPUT_TOINT(double temp)
228{
229 $target = &temp;
230}
231
232
233%typemap(python,argout) float *T_OUTPUT_TOINT,
234 double *T_OUTPUT_TOINT
235{
236 PyObject *o;
237 o = PyInt_FromLong((long) (*$source));
238 $target = t_output_helper($target, o);
239}
240
241//---------------------------------------------------------------------------
2f90df85 242//---------------------------------------------------------------------------
7bf85405 243