Classes: wxDataObject, wxTextDataObject, wxDropSource, wxDropTarget, wxTextDropTarget, wxFileDropTarget
It has to be noted that the API for drag and drop in wxWindows is not yet finished which is mostly due to the fact that DnD support under GTK 1.0 is very rudimentary and entirely different from the XDnD protocoll used by GTK 1.2. This also entails that not all of the documentation concerning DnD might be correct and some of the code might get broken in the future. The next release of wxWindows will be based on GTK 1.2 and will hopefully include a much improved DnD support. The general design on the wxDropSource side will be the same but especially the wxDropTarget is almost certain to change.
Note that wxUSE_DRAG_AND_DROP must be defined in setup.h in order to use Drag'n'Drop in wxWindows.
This overview describes wxWindows support for drag and drop and clipboard operations. Both of these topics are discussed here because, in fact, they're quite related. Drag and drop and clipboard are just two ways of passing the data around and so the code required to implement both types of the operations is almost the same.
Both operations involve passing some data from one program to another, although the data can be received in the same program as the source. In the case of clipboard transfer, the data is first placed on the clipboard and then pasted into the destination program, while for a drag-and-drop operation the data object is not stored anywhere but is created when the user starts dragging and is destroyed as soon as he ends it, whether the operation was ended successfully or cancelled.
To be a drag source, i.e. to provide the data which may be dragged by user elsewhere, you should implement the following steps:
wxDataObject *my_data = new wxTextDataObject data("This string will be dragged.");
wxDropSource dragSource( this ); dragSource.SetData( my_data );
To be a drop target, i.e. to receive the data dropped by user you should follow the instructions below: