| Version: 3.3.1

Public Member Functions | List of all members
wxDropTarget Class Referenceabstract
Class List by Category » Clipboard and Drag & Drop

`#include <wx/dnd.h>`

Inheritance diagram for wxDropTarget:
[legend]

## Detailed Description

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(), OnDragOver() possibly many times, OnDrop() and finally OnData().

##

Library: wxCore
Category: Clipboard and Drag & Drop

See also
  Drag and Drop Overview, wxDataObject Overview, wxDropSource, wxTextDropTarget, wxFileDropTarget, wxDataFormat, wxDataObject

## Public Member Functions
| wxDropTarget (wxDataObject *data=nullptr)
| Constructor. More...
virtual | ~wxDropTarget ()
| Destructor. More...
virtual bool | GetData ()
| This method may only be called from within OnData(). More...
virtual wxDragResult | OnData (wxCoord x, wxCoord y, wxDragResult defResult)=0
| Called after OnDrop() returns true. More...
virtual wxDragResult | OnDragOver (wxCoord x, wxCoord y, wxDragResult defResult)
| Called when the mouse is being dragged over the drop target. More...
virtual bool | OnDrop (wxCoord x, wxCoord y)
| Called when the user drops a data object on the target. More...
virtual wxDragResult | OnEnter (wxCoord x, wxCoord y, wxDragResult defResult)
| Called when the mouse enters the drop target. More...
virtual void | OnLeave ()
| Called when the mouse leaves the drop target. More...
wxDataObject * | GetDataObject () const
| Returns the data wxDataObject associated with the drop target. More...
void | SetDataObject (wxDataObject *data)
| Sets the data wxDataObject associated with the drop target and deletes any previously associated data object. More...
void | SetDefaultAction (wxDragResult action)
| Sets the default action for drag and drop. More...
wxDragResult | GetDefaultAction ()
| Returns default action for drag and drop or wxDragNone if this not specified. More...

## Constructor & Destructor Documentation

## ◆ wxDropTarget()

wxDropTarget::wxDropTarget | ( | wxDataObject * | data = `nullptr` | ) |

Constructor.

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

## ◆ ~wxDropTarget()

virtual wxDropTarget::~wxDropTarget | ( |  | ) |
| virtual

Destructor.

Deletes the associated data object, if any.

## Member Function Documentation

## ◆ GetData()

virtual bool wxDropTarget::GetData | ( |  | ) |
| virtual

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.

## ◆ GetDataObject()

wxDataObject* wxDropTarget::GetDataObject | ( |  | ) | const

Returns the data wxDataObject associated with the drop target.

## ◆ GetDefaultAction()

wxDragResult wxDropTarget::GetDefaultAction | ( |  | ) |

Returns default action for drag and drop or wxDragNone if this not specified.

## ◆ OnData()

virtual wxDragResult wxDropTarget::OnData | ( | wxCoord | x,
|  | wxCoord | y,
|  | wxDragResult | defResult
| ) |  |
| pure virtual

Called after OnDrop() returns true.

By default this will usually GetData() and will return the suggested default value defResult.

## ◆ OnDragOver()

virtual wxDragResult wxDropTarget::OnDragOver | ( | wxCoord | x,
|  | wxCoord | y,
|  | wxDragResult | defResult
| ) |  |
| virtual

Called when the mouse is being dragged over the drop target.

By default, this calls functions return the suggested return value defResult.

Parameters

  x | The x coordinate of the mouse.
  y | The y coordinate of the mouse.
  defResult | Suggested value for return value. Determined by SHIFT or CONTROL key states.

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.

## ◆ OnDrop()

virtual bool wxDropTarget::OnDrop | ( | wxCoord | x,
|  | wxCoord | y
| ) |  |
| virtual

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.

Returns
  true to accept the data, or false to veto the operation.

Reimplemented in wxFileDropTarget, and wxTextDropTarget.

## ◆ OnEnter()

virtual wxDragResult wxDropTarget::OnEnter | ( | wxCoord | x,
|  | wxCoord | y,
|  | wxDragResult | defResult
| ) |  |
| virtual

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.
  defResult | Suggested default for return value. Determined by SHIFT or CONTROL key states.

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.

## ◆ OnLeave()

virtual void wxDropTarget::OnLeave | ( |  | ) |
| virtual

Called when the mouse leaves the drop target.

## ◆ SetDataObject()

void wxDropTarget::SetDataObject | ( | wxDataObject * | data | ) |

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

## ◆ SetDefaultAction()

void wxDropTarget::SetDefaultAction | ( | wxDragResult | action | ) |

Sets the default action for drag and drop.

Use wxDragMove or wxDragCopy to set default action to move or copy and use wxDragNone (default) to set default action specified by initialization of dragging (see wxDropSource::DoDragDrop())