]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/my_typemaps.i
Implemented wxGetClientDisplayRect which returns the dimensions of the
[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
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
de9d9ed2
RD
48// wxDash is a signed char
49%typemap(python,in) wxDash* choices {
50 $target = (wxDash*)byte_LIST_helper($source);
51 if ($target == NULL) {
52 return NULL;
53 }
54}
55%typemap(python,freearg) wxDash* choices {
56 delete [] $source;
57}
58
b639c3c5 59
eec92d76 60%typemap(python,in) int* choices {
7bf85405
RD
61 $target = int_LIST_helper($source);
62 if ($target == NULL) {
63 return NULL;
64 }
65}
eec92d76 66%typemap(python,freearg) int* choices {
7bf85405
RD
67 delete [] $source;
68}
69
70
eec92d76 71%typemap(python,in) long* choices {
7bf85405
RD
72 $target = long_LIST_helper($source);
73 if ($target == NULL) {
74 return NULL;
75 }
76}
eec92d76 77%typemap(python,freearg) long* choices {
7bf85405
RD
78 delete [] $source;
79}
80
81
eec92d76 82%typemap(python,in) unsigned long* choices {
7bf85405
RD
83 $target = (unsigned long*)long_LIST_helper($source);
84 if ($target == NULL) {
85 return NULL;
86 }
87}
eec92d76 88%typemap(python,freearg) unsigned long* choices {
7bf85405
RD
89 delete [] $source;
90}
91
92
eec92d76 93%typemap(python,in) char** choices {
7bf85405
RD
94 $target = string_LIST_helper($source);
95 if ($target == NULL) {
96 return NULL;
97 }
98}
eec92d76 99%typemap(python,freearg) char** choices {
7bf85405
RD
100 delete [] $source;
101}
102
103
eec92d76
RD
104%typemap(python,in) wxBitmap** choices {
105 $target = wxBitmap_LIST_helper($source);
7bf85405
RD
106 if ($target == NULL) {
107 return NULL;
108 }
109}
eec92d76 110%typemap(python,freearg) wxBitmap** choices {
7bf85405
RD
111 delete [] $source;
112}
113
eec92d76
RD
114%typemap(python,in) wxString* choices {
115 $target = wxString_LIST_helper($source);
7bf85405
RD
116 if ($target == NULL) {
117 return NULL;
118 }
119}
eec92d76 120%typemap(python,freearg) wxString* choices {
7bf85405
RD
121 delete [] $source;
122}
123
eec92d76
RD
124%typemap(python,in) wxAcceleratorEntry* choices {
125 $target = wxAcceleratorEntry_LIST_helper($source);
7bf85405
RD
126 if ($target == NULL) {
127 return NULL;
128 }
129}
eec92d76 130%typemap(python,freearg) wxAcceleratorEntry* choices {
7bf85405
RD
131 delete [] $source;
132}
133
eec92d76 134%typemap(python,build) int PCOUNT {
e0672e2f 135 $target = NPOINTS;
eec92d76
RD
136}
137
e0672e2f
RD
138%typemap(python,in) wxPoint* points (int NPOINTS) {
139 $target = wxPoint_LIST_helper($source, &NPOINTS);
140 if ($target == NULL) {
141 return NULL;
142 }
7bf85405 143}
eec92d76 144%typemap(python,freearg) wxPoint* points {
7bf85405
RD
145 delete [] $source;
146}
147
148
eec92d76 149
e0672e2f 150
7bf85405
RD
151//---------------------------------------------------------------------------
152
153%{
154static char* wxStringErrorMsg = "string type is required for parameter";
155%}
156
185d7c3e
RD
157// TODO: Which works best???
158
159// Implementation #1
160// %typemap(python, in) wxString& (PyObject* temp, int tmpDoDecRef) {
161// temp = $source;
162// tmpDoDecRef = 0;
163// #if PYTHON_API_VERSION >= 1009
164// if (PyUnicode_Check(temp) {
165// temp = PyUnicode_AsUTF8String(temp);
166// if (! temp) {
167// PyErr_SetString(PyExc_TypeError, "Unicode encoding to UTF8 failed.");
168// return NULL;
169// }
170// tmpDoDecRef = 1;
171// #endif
172// if (!PyString_Check(temp)) {
173// PyErr_SetString(PyExc_TypeError, wxStringErrorMsg);
174// return NULL;
175// }
176// $target = new wxString(PyString_AsString(temp), PyString_Size(temp));
177// #if PYTHON_API_VERESION >= 1009
178// if (tmpDoDecRef) Py_DECREF(temp);
179// #endif
180// }
181
182
183// Implementation #2
7bf85405 184%typemap(python, in) wxString& {
185d7c3e
RD
185#if PYTHON_API_VERSION >= 1009
186 char* tmpPtr; int tmpSize;
187 if (!PyString_Check($source) && !PyUnicode_Check($source)) {
188 PyErr_SetString(PyExc_TypeError, "String or Unicode type required");
189 return NULL;
190 }
191 if (PyString_AsStringAndSize($source, &tmpPtr, &tmpSize) == -1)
192 return NULL;
193 $target = new wxString(tmpPtr, tmpSize);
194#else
7bf85405
RD
195 if (!PyString_Check($source)) {
196 PyErr_SetString(PyExc_TypeError, wxStringErrorMsg);
197 return NULL;
198 }
185d7c3e
RD
199 $target = new wxString(PyString_AS_STRING($source), PyString_GET_SIZE($source));
200#endif
7bf85405 201}
185d7c3e
RD
202
203
204
205
7bf85405
RD
206%typemap(python, freearg) wxString& {
207 if ($target)
208 delete $source;
209}
210
211
212
213%typemap(python, out) wxString {
eec92d76 214 $target = PyString_FromStringAndSize($source->c_str(), $source->Len());
7bf85405
RD
215}
216%typemap(python, ret) wxString {
217 delete $source;
218}
219
220
221%typemap(python, out) wxString* {
eec92d76 222 $target = PyString_FromStringAndSize($source->c_str(), $source->Len());
7bf85405
RD
223}
224
225
2f90df85
RD
226
227
228
7bf85405 229//---------------------------------------------------------------------------
2f90df85
RD
230// Typemaps to convert Python sequence objects (2-tuples, etc.) to
231// wxSize, wxPoint, wxRealPoint, and wxRect.
232
233%typemap(python,in) wxSize& (wxSize temp) {
234 $target = &temp;
235 if (! wxSize_helper($source, &$target))
236 return NULL;
237}
238
239%typemap(python,in) wxPoint& (wxPoint temp) {
240 $target = &temp;
241 if (! wxPoint_helper($source, &$target))
242 return NULL;
243}
244
245%typemap(python,in) wxRealPoint& (wxRealPoint temp) {
246 $target = &temp;
247 if (! wxRealPoint_helper($source, &$target))
248 return NULL;
249}
7bf85405 250
2f90df85
RD
251%typemap(python,in) wxRect& (wxRect temp) {
252 $target = &temp;
253 if (! wxRect_helper($source, &$target))
254 return NULL;
255}
7bf85405 256
f6bcfd97
BP
257//---------------------------------------------------------------------------
258// Typemap to convert strings to wxColour. Two string formats are accepted,
de20db99 259// either a colour name, or a hex colour spec like "#RRGGBB"
f6bcfd97
BP
260
261%typemap(python,in) wxColour& (wxColour temp) {
262 $target = &temp;
263 if (! wxColour_helper($source, &$target))
264 return NULL;
265}
266
7bf85405 267
2f90df85 268//---------------------------------------------------------------------------
7bf85405
RD
269// Map T_OUTPUTs for floats to return ints.
270
271
272%typemap(python,ignore) float *T_OUTPUT_TOINT(float temp),
273 double *T_OUTPUT_TOINT(double temp)
274{
275 $target = &temp;
276}
277
278
279%typemap(python,argout) float *T_OUTPUT_TOINT,
280 double *T_OUTPUT_TOINT
281{
282 PyObject *o;
283 o = PyInt_FromLong((long) (*$source));
284 $target = t_output_helper($target, o);
285}
286
287//---------------------------------------------------------------------------
2f90df85 288//---------------------------------------------------------------------------
7bf85405 289