Sets the calling widget as a drag-and-drop destination.
flags is one of four
GtkDestDefaults values which define how the widget
reacts when the drag is over the widget.
The targets parameter defines a list with all
data types which can be dropped over the widget. The parameter is an
array of arrays of size three:
In our example, the widget would accept textual data and files. The
files could be dragged from everywhere (flag
parameter 0), but the textual data are only accepted if they come
from within our application.
It is not possible to use
a "*" mime type in the target.
The flags of the targets
determine from which widget the drag has to come from:
Table 9. Values for flags
0
Accept drags from everywhere.
GTK_TARGET_SAME_APP
Accept drags only from widgets of the same application only.
GTK_TARGET_SAME_WIDGET
Accept drags only from the same widget. This is useful for
e.g. moving items up/down in a list by dragging them.
info allows you to pass a number to the
function connected to the
"drag-data-received"
signal. This is useful when e.g. allowing multiple image types to
be dropped, as well as some other non-image types: All image types
could be assigned "1" as info parameter, all other types "2" or so.
In the drag received function could pass the necessary data to
a image open function by checking if the info
parameter is "1", without having to compare the mime type.
Example 57. Using the info parameter
define('TYPE_IMAGE', 1);
define('TYPE_PDF' , 2);
define('TYPE_OTHER', 3);
$targets = array(
array( 'image/jpg' , 0, TYPE_IMAGE),
array( 'image/jpeg', 0, TYPE_IMAGE),
array( 'image/gif' , 0, TYPE_IMAGE),
array( 'image/png' , 0, TYPE_IMAGE),
array( 'application/pdf', 0, TYPE_PDF),
array( 'text/plain' , 0, TYPE_OTHER)
);
$list->drag_dest_set(GTK_DEST_DEFAULT_ALL, $targets, GDK_ACTION_COPY | GDK_ACTION_MOVE);
$list->connect('drag-data-received', 'dnd_drag_data_received');
function dnd_drag_data_received( $widget, $context, $x, $y, $data, $info, $time)
{
if( $info == TYPE_IMAGE) { handle_image( $data); return; }
//do different things with pdf and other type here
}