this is probably too late to help you, but for anyone else:
Note that this is based on some old code that I have lying around. JUCE may well have new methods to simplify some of this, but at least if you can get it working, you can work out how to improve it yourself…
basically, what you need to do is simply create a treeview class, and treeitem class, and component class, as such:
class MyTreeViewItemComponent()
{
public:
MyTreeViewItemComponent(TreeViewItem& creatorItem);
~MyTreeViewItemComponent();
virtual void mouseDrag(const MouseEvent& e);
virtual void mouseDown(const MouseEvent& e);
virtual void paint(Graphics& g);
private:
TreeViewItem* _creatorItem;
};
In your ctor, assign the reference to the creator tree view item to the _creatorItem pointer.
In the mouseDown() simply call _creatorItem->setSelected(true, true) to let the creator item know that the user has selected this item.
Your mouse down will be used to build your drag and drop behaviour, so we’ll look at that later.
The paint method should simply paint your item. You can call _creatorItem->getUniqueName() to get the text for the item. For a file list, the uinque name will most likely be the fully qualified file path of the item.
Now implement your TreeViewItem sub class as normal, but override the method createItemComponent() as follows:
Component* MyTreeViewItem::createItemComponent()
{
MyTreeViewComponent* newComp = new MyTreeViewComponent(this);
return newComp;
}
In addition to this, you’ll probably find yourself burying at least some of the logic for building the tree list into your TreeViewItem subclass.
Because Windows can have multiple drives, you may find it best to leave the root node as an empty string, and create your drives and directories as children of the root.
OK, so the last thing you need to do, other than implement your TreeView subclass, is to implement the mousedrag method in your custom tree view item component.
As long as one of your higher level components derives from DragAndDropContainer, you simpky need to make the mouseDrag() method look something like:
void MyTreeViewComponent::mouseDrag(const MouseEvent& e)
{
DragAndDropContainer* dragC = DragAndDropContainer::findParentDragContainerFor(this);
if (!dragC->isDragAndDropActive())
{
dragC->startDragging(_creatorItem->getUniqueName(), this);
}
}
Because you are passing a string that describes the DnD operation, you can do put any kind of data in there that you want. In this instance we are just passing the unique name of the TreeView item.
omissions and errors are likely as I did that from memory, and it was a long time ago that I last did this.