bool wxRect_helper(PyObject* source, wxRect** obj);
bool wxColour_helper(PyObject* source, wxColour** obj);
+//----------------------------------------------------------------------
+// Other helpful stuff
+
#if PYTHON_API_VERSION < 1009
#define PySequence_Fast_GET_ITEM(o, i) \
(PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i))
PyObject* wxArrayString2PyList_helper(const wxArrayString& arr);
PyObject* wxArrayInt2PyList_helper(const wxArrayInt& arr);
-
-#define RETURN_NONE() { Py_INCREF(Py_None); return Py_None; }
+#define RETURN_NONE() { Py_INCREF(Py_None); return Py_None; }
+#define DECLARE_DEF_STRING(name) static const wxString wxPy##name(wx##name)
+#define DECLARE_DEF_STRING2(name,val) static const wxString wxPy##name(val)
//----------------------------------------------------------------------
};
+
+//----------------------------------------------------------------------
+// Forward decalre a few things used in the exported API
+class wxPyClientData;
+class wxPyUserData;
+class wxPyOORClientData;
+
+void wxPyClientData_dtor(wxPyClientData* self);
+void wxPyUserData_dtor(wxPyUserData* self);
+void wxPyOORClientData_dtor(wxPyOORClientData* self);
+
+
//---------------------------------------------------------------------------
// 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
void (*p_wxPyPtrTypeMap_Add)(const char* commonName, const char* ptrName);
PyObject* (*p_wxArrayString2PyList_helper)(const wxArrayString& arr);
PyObject* (*p_wxArrayInt2PyList_helper)(const wxArrayInt& arr);
+
+ void (*p_wxPyClientData_dtor)(wxPyClientData*);
+ void (*p_wxPyUserData_dtor)(wxPyUserData*);
+ void (*p_wxPyOORClientData_dtor)(wxPyOORClientData*);
+};
+
+#ifdef wxPyUSE_EXPORT
+static wxPyCoreAPI* wxPyCoreAPIPtr = NULL; // Each module needs one, but doesn't have to use it.
+#endif
+
+
+//---------------------------------------------------------------------------
+
+
+class wxPyUserData : public wxObject {
+public:
+ wxPyUserData(PyObject* obj) {
+ m_obj = obj;
+ Py_INCREF(m_obj);
+ }
+
+ ~wxPyUserData() {
+#ifdef wxPyUSE_EXPORT
+ wxPyCoreAPIPtr->p_wxPyUserData_dtor(this);
+#else
+ wxPyUserData_dtor(this);
+#endif
+ }
+ PyObject* m_obj;
};
+
+class wxPyClientData : public wxClientData {
+public:
+ wxPyClientData(PyObject* obj) {
+ m_obj = obj;
+ Py_INCREF(m_obj);
+ }
+
+ ~wxPyClientData() {
+#ifdef wxPyUSE_EXPORT
+ wxPyCoreAPIPtr->p_wxPyClientData_dtor(this);
+#else
+ wxPyClientData_dtor(this);
+#endif
+ }
+ PyObject* m_obj;
+};
+
+
+class wxPyOORClientData : public wxPyClientData {
+public:
+ wxPyOORClientData(PyObject* obj)
+ : wxPyClientData(obj) {}
+
+ ~wxPyOORClientData() {
#ifdef wxPyUSE_EXPORT
-static wxPyCoreAPI* wxPyCoreAPIPtr = NULL; // Each module needs one, but may not use it.
+ wxPyCoreAPIPtr->p_wxPyOORClientData_dtor(this);
+#else
+ wxPyOORClientData_dtor(this);
#endif
+ }
+};
//---------------------------------------------------------------------------
// This class holds an instance of a Python Shadow Class object and assists
-//----------------------------------------------------------------------
-
-class wxPyUserData : public wxObject {
-public:
- wxPyUserData(PyObject* obj) {
- m_obj = obj;
- Py_INCREF(m_obj);
- }
-
- ~wxPyUserData() {
-#ifdef wxPyUSE_EXPORT
- wxPyCoreAPIPtr->p_wxPyBeginBlockThreads();
- Py_DECREF(m_obj);
- wxPyCoreAPIPtr->p_wxPyEndBlockThreads();
-#else
- wxPyBeginBlockThreads();
- Py_DECREF(m_obj);
- wxPyEndBlockThreads();
-#endif
- }
- PyObject* m_obj;
-};
-
-
-
-class wxPyClientData : public wxClientData {
-public:
- wxPyClientData(PyObject* obj) {
- m_obj = obj;
- Py_INCREF(m_obj);
- }
-
- ~wxPyClientData() {
-#ifdef wxPyUSE_EXPORT
- wxPyCoreAPIPtr->p_wxPyBeginBlockThreads();
- Py_DECREF(m_obj);
- wxPyCoreAPIPtr->p_wxPyEndBlockThreads();
-#else
- wxPyBeginBlockThreads();
- Py_DECREF(m_obj);
- wxPyEndBlockThreads();
-#endif
- }
- PyObject* m_obj;
-};
-
-
//---------------------------------------------------------------------------
// These macros are used to implement the virtual methods that should
#define IMP_PYCALLBACK_wxSize__pure(CLASS, PCLASS, CBNAME) \
wxSize CLASS::CBNAME() { \
+ const char* errmsg = #CBNAME " should return a 2-tuple of integers or a wxSize object."; \
wxSize rval(0,0); \
- wxPyBeginBlockThreads(); \
+ wxPyBeginBlockThreads(); \
if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
PyObject* ro; \
wxSize* ptr; \
if (ro) { \
if (! SWIG_GetPtrObj(ro, (void **)&ptr, "_wxSize_p")) \
rval = *ptr; \
+ else if (PySequence_Check(ro) && PyObject_Length(ro) == 2) { \
+ PyObject* o1 = PySequence_GetItem(ro, 0); \
+ PyObject* o2 = PySequence_GetItem(ro, 1); \
+ if (PyNumber_Check(o1) && PyNumber_Check(o2)) \
+ rval = wxSize(PyInt_AsLong(o1), PyInt_AsLong(o2)); \
+ else \
+ PyErr_SetString(PyExc_TypeError, errmsg); \
+ Py_DECREF(o1); \
+ Py_DECREF(o2); \
+ } \
+ else { \
+ PyErr_SetString(PyExc_TypeError, errmsg); \
+ } \
Py_DECREF(ro); \
} \
} \
- wxPyEndBlockThreads(); \
+ wxPyEndBlockThreads(); \
return rval; \
}
wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
int rval=0; \
bool found; \
- wxPyBeginBlockThreads(); \
+ wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c));\
- wxPyEndBlockThreads(); \
+ wxPyEndBlockThreads(); \
if (! found) \
rval = PCLASS::CBNAME(a, b, c); \
return (wxDragResult)rval; \
#define IMP_PYCALLBACK_FSF_FSSTRING_pure(CLASS, PCLASS, CBNAME) \
wxFSFile* CLASS::CBNAME(wxFileSystem& a,const wxString& b) { \
- wxPyBeginBlockThreads(); \
+ wxPyBeginBlockThreads(); \
wxFSFile* rval=0; \
if (wxPyCBH_findCallback(m_myInst, #CBNAME)) { \
PyObject* ro; \
PyObject* obj = wxPyMake_wxObject(&a); \
ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OO)",\
- obj, wx2PyString)); \
+ obj, wx2PyString(b))); \
if (ro) { \
SWIG_GetPtrObj(ro, (void **)&rval, "_wxFSFILE_p"); \
Py_DECREF(ro); \
} \
Py_DECREF(obj); \
} \
- wxPyEndBlockThreads(); \
+ wxPyEndBlockThreads(); \
return rval; \
};