]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/wxPython/src/helpers.h
Some updates and fixes
[wxWidgets.git] / utils / wxPython / src / helpers.h
index fbe3318fcdc50ad358f75dca09154994a4ab914c..ae0d93b672eed1a931325312f3e4507732a23399 100644 (file)
@@ -1,4 +1,4 @@
-/////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////
 // Name:        helpers.h
 // Purpose:     Helper functions/classes for the wxPython extenaion module
 //
@@ -66,10 +66,24 @@ PyObject* __wxSetDictionary(PyObject*, PyObject* args);
 
 void wxPyEventThunker(wxObject*, wxEvent& event);
 
-HELPEREXPORT PyObject* wxPyConstructObject(void* ptr, char* className);
+HELPEREXPORT PyObject* wxPyConstructObject(void* ptr, const char* className);
 HELPEREXPORT bool wxPyRestoreThread();
 HELPEREXPORT void wxPySaveThread(bool doSave);
-HELPEREXPORT PyObject* wxPy_ConvertList(wxListBase* list, char* className);
+HELPEREXPORT PyObject* wxPy_ConvertList(wxListBase* list, const char* className);
+HELPEREXPORT long wxPyGetWinHandle(wxWindow* win);
+
+//----------------------------------------------------------------------
+
+class wxPyUserData : public wxObject {
+public:
+    wxPyUserData(PyObject* obj) { m_obj = obj; Py_INCREF(m_obj); }
+    ~wxPyUserData() {
+        bool doSave = wxPyRestoreThread();
+        Py_DECREF(m_obj);
+        wxPySaveThread(doSave);
+    }
+    PyObject* m_obj;
+};
 
 //----------------------------------------------------------------------
 // These are helpers used by the typemaps
@@ -122,19 +136,6 @@ public:
     PyObject*   m_func;
 };
 
-//---------------------------------------------------------------------------
-
-//  class wxPyMenu : public wxMenu {
-//  public:
-//      wxPyMenu(const wxString& title = "", PyObject* func=NULL);
-//      ~wxPyMenu();
-
-//  private:
-//      static void MenuCallback(wxMenu& menu, wxCommandEvent& evt);
-//      PyObject*   func;
-//  };
-
-
 //---------------------------------------------------------------------------
 
 class wxPyTimer : public wxTimer {
@@ -179,18 +180,59 @@ public:
 private:
     PyObject*   m_self;
     PyObject*   m_lastFound;
+    int         m_incRef;
+};
+
+
+//---------------------------------------------------------------------------
+//---------------------------------------------------------------------------
+// These Event classes can be derived from in Python and passed through the
+// event system without loosing anything.  They do this by keeping a reference
+// to themselves and some special case handling in wxPyCallback::EventThunker.
+
+
+class wxPyEvtSelfRef {
+public:
+    wxPyEvtSelfRef();
+    ~wxPyEvtSelfRef();
+
+    void SetSelf(PyObject* self, bool clone=FALSE);
+    PyObject* GetSelf() const;
+
+protected:
+    PyObject*   m_self;
+    bool        m_cloned;
+};
+
+
+class wxPyEvent : public wxEvent, public wxPyEvtSelfRef {
+    DECLARE_DYNAMIC_CLASS(wxPyEvent)
+public:
+    wxPyEvent(int id=0);
+    ~wxPyEvent();
+
+    void CopyObject(wxObject& dest) const;
 };
 
 
+class wxPyCommandEvent : public wxCommandEvent, public wxPyEvtSelfRef {
+    DECLARE_DYNAMIC_CLASS(wxPyCommandEvent)
+public:
+    wxPyCommandEvent(wxEventType commandType = wxEVT_NULL, int id=0);
+    ~wxPyCommandEvent();
+
+    void CopyObject(wxObject& dest) const;
+};
+
 
 //---------------------------------------------------------------------------
 // These macros are used to implement the virtual methods that should
 // redirect to a Python method if one exists.  The names designate the
-// return type, if any as well as any parameter types.
+// return type, if any, as well as any parameter types.
 //---------------------------------------------------------------------------
 
 #define PYPRIVATE                                       \
-    void _setSelf(PyObject* self, int incref=TRUE) {    \
+    void _setSelf(PyObject* self, int incref=1) {       \
         m_myInst.setSelf(self, incref);                 \
     }                                                   \
     private: wxPyCallbackHelper m_myInst;
@@ -271,7 +313,7 @@ private:
         bool doSave = wxPyRestoreThread();                              \
         if (m_myInst.findCallback(#CBNAME))                             \
             rval = m_myInst.callCallback(Py_BuildValue("(i)",a));       \
-        else rval = false;                                              \
+        else rval = FALSE;                                              \
         wxPySaveThread(doSave);                                         \
         return rval;                                                    \
     }
@@ -664,12 +706,12 @@ private:
             rval = PyString_AsString(PyObject_Str(ro));                         \
         }                                                                       \
         else                                                                    \
-            rval = PCLASS::CBNAME(a);                                           \
+            rval = PCLASS::CBNAME();                                            \
         wxPySaveThread(doSave);                                                 \
         return rval;                                                            \
     }                                                                           \
-    bool CLASS::base_##CBNAME(const wxString& a) {                              \
-        return PCLASS::CBNAME(a);                                               \
+    wxString CLASS::base_##CBNAME() {                                           \
+        return PCLASS::CBNAME();                                                \
     }
 
 //---------------------------------------------------------------------------
@@ -699,7 +741,7 @@ private:
 
 #define IMP_PYCALLBACK_BOOL_TAG_pure(CLASS, PCLASS, CBNAME)                     \
     bool CLASS::CBNAME(const wxHtmlTag& a)  {                                   \
-        bool rval = false;                                                      \
+        bool rval = FALSE;                                                      \
         bool doSave = wxPyRestoreThread();                                      \
         if (m_myInst.findCallback(#CBNAME))                                     \
             rval = m_myInst.callCallback(Py_BuildValue("(O)",                   \
@@ -788,6 +830,131 @@ private:
         return PCLASS::CBNAME();                                        \
     }
 
+//---------------------------------------------------------------------------
+
+#define DEC_PYCALLBACK_DR_2WXCDR(CBNAME)                 \
+    wxDragResult CBNAME(wxCoord x, wxCoord y, wxDragResult def);    \
+    wxDragResult base_##CBNAME(wxCoord x, wxCoord y, wxDragResult def);
+
+
+#define IMP_PYCALLBACK_DR_2WXCDR(CLASS, PCLASS, CBNAME)                 \
+    wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) {  \
+        bool doSave = wxPyRestoreThread();                              \
+        int rval;                                                       \
+        if (m_myInst.findCallback(#CBNAME))                             \
+            rval = m_myInst.callCallback(Py_BuildValue("(iii)", a,b,c));\
+        else                                                            \
+            rval = PCLASS::CBNAME(a, b, c);                             \
+        wxPySaveThread(doSave);                                         \
+        return (wxDragResult)rval;                                      \
+    }                                                                   \
+    wxDragResult CLASS::base_##CBNAME(wxCoord a, wxCoord b, wxDragResult c) { \
+        return PCLASS::CBNAME(a, b, c);                                       \
+    }
+
+//---------------------------------------------------------------------------
+
+#define DEC_PYCALLBACK_BOOL_DR(CBNAME)                  \
+    bool CBNAME(wxDragResult a);                        \
+    bool base_##CBNAME(wxDragResult a);
+
+
+#define IMP_PYCALLBACK_BOOL_DR(CLASS, PCLASS, CBNAME)                   \
+    bool CLASS::CBNAME(wxDragResult a) {                                \
+        bool doSave = wxPyRestoreThread();                              \
+        bool rval;                                                      \
+        if (m_myInst.findCallback(#CBNAME))                             \
+            rval = m_myInst.callCallback(Py_BuildValue("(i)", a));      \
+        else                                                            \
+            rval = PCLASS::CBNAME(a);                                   \
+        wxPySaveThread(doSave);                                         \
+        return rval;                                                    \
+    }                                                                   \
+    bool CLASS::base_##CBNAME(wxDragResult a) {                         \
+        return PCLASS::CBNAME(a);                                       \
+    }
+
+//---------------------------------------------------------------------------
+
+#define DEC_PYCALLBACK_DR_2WXCDR_pure(CBNAME)   \
+    wxDragResult CBNAME(wxCoord x, wxCoord y, wxDragResult def);
+
+
+#define IMP_PYCALLBACK_DR_2WXCDR_pure(CLASS, PCLASS, CBNAME)            \
+    wxDragResult CLASS::CBNAME(wxCoord a, wxCoord b, wxDragResult c) {  \
+        bool doSave = wxPyRestoreThread();                              \
+        int rval;                                                       \
+        if (m_myInst.findCallback(#CBNAME))                             \
+            rval = m_myInst.callCallback(Py_BuildValue("(iii)", a,b,c));\
+        wxPySaveThread(doSave);                                         \
+        return (wxDragResult)rval;                                      \
+    }                                                                   \
+
+//---------------------------------------------------------------------------
+
+#define DEC_PYCALLBACK_BOOL_INTINTSTR_pure(CBNAME)                      \
+    bool CBNAME(int a, int b, const wxString& c);
+
+
+#define IMP_PYCALLBACK_BOOL_INTINTSTR_pure(CLASS, PCLASS, CBNAME)       \
+    bool CLASS::CBNAME(int a, int b, const wxString& c) {               \
+        bool rval;                                                      \
+        bool doSave = wxPyRestoreThread();                              \
+        if (m_myInst.findCallback(#CBNAME))                             \
+            rval = m_myInst.callCallback(Py_BuildValue("(iis)",a,b,c.c_str()));\
+        wxPySaveThread(doSave);                                         \
+        return rval;                                                    \
+    }                                                                   \
+
+//---------------------------------------------------------------------------
+
+#define DEC_PYCALLBACK_SIZET_(CBNAME)                  \
+    size_t CBNAME();                                   \
+    size_t base_##CBNAME();
+
+
+#define IMP_PYCALLBACK_SIZET_(CLASS, PCLASS, CBNAME)                            \
+    size_t CLASS::CBNAME() {                                                    \
+        size_t rval;                                                            \
+        bool doSave = wxPyRestoreThread();                                      \
+        if (m_myInst.findCallback(#CBNAME))                                     \
+            rval = m_myInst.callCallback(Py_BuildValue("()"));                  \
+        else                                                                    \
+            rval = PCLASS::CBNAME();                                            \
+        wxPySaveThread(doSave);                                                 \
+        return rval;                                                            \
+    }                                                                           \
+    size_t CLASS::base_##CBNAME() {                                             \
+        return PCLASS::CBNAME();                                                \
+    }
+
+//---------------------------------------------------------------------------
+
+#define DEC_PYCALLBACK_DATAFMT_SIZET(CBNAME)                  \
+    wxDataFormat  CBNAME();                                        \
+    wxDataFormat  base_##CBNAME();
+
+
+#define IMP_PYCALLBACK_DATAFMT_SIZET(CLASS, PCLASS, CBNAME)                     \
+    wxDataFormat CLASS::CBNAME(size_t a) {                                      \
+        wxDataFormat rval;                                                      \
+        bool doSave = wxPyRestoreThread();                                      \
+        if (m_myInst.findCallback(#CBNAME)) {                                   \
+            PyObject* ro;                                                       \
+            wxDataFormat* ptr;                                                  \
+            ro = m_myInst.callCallbackObj(Py_BuildValue("(i)", a));             \
+            if (! SWIG_GetPtrObj(ro, (void **)&ptr, "_wxDataFormat_p"))         \
+                rval = *ptr;                                                    \
+        }                                                                       \
+        else                                                                    \
+            rval = PCLASS::CBNAME(a);                                           \
+        wxPySaveThread(doSave);                                                 \
+        return rval;                                                            \
+    }                                                                           \
+    wxDataFormat  CLASS::base_##CBNAME(size_t a) {                              \
+        return PCLASS::CBNAME(a);                                               \
+    }
+
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
@@ -796,3 +963,4 @@ private:
 
 
 
+