From: Robin Dunn Date: Mon, 20 Mar 2006 18:02:37 +0000 (+0000) Subject: Editors, Renderers and Attrs need to have a destructor so SWIG won't X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/607a3fa066378bd969ceb0803dad87611c460e8d Editors, Renderers and Attrs need to have a destructor so SWIG won't complain about it, but since they are protected in C++ we need to give them a dummy one. In the future these shoud be changed to use %ref/%unref and let SWIG manage the refcount for us. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38226 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/wxPython/src/_defs.i b/wxPython/src/_defs.i index 1ceba2c622..9347ef9995 100644 --- a/wxPython/src/_defs.i +++ b/wxPython/src/_defs.i @@ -104,6 +104,8 @@ typedef unsigned long wxUIntPtr; #define %disownarg(typespec) %typemap(in) typespec = SWIGTYPE* DISOWN #define %cleardisown(typespec) %typemap(in) typespec +#define %ref %feature("ref") +#define %unref %feature("unref") #ifndef %pythoncode diff --git a/wxPython/src/_grid_rename.i b/wxPython/src/_grid_rename.i index befc12a39d..79e04987aa 100644 --- a/wxPython/src/_grid_rename.i +++ b/wxPython/src/_grid_rename.i @@ -24,6 +24,7 @@ %rename(GRID_MIN_ROW_HEIGHT) wxGRID_MIN_ROW_HEIGHT; %rename(GRID_MIN_COL_WIDTH) wxGRID_MIN_COL_WIDTH; %rename(GRID_DEFAULT_SCROLLBAR_WIDTH) wxGRID_DEFAULT_SCROLLBAR_WIDTH; +%rename(GridCellWorker) wxGridCellWorker; %rename(GridCellRenderer) wxGridCellRenderer; %rename(PyGridCellRenderer) wxPyGridCellRenderer; %rename(GridCellStringRenderer) wxGridCellStringRenderer; diff --git a/wxPython/src/grid.i b/wxPython/src/grid.i index e45dd130b1..d6f7f1c6ef 100644 --- a/wxPython/src/grid.i +++ b/wxPython/src/grid.i @@ -491,11 +491,14 @@ enum { //--------------------------------------------------------------------------- -// wxGridCellRenderer is an ABC, and several derived classes are available. -// Classes implemented in Python should be derived from wxPyGridCellRenderer. +// TODO: Use these to have SWIG automatically handle the IncRef/DecRef calls: +// +// %ref wxGridCellWorker "$this->IncRef();"; +// %unref wxGridCellWorker "$this->DecRef();"; +// -class wxGridCellRenderer +class wxGridCellWorker { public: %extend { @@ -503,12 +506,25 @@ public: if (!self->GetClientObject()) self->SetClientObject(new wxPyOORClientData(_self)); } + + // A dummy dtor to shut up SWIG. (The real one is protected and can + // only be called by DecRef) + ~wxGridCellWorker() { + } } void SetParameters(const wxString& params); void IncRef(); void DecRef(); +}; + + +// wxGridCellRenderer is an ABC, and several derived classes are available. +// Classes implemented in Python should be derived from wxPyGridCellRenderer. + +class wxGridCellRenderer : public wxGridCellWorker +{ virtual void Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, @@ -523,6 +539,7 @@ public: }; + // The C++ version of wxPyGridCellRenderer %{ class wxPyGridCellRenderer : public wxGridCellRenderer @@ -703,16 +720,9 @@ public: // wxGridCellEditor is an ABC, and several derived classes are available. // Classes implemented in Python should be derived from wxPyGridCellEditor. -class wxGridCellEditor +class wxGridCellEditor : public wxGridCellWorker { public: - %extend { - void _setOORInfo(PyObject* _self) { - if (!self->GetClientObject()) - self->SetClientObject(new wxPyOORClientData(_self)); - } - } - bool IsCreated(); wxControl* GetControl(); void SetControl(wxControl* control); @@ -720,10 +730,6 @@ public: wxGridCellAttr* GetCellAttr(); void SetCellAttr(wxGridCellAttr* attr); - void SetParameters(const wxString& params); - void IncRef(); - void DecRef(); - virtual void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler); @@ -991,11 +997,20 @@ public: %pythonAppend wxGridCellAttr "self._setOORInfo(self)" wxGridCellAttr(wxGridCellAttr *attrDefault = NULL); + + %extend { + // A dummy dtor to shut up SWIG. (The real one is protected and can + // only be called by DecRef) + ~wxGridCellAttr() { + } + } wxGridCellAttr *Clone() const; void MergeWith(wxGridCellAttr *mergefrom); + void IncRef(); void DecRef(); + void SetTextColour(const wxColour& colText); void SetBackgroundColour(const wxColour& colBack); void SetFont(const wxFont& font); @@ -1092,7 +1107,7 @@ public: void _setCallbackInfo(PyObject* self, PyObject* _class); wxGridCellAttr *GetAttr(int row, int col, - wxGridCellAttr::wxAttrKind kind); + wxGridCellAttr::wxAttrKind kind); void SetAttr(wxGridCellAttr *attr, int row, int col); void SetRowAttr(wxGridCellAttr *attr, int row); void SetColAttr(wxGridCellAttr *attr, int col); diff --git a/wxPython/wxPython/grid.py b/wxPython/wxPython/grid.py index f94389f540..a93c6af23f 100644 --- a/wxPython/wxPython/grid.py +++ b/wxPython/wxPython/grid.py @@ -40,6 +40,8 @@ wxGRID_LABEL_EDGE_ZONE = wx.grid.GRID_LABEL_EDGE_ZONE wxGRID_MIN_ROW_HEIGHT = wx.grid.GRID_MIN_ROW_HEIGHT wxGRID_MIN_COL_WIDTH = wx.grid.GRID_MIN_COL_WIDTH wxGRID_DEFAULT_SCROLLBAR_WIDTH = wx.grid.GRID_DEFAULT_SCROLLBAR_WIDTH +wxGridCellWorker = wx.grid.GridCellWorker +wxGridCellWorkerPtr = wx.grid.GridCellWorkerPtr wxGridCellRenderer = wx.grid.GridCellRenderer wxGridCellRendererPtr = wx.grid.GridCellRendererPtr wxPyGridCellRenderer = wx.grid.PyGridCellRenderer