GtkDropTarget — Event controller to receive DND drops
GtkDropTarget * | gtk_drop_target_new () |
void | gtk_drop_target_set_gtypes () |
const GType * | gtk_drop_target_get_gtypes () |
GdkContentFormats * | gtk_drop_target_get_formats () |
void | gtk_drop_target_set_actions () |
GdkDragAction | gtk_drop_target_get_actions () |
void | gtk_drop_target_set_preload () |
gboolean | gtk_drop_target_get_preload () |
GdkDrop * | gtk_drop_target_get_drop () |
const GValue * | gtk_drop_target_get_value () |
void | gtk_drop_target_reject () |
GdkDragAction | actions | Read / Write |
GdkDrop * | drop | Read |
GdkContentFormats * | formats | Read |
gboolean | preload | Read / Write |
GValue * | value | Read |
gboolean | accept | Run Last |
gboolean | drop | Run Last |
GdkDragAction | enter | Run Last |
void | leave | Run Last |
GdkDragAction | motion | Run Last |
GObject ╰── GtkEventController ╰── GtkDropTarget
#include <gtk/gtk.h>
GtkDropTarget is an event controller implementing a simple way to receive Drag-and-Drop operations.
The most basic way to use a GtkDropTarget to receive drops on a widget is to create it via gtk_drop_target_new()
passing in the GType of the data you want to receive and connect to the GtkDropTarget::drop signal to receive the data.
GtkDropTarget supports more options, such as:
rejecting potential drops via the “accept” signal and the gtk_drop_target_reject()
function to let other drop targets handle the drop
tracking an ongoing drag operation before the drop via the “enter”, “motion” and “leave” signals
configuring how to receive data by setting the “preload” property and listening for its availability via the “value” property
However, GtkDropTarget is ultimately modeled in a synchronous way and only supports data transferred via GType. If you want full control over an ongoing drop, the GtkDropTargetAsync object gives you this ability.
While a pointer is dragged over the drop target's widget and the drop has not been rejected, that widget will receive the GTK_STATE_FLAG_DROP_ACTIVE
state, which can be used to style the widget.
GtkDropTarget * gtk_drop_target_new (GType type
,GdkDragAction actions
);
Creates a new GtkDropTarget object.
If the drop target should support more than 1 type, pass G_TYPE_INVALID
for type
and then call gtk_drop_target_set_gtypes()
.
type | The supported type or | |
actions | the supported actions |
the new GtkDropTarget
void gtk_drop_target_set_gtypes (GtkDropTarget *self
,GType *types
,gsize n_types
);
Sets the supported GTypes for this drop target.
The GtkDropTarget::drop signal will
self | ||
types | all supported GTypes that can be dropped. | [nullable][transfer none][array length=n_types] |
n_types | number of |
const GType * gtk_drop_target_get_gtypes (GtkDropTarget *self
,gsize *n_types
);
Gets the list of supported GTypes for self
. If no type have been set, NULL
will be returned.
self | ||
n_types | optional pointer to take the number of GTypes contained in the return value. | [out][optional] |
G_TYPE_INVALID
-terminated array of types included in formats
or NULL
if none.
[transfer none][nullable][array length=n_types]
GdkContentFormats *
gtk_drop_target_get_formats (GtkDropTarget *self
);
Gets the data formats that this drop target accepts.
If the result is NULL
, all formats are expected to be supported.
self |
the supported data formats.
[nullable]
void gtk_drop_target_set_actions (GtkDropTarget *self
,GdkDragAction actions
);
Sets the actions that this drop target supports.
self | ||
actions | the supported actions |
GdkDragAction
gtk_drop_target_get_actions (GtkDropTarget *self
);
Gets the actions that this drop target supports.
self |
the actions that this drop target supports
void gtk_drop_target_set_preload (GtkDropTarget *self
,gboolean preload
);
Sets the GtkDropTarget:preload property.
self | ||
preload |
|
gboolean
gtk_drop_target_get_preload (GtkDropTarget *self
);
Gets the value of the GtkDropTarget:preload property.
self |
TRUE
if drop data should be preloaded
GdkDrop *
gtk_drop_target_get_drop (GtkDropTarget *self
);
Gets the currently handled drop operation.
If no drop operation is going on, NULL
is returned.
self |
The current drop.
[nullable][transfer none]
const GValue *
gtk_drop_target_get_value (GtkDropTarget *self
);
Gets the value of the GtkDropTarget:value property.
self |
The current drop data.
[nullable][transfer none]
void
gtk_drop_target_reject (GtkDropTarget *self
);
Rejects the ongoing drop operation.
If no drop operation is ongoing - when GdkDropTarget:drop returns NULL
- this function does nothing.
This function should be used when delaying the decision on whether to accept a drag or not until after reading the data.
self |
typedef struct _GtkDropTarget GtkDropTarget;
“actions”
property“actions” GdkDragAction
The GdkDragActions that this drop target supports
Owner: GtkDropTarget
Flags: Read / Write
“drop”
property“drop” GdkDrop *
The GdkDrop that is currently being performed
Owner: GtkDropTarget
Flags: Read
“formats”
property“formats” GdkContentFormats *
The GdkContentFormats that determine the supported data formats
Owner: GtkDropTarget
Flags: Read
“preload”
property“preload” gboolean
Whether the drop data should be preloaded when the pointer is only hovering over the widget but has not been released.
Setting this property allows finer grained reaction to an ongoing drop at the cost of loading more data.
The default value for this property is FALSE
to avoid downloading huge amounts of data by accident. For example, if somebody drags a full document of gigabytes of text from a text editor across a widget with a preloading drop target, this data will be downloaded, even if the data is ultimately dropped elsewhere.
For a lot of data formats, the amount of data is very small (like GDK_TYPE_RGBA
), so enabling this property does not hurt at all. And for local-only drag'n'drop operations, no data transfer is done, so enabling it there is free.
Owner: GtkDropTarget
Flags: Read / Write
Default value: FALSE
“value”
property“value” GValue *
The value for this drop operation or NULL
if the data has not been loaded yet or no drop operation is going on.
Data may be available before the GtkDropTarget::drop signal gets emitted - for example when the GtkDropTarget:preload property is set. You can use the GObject::notify signal to be notified of available data.
Owner: GtkDropTarget
Flags: Read
“accept”
signalgboolean user_function (GtkDropTarget *self, GdkDrop *drop, gpointer user_data)
The ::accept signal is emitted on the drop site when a drop operation is about to begin. If the drop is not accepted, FALSE
will be returned and the drop target will ignore the drop. If TRUE
is returned, the drop is accepted for now but may be rejected later via a call to gtk_drop_target_reject()
or ultimately by returning FALSE
from GtkDropTarget::drop
The default handler for this signal decides whether to accept the drop based on the formats provided by the drop
.
If the decision whether the drop will be accepted or rejected needs inspecting the data, this function should return TRUE
, the GtkDropTarget:preload property should be set and the value should be inspected via the GObject::notify:value signal and then call gtk_drop_target_reject()
.
self | the GtkDropTarget | |
drop | the GdkDrop | |
user_data | user data set when the signal handler was connected. |
TRUE
if drop
is accepted
Flags: Run Last
“drop”
signalgboolean user_function (GtkDropTarget *self, GValue *value, double x, double y, gpointer user_data)
The ::drop signal is emitted on the drop site when the user drops the data onto the widget. The signal handler must determine whether the pointer position is in a drop zone or not. If it is not in a drop zone, it returns FALSE
and no further processing is necessary.
Otherwise, the handler returns TRUE
. In this case, this handler will accept the drop. The handler is responsible for rading the given value
and performing the drop operation.
self | the GtkDropTarget | |
value | the GValue being dropped | |
x | the x coordinate of the current pointer position | |
y | the y coordinate of the current pointer position | |
user_data | user data set when the signal handler was connected. |
whether the drop was accepted at the given pointer position
Flags: Run Last
“enter”
signalGdkDragAction user_function (GtkDropTarget *self, double x, double y, gpointer user_data)
The ::enter signal is emitted on the drop site when the pointer enters the widget. It can be used to set up custom highlighting.
self | the GtkDropTarget | |
x | the x coordinate of the current pointer position | |
y | the y coordinate of the current pointer position | |
user_data | user data set when the signal handler was connected. |
Preferred action for this drag operation or 0 if dropping is not supported at the current x
,y
location.
Flags: Run Last
“leave”
signalvoid user_function (GtkDropTarget *self, gpointer user_data)
The ::leave signal is emitted on the drop site when the pointer leaves the widget. Its main purpose it to undo things done in “enter”.
self | the GtkDropTarget | |
user_data | user data set when the signal handler was connected. |
Flags: Run Last
“motion”
signalGdkDragAction user_function (GtkDropTarget *self, double x, double y, gpointer user_data)
The ::motion signal is emitted while the pointer is moving over the drop target.
self | the GtkDropTarget | |
x | the x coordinate of the current pointer position | |
y | the y coordinate of the current pointer position | |
user_data | user data set when the signal handler was connected. |
Preferred action for this drag operation or 0 if dropping is not supported at the current x
,y
location.
Flags: Run Last
© 2005–2020 The GNOME Project
Licensed under the GNU Lesser General Public License version 2.1 or later.
https://developer.gnome.org/gtk4/4.0/GtkDropTarget.html