]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/helpers.h
SWIGged code update for wxGTK
[wxWidgets.git] / wxPython / src / helpers.h
index 1d503a2046aa643616c0ac61944a9e7d59567d22..3eb8574c2223dd1609c496f8eb47d22c95471d65 100644 (file)
@@ -65,7 +65,8 @@ PyObject* wxPyConstructObject(void* ptr,
                               PyObject* klass,
                               int setThisOwn=0);
 PyObject*  wxPyClassExists(const char* className);
-PyObject*  wxPyMake_wxObject(wxObject* source);
+PyObject*  wxPyMake_wxObject(wxObject* source, bool checkEvtHandler=TRUE);
+PyObject*  wxPyMake_wxSizer(wxSizer* source);
 void       wxPyPtrTypeMap_Add(const char* commonName, const char* ptrName);
 
 PyObject* wxPy_ConvertList(wxListBase* list, const char* className);
@@ -134,6 +135,7 @@ wxPoint* wxPoint_LIST_helper(PyObject* source, int* npoints);
 wxBitmap** wxBitmap_LIST_helper(PyObject* source);
 wxString* wxString_LIST_helper(PyObject* source);
 wxAcceleratorEntry* wxAcceleratorEntry_LIST_helper(PyObject* source);
+wxPen** wxPen_LIST_helper(PyObject* source);
 
 bool wxSize_helper(PyObject* source, wxSize** obj);
 bool wxPoint_helper(PyObject* source, wxPoint** obj);
@@ -141,6 +143,20 @@ bool wxRealPoint_helper(PyObject* source, wxRealPoint** obj);
 bool wxRect_helper(PyObject* source, wxRect** obj);
 bool wxColour_helper(PyObject* source, wxColour** obj);
 
+#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))
+#endif
+
+bool _2int_seq_helper(PyObject* source, int* i1, int* i2);
+bool _4int_seq_helper(PyObject* source, int* i1, int* i2, int* i3, int* i4);
+
+
+PyObject* wxArrayString2PyList_helper(const wxArrayString& arr);
+
+
+#define RETURN_NONE()   { Py_INCREF(Py_None); return Py_None; }
+
 //----------------------------------------------------------------------
 
 #ifndef SWIGCODE
@@ -204,22 +220,24 @@ protected:
 
 
 class wxPyEvent : public wxEvent, public wxPyEvtSelfRef {
-    DECLARE_DYNAMIC_CLASS(wxPyEvent)
+    DECLARE_ABSTRACT_CLASS(wxPyEvent)
 public:
     wxPyEvent(int id=0);
+    wxPyEvent(const wxPyEvent& evt);
     ~wxPyEvent();
 
-    void CopyObject(wxObject& dest) const;
+    virtual wxEvent* Clone() const { return new wxPyEvent(*this); }
 };
 
 
 class wxPyCommandEvent : public wxCommandEvent, public wxPyEvtSelfRef {
-    DECLARE_DYNAMIC_CLASS(wxPyCommandEvent)
+    DECLARE_ABSTRACT_CLASS(wxPyCommandEvent)
 public:
     wxPyCommandEvent(wxEventType commandType = wxEVT_NULL, int id=0);
+    wxPyCommandEvent(const wxPyCommandEvent& evt);
     ~wxPyCommandEvent();
 
-    void CopyObject(wxObject& dest) const;
+    virtual wxEvent* Clone() const { return new wxPyCommandEvent(*this); }
 };
 
 
@@ -260,16 +278,17 @@ struct wxPyCoreAPI {
     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);
+    void        (*p_wxPyCBH_setCallbackInfo)(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);
 
     PyObject*   (*p_wxPyClassExists)(const char* className);
-    PyObject*   (*p_wxPyMake_wxObject)(wxObject* source);
+    PyObject*   (*p_wxPyMake_wxObject)(wxObject* source, bool checkEvtHandler);
+    PyObject*   (*p_wxPyMake_wxSizer)(wxSizer* source);
     void        (*p_wxPyPtrTypeMap_Add)(const char* commonName, const char* ptrName);
-
+    PyObject*   (*p_wxArrayString2PyList_helper)(const wxArrayString& arr);
 };
 
 #ifdef wxPyUSE_EXPORT
@@ -318,7 +337,7 @@ private:
 };
 
 
-void wxPyCBH_setSelf(wxPyCallbackHelper& cbh, PyObject* self, PyObject* klass, int incref);
+void wxPyCBH_setCallbackInfo(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);
@@ -351,6 +370,29 @@ public:
 
 
 
+class wxPyClientData : public wxClientData {
+public:
+    wxPyClientData(PyObject* obj) {
+        m_obj = obj;
+        Py_INCREF(m_obj);
+    }
+
+    ~wxPyClientData() {
+#ifdef wxPyUSE_EXPORT
+        wxPyTState* state = wxPyCoreAPIPtr->p_wxPyBeginBlockThreads();
+        Py_DECREF(m_obj);
+        wxPyCoreAPIPtr->p_wxPyEndBlockThreads(state);
+#else
+        wxPyTState* state = wxPyBeginBlockThreads();
+        Py_DECREF(m_obj);
+        wxPyEndBlockThreads(state);
+#endif
+    }
+    PyObject* m_obj;
+};
+
+
+
 //---------------------------------------------------------------------------
 // These macros are used to implement the virtual methods that should
 // redirect to a Python method if one exists.  The names designate the
@@ -358,8 +400,8 @@ public:
 //---------------------------------------------------------------------------
 
 #define PYPRIVATE                                                       \
-    void _setSelf(PyObject* self, PyObject* _class, int incref=1) {     \
-        wxPyCBH_setSelf(m_myInst, self, _class, incref);                \
+    void _setCallbackInfo(PyObject* self, PyObject* _class, int incref=1) {     \
+        wxPyCBH_setCallbackInfo(m_myInst, self, _class, incref);                \
     }                                                                   \
     private: wxPyCallbackHelper m_myInst
 
@@ -393,7 +435,7 @@ public:
 
 #define IMP_PYCALLBACK_BOOL_INTINT(CLASS, PCLASS, CBNAME)               \
     bool CLASS::CBNAME(int a, int b) {                                  \
-        bool rval, found;                                               \
+        bool rval=FALSE, found;                                         \
         wxPyTState* state = wxPyBeginBlockThreads();                    \
         if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME)))          \
             rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b));    \
@@ -436,10 +478,10 @@ public:
 
 #define IMP_PYCALLBACK_BOOL_INT(CLASS, PCLASS, CBNAME)                  \
     bool CLASS::CBNAME(int a) {                                         \
-        bool rval, found;                                               \
+        bool rval=FALSE, found;                                         \
         wxPyTState* state = wxPyBeginBlockThreads();                    \
         if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME)))          \
-            rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)",a));       \
+            rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)",a));\
         wxPyEndBlockThreads(state);                                     \
         if (! found)                                                    \
             rval = PCLASS::CBNAME(a);                                   \
@@ -457,7 +499,7 @@ public:
 
 #define IMP_PYCALLBACK_BOOL_INT_pure(CLASS, PCLASS, CBNAME)             \
     bool CLASS::CBNAME(int a) {                                         \
-        bool rval;                                                      \
+        bool rval=FALSE;                                                \
         wxPyTState* state = wxPyBeginBlockThreads();                    \
         if (wxPyCBH_findCallback(m_myInst, #CBNAME))                    \
             rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)",a));       \
@@ -619,7 +661,7 @@ public:
     bool CLASS::CBNAME(wxDC& a, double b, double c, double d, double e, bool f) {       \
         bool found;                                                                     \
         wxPyTState* state = wxPyBeginBlockThreads();                                    \
-        bool rval;                                                                      \
+        bool rval=FALSE;                                                                \
         if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) {                        \
             PyObject* obj = wxPyMake_wxObject(&a);                                      \
             rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(Oddddi)", obj, b, c, d, e, (int)f));\
@@ -828,7 +870,7 @@ public:
 
 #define IMP_PYCALLBACK_BOOL_STRING(CLASS, PCLASS, CBNAME)                       \
     bool CLASS::CBNAME(const wxString& a)  {                                    \
-        bool rval;                                                              \
+        bool rval=FALSE;                                                        \
         bool found;                                                             \
         wxPyTState* state = wxPyBeginBlockThreads();                            \
         if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME)))                  \
@@ -849,7 +891,7 @@ public:
                    \
 #define IMP_PYCALLBACK_BOOL_STRING_pure(CLASS, PCLASS, CBNAME)                          \
     bool CLASS::CBNAME(const wxString& a)  {                                            \
-        bool rval;                                                                      \
+        bool rval=FALSE;                                                                \
         wxPyTState* state = wxPyBeginBlockThreads();                                    \
         if (wxPyCBH_findCallback(m_myInst, #CBNAME))                                    \
             rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(s)", a.c_str()));     \
@@ -910,7 +952,7 @@ public:
 
 #define IMP_PYCALLBACK_BOOL_STRINGSTRING(CLASS, PCLASS, CBNAME)                 \
     bool CLASS::CBNAME(const wxString& a, const wxString& b) {                  \
-        bool rval;                                                              \
+        bool rval=FALSE;                                                        \
         bool found;                                                             \
         wxPyTState* state = wxPyBeginBlockThreads();                            \
         if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME)))                  \
@@ -986,7 +1028,7 @@ public:
 
 #define IMP_PYCALLBACK_BOOL_TAG_pure(CLASS, PCLASS, CBNAME)                     \
     bool CLASS::CBNAME(const wxHtmlTag& a)  {                                   \
-        bool rval = FALSE;                                                      \
+        bool rval=FALSE;                                                        \
         wxPyTState* state = wxPyBeginBlockThreads();                            \
         if (wxPyCBH_findCallback(m_myInst, #CBNAME)) {                          \
             PyObject* obj = wxPyConstructObject((void*)&a, "wxHtmlTag", 0);     \
@@ -997,6 +1039,58 @@ public:
         return rval;                                                            \
     }
 
+//---------------------------------------------------------------------------
+
+#define DEC_PYCALLBACK__CELLINTINT(CBNAME)                                      \
+    void CBNAME(wxHtmlCell *cell, wxCoord x, wxCoord y);                        \
+    void base_##CBNAME(wxHtmlCell *cell, wxCoord x, wxCoord y);
+
+#define IMP_PYCALLBACK__CELLINTINT(CLASS, PCLASS, CBNAME)                       \
+    void CLASS::CBNAME(wxHtmlCell *cell, wxCoord x, wxCoord y) {                \
+        wxString rval;                                                          \
+        bool found;                                                             \
+        wxPyTState* state = wxPyBeginBlockThreads();                            \
+        if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) {                \
+            PyObject* obj = wxPyConstructObject((void*)cell, "wxHtmlCell", 0);  \
+            wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(Oii)",obj,x,y));  \
+            Py_DECREF(obj);                                                     \
+        }                                                                       \
+        wxPyEndBlockThreads(state);                                             \
+        if (! found)                                                            \
+            PCLASS::CBNAME(cell, x, y);                                         \
+    }                                                                           \
+    void CLASS::base_##CBNAME(wxHtmlCell *cell, wxCoord x, wxCoord y) {         \
+        PCLASS::CBNAME(cell, x, y);                                             \
+    }
+
+
+//---------------------------------------------------------------------------
+
+#define DEC_PYCALLBACK__CELLINTINTME(CBNAME)                                    \
+    void CBNAME(wxHtmlCell *cell, wxCoord x, wxCoord y, const wxMouseEvent& e); \
+    void base_##CBNAME(wxHtmlCell *cell, wxCoord x, wxCoord y, const wxMouseEvent& e);
+
+#define IMP_PYCALLBACK__CELLINTINTME(CLASS, PCLASS, CBNAME)                       \
+    void CLASS::CBNAME(wxHtmlCell *cell, wxCoord x, wxCoord y, const wxMouseEvent& e) {                \
+        bool found;                                                             \
+        wxPyTState* state = wxPyBeginBlockThreads();                            \
+        if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) {                \
+            PyObject* obj = wxPyConstructObject((void*)cell, "wxHtmlCell", 0);  \
+            PyObject* o2  = wxPyConstructObject((void*)&e, "wxMouseEvent", 0);  \
+            wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OiiO)",obj,x,y,o2));  \
+            Py_DECREF(obj);                                                     \
+            Py_DECREF(o2);                                                      \
+        }                                                                       \
+        wxPyEndBlockThreads(state);                                             \
+        if (! found)                                                            \
+            PCLASS::CBNAME(cell, x, y, e);                                         \
+    }                                                                           \
+    void CLASS::base_##CBNAME(wxHtmlCell *cell, wxCoord x, wxCoord y, const wxMouseEvent& e) {         \
+        PCLASS::CBNAME(cell, x, y, e);                                             \
+    }
+
+
+
 //---------------------------------------------------------------------------
 
 #define DEC_PYCALLBACK___pure(CBNAME)                         \
@@ -1044,7 +1138,7 @@ public:
 
 #define IMP_PYCALLBACK_BOOL_WXWIN(CLASS, PCLASS, CBNAME)                        \
     bool CLASS::CBNAME(wxWindow* a) {                                           \
-        bool rval;                                                              \
+        bool rval=FALSE;                                                        \
         bool found;                                                             \
         wxPyTState* state = wxPyBeginBlockThreads();                            \
         if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) {                \
@@ -1070,7 +1164,7 @@ public:
 
 #define IMP_PYCALLBACK_BOOL_(CLASS, PCLASS, CBNAME)                             \
     bool CLASS::CBNAME() {                                                      \
-        bool rval;                                                              \
+        bool rval=FALSE;                                                        \
         bool found;                                                             \
         wxPyTState* state = wxPyBeginBlockThreads();                            \
         if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME)))                  \
@@ -1093,9 +1187,9 @@ public:
 
 #define IMP_PYCALLBACK_DR_2WXCDR(CLASS, PCLASS, CBNAME)                         \
     wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) {          \
+        int rval=0;                                                             \
         bool found;                                                             \
         wxPyTState* state = wxPyBeginBlockThreads();                            \
-        int rval;                                                               \
         if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME)))                  \
             rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c));\
         wxPyEndBlockThreads(state);                                             \
@@ -1140,9 +1234,9 @@ public:
 
 #define IMP_PYCALLBACK_BOOL_DR(CLASS, PCLASS, CBNAME)                   \
     bool CLASS::CBNAME(wxDragResult a) {                                \
+        bool rval=FALSE;                                                \
         bool found;                                                     \
         wxPyTState* state = wxPyBeginBlockThreads();                    \
-        bool rval;                                                      \
         if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME)))          \
             rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)", a));\
         wxPyEndBlockThreads(state);                                     \
@@ -1163,7 +1257,7 @@ public:
 #define IMP_PYCALLBACK_DR_2WXCDR_pure(CLASS, PCLASS, CBNAME)            \
     wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) {  \
         wxPyTState* state = wxPyBeginBlockThreads();                    \
-        int rval;                                                       \
+        int rval=0;                                                     \
         if (wxPyCBH_findCallback(m_myInst, #CBNAME))                    \
             rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iii)", a,b,c));\
         wxPyEndBlockThreads(state);                                     \
@@ -1178,7 +1272,7 @@ public:
 
 #define IMP_PYCALLBACK_BOOL_INTINTSTR_pure(CLASS, PCLASS, CBNAME)       \
     bool CLASS::CBNAME(int a, int b, const wxString& c) {               \
-        bool rval;                                                      \
+        bool rval=FALSE;                                                \
         wxPyTState* state = wxPyBeginBlockThreads();                    \
         if (wxPyCBH_findCallback(m_myInst, #CBNAME))                    \
             rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iis)",a,b,c.c_str()));\
@@ -1195,7 +1289,7 @@ public:
 
 #define IMP_PYCALLBACK_SIZET_(CLASS, PCLASS, CBNAME)                            \
     size_t CLASS::CBNAME() {                                                    \
-        size_t rval;                                                            \
+        size_t rval=0;                                                          \
         bool found;                                                             \
         wxPyTState* state = wxPyBeginBlockThreads();                            \
         if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME)))                  \
@@ -1218,7 +1312,7 @@ public:
 
 #define IMP_PYCALLBACK_DATAFMT_SIZET(CLASS, PCLASS, CBNAME)                     \
     wxDataFormat CLASS::CBNAME(size_t a) {                                      \
-        wxDataFormat rval;                                                      \
+        wxDataFormat rval=0;                                                    \
         bool found;                                                             \
         wxPyTState* state = wxPyBeginBlockThreads();                            \
         if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) {                \
@@ -1298,7 +1392,7 @@ public:
 
 #define IMP_PYCALLBACK_bool_any(CLASS, PCLASS, CBNAME, Type)                    \
     bool CLASS::CBNAME(Type& a) {                                               \
-        bool rv;                                                                \
+        bool rv=FALSE;                                                          \
         bool found;                                                             \
         wxPyTState* state = wxPyBeginBlockThreads();                            \
         if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) {                \
@@ -1408,4 +1502,35 @@ public:
 
 //---------------------------------------------------------------------------
 
+#define DEC_PYCALLBACK_BOOL_ME(CBNAME) \
+    bool CBNAME(wxMouseEvent& e); \
+    bool base_##CBNAME(wxMouseEvent& e);
+
+#define IMP_PYCALLBACK_BOOL_ME(CLASS, PCLASS, CBNAME) \
+    bool CLASS::CBNAME(wxMouseEvent& e) { \
+        bool rval=FALSE; \
+        bool found; \
+        wxPyTState* state = wxPyBeginBlockThreads(); \
+        if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
+            PyObject* ro; \
+            PyObject* obj  = wxPyConstructObject((void*)&e, "wxMouseEvent", 0);  \
+            ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(O)",obj));  \
+            if (ro) { \
+                rval = PyInt_AsLong(ro); \
+                Py_DECREF(ro); \
+            } \
+            Py_DECREF(obj); \
+        } \
+        wxPyEndBlockThreads(state); \
+        if (! found) \
+            return PCLASS::CBNAME(e); \
+        return rval; \
+    } \
+    bool CLASS::base_##CBNAME(wxMouseEvent& e) { \
+        return PCLASS::CBNAME(e); \
+    }
+
+
+//---------------------------------------------------------------------------
+
 #endif