]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/controls2.i
correction for memory leak
[wxWidgets.git] / wxPython / src / controls2.i
index 01436fa680ad2317d1f181c42909a23251619cfa..11e599148c659171bd68fc84021cdfa02486eda3 100644 (file)
@@ -392,6 +392,7 @@ IMP_PYCALLBACK_LISTATTR_LONG(wxPyListCtrl, wxListCtrl, OnGetItemAttr);
 %}
 
 
 %}
 
 
+
 %name(wxListCtrl)class wxPyListCtrl : public wxControl {
 public:
     wxPyListCtrl(wxWindow* parent, wxWindowID id = -1,
 %name(wxListCtrl)class wxPyListCtrl : public wxControl {
 public:
     wxPyListCtrl(wxWindow* parent, wxWindowID id = -1,
@@ -695,7 +696,7 @@ public:
     int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
         int retval = 0;
         PyObject* func = (PyObject*)funcPtr;
     int wxCALLBACK wxPyListCtrl_SortItems(long item1, long item2, long funcPtr) {
         int retval = 0;
         PyObject* func = (PyObject*)funcPtr;
-        bool doSave = wxPyRestoreThread();
+        wxPyTState* state = wxPyBeginBlockThreads();
 
         PyObject* args = Py_BuildValue("(ii)", item1, item2);
         PyObject* result = PyEval_CallObject(func, args);
 
         PyObject* args = Py_BuildValue("(ii)", item1, item2);
         PyObject* result = PyEval_CallObject(func, args);
@@ -705,7 +706,7 @@ public:
             Py_DECREF(result);
         }
 
             Py_DECREF(result);
         }
 
-        wxPySaveThread(doSave);
+        wxPyEndBlockThreads(state);
         return retval;
     }
 
         return retval;
     }
 
@@ -940,9 +941,9 @@ public:
     }
 
     ~wxPyTreeItemData() {
     }
 
     ~wxPyTreeItemData() {
-        bool doSave = wxPyRestoreThread();
+        wxPyTState* state = wxPyBeginBlockThreads();
         Py_DECREF(m_obj);
         Py_DECREF(m_obj);
-        wxPySaveThread(doSave);
+        wxPyEndBlockThreads(state);
     }
 
     PyObject* GetData() {
     }
 
     PyObject* GetData() {
@@ -951,9 +952,9 @@ public:
     }
 
     void SetData(PyObject* obj) {
     }
 
     void SetData(PyObject* obj) {
-        bool doSave = wxPyRestoreThread();
+        wxPyTState* state = wxPyBeginBlockThreads();
         Py_DECREF(m_obj);
         Py_DECREF(m_obj);
-        wxPySaveThread(doSave);
+        wxPyEndBlockThreads(state);
         m_obj = obj;
         Py_INCREF(obj);
     }
         m_obj = obj;
         Py_INCREF(obj);
     }
@@ -984,6 +985,7 @@ public:
     wxTreeItemId GetItem();
     wxTreeItemId GetOldItem();
     wxPoint GetPoint();
     wxTreeItemId GetItem();
     wxTreeItemId GetOldItem();
     wxPoint GetPoint();
+    const wxKeyEvent& GetKeyEvent();
     int GetCode();
     const wxString& GetLabel();
 };
     int GetCode();
     const wxString& GetLabel();
 };
@@ -1016,15 +1018,16 @@ public:
     int OnCompareItems(const wxTreeItemId& item1,
                        const wxTreeItemId& item2) {
         int rval = 0;
     int OnCompareItems(const wxTreeItemId& item1,
                        const wxTreeItemId& item2) {
         int rval = 0;
-        bool doSave = wxPyRestoreThread();
-        if (m_myInst.findCallback("OnCompareItems"))
+        bool found;
+        wxPyTState* state = wxPyBeginBlockThreads();
+        if ((found = m_myInst.findCallback("OnCompareItems")))
             rval = m_myInst.callCallback(Py_BuildValue(
                 "(OO)",
                 wxPyConstructObject((void*)&item1, "wxTreeItemId"),
                 wxPyConstructObject((void*)&item2, "wxTreeItemId")));
             rval = m_myInst.callCallback(Py_BuildValue(
                 "(OO)",
                 wxPyConstructObject((void*)&item1, "wxTreeItemId"),
                 wxPyConstructObject((void*)&item2, "wxTreeItemId")));
-        else
+        wxPyEndBlockThreads(state);
+        if (! found)
             rval = wxTreeCtrl::OnCompareItems(item1, item2);
             rval = wxTreeCtrl::OnCompareItems(item1, item2);
-        wxPySaveThread(doSave);
         return rval;
     }
     PYPRIVATE;
         return rval;
     }
     PYPRIVATE;
@@ -1138,7 +1141,7 @@ public:
     //size_t GetSelections(wxArrayTreeItemIds& selection);
     %addmethods {
         PyObject* GetSelections() {
     //size_t GetSelections(wxArrayTreeItemIds& selection);
     %addmethods {
         PyObject* GetSelections() {
-            bool doSave = wxPyRestoreThread();
+            wxPyTState* state = wxPyBeginBlockThreads();
             PyObject*           rval = PyList_New(0);
             wxArrayTreeItemIds  array;
             size_t              num, x;
             PyObject*           rval = PyList_New(0);
             wxArrayTreeItemIds  array;
             size_t              num, x;
@@ -1148,7 +1151,7 @@ public:
                 PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
                 PyList_Append(rval, item);
             }
                 PyObject* item = wxPyConstructObject((void*)tii, "wxTreeItemId", TRUE);
                 PyList_Append(rval, item);
             }
-            wxPySaveThread(doSave);
+            wxPyEndBlockThreads(state);
             return rval;
         }
     }
             return rval;
         }
     }
@@ -1233,10 +1236,10 @@ public:
         PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
             wxRect rect;
             if (self->GetBoundingRect(item, rect, textOnly)) {
         PyObject* GetBoundingRect(const wxTreeItemId& item, int textOnly = FALSE) {
             wxRect rect;
             if (self->GetBoundingRect(item, rect, textOnly)) {
-                bool doSave = wxPyRestoreThread();
+                wxPyTState* state = wxPyBeginBlockThreads();
                 wxRect* r = new wxRect(rect);
                 PyObject* val = wxPyConstructObject((void*)r, "wxRect");
                 wxRect* r = new wxRect(rect);
                 PyObject* val = wxPyConstructObject((void*)r, "wxRect");
-                wxPySaveThread(doSave);
+                wxPyEndBlockThreads(state);
                 return val;
             }
             else {
                 return val;
             }
             else {
@@ -1271,8 +1274,10 @@ public:
 //----------------------------------------------------------------------
 
 %init %{
 //----------------------------------------------------------------------
 
 %init %{
+    // Map renamed classes back to their common name for OOR
     wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
     wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
     wxPyPtrTypeMap_Add("wxTreeItemData", "wxPyTreeItemData");
     wxPyPtrTypeMap_Add("wxTreeCtrl", "wxPyTreeCtrl");
+    wxPyPtrTypeMap_Add("wxListCtrl", "wxPyListCtrl");
 %}
 
 //----------------------------------------------------------------------
 %}
 
 //----------------------------------------------------------------------