X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0699c8646a72ffd13f3a0b3ab746ec3cbec5bd28..d9f39e09e82e99c422619f4e3df536d0a9e87987:/utils/wxPython/src/controls2.i diff --git a/utils/wxPython/src/controls2.i b/utils/wxPython/src/controls2.i index db89aaf1ce..4e85f0fe10 100644 --- a/utils/wxPython/src/controls2.i +++ b/utils/wxPython/src/controls2.i @@ -233,19 +233,49 @@ public: -// **** This isn't very useful yet. This needs to be specialized to enable -// derived Python classes... -class wxTreeItemData { +%{ +class wxPyTreeItemData : public wxTreeItemData { public: - wxTreeItemData(); - ~wxTreeItemData(); + wxPyTreeItemData(PyObject* obj = NULL) { + if (obj == NULL) + obj = Py_None; + Py_INCREF(obj); + m_obj = obj; + } - const wxTreeItemId& GetId(); - void SetId(const wxTreeItemId& id); + ~wxPyTreeItemData() { + Py_DECREF(m_obj); + } + + PyObject* GetData() { + Py_INCREF(m_obj); + return m_obj; + } + + void SetData(PyObject* obj) { + Py_DECREF(m_obj); + m_obj = obj; + Py_INCREF(obj); + } + + PyObject* m_obj; }; +%} +%name(wxTreeItemData) class wxPyTreeItemData { +public: + wxPyTreeItemData(PyObject* obj = NULL); + + PyObject* GetData(); + void SetData(PyObject* obj); + + const wxTreeItemId& GetId(); + void SetId(const wxTreeItemId& id); +}; + + class wxTreeEvent : public wxCommandEvent { public: @@ -284,14 +314,50 @@ public: wxString GetItemText(const wxTreeItemId& item); int GetItemImage(const wxTreeItemId& item); int GetItemSelectedImage(const wxTreeItemId& item); - wxTreeItemData *GetItemData(const wxTreeItemId& item); void SetItemText(const wxTreeItemId& item, const wxString& text); void SetItemImage(const wxTreeItemId& item, int image); void SetItemSelectedImage(const wxTreeItemId& item, int image); - void SetItemData(const wxTreeItemId& item, wxTreeItemData *data); void SetItemHasChildren(const wxTreeItemId& item, bool hasChildren = TRUE); + %addmethods { + // [Get|Set]ItemData substitutes. Automatically create wxPyTreeItemData + // if needed. + wxPyTreeItemData* GetItemData(const wxTreeItemId& item) { + wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); + if (data == NULL) { + data = new wxPyTreeItemData(); + self->SetItemData(item, data); + } + return data; + } + + void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) { + self->SetItemData(item, data); + } + + // [Get|Set]PyData are short-cuts. Also made somewhat crash-proof by + // automatically creating data classes. + PyObject* GetPyData(const wxTreeItemId& item) { + wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); + if (data == NULL) { + data = new wxPyTreeItemData(); + self->SetItemData(item, data); + } + return data->GetData(); + } + + void SetPyData(const wxTreeItemId& item, PyObject* obj) { + wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item); + if (data == NULL) { + data = new wxPyTreeItemData(obj); + self->SetItemData(item, data); + } else + data->SetData(obj); + } + } + + bool IsVisible(const wxTreeItemId& item); bool ItemHasChildren(const wxTreeItemId& item); bool IsExpanded(const wxTreeItemId& item); @@ -312,20 +378,20 @@ public: wxTreeItemId AddRoot(const wxString& text, int image = -1, int selectedImage = -1, - wxTreeItemData *data = NULL); + wxPyTreeItemData *data = NULL); wxTreeItemId PrependItem(const wxTreeItemId& parent, const wxString& text, int image = -1, int selectedImage = -1, - wxTreeItemData *data = NULL); + wxPyTreeItemData *data = NULL); wxTreeItemId InsertItem(const wxTreeItemId& parent, const wxTreeItemId& idPrevious, const wxString& text, int image = -1, int selectedImage = -1, - wxTreeItemData *data = NULL); + wxPyTreeItemData *data = NULL); wxTreeItemId AppendItem(const wxTreeItemId& parent, const wxString& text, int image = -1, int selectedImage = -1, - wxTreeItemData *data = NULL); + wxPyTreeItemData *data = NULL); void Delete(const wxTreeItemId& item); void DeleteChildren(const wxTreeItemId& item); @@ -417,7 +483,12 @@ public: ///////////////////////////////////////////////////////////////////////////// // // $Log$ +// Revision 1.17 1999/04/30 03:29:18 RD +// wxPython 2.0b9, first phase (win32) +// Added gobs of stuff, see wxPython/README.txt for details +// // Revision 1.16 1999/02/25 07:08:32 RD +// // wxPython version 2.0b5 // // Revision 1.15 1999/02/20 09:02:56 RD