wxDropTarget

This class represents a target for a drag and drop operation. A wxDataObject can be associated with it and by default, this object will be filled with the data from the drag source, if the data formats supported by the data object match the drag source data format.

There are various virtual handler functions defined in this class which may be overridden to give visual feedback or react in a more fine-tuned way, e.g. by not accepting data on the whole window area, but only a small portion of it. The normal sequence of calls is OnEnter, possibly many times OnDragOver, OnDrop and finally OnData.

See Drag and drop overview and wxDataObject overview for more information.

Derived from

None

Include files

<wx/dnd.h>

Types

wxDragResult is defined as follows:

enum wxDragResult
{
    wxDragError,    // error prevented the d&d operation from completing
    wxDragNone,     // drag target didn't accept the data
    wxDragCopy,     // the data was successfully copied
    wxDragMove,     // the data was successfully moved (MSW only)
    wxDragLink,     // operation is a drag-link
    wxDragCancel    // the operation was cancelled by user (not an error)
};

See also

wxDropSource, wxTextDropTarget, wxFileDropTarget, wxDataFormat, wxDataObject



wxDropTarget::wxDropTarget



wxDropTarget(wxDataObject* data = NULL)

Constructor. data is the data to be associated with the drop target.



wxDropTarget::~wxDropTarget



~wxDropTarget(void)

Destructor. Deletes the associated data object, if any.



wxDropTarget::GetData



virtual void GetData(void)

This method may only be called from within OnData. By default, this method copies the data from the drop source to the wxDataObject associated with this drop target, calling its wxDataObject::SetData method.



wxDropTarget::OnData



virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def)

Called after OnDrop returns true. By default this will usually GetData and will return the suggested default value def.



wxDropTarget::OnDrop



virtual bool OnDrop(wxCoord x, wxCoord y)

Called when the user drops a data object on the target. Return false to veto the operation.

Parameters

x
The x coordinate of the mouse.

y
The y coordinate of the mouse.

Return value

Return true to accept the data, false to veto the operation.



wxDropTarget::OnEnter



virtual wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult def)

Called when the mouse enters the drop target. By default, this calls OnDragOver.

Parameters

x
The x coordinate of the mouse.

y
The y coordinate of the mouse.

def
Suggested default for return value. Determined by SHIFT or CONTROL key states.

Return value

Returns the desired operation or wxDragNone. This is used for optical feedback from the side of the drop source, typically in form of changing the icon.



wxDropTarget::OnDragOver



virtual wxDragResult OnDragOver(wxCoord x, wxCoord y, wxDragResult def)

Called when the mouse is being dragged over the drop target. By default, this calls functions return the suggested return value def.

Parameters

x
The x coordinate of the mouse.

y
The y coordinate of the mouse.

def
Suggested value for return value. Determined by SHIFT or CONTROL key states.

Return value

Returns the desired operation or wxDragNone. This is used for optical feedback from the side of the drop source, typically in form of changing the icon.



wxDropTarget::OnLeave



virtual void OnLeave(void)

Called when the mouse leaves the drop target.



wxDropTarget::SetDataObject



void SetDataObject(wxDataObject* data)

Sets the data wxDataObject associated with the drop target and deletes any previously associated data object.

ymasuda 平成17年11月19日