]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/wxPython/src/helpers.h
list of official wxWin translators
[wxWidgets.git] / utils / wxPython / src / helpers.h
index 9540e728e40bde414d38c480ea6df47fd8370e0d..ae0d93b672eed1a931325312f3e4507732a23399 100644 (file)
@@ -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,9 +180,50 @@ 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
@@ -190,7 +232,7 @@ private:
 //---------------------------------------------------------------------------
 
 #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;                                                    \
     }
@@ -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)",                   \