wxRuby Documentation Home

# Wx::DropSource

This class represents a source for a drag and drop operation.

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

DropTarget,
TextDropTarget, FileDropTarget

## Methods

- DropSource.new
- DropSource#set_data
- DropSource#do_drag_drop
- DropSource#get_data_object
- DropSource#give_feedback
- DropSource#set_cursor

### DropSource.new

DropSource.new(%(arg-type)Window% win = nil, IconOrCursor iconCopy = NullIconOrCursor, IconOrCursor iconMove = NullIconOrCursor, IconOrCursor iconNone = NullIconOrCursor) DropSource.new(%(arg-type)DataObject% data, Window win = nil, IconOrCursor iconCopy = NullIconOrCursor, IconOrCursor iconMove = NullIconOrCursor, IconOrCursor iconNone = NullIconOrCursor)

The constructors for DataObject.

If you use the constructor without data parameter you must call
set_data later.

Note that the exact type of iconCopy and subsequent parameters differs
between MSW and GTK: these are cursors under Windows but icons for GTK.
You should use the macro DROP_ICON in portable
programs instead of directly using either of these types.

#### Parameters

- win The window which initiates the drag and drop operation.
- iconCopy The icon or cursor used for feedback for copy operation.
- iconMove The icon or cursor used for feedback for move operation.
- iconNone The icon or cursor used for feedback when operation can’t be done.

win is the window which initiates the drag and drop operation.

destructor()

### DropSource#set_data

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

Sets the data DataObject associated with the
drop source. This will not delete any previously associated data.

### DropSource#do_drag_drop

DragResult do_drag_drop(%(arg-type)Integer% flags = `Drag_CopyOnly`)

Do it (call this in response to a mouse button press, for example). This starts
the drag-and-drop operation which will terminate when the user releases the
mouse.

#### Parameters

- flags If `Drag_AllowMove` is included in the flags, data may
  be moved and not only copied (default). If `Drag_DefaultMove` is
  specified (which includes the previous flag), this is even the default
  operation.

#### Return value

Returns the operation requested by the user, may be `DragCopy`,
DragMove, `DragLink`, `DragCancel` or `DragNone` if an error occurred.

### DropSource#get_data_object

DataObject get_data_object()

Returns the DataObject object that has been assigned previously.

### DropSource#give_feedback

Boolean give_feedback(%(arg-type)DragResult% effect)

Overridable: you may give some custom UI feedback during the drag and drop operation
in this function. It is called on each mouse move, so your implementation must not be too
slow.

#### Parameters

- effect The effect to implement. One of `DragCopy`, `DragMove`, `DragLink` and `DragNone`.
- scrolling true if the window is scrolling. MSW only.

#### Return value

Return false if you want default feedback, or true if you implement your own
feedback. The return values is ignored under GTK.

### DropSource#set_cursor

set_cursor(%(arg-type)DragResult% res, Cursor cursor)

Set the icon to use for a certain drag result.

#### Parameters

- res The drag result to set the icon for.
- cursor The ion to show when this drag result occurs.

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