wxRuby Documentation Home

# Wx::DropTarget

This class represents a target for a drag and drop operation. A DataObject
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
on_enter, possibly many times on_drag_over,
on_drop and finally on_data.

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

## Derived from

None

## Types

DragResultDragResult is defined as follows:

enum DragResult { DragError, // error prevented the d&d operation from completing DragNone, // drag target didn’t accept the data DragCopy, // the data was successfully copied DragMove, // the data was successfully moved (MSW only) DragLink, // operation is a drag-link DragCancel // the operation was cancelled by user (not an error) };

## See also

DropSource,
TextDropTarget, FileDropTarget,
DataFormat, DataObject

## Methods

- DropTarget.new
- DropTarget#get_data
- DropTarget#on_data
- DropTarget#on_drop
- DropTarget#on_enter
- DropTarget#on_drag_over
- DropTarget#on_leave
- DropTarget#set_data_object

### DropTarget.new

DropTarget.new(%(arg-type)DataObject% data = nil)

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

destructor()

Destructor. Deletes the associated data object, if any.

### DropTarget#get_data

get_data()

This method may only be called from within on_data.
By default, this method copies the data from the drop source to the
DataObject associated with this drop target,
calling its DataObject#set_data method.

### DropTarget#on_data

DragResult on_data(%(arg-type)Integer% x, Integer y, DragResult def)

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

### DropTarget#on_drop

Boolean on_drop(%(arg-type)Integer% x, Integer 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.

### DropTarget#on_enter

DragResult on_enter(%(arg-type)Integer% x, Integer y, DragResult def)

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

#### 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 `DragNone`. This is used for optical feedback
from the side of the drop source, typically in form of changing the icon.

### DropTarget#on_drag_over

DragResult on_drag_over(%(arg-type)Integer% x, Integer y, DragResult 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 `DragNone`. This is used for optical feedback
from the side of the drop source, typically in form of changing the icon.

### DropTarget#on_leave

on_leave()

Called when the mouse leaves the drop target.

### DropTarget#set_data_object

set_data_object(%(arg-type)DataObject% data)

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

[This page automatically generated from the Textile source at 2023-06-09 00:45:29 +0000]