+//---------------------------------------------------------------------------
+// Export a C API in a struct. Other modules will be able to load this from
+// the wxc module and will then have safe access to these functions, even if
+// in another shared library.
+
+class wxPyCallbackHelper;
+
+struct wxPyCoreAPI {
+
+ void (*p_SWIG_MakePtr)(char*, void*, char*);
+ char* (*p_SWIG_GetPtr)(char*, void**, char*);
+ char* (*p_SWIG_GetPtrObj)(PyObject*, void**, char*);
+ void (*p_SWIG_RegisterMapping)(char*, char*, void *(*cast)(void *));
+ void (*p_SWIG_addvarlink)(PyObject*, char*, PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p));
+ PyObject* (*p_SWIG_newvarlink)(void);
+
+ void (*p_wxPySaveThread)(bool);
+ bool (*p_wxPyRestoreThread)();
+ PyObject* (*p_wxPyConstructObject)(void *, const char *, int);
+ PyObject* (*p_wxPy_ConvertList)(wxListBase* list, const char* className);
+
+ byte* (*p_byte_LIST_helper)(PyObject* source);
+ int* (*p_int_LIST_helper)(PyObject* source);
+ long* (*p_long_LIST_helper)(PyObject* source);
+ char** (*p_string_LIST_helper)(PyObject* source);
+ wxPoint* (*p_wxPoint_LIST_helper)(PyObject* source, int* npoints);
+ wxBitmap** (*p_wxBitmap_LIST_helper)(PyObject* source);
+ wxString* (*p_wxString_LIST_helper)(PyObject* source);
+ wxAcceleratorEntry* (*p_wxAcceleratorEntry_LIST_helper)(PyObject* source);
+
+ bool (*p_wxSize_helper)(PyObject* source, wxSize** obj);
+ bool (*p_wxPoint_helper)(PyObject* source, wxPoint** obj);
+ bool (*p_wxRealPoint_helper)(PyObject* source, wxRealPoint** obj);
+ bool (*p_wxRect_helper)(PyObject* source, wxRect** obj);
+ bool (*p_wxColour_helper)(PyObject* source, wxColour** obj);
+
+ void (*p_wxPyCBH_setSelf)(wxPyCallbackHelper& cbh, PyObject* self, PyObject* klass, int incref);
+ bool (*p_wxPyCBH_findCallback)(const wxPyCallbackHelper& cbh, const char* name);
+ int (*p_wxPyCBH_callCallback)(const wxPyCallbackHelper& cbh, PyObject* argTuple);
+ PyObject* (*p_wxPyCBH_callCallbackObj)(const wxPyCallbackHelper& cbh, PyObject* argTuple);
+ void (*p_wxPyCBH_delete)(wxPyCallbackHelper* cbh);
+
+};
+
+#ifdef wxPyUSE_EXPORT
+static wxPyCoreAPI* wxPyCoreAPIPtr = NULL; // Each module needs one, but may not use it.
+#endif
+
+//---------------------------------------------------------------------------
+// This class holds an instance of a Python Shadow Class object and assists
+// with looking up and invoking Python callback methods from C++ virtual
+// method redirections. For all classes which have virtuals which should be
+// overridable in wxPython, a new subclass is created that contains a
+// wxPyCallbackHelper.
+//
+
+class wxPyCallbackHelper {
+public:
+ wxPyCallbackHelper(const wxPyCallbackHelper& other);
+
+ wxPyCallbackHelper() {
+ m_class = NULL;
+ m_self = NULL;
+ m_lastFound = NULL;
+ m_incRef = FALSE;
+ }
+
+ ~wxPyCallbackHelper() {
+#ifdef wxPyUSE_EXPORT
+ wxPyCoreAPIPtr->p_wxPyCBH_delete(this);
+#else
+ wxPyCBH_delete(this);
+#endif
+ }
+
+ void setSelf(PyObject* self, PyObject* klass, int incref=TRUE);
+ bool findCallback(const char* name) const;
+ int callCallback(PyObject* argTuple) const;
+ PyObject* callCallbackObj(PyObject* argTuple) const;
+
+private:
+ PyObject* m_self;
+ PyObject* m_class;
+ PyObject* m_lastFound;
+ int m_incRef;
+
+ friend void wxPyCBH_delete(wxPyCallbackHelper* cbh);
+};
+
+
+void wxPyCBH_setSelf(wxPyCallbackHelper& cbh, PyObject* self, PyObject* klass, int incref);
+bool wxPyCBH_findCallback(const wxPyCallbackHelper& cbh, const char* name);
+int wxPyCBH_callCallback(const wxPyCallbackHelper& cbh, PyObject* argTuple);
+PyObject* wxPyCBH_callCallbackObj(const wxPyCallbackHelper& cbh, PyObject* argTuple);
+void wxPyCBH_delete(wxPyCallbackHelper* cbh);
+
+
+
+//----------------------------------------------------------------------
+
+class wxPyUserData : public wxObject {
+public:
+ wxPyUserData(PyObject* obj) {
+ m_obj = obj;
+ Py_INCREF(m_obj);
+ }
+
+ ~wxPyUserData() {
+ bool doSave;
+#ifdef wxPyUSE_EXPORT
+ doSave = wxPyCoreAPIPtr->p_wxPyRestoreThread();
+ Py_DECREF(m_obj);
+ wxPyCoreAPIPtr->p_wxPySaveThread(doSave);
+#else
+ doSave = wxPyRestoreThread();
+ Py_DECREF(m_obj);
+ wxPySaveThread(doSave);
+#endif
+ }
+ PyObject* m_obj;
+};
+
+
+