- // [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();
- data->SetId(item); // set the id
- self->SetItemData(item, data);
- }
- return data;
- }
-
- void SetItemData(const wxTreeItemId& item, wxPyTreeItemData* data) {
- data->SetId(item); // set the id
- self->SetItemData(item, data);
- }
-
- // [Get|Set]ItemPyData are short-cuts. Also made somewhat crash-proof by
- // automatically creating data classes.
- PyObject* GetItemPyData(const wxTreeItemId& item) {
- wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
- if (data == NULL) {
- data = new wxPyTreeItemData();
- data->SetId(item); // set the id
- self->SetItemData(item, data);
- }
- return data->GetData();
- }
-
- void SetItemPyData(const wxTreeItemId& item, PyObject* obj) {
- wxPyTreeItemData* data = (wxPyTreeItemData*)self->GetItemData(item);
- if (data == NULL) {
- data = new wxPyTreeItemData(obj);
- data->SetId(item); // set the id
- self->SetItemData(item, data);
- } else
- data->SetData(obj);
- }
- }
-
-
- // force appearance of [+] button near the item. This is useful to
- // allow the user to expand the items which don't have any children now
- // - but instead add them only when needed, thus minimizing memory
- // usage and loading time.
- void SetItemHasChildren(const wxTreeItemId& item, bool has = True);
-
- // the item will be shown in bold
- void SetItemBold(const wxTreeItemId& item, bool bold = True);
-
- // set the item's text colour
- void SetItemTextColour(const wxTreeItemId& item, const wxColour& col);
-
- // set the item's background colour
- void SetItemBackgroundColour(const wxTreeItemId& item,
- const wxColour& col);
-
- // set the item's font (should be of the same height for all items)
- void SetItemFont(const wxTreeItemId& item, const wxFont& font);
-
-
- bool GetItemBold(const wxTreeItemId& item) const;
- wxColour GetItemTextColour(const wxTreeItemId& item) const;
- wxColour GetItemBackgroundColour(const wxTreeItemId& item) const;
- wxFont GetItemFont(const wxTreeItemId& item) const;
-
- // is the item visible (it might be outside the view or not expanded)?
- bool IsVisible(const wxTreeItemId& item) const;
-
- // does the item has any children?
- bool ItemHasChildren(const wxTreeItemId& item) const;
-
- // is the item expanded (only makes sense if HasChildren())?
- bool IsExpanded(const wxTreeItemId& item) const;
-
- // is this item currently selected (the same as has focus)?
- bool IsSelected(const wxTreeItemId& item) const;
-
- // is item text in bold font?
- bool IsBold(const wxTreeItemId& item) const;
-
- // if 'recursively' is False, only immediate children count, otherwise
- // the returned number is the number of all items in this branch
- size_t GetChildrenCount(const wxTreeItemId& item, bool recursively = True);
-
-
- // wxTreeItemId.IsOk() will return False if there is no such item
-
- // get the root tree item
- wxTreeItemId GetRootItem() const;
-
- // get the item currently selected (may return NULL if no selection)
- wxTreeItemId GetSelection() const;
-
- // get the items currently selected, return the number of such item
- //size_t GetSelections(wxArrayTreeItemIds&) const;
- %extend {
- PyObject* GetSelections() {
- wxPyBeginBlockThreads();
- PyObject* rval = PyList_New(0);
- wxArrayTreeItemIds array;
- size_t num, x;
- num = self->GetSelections(array);
- for (x=0; x < num; x++) {
- wxTreeItemId *tii = new wxTreeItemId(array.Item(x));
- PyObject* item = wxPyConstructObject((void*)tii, wxT("wxTreeItemId"), True);
- PyList_Append(rval, item);
- }
- wxPyEndBlockThreads();
- return rval;
- }
- }
-
-
- // get the parent of this item (may return NULL if root)
- %name(GetItemParent)wxTreeItemId GetParent(const wxTreeItemId& item) const;
-
- // for this enumeration function you must pass in a "cookie" parameter
- // which is opaque for the application but is necessary for the library
- // to make these functions reentrant (i.e. allow more than one
- // enumeration on one and the same object simultaneously). Of course,
- // the "cookie" passed to GetFirstChild() and GetNextChild() should be
- // the same!
-
-
- %extend {
- // Get the first child of this item. Returns a wxTreeItemId and an
- // opaque "cookie" value that should be passed to GetNextChild in
- // order to continue the search.
- PyObject* GetFirstChild(const wxTreeItemId& item) {
- long cookie = 0;
- wxTreeItemId ritem = self->GetFirstChild(item, cookie);
- wxPyBeginBlockThreads();
- PyObject* tup = PyTuple_New(2);
- PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(&ritem, wxT("wxTreeItemId"), true));
- PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
- wxPyEndBlockThreads();
- return tup;
- }
-
-
- // Get the next child of this item. The cookie parameter is the 2nd
- // value returned from GetFirstChild or the previous GetNextChild.
- // Returns a wxTreeItemId and an opaque "cookie" value that should be
- // passed to GetNextChild in order to continue the search.
- PyObject* GetNextChild(const wxTreeItemId& item, long cookie) {
- wxTreeItemId ritem = self->GetNextChild(item, cookie);
- wxPyBeginBlockThreads();
- PyObject* tup = PyTuple_New(2);
- PyTuple_SET_ITEM(tup, 0, wxPyConstructObject(&ritem, wxT("wxTreeItemId"), true));
- PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(cookie));
- wxPyEndBlockThreads();
- return tup;
- }
- }
-
- // get the last child of this item - this method doesn't use cookies
- wxTreeItemId GetLastChild(const wxTreeItemId& item) const;