+ wxDELETE( m_hilightBrush );
+
+ DeleteAllItems();
+}
+
+// -----------------------------------------------------------------------------
+// accessors
+// -----------------------------------------------------------------------------
+
+size_t wxTreeCtrl::GetCount() const
+{
+ return m_anchor == NULL ? 0u : m_anchor->GetChildrenCount();
+}
+
+void wxTreeCtrl::SetIndent(unsigned int indent)
+{
+ m_indent = indent;
+ m_dirty = TRUE;
+ Refresh();
+}
+
+void wxTreeCtrl::SetSpacing(unsigned int spacing)
+{
+ m_spacing = spacing;
+ m_dirty = TRUE;
+ Refresh();
+}
+
+size_t wxTreeCtrl::GetChildrenCount(const wxTreeItemId& item, bool recursively)
+{
+ wxCHECK_MSG( item.IsOk(), 0u, _T("invalid tree item") );
+
+ return item.m_pItem->GetChildrenCount(recursively);
+}
+
+// -----------------------------------------------------------------------------
+// functions to work with tree items
+// -----------------------------------------------------------------------------
+
+wxString wxTreeCtrl::GetItemText(const wxTreeItemId& item) const
+{
+ wxCHECK_MSG( item.IsOk(), _T(""), _T("invalid tree item") );
+
+ return item.m_pItem->GetText();
+}
+
+int wxTreeCtrl::GetItemImage(const wxTreeItemId& item) const
+{
+ wxCHECK_MSG( item.IsOk(), -1, _T("invalid tree item") );
+
+ return item.m_pItem->GetImage();
+}
+
+int wxTreeCtrl::GetItemSelectedImage(const wxTreeItemId& item) const
+{
+ wxCHECK_MSG( item.IsOk(), -1, _T("invalid tree item") );
+
+ return item.m_pItem->GetSelectedImage();
+}
+
+wxTreeItemData *wxTreeCtrl::GetItemData(const wxTreeItemId& item) const
+{
+ wxCHECK_MSG( item.IsOk(), NULL, _T("invalid tree item") );
+
+ return item.m_pItem->GetData();
+}
+
+void wxTreeCtrl::SetItemText(const wxTreeItemId& item, const wxString& text)
+{
+ wxCHECK_RET( item.IsOk(), _T("invalid tree item") );
+
+ wxClientDC dc(this);
+ wxGenericTreeItem *pItem = item.m_pItem;
+ pItem->SetText(text);
+ CalculateSize(pItem, dc);
+ RefreshLine(pItem);
+}
+
+void wxTreeCtrl::SetItemImage(const wxTreeItemId& item, int image)
+{
+ wxCHECK_RET( item.IsOk(), _T("invalid tree item") );
+
+ wxClientDC dc(this);
+ wxGenericTreeItem *pItem = item.m_pItem;
+ pItem->SetImage(image);
+ CalculateSize(pItem, dc);
+ RefreshLine(pItem);
+}
+
+void wxTreeCtrl::SetItemSelectedImage(const wxTreeItemId& item, int image)
+{
+ wxCHECK_RET( item.IsOk(), _T("invalid tree item") );
+
+ wxClientDC dc(this);
+ wxGenericTreeItem *pItem = item.m_pItem;
+ pItem->SetSelectedImage(image);
+ CalculateSize(pItem, dc);
+ RefreshLine(pItem);
+}
+
+void wxTreeCtrl::SetItemData(const wxTreeItemId& item, wxTreeItemData *data)
+{
+ wxCHECK_RET( item.IsOk(), _T("invalid tree item") );
+
+ item.m_pItem->SetData(data);
+}
+
+void wxTreeCtrl::SetItemHasChildren(const wxTreeItemId& item, bool has)
+{
+ wxCHECK_RET( item.IsOk(), _T("invalid tree item") );
+
+ wxGenericTreeItem *pItem = item.m_pItem;
+ pItem->SetHasPlus(has);
+ RefreshLine(pItem);
+}
+
+void wxTreeCtrl::SetItemBold(const wxTreeItemId& item, bool bold)
+{
+ wxCHECK_RET( item.IsOk(), _T("invalid tree item") );
+
+ // avoid redrawing the tree if no real change
+ wxGenericTreeItem *pItem = item.m_pItem;
+ if ( pItem->IsBold() != bold )
+ {
+ pItem->SetBold(bold);
+ RefreshLine(pItem);
+ }
+}
+
+// -----------------------------------------------------------------------------
+// item status inquiries
+// -----------------------------------------------------------------------------
+
+bool wxTreeCtrl::IsVisible(const wxTreeItemId& WXUNUSED(item)) const
+{
+ wxFAIL_MSG(_T("not implemented"));
+
+ return TRUE;
+}
+
+bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId& item) const
+{
+ wxCHECK_MSG( item.IsOk(), FALSE, _T("invalid tree item") );
+
+ return !item.m_pItem->GetChildren().IsEmpty();
+}
+
+bool wxTreeCtrl::IsExpanded(const wxTreeItemId& item) const
+{
+ wxCHECK_MSG( item.IsOk(), FALSE, _T("invalid tree item") );
+
+ return item.m_pItem->IsExpanded();
+}
+
+bool wxTreeCtrl::IsSelected(const wxTreeItemId& item) const
+{
+ wxCHECK_MSG( item.IsOk(), FALSE, _T("invalid tree item") );
+
+ return item.m_pItem->HasHilight();
+}
+
+bool wxTreeCtrl::IsBold(const wxTreeItemId& item) const
+{
+ wxCHECK_MSG( item.IsOk(), FALSE, _T("invalid tree item") );
+
+ return item.m_pItem->IsBold();
+}
+
+// -----------------------------------------------------------------------------
+// navigation
+// -----------------------------------------------------------------------------
+
+wxTreeItemId wxTreeCtrl::GetParent(const wxTreeItemId& item) const
+{
+ wxCHECK_MSG( item.IsOk(), wxTreeItemId(), _T("invalid tree item") );
+
+ return item.m_pItem->GetParent();
+}
+
+wxTreeItemId wxTreeCtrl::GetFirstChild(const wxTreeItemId& item, long& cookie) const
+{
+ wxCHECK_MSG( item.IsOk(), wxTreeItemId(), _T("invalid tree item") );
+
+ cookie = 0;
+ return GetNextChild(item, cookie);
+}
+
+wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& item, long& cookie) const
+{
+ wxCHECK_MSG( item.IsOk(), wxTreeItemId(), _T("invalid tree item") );
+
+ wxArrayGenericTreeItems& children = item.m_pItem->GetChildren();
+ if ( (size_t)cookie < children.Count() )
+ {
+ return children.Item(cookie++);
+ }
+ else
+ {
+ // there are no more of them
+ return wxTreeItemId();
+ }
+}
+
+wxTreeItemId wxTreeCtrl::GetLastChild(const wxTreeItemId& item) const
+{
+ wxCHECK_MSG( item.IsOk(), wxTreeItemId(), _T("invalid tree item") );
+
+ wxArrayGenericTreeItems& children = item.m_pItem->GetChildren();
+ return (children.IsEmpty() ? wxTreeItemId() : wxTreeItemId(children.Last()));
+}
+
+wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const
+{
+ wxCHECK_MSG( item.IsOk(), wxTreeItemId(), _T("invalid tree item") );
+
+ wxGenericTreeItem *i = item.m_pItem;
+ wxGenericTreeItem *parent = i->GetParent();
+ if ( parent == NULL )
+ {
+ // root item doesn't have any siblings
+ return wxTreeItemId();
+ }
+
+ wxArrayGenericTreeItems& siblings = parent->GetChildren();
+ int index = siblings.Index(i);
+ wxASSERT( index != wxNOT_FOUND ); // I'm not a child of my parent?
+
+ size_t n = (size_t)(index + 1);
+ return n == siblings.Count() ? wxTreeItemId() : wxTreeItemId(siblings[n]);
+}
+
+wxTreeItemId wxTreeCtrl::GetPrevSibling(const wxTreeItemId& item) const
+{
+ wxCHECK_MSG( item.IsOk(), wxTreeItemId(), _T("invalid tree item") );
+
+ wxGenericTreeItem *i = item.m_pItem;
+ wxGenericTreeItem *parent = i->GetParent();
+ if ( parent == NULL )
+ {
+ // root item doesn't have any siblings
+ return wxTreeItemId();
+ }
+
+ wxArrayGenericTreeItems& siblings = parent->GetChildren();
+ int index = siblings.Index(i);
+ wxASSERT( index != wxNOT_FOUND ); // I'm not a child of my parent?
+
+ return index == 0 ? wxTreeItemId()
+ : wxTreeItemId(siblings[(size_t)(index - 1)]);
+}
+
+wxTreeItemId wxTreeCtrl::GetFirstVisibleItem() const
+{
+ wxFAIL_MSG(_T("not implemented"));
+
+ return wxTreeItemId();
+}
+
+wxTreeItemId wxTreeCtrl::GetNextVisible(const wxTreeItemId& item) const
+{
+ wxCHECK_MSG( item.IsOk(), wxTreeItemId(), _T("invalid tree item") );
+
+ wxFAIL_MSG(_T("not implemented"));
+
+ return wxTreeItemId();
+}
+
+wxTreeItemId wxTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const
+{
+ wxCHECK_MSG( item.IsOk(), wxTreeItemId(), _T("invalid tree item") );
+
+ wxFAIL_MSG(_T("not implemented"));
+
+ return wxTreeItemId();
+}
+
+// -----------------------------------------------------------------------------
+// operations
+// -----------------------------------------------------------------------------
+
+wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parentId,
+ size_t previous,
+ const wxString& text,
+ int image, int selImage,
+ wxTreeItemData *data)
+{
+ wxGenericTreeItem *parent = parentId.m_pItem;
+ if ( !parent )
+ {
+ // should we give a warning here?
+ return AddRoot(text, image, selImage, data);
+ }
+
+ wxClientDC dc(this);
+ wxGenericTreeItem *item = new wxGenericTreeItem(parent,
+ text, dc,
+ image, selImage,
+ data);
+
+ if ( data != NULL )
+ {
+ data->m_pItem = item;
+ }
+
+ parent->Insert( item, previous );
+
+ m_dirty = TRUE;
+
+ return item;
+}
+
+wxTreeItemId wxTreeCtrl::AddRoot(const wxString& text,
+ int image, int selImage,
+ wxTreeItemData *data)
+{
+ wxCHECK_MSG( !m_anchor, wxTreeItemId(), _T("tree can have only one root") );
+
+ wxClientDC dc(this);
+ m_anchor = new wxGenericTreeItem((wxGenericTreeItem *)NULL, text, dc,
+ image, selImage, data);
+ if ( data != NULL )
+ {
+ data->m_pItem = m_anchor;
+ }
+
+ Refresh();
+ AdjustMyScrollbars();
+
+ return m_anchor;
+}
+
+wxTreeItemId wxTreeCtrl::PrependItem(const wxTreeItemId& parent,
+ const wxString& text,
+ int image, int selImage,
+ wxTreeItemData *data)
+{
+ return DoInsertItem(parent, 0u, text, image, selImage, data);
+}
+
+wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parentId,
+ const wxTreeItemId& idPrevious,
+ const wxString& text,
+ int image, int selImage,
+ wxTreeItemData *data)
+{
+ wxGenericTreeItem *parent = parentId.m_pItem;
+ if ( !parent )
+ {
+ // should we give a warning here?
+ return AddRoot(text, image, selImage, data);
+ }
+
+ int index = parent->GetChildren().Index(idPrevious.m_pItem);
+ wxASSERT_MSG( index != wxNOT_FOUND,
+ _T("previous item in wxTreeCtrl::InsertItem() is not a sibling") );
+ return DoInsertItem(parentId, (size_t)++index, text, image, selImage, data);
+}
+
+wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parentId,
+ const wxString& text,
+ int image, int selImage,
+ wxTreeItemData *data)
+{
+ wxGenericTreeItem *parent = parentId.m_pItem;
+ if ( !parent )
+ {
+ // should we give a warning here?
+ return AddRoot(text, image, selImage, data);
+ }