]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _core_api.i | |
3 | // Purpose: | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 13-Sept-2003 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2003 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
16 | //--------------------------------------------------------------------------- | |
17 | %{ | |
18 | #ifndef wxPyUSE_EXPORT | |
19 | // Helper functions for dealing with SWIG objects and such. These are | |
20 | // located here so they know about the SWIG types and functions declared | |
21 | // in the wrapper code. | |
22 | ||
23 | #include <wx/hashmap.h> | |
24 | WX_DECLARE_STRING_HASH_MAP( swig_type_info*, wxPyTypeInfoHashMap ); | |
25 | ||
26 | ||
27 | // Maintains a hashmap of className to swig_type_info pointers. Given the | |
28 | // name of a class either looks up the type info in the cache, or scans the | |
29 | // SWIG tables for it. | |
30 | extern PyObject* wxPyPtrTypeMap; | |
31 | static | |
32 | swig_type_info* wxPyFindSwigType(const wxChar* className) { | |
33 | ||
34 | static wxPyTypeInfoHashMap* typeInfoCache = NULL; | |
35 | ||
36 | if (typeInfoCache == NULL) | |
37 | typeInfoCache = new wxPyTypeInfoHashMap; | |
38 | ||
39 | wxString name(className); | |
40 | swig_type_info* swigType = (*typeInfoCache)[name]; | |
41 | ||
42 | if (! swigType) { | |
43 | // it wasn't in the cache, so look it up from SWIG | |
44 | name.Append(wxT(" *")); | |
45 | swigType = SWIG_Python_TypeQuery(name.mb_str()); | |
46 | ||
47 | // if it still wasn't found, try looking for a mapped name | |
48 | if (!swigType) { | |
49 | PyObject* item; | |
50 | name = className; | |
51 | ||
52 | if ((item = PyDict_GetItemString(wxPyPtrTypeMap, | |
53 | (char*)(const char*)name.mbc_str())) != NULL) { | |
54 | name = wxString(PyString_AsString(item), *wxConvCurrent); | |
55 | name.Append(wxT(" *")); | |
56 | swigType = SWIG_Python_TypeQuery(name.mb_str()); | |
57 | } | |
58 | } | |
59 | if (swigType) { | |
60 | // and add it to the map if found | |
61 | (*typeInfoCache)[className] = swigType; | |
62 | } | |
63 | } | |
64 | return swigType; | |
65 | } | |
66 | ||
67 | ||
68 | // Check if a class name is a type known to SWIG | |
69 | bool wxPyCheckSwigType(const wxChar* className) { | |
70 | ||
71 | swig_type_info* swigType = wxPyFindSwigType(className); | |
72 | return swigType != NULL; | |
73 | } | |
74 | ||
75 | ||
76 | // Given a pointer to a C++ object and a class name, construct a Python proxy | |
77 | // object for it. | |
78 | PyObject* wxPyConstructObject(void* ptr, | |
79 | const wxChar* className, | |
80 | int setThisOwn) { | |
81 | ||
82 | swig_type_info* swigType = wxPyFindSwigType(className); | |
83 | wxCHECK_MSG(swigType != NULL, NULL, wxT("Unknown type in wxPyConstructObject")); | |
84 | ||
85 | return SWIG_Python_NewPointerObj(ptr, swigType, setThisOwn); | |
86 | } | |
87 | ||
88 | ||
89 | // Extract a pointer to the wrapped C++ object from a Python proxy object. | |
90 | // Ensures that the proxy object is of the specified (or derived) type. If | |
91 | // not able to perform the conversion then a Python exception is set and the | |
dd9f7fea | 92 | // error should be handled properly in the caller. Returns True on success. |
d14a1e28 RD |
93 | bool wxPyConvertSwigPtr(PyObject* obj, void **ptr, |
94 | const wxChar* className) { | |
95 | ||
96 | swig_type_info* swigType = wxPyFindSwigType(className); | |
dd9f7fea | 97 | wxCHECK_MSG(swigType != NULL, False, wxT("Unknown type in wxPyConvertSwigPtr")); |
d14a1e28 RD |
98 | |
99 | return SWIG_Python_ConvertPtr(obj, ptr, swigType, SWIG_POINTER_EXCEPTION) != -1; | |
100 | } | |
101 | ||
102 | ||
103 | // Make a SWIGified pointer object suitable for a .this attribute | |
104 | PyObject* wxPyMakeSwigPtr(void* ptr, const wxChar* className) { | |
105 | ||
106 | PyObject* robj = NULL; | |
107 | ||
108 | swig_type_info* swigType = wxPyFindSwigType(className); | |
109 | wxCHECK_MSG(swigType != NULL, NULL, wxT("Unknown type in wxPyConvertSwigPtr")); | |
110 | ||
111 | #ifdef SWIG_COBJECT_TYPES | |
112 | robj = PyCObject_FromVoidPtrAndDesc((void *) ptr, (char *) swigType->name, NULL); | |
113 | #else | |
114 | { | |
115 | char result[1024]; | |
116 | char *r = result; | |
117 | *(r++) = '_'; | |
118 | r = SWIG_Python_PackData(r, &ptr, sizeof(void *)); | |
119 | strcpy(r, swigType->name); | |
120 | robj = PyString_FromString(result); | |
121 | } | |
122 | #endif | |
123 | ||
124 | return robj; | |
125 | } | |
126 | ||
127 | ||
128 | ||
129 | ||
130 | // Export a C API in a struct. Other modules will be able to load this from | |
131 | // the wx.core module and will then have safe access to these functions, even if | |
132 | // they are located in another shared library. | |
133 | static wxPyCoreAPI API = { | |
134 | ||
135 | (p_SWIG_Python_TypeRegister_t)SWIG_Python_TypeRegister, | |
136 | (p_SWIG_Python_TypeCheck_t)SWIG_Python_TypeCheck, | |
137 | (p_SWIG_Python_TypeCast_t)SWIG_Python_TypeCast, | |
138 | (p_SWIG_Python_TypeDynamicCast_t)SWIG_Python_TypeDynamicCast, | |
139 | (p_SWIG_Python_TypeName_t)SWIG_Python_TypeName, | |
140 | (p_SWIG_Python_TypeQuery_t)SWIG_Python_TypeQuery, | |
141 | (p_SWIG_Python_TypeClientData_t)SWIG_Python_TypeClientData, | |
142 | (p_SWIG_Python_newvarlink_t)SWIG_Python_newvarlink, | |
143 | (p_SWIG_Python_addvarlink_t)SWIG_Python_addvarlink, | |
144 | (p_SWIG_Python_ConvertPtr_t)SWIG_Python_ConvertPtr, | |
145 | (p_SWIG_Python_ConvertPacked_t)SWIG_Python_ConvertPacked, | |
146 | (p_SWIG_Python_PackData_t)SWIG_Python_PackData, | |
147 | (p_SWIG_Python_UnpackData_t)SWIG_Python_UnpackData, | |
148 | (p_SWIG_Python_NewPointerObj_t)SWIG_Python_NewPointerObj, | |
149 | (p_SWIG_Python_NewPackedObj_t)SWIG_Python_NewPackedObj, | |
150 | (p_SWIG_Python_InstallConstants_t)SWIG_Python_InstallConstants, | |
151 | (p_SWIG_Python_MustGetPtr_t)SWIG_Python_MustGetPtr, | |
152 | ||
d7f82584 RD |
153 | (p_SWIG_PyObj_AsCharPtr_t)SWIG_PyObj_AsCharPtr, |
154 | (p_SWIG_PyObj_FromCharPtr_t)SWIG_PyObj_FromCharPtr, | |
155 | (p_SWIG_PyObj_AsUnsignedLong_t)SWIG_PyObj_AsUnsignedLong, | |
156 | (p_SWIG_PyObj_AsLongInRange_t)SWIG_PyObj_AsLongInRange, | |
157 | (p_SWIG_PyObj_AsUnsignedLongInRange_t)SWIG_PyObj_AsUnsignedLongInRange, | |
158 | (p_SWIG_PyObj_AsNewCharPtr_t)SWIG_PyObj_AsNewCharPtr, | |
159 | (p_SWIG_PyObj_AsCharPtrAndSize_t)SWIG_PyObj_AsCharPtrAndSize, | |
160 | (p_SWIG_PyObj_AsCharArray_t)SWIG_PyObj_AsCharArray, | |
161 | (p_SWIG_PyObj_FromCharArray_t)SWIG_PyObj_FromCharArray, | |
162 | (p_SWIG_PyObj_AsFloatConv_t)SWIG_PyObj_AsFloatConv, | |
163 | ||
d14a1e28 RD |
164 | wxPyCheckSwigType, |
165 | wxPyConstructObject, | |
166 | wxPyConvertSwigPtr, | |
167 | wxPyMakeSwigPtr, | |
168 | ||
169 | wxPyBeginAllowThreads, | |
170 | wxPyEndAllowThreads, | |
171 | wxPyBeginBlockThreads, | |
172 | wxPyEndBlockThreads, | |
173 | ||
174 | wxPy_ConvertList, | |
175 | ||
176 | wxString_in_helper, | |
177 | Py2wxString, | |
178 | wx2PyString, | |
179 | ||
180 | byte_LIST_helper, | |
181 | int_LIST_helper, | |
182 | long_LIST_helper, | |
183 | string_LIST_helper, | |
184 | wxPoint_LIST_helper, | |
185 | wxBitmap_LIST_helper, | |
186 | wxString_LIST_helper, | |
187 | wxAcceleratorEntry_LIST_helper, | |
188 | ||
189 | wxSize_helper, | |
190 | wxPoint_helper, | |
191 | wxRealPoint_helper, | |
192 | wxRect_helper, | |
193 | wxColour_helper, | |
194 | wxPoint2D_helper, | |
195 | ||
196 | wxPySimple_typecheck, | |
197 | wxColour_typecheck, | |
198 | ||
199 | wxPyCBH_setCallbackInfo, | |
200 | wxPyCBH_findCallback, | |
201 | wxPyCBH_callCallback, | |
202 | wxPyCBH_callCallbackObj, | |
203 | wxPyCBH_delete, | |
204 | ||
205 | wxPyMake_wxObject, | |
206 | wxPyMake_wxSizer, | |
207 | wxPyPtrTypeMap_Add, | |
208 | wxPy2int_seq_helper, | |
209 | wxPy4int_seq_helper, | |
210 | wxArrayString2PyList_helper, | |
211 | wxArrayInt2PyList_helper, | |
212 | ||
213 | wxPyClientData_dtor, | |
214 | wxPyUserData_dtor, | |
215 | wxPyOORClientData_dtor, | |
216 | ||
217 | wxPyCBInputStream_create, | |
218 | ||
219 | wxPyInstance_Check, | |
220 | wxPySwigInstance_Check | |
221 | ||
222 | }; | |
223 | ||
224 | #endif | |
225 | %} | |
226 | ||
227 | ||
228 | ||
229 | ||
230 | %init %{ | |
231 | #ifndef wxPyUSE_EXPORT | |
232 | // Make our API structure a CObject so other modules can import it | |
233 | // from this module. | |
234 | PyObject* cobj = PyCObject_FromVoidPtr(&API, NULL); | |
235 | PyDict_SetItemString(d,"_wxPyCoreAPI", cobj); | |
236 | Py_XDECREF(cobj); | |
237 | #endif | |
238 | %} | |
239 | ||
240 | //--------------------------------------------------------------------------- |