Version: 2.9.4
Drag and Drop Overview

Classes: wxDataObject, wxTextDataObject, wxDropSource, wxDropTarget, wxTextDropTarget, wxFileDropTarget

Note that wxUSE_DRAG_AND_DROP must be defined in setup.h in order to use drag and drop in wxWidgets.

See also: wxDataObject Overview and Drag & Drop Sample.

It may be noted that data transfer to and from the clipboard is quite similar to data transfer with drag and drop and the code to implement these two types is almost the same. In particular, both data transfer mechanisms store data in some kind of wxDataObject and identify its format(s) using the wxDataFormat class.

To be a drag source, i.e. to provide the data which may be dragged by the user elsewhere, you should implement the following steps:

    wxTextDataObject my_data("This text will be dragged.");
    wxDropSource dragSource( this );
    dragSource.SetData( my_data );
    wxDragResult result = dragSource.DoDragDrop( true );
    switch (result)
    {
        case wxDragCopy:
            // copy the data
            break;
        case wxDragMove:
            // move the data
            break;
        default:
            // do nothing
            break;
    }

To be a drop target, i.e. to receive the data dropped by the user you should follow the instructions below: