+void MyTreeCtrl::OnBeginDrag(wxTreeEvent& event)
+{
+ // need to explicitly allow drag
+ if ( event.GetItem() != GetRootItem() )
+ {
+ m_draggedItem = event.GetItem();
+
+ wxLogMessage("OnBeginDrag: started dragging %s",
+ GetItemText(m_draggedItem).c_str());
+
+ event.Allow();
+ }
+ else
+ {
+ wxLogMessage("OnBeginDrag: this item can't be dragged.");
+ }
+}
+
+void MyTreeCtrl::OnEndDrag(wxTreeEvent& event)
+{
+ wxTreeItemId itemSrc = m_draggedItem,
+ itemDst = event.GetItem();
+ m_draggedItem = (wxTreeItemId)0l;
+
+ // where to copy the item?
+ if ( itemDst.IsOk() && !ItemHasChildren(itemDst) )
+ {
+ // copy to the parent then
+ itemDst = GetParent(itemDst);
+ }
+
+ if ( !itemDst.IsOk() )
+ {
+ wxLogMessage("OnEndDrag: can't drop here.");
+
+ return;
+ }
+
+ wxString text = GetItemText(itemSrc);
+ wxLogMessage("OnEndDrag: '%s' copied to '%s'.",
+ text.c_str(), GetItemText(itemDst).c_str());
+
+ // just do append here - we could also insert it just before/after the item
+ // on which it was dropped, but this requires slightly more work... we also
+ // completely ignore the client data and icon of the old item but could
+ // copy them as well.
+ //
+ // Finally, we only copy one item here but we might copy the entire tree if
+ // we were dragging a folder.
+ AppendItem(itemDst, text, TreeCtrlIcon_File);
+}
+