Package ch.bailu.gtk.gtk
Class DragSource
- All Implemented Interfaces:
PointerInterface
`GtkDragSource` is an event controller to initiate Drag-And-Drop operations.
`GtkDragSource` can be set up with the necessary
ingredients for a DND operation ahead of time. This includes
the source for the data that is being transferred, in the form
of a [class@Gdk.ContentProvider], the desired action, and the icon to
use during the drag operation. After setting it up, the drag
source must be added to a widget as an event controller, using
[method@Gtk.Widget.add_controller].
```c
static void
my_widget_init (MyWidget *self)
{
GtkDragSource *drag_source = gtk_drag_source_new ();
g_signal_connect (drag_source, "prepare", G_CALLBACK (on_drag_prepare), self);
g_signal_connect (drag_source, "drag-begin", G_CALLBACK (on_drag_begin), self);
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (drag_source));
}
```
Setting up the content provider and icon ahead of time only makes
sense when the data does not change. More commonly, you will want
to set them up just in time. To do so, `GtkDragSource` has
[signal@Gtk.DragSource::prepare] and [signal@Gtk.DragSource::drag-begin]
signals.
The ::prepare signal is emitted before a drag is started, and
can be used to set the content provider and actions that the
drag should be started with.
```c
static GdkContentProvider *
on_drag_prepare (GtkDragSource *source,
double x,
double y,
MyWidget *self)
{
// This widget supports two types of content: GFile objects
// and GdkPixbuf objects; GTK will handle the serialization
// of these types automatically
GFile *file = my_widget_get_file (self);
GdkPixbuf *pixbuf = my_widget_get_pixbuf (self);
return gdk_content_provider_new_union ((GdkContentProvider *[2]) {
gdk_content_provider_new_typed (G_TYPE_FILE, file),
gdk_content_provider_new_typed (GDK_TYPE_PIXBUF, pixbuf),
}, 2);
}
```
The ::drag-begin signal is emitted after the `GdkDrag` object has
been created, and can be used to set up the drag icon.
```c
static void
on_drag_begin (GtkDragSource *source,
GdkDrag *drag,
MyWidget *self)
{
// Set the widget as the drag icon
GdkPaintable *paintable = gtk_widget_paintable_new (GTK_WIDGET (self));
gtk_drag_source_set_icon (source, paintable, 0, 0);
g_object_unref (paintable);
}
```
During the DND operation, `GtkDragSource` emits signals that
can be used to obtain updates about the status of the operation,
but it is not normally necessary to connect to any signals,
except for one case: when the supported actions include
%GDK_ACTION_MOVE, you need to listen for the
[signal@Gtk.DragSource::drag-end] signal and delete the
data after it has been transferred.
`GtkDragSource` can be set up with the necessary
ingredients for a DND operation ahead of time. This includes
the source for the data that is being transferred, in the form
of a [class@Gdk.ContentProvider], the desired action, and the icon to
use during the drag operation. After setting it up, the drag
source must be added to a widget as an event controller, using
[method@Gtk.Widget.add_controller].
```c
static void
my_widget_init (MyWidget *self)
{
GtkDragSource *drag_source = gtk_drag_source_new ();
g_signal_connect (drag_source, "prepare", G_CALLBACK (on_drag_prepare), self);
g_signal_connect (drag_source, "drag-begin", G_CALLBACK (on_drag_begin), self);
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (drag_source));
}
```
Setting up the content provider and icon ahead of time only makes
sense when the data does not change. More commonly, you will want
to set them up just in time. To do so, `GtkDragSource` has
[signal@Gtk.DragSource::prepare] and [signal@Gtk.DragSource::drag-begin]
signals.
The ::prepare signal is emitted before a drag is started, and
can be used to set the content provider and actions that the
drag should be started with.
```c
static GdkContentProvider *
on_drag_prepare (GtkDragSource *source,
double x,
double y,
MyWidget *self)
{
// This widget supports two types of content: GFile objects
// and GdkPixbuf objects; GTK will handle the serialization
// of these types automatically
GFile *file = my_widget_get_file (self);
GdkPixbuf *pixbuf = my_widget_get_pixbuf (self);
return gdk_content_provider_new_union ((GdkContentProvider *[2]) {
gdk_content_provider_new_typed (G_TYPE_FILE, file),
gdk_content_provider_new_typed (GDK_TYPE_PIXBUF, pixbuf),
}, 2);
}
```
The ::drag-begin signal is emitted after the `GdkDrag` object has
been created, and can be used to set up the drag icon.
```c
static void
on_drag_begin (GtkDragSource *source,
GdkDrag *drag,
MyWidget *self)
{
// Set the widget as the drag icon
GdkPaintable *paintable = gtk_widget_paintable_new (GTK_WIDGET (self));
gtk_drag_source_set_icon (source, paintable, 0, 0);
g_object_unref (paintable);
}
```
During the DND operation, `GtkDragSource` emits signals that
can be used to obtain updates about the status of the operation,
but it is not normally necessary to connect to any signals,
except for one case: when the supported actions include
%GDK_ACTION_MOVE, you need to listen for the
[signal@Gtk.DragSource::drag-end] signal and delete the
data after it has been transferred.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
static interface
Nested classes/interfaces inherited from class ch.bailu.gtk.gtk.Gesture
Gesture.OnBegin, Gesture.OnCancel, Gesture.OnEnd, Gesture.OnSequenceStateChanged, Gesture.OnUpdate
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDestroyNotify, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
Fields inherited from class ch.bailu.gtk.gtk.Gesture
SIGNAL_ON_BEGIN, SIGNAL_ON_CANCEL, SIGNAL_ON_END, SIGNAL_ON_SEQUENCE_STATE_CHANGED, SIGNAL_ON_UPDATE
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Cancels a currently ongoing drag operation.int
Gets the actions that are currently set on the `GtkDragSource`.static ClassHandler
Gets the current content provider of a `GtkDragSource`.getDrag()
Returns the underlying `GdkDrag` object for an ongoing drag.static int
static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
onDragBegin
(DragSource.OnDragBegin signal) Connect to signal "drag-begin".onDragCancel
(DragSource.OnDragCancel signal) Connect to signal "drag-cancel".onDragEnd
(DragSource.OnDragEnd signal) Connect to signal "drag-end".onPrepare
(DragSource.OnPrepare signal) Connect to signal "prepare".void
setActions
(int actions) Sets the actions on the `GtkDragSource`.void
setContent
(ContentProvider content) Sets a content provider on a `GtkDragSource`.void
Sets a paintable to use as icon during DND operations.Methods inherited from class ch.bailu.gtk.gtk.GestureSingle
getButton, getCurrentButton, getCurrentSequence, getExclusive, getTouchOnly, setButton, setExclusive, setTouchOnly
Methods inherited from class ch.bailu.gtk.gtk.Gesture
getBoundingBox, getDevice, getGroup, getLastEvent, getLastUpdatedSequence, getSequences, getSequenceState, group, handlesSequence, isActive, isGroupedWith, isRecognized, onBegin, onCancel, onEnd, onSequenceStateChanged, onUpdate, setSequenceState, setState, ungroup
Methods inherited from class ch.bailu.gtk.gtk.EventController
getCurrentEvent, getCurrentEventDevice, getCurrentEventState, getCurrentEventTime, getName, getPropagationLimit, getPropagationPhase, getWidget, reset, setName, setName, setPropagationLimit, setPropagationPhase, setStaticName, setStaticName
Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
SIGNAL_ON_DRAG_BEGIN
- See Also:
-
SIGNAL_ON_DRAG_CANCEL
- See Also:
-
SIGNAL_ON_DRAG_END
- See Also:
-
SIGNAL_ON_PREPARE
- See Also:
-
-
Constructor Details
-
DragSource
-
DragSource
public DragSource()Creates a new `GtkDragSource` object.
-
-
Method Details
-
getClassHandler
-
dragCancel
public void dragCancel()Cancels a currently ongoing drag operation. -
getActions
public int getActions()Gets the actions that are currently set on the `GtkDragSource`.- Returns:
- the actions set on @source
-
getContent
Gets the current content provider of a `GtkDragSource`.- Returns:
- the `GdkContentProvider` of @source
-
getDrag
Returns the underlying `GdkDrag` object for an ongoing drag.- Returns:
- the `GdkDrag` of the current drag operation
-
setActions
public void setActions(int actions) Sets the actions on the `GtkDragSource`.
During a DND operation, the actions are offered to potential
drop targets. If @actions include %GDK_ACTION_MOVE, you need
to listen to the [signal@Gtk.DragSource::drag-end] signal and
handle @delete_data being %TRUE.
This function can be called before a drag is started,
or in a handler for the [signal@Gtk.DragSource::prepare] signal.- Parameters:
actions
- the actions to offer
-
setContent
Sets a content provider on a `GtkDragSource`.
When the data is requested in the cause of a DND operation,
it will be obtained from the content provider.
This function can be called before a drag is started,
or in a handler for the [signal@Gtk.DragSource::prepare] signal.
You may consider setting the content provider back to
%NULL in a [signal@Gtk.DragSource::drag-end] signal handler.- Parameters:
content
- a `GdkContentProvider`
-
setIcon
Sets a paintable to use as icon during DND operations.
The hotspot coordinates determine the point on the icon
that gets aligned with the hotspot of the cursor.
If @paintable is %NULL, a default icon is used.
This function can be called before a drag is started, or in
a [signal@Gtk.DragSource::prepare] or
[signal@Gtk.DragSource::drag-begin] signal handler.- Parameters:
paintable
- the `GdkPaintable` to use as iconhot_x
- the hotspot X coordinate on the iconhot_y
- the hotspot Y coordinate on the icon
-
onDragBegin
Connect to signal "drag-begin".
SeeDragSource.OnDragBegin.onDragBegin(ch.bailu.gtk.gdk.Drag)
for signal description.
FieldSIGNAL_ON_DRAG_BEGIN
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onDragCancel
Connect to signal "drag-cancel".
SeeDragSource.OnDragCancel.onDragCancel(ch.bailu.gtk.gdk.Drag, int)
for signal description.
FieldSIGNAL_ON_DRAG_CANCEL
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onDragEnd
Connect to signal "drag-end".
SeeDragSource.OnDragEnd.onDragEnd(ch.bailu.gtk.gdk.Drag, boolean)
for signal description.
FieldSIGNAL_ON_DRAG_END
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onPrepare
Connect to signal "prepare".
SeeDragSource.OnPrepare.onPrepare(double, double)
for signal description.
FieldSIGNAL_ON_PREPARE
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-