]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_core_api.i
get (temporarily) rid of GTK+ debugging messages about negative width and size as...
[wxWidgets.git] / wxPython / src / _core_api.i
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 static
24 swig_type_info* wxPyFindSwigType(const wxChar* className);
25
26 %}
27
28
29 #if SWIG_VERSION < 0x010328
30 %{
31 // Make a SWIGified pointer object suitable for a .this attribute
32 PyObject* wxPyMakeSwigPtr(void* ptr, const wxChar* className) {
33
34 PyObject* robj = NULL;
35
36 swig_type_info* swigType = wxPyFindSwigType(className);
37 wxCHECK_MSG(swigType != NULL, NULL, wxT("Unknown type in wxPyMakeSwigPtr"));
38
39 #ifdef SWIG_COBJECT_TYPES
40 robj = PySwigObject_FromVoidPtrAndDesc((void *) ptr, (char *)swigType->name);
41 #else
42 {
43 char result[1024];
44 robj = SWIG_PackVoidPtr(result, ptr, swigType->name, sizeof(result)) ?
45 PyString_FromString(result) : 0;
46 }
47 #endif
48 return robj;
49 }
50 %}
51
52 #else // SWIG_VERSION >= 1.3.28
53 %{
54 // Make a SWIGified pointer object suitable for a .this attribute
55 PyObject* wxPyMakeSwigPtr(void* ptr, const wxChar* className) {
56
57 PyObject* robj = NULL;
58
59 swig_type_info* swigType = wxPyFindSwigType(className);
60 wxCHECK_MSG(swigType != NULL, NULL, wxT("Unknown type in wxPyMakeSwigPtr"));
61
62 robj = PySwigObject_New(ptr, swigType, 0);
63 return robj;
64 }
65 %}
66 #endif
67
68
69
70
71 %{
72 #include <wx/hashmap.h>
73 WX_DECLARE_STRING_HASH_MAP( swig_type_info*, wxPyTypeInfoHashMap );
74
75
76 // Maintains a hashmap of className to swig_type_info pointers. Given the
77 // name of a class either looks up the type info in the cache, or scans the
78 // SWIG tables for it.
79 extern PyObject* wxPyPtrTypeMap;
80 static
81 swig_type_info* wxPyFindSwigType(const wxChar* className) {
82
83 static wxPyTypeInfoHashMap* typeInfoCache = NULL;
84
85 if (typeInfoCache == NULL)
86 typeInfoCache = new wxPyTypeInfoHashMap;
87
88 wxString name(className);
89 swig_type_info* swigType = (*typeInfoCache)[name];
90
91 if (! swigType) {
92 // it wasn't in the cache, so look it up from SWIG
93 name.Append(wxT(" *"));
94 swigType = SWIG_TypeQuery(name.mb_str());
95
96 // if it still wasn't found, try looking for a mapped name
97 if (!swigType) {
98 PyObject* item;
99 name = className;
100
101 if ((item = PyDict_GetItemString(wxPyPtrTypeMap,
102 (char*)(const char*)name.mbc_str())) != NULL) {
103 name = wxString(PyString_AsString(item), *wxConvCurrent);
104 name.Append(wxT(" *"));
105 swigType = SWIG_TypeQuery(name.mb_str());
106 }
107 }
108 if (swigType) {
109 // and add it to the map if found
110 (*typeInfoCache)[className] = swigType;
111 }
112 }
113 return swigType;
114 }
115
116
117 // Check if a class name is a type known to SWIG
118 bool wxPyCheckSwigType(const wxChar* className) {
119
120 swig_type_info* swigType = wxPyFindSwigType(className);
121 return swigType != NULL;
122 }
123
124
125 // Given a pointer to a C++ object and a class name, construct a Python proxy
126 // object for it.
127 PyObject* wxPyConstructObject(void* ptr,
128 const wxChar* className,
129 int setThisOwn) {
130
131 swig_type_info* swigType = wxPyFindSwigType(className);
132 wxCHECK_MSG(swigType != NULL, NULL, wxT("Unknown type in wxPyConstructObject"));
133
134 return SWIG_Python_NewPointerObj(ptr, swigType, setThisOwn);
135 }
136
137
138 // Extract a pointer to the wrapped C++ object from a Python proxy object.
139 // Ensures that the proxy object is of the specified (or derived) type. If
140 // not able to perform the conversion then a Python exception is set and the
141 // error should be handled properly in the caller. Returns True on success.
142 bool wxPyConvertSwigPtr(PyObject* obj, void **ptr,
143 const wxChar* className) {
144
145 swig_type_info* swigType = wxPyFindSwigType(className);
146 wxCHECK_MSG(swigType != NULL, false, wxT("Unknown type in wxPyConvertSwigPtr"));
147
148 return SWIG_Python_ConvertPtr(obj, ptr, swigType, SWIG_POINTER_EXCEPTION) != -1;
149 }
150
151
152
153
154 // Python's PyInstance_Check does not return True for instances of new-style
155 // classes. This should get close enough for both new and old classes but I
156 // should re-evaluate the need for doing instance checks...
157 bool wxPyInstance_Check(PyObject* obj) {
158 return PyObject_HasAttrString(obj, "__class__") != 0;
159 }
160
161
162
163 // This one checks if the object is an instance of a SWIG proxy class (it has
164 // a .this attribute, and the .this attribute is a PySwigObject.)
165 bool wxPySwigInstance_Check(PyObject* obj) {
166 static PyObject* this_str = NULL;
167 if (this_str == NULL)
168 this_str = PyString_FromString("this");
169
170 PyObject* this_attr = PyObject_GetAttr(obj, this_str);
171 if (this_attr) {
172 bool retval = (PySwigObject_Check(this_attr) != 0);
173 Py_DECREF(this_attr);
174 return retval;
175 }
176
177 PyErr_Clear();
178 return false;
179 }
180
181
182
183 // Export a C API in a struct. Other modules will be able to load this from
184 // the wx._core_ module and will then have safe access to these functions,
185 // even if they are located in another shared library.
186 static wxPyCoreAPI API = {
187
188 wxPyCheckSwigType,
189 wxPyConstructObject,
190 wxPyConvertSwigPtr,
191 wxPyMakeSwigPtr,
192
193 wxPyBeginAllowThreads,
194 wxPyEndAllowThreads,
195 wxPyBeginBlockThreads,
196 wxPyEndBlockThreads,
197
198 wxPy_ConvertList,
199
200 wxString_in_helper,
201 Py2wxString,
202 wx2PyString,
203
204 byte_LIST_helper,
205 int_LIST_helper,
206 long_LIST_helper,
207 string_LIST_helper,
208 wxPoint_LIST_helper,
209 wxBitmap_LIST_helper,
210 wxString_LIST_helper,
211 wxAcceleratorEntry_LIST_helper,
212
213 wxSize_helper,
214 wxPoint_helper,
215 wxRealPoint_helper,
216 wxRect_helper,
217 wxColour_helper,
218 wxPoint2D_helper,
219
220 wxPySimple_typecheck,
221 wxColour_typecheck,
222
223 wxPyCBH_setCallbackInfo,
224 wxPyCBH_findCallback,
225 wxPyCBH_callCallback,
226 wxPyCBH_callCallbackObj,
227 wxPyCBH_delete,
228
229 wxPyMake_wxObject,
230 wxPyMake_wxSizer,
231 wxPyPtrTypeMap_Add,
232 wxPy2int_seq_helper,
233 wxPy4int_seq_helper,
234 wxArrayString2PyList_helper,
235 wxArrayInt2PyList_helper,
236
237 wxPyClientData_dtor,
238 wxPyUserData_dtor,
239 wxPyOORClientData_dtor,
240
241 wxPyCBInputStream_create,
242 wxPyCBInputStream_copy,
243
244 wxPyInstance_Check,
245 wxPySwigInstance_Check,
246
247 wxPyCheckForApp
248
249 };
250
251 #endif
252 %}
253
254
255
256
257 %init %{
258 #ifndef wxPyUSE_EXPORT
259 // Make our API structure a CObject so other modules can import it
260 // from this module.
261 PyObject* cobj = PyCObject_FromVoidPtr(&API, NULL);
262 PyDict_SetItemString(d,"_wxPyCoreAPI", cobj);
263 Py_XDECREF(cobj);
264 #endif
265 %}
266
267 //---------------------------------------------------------------------------