DragSourceProtocol
public protocol DragSourceProtocol : GestureSingleProtocol
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 [classGdk.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
[methodGtk.Widget.add_controller].
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
[signalGtk.DragSource::prepare] and [signalGtk.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.
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.
static void
on_drag_begin (GtkDragSource *source,
GtkDrag *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
[signalGtk.DragSource::drag-end] signal and delete the
data after it has been transferred.
The DragSourceProtocol protocol exposes the methods and properties of an underlying GtkDragSource instance.
The default implementation of these can be found in the protocol extension below.
For a concrete class that implements these methods and properties, see DragSource.
Alternatively, use DragSourceRef as a lighweight, unowned reference if you already have an instance you just want to use.
-
Untyped pointer to the underlying
GtkDragSourceinstance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get } -
drag_source_ptrDefault implementationTyped pointer to the underlying
GtkDragSourceinstance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GtkDragSourceinstance.Declaration
Swift
var drag_source_ptr: UnsafeMutablePointer<GtkDragSource>! { get } -
Required Initialiser for types conforming to
DragSourceProtocolDeclaration
Swift
init(raw: UnsafeMutableRawPointer)
-
bind(property:Extension methodto: _: flags: transformFrom: transformTo: ) Bind a
DragSourcePropertyNamesource property to a given target object.Declaration
Swift
@discardableResult @inlinable func bind<Q, T>(property source_property: DragSourcePropertyName, to target: T, _ target_property: Q, flags f: BindingFlags = .default, transformFrom transform_from: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }, transformTo transform_to: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }) -> BindingRef! where Q : PropertyNameProtocol, T : ObjectProtocolParameters
source_propertythe source property to bind
targetthe target object to bind to
target_propertythe target property to bind to
flagsthe flags to pass to the
Bindingtransform_fromValueTransformerto use for forward transformationtransform_toValueTransformerto use for backwards transformationReturn Value
binding reference or
nilin case of an error -
get(property:Extension method) Get the value of a DragSource property
Declaration
Swift
@inlinable func get(property: DragSourcePropertyName) -> GLibObject.ValueParameters
propertythe property to get the value for
Return Value
the value of the named property
-
set(property:Extension methodvalue: ) Set the value of a DragSource property. Note that this will only have an effect on properties that are writable and not construct-only!
Declaration
Swift
@inlinable func set(property: DragSourcePropertyName, value v: GLibObject.Value)Parameters
propertythe property to get the value for
Return Value
the value of the named property
-
connect(signal:Extension methodflags: handler: ) Connect a Swift signal handler to the given, typed
DragSourceSignalNamesignalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: DragSourceSignalName, flags f: ConnectFlags = ConnectFlags(0), handler h: @escaping SignalHandler) -> IntParameters
signalThe signal to connect
flagsThe connection flags to use
dataA pointer to user data to provide to the callback
destroyDataA
GClosureNotifyC function to destroy the data pointed to byuserDatahandlerThe Swift signal handler (function or callback) to invoke on the given signal
Return Value
The signal handler ID (always greater than 0 for successful connections)
-
connect(signal:Extension methodflags: data: destroyData: signalHandler: ) Connect a C signal handler to the given, typed
DragSourceSignalNamesignalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: DragSourceSignalName, flags f: ConnectFlags = ConnectFlags(0), data userData: gpointer!, destroyData destructor: GClosureNotify? = nil, signalHandler h: @escaping GCallback) -> IntParameters
signalThe signal to connect
flagsThe connection flags to use
dataA pointer to user data to provide to the callback
destroyDataA
GClosureNotifyC function to destroy the data pointed to byuserDatasignalHandlerThe C function to be called on the given signal
Return Value
The signal handler ID (always greater than 0 for successful connections)
-
prepareSignalExtension methodEmitted when a drag is about to be initiated.
It returns the
GdkContentProviderto use for the drag that is about to start. The default handler for this signal returns the value of the [propertyGtk.DragSource:content] property, so if you set up that property ahead of time, you don’t need to connect to this signal.Note
This represents the underlyingpreparesignalWarning
aonPreparewrapper for this signal could not be generated because it contains unimplemented features: { (8) nullable argument or return type is not allowed, (9) Record return type is not yet supported }Note
Instead, you can connectprepareSignalusing theconnect(signal:)methodsDeclaration
Swift
static var prepareSignal: DragSourceSignalName { get }Parameters
flagsFlags
unownedSelfReference to instance of self
xthe X coordinate of the drag starting point
ythe Y coordinate fo the drag starting point
handlera
GdkContentProvider -
onDragBegin(flags:Extension methodhandler: ) Emitted on the drag source when a drag is started.
It can be used to e.g. set a custom drag icon with [method
Gtk.DragSource.set_icon].Note
This represents the underlyingdrag-beginsignalDeclaration
Swift
@discardableResult @inlinable func onDragBegin(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: DragSourceRef, _ drag: Gdk.DragRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
dragthe
GdkDragobjecthandlerThe signal handler to call Run the given callback whenever the
dragBeginsignal is emitted -
dragBeginSignalExtension methodTyped
drag-beginsignal for using theconnect(signal:)methodsDeclaration
Swift
static var dragBeginSignal: DragSourceSignalName { get } -
onDragCancel(flags:Extension methodhandler: ) Emitted on the drag source when a drag has failed.
The signal handler may handle a failed drag operation based on the type of error. It should return
trueif the failure has been handled and the default “drag operation failed” animation should not be shown.Note
This represents the underlyingdrag-cancelsignalDeclaration
Swift
@discardableResult @inlinable func onDragCancel(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: DragSourceRef, _ drag: Gdk.DragRef, _ reason: Gdk.DragCancelReason) -> Bool) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
dragthe
GdkDragobjectreasoninformation on why the drag failed
handlertrueif the failed drag operation has been already handled Run the given callback whenever thedragCancelsignal is emitted -
dragCancelSignalExtension methodTyped
drag-cancelsignal for using theconnect(signal:)methodsDeclaration
Swift
static var dragCancelSignal: DragSourceSignalName { get } -
onDragEnd(flags:Extension methodhandler: ) Emitted on the drag source when a drag is finished.
A typical reason to connect to this signal is to undo things done in [signal
Gtk.DragSource::prepare] or [signalGtk.DragSource::drag-begin] handlers.Note
This represents the underlyingdrag-endsignalDeclaration
Swift
@discardableResult @inlinable func onDragEnd(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: DragSourceRef, _ drag: Gdk.DragRef, _ deleteData: Bool) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
dragthe
GdkDragobjectdeleteDatatrueif the drag was performingGDK_ACTION_MOVE, and the data should be deletedhandlerThe signal handler to call Run the given callback whenever the
dragEndsignal is emitted -
dragEndSignalExtension methodTyped
drag-endsignal for using theconnect(signal:)methodsDeclaration
Swift
static var dragEndSignal: DragSourceSignalName { get } -
onNotifyActions(flags:Extension methodhandler: ) The notify signal is emitted on an object when one of its properties has its value set through
g_object_set_property(),g_object_set(), et al.Note that getting this signal doesn’t itself guarantee that the value of the property has actually changed. When it is emitted is determined by the derived GObject class. If the implementor did not create the property with
G_PARAM_EXPLICIT_NOTIFY, then any call tog_object_set_property()results innotifybeing emitted, even if the new value is the same as the old. If they did passG_PARAM_EXPLICIT_NOTIFY, then this signal is emitted only when they explicitly callg_object_notify()org_object_notify_by_pspec(), and common practice is to do that only when the value has actually changed.This signal is typically used to obtain change notification for a single property, by specifying the property name as a detail in the
g_signal_connect()call, like this:(C Language Example):
g_signal_connect (text_view->buffer, "notify::paste-target-list", G_CALLBACK (gtk_text_view_target_list_notify), text_view)It is important to note that you must use canonical parameter names as detail strings for the notify signal.
Note
This represents the underlyingnotify::actionssignalDeclaration
Swift
@discardableResult @inlinable func onNotifyActions(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: DragSourceRef, _ pspec: ParamSpecRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
pspecthe
GParamSpecof the property which changed.handlerThe signal handler to call Run the given callback whenever the
notifyActionssignal is emitted -
notifyActionsSignalExtension methodTyped
notify::actionssignal for using theconnect(signal:)methodsDeclaration
Swift
static var notifyActionsSignal: DragSourceSignalName { get } -
onNotifyContent(flags:Extension methodhandler: ) The notify signal is emitted on an object when one of its properties has its value set through
g_object_set_property(),g_object_set(), et al.Note that getting this signal doesn’t itself guarantee that the value of the property has actually changed. When it is emitted is determined by the derived GObject class. If the implementor did not create the property with
G_PARAM_EXPLICIT_NOTIFY, then any call tog_object_set_property()results innotifybeing emitted, even if the new value is the same as the old. If they did passG_PARAM_EXPLICIT_NOTIFY, then this signal is emitted only when they explicitly callg_object_notify()org_object_notify_by_pspec(), and common practice is to do that only when the value has actually changed.This signal is typically used to obtain change notification for a single property, by specifying the property name as a detail in the
g_signal_connect()call, like this:(C Language Example):
g_signal_connect (text_view->buffer, "notify::paste-target-list", G_CALLBACK (gtk_text_view_target_list_notify), text_view)It is important to note that you must use canonical parameter names as detail strings for the notify signal.
Note
This represents the underlyingnotify::contentsignalDeclaration
Swift
@discardableResult @inlinable func onNotifyContent(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: DragSourceRef, _ pspec: ParamSpecRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
pspecthe
GParamSpecof the property which changed.handlerThe signal handler to call Run the given callback whenever the
notifyContentsignal is emitted -
notifyContentSignalExtension methodTyped
notify::contentsignal for using theconnect(signal:)methodsDeclaration
Swift
static var notifyContentSignal: DragSourceSignalName { get }
-
dragCancel()Extension methodCancels a currently ongoing drag operation.
Declaration
Swift
@inlinable func dragCancel() -
getActions()Extension methodGets the actions that are currently set on the
GtkDragSource.Declaration
Swift
@inlinable func getActions() -> Gdk.DragAction -
getContent()Extension methodGets the current content provider of a
GtkDragSource.Declaration
Swift
@inlinable func getContent() -> Gdk.ContentProviderRef! -
getDrag()Extension methodReturns the underlying
GdkDragobject for an ongoing drag.Declaration
Swift
@inlinable func getDrag() -> Gdk.DragRef! -
set(actions:Extension method) Sets the actions on the
GtkDragSource.During a DND operation, the actions are offered to potential drop targets. If
actionsincludeGDK_ACTION_MOVE, you need to listen to the [signalGtk.DragSource::drag-end] signal and handledelete_databeingtrue.This function can be called before a drag is started, or in a handler for the [signal
Gtk.DragSource::prepare] signal.Declaration
Swift
@inlinable func set(actions: Gdk.DragAction) -
set(content:Extension method) 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
nilin a [signalGtk.DragSource::drag-end] signal handler.Declaration
Swift
@inlinable func set(content: Gdk.ContentProviderRef? = nil) -
set(content:Extension method) 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
nilin a [signalGtk.DragSource::drag-end] signal handler.Declaration
Swift
@inlinable func set<ContentProviderT>(content: ContentProviderT?) where ContentProviderT : ContentProviderProtocol -
setIcon(paintable:Extension methodhotX: hotY: ) 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
paintableisnil, a default icon is used.This function can be called before a drag is started, or in a [signal
Gtk.DragSource::prepare] or [signalGtk.DragSource::drag-begin] signal handler.Declaration
Swift
@inlinable func setIcon(paintable: Gdk.PaintableRef? = nil, hotX: Int, hotY: Int) -
setIcon(paintable:Extension methodhotX: hotY: ) 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
paintableisnil, a default icon is used.This function can be called before a drag is started, or in a [signal
Gtk.DragSource::prepare] or [signalGtk.DragSource::drag-begin] signal handler.Declaration
Swift
@inlinable func setIcon<PaintableT>(paintable: PaintableT?, hotX: Int, hotY: Int) where PaintableT : PaintableProtocol -
actionsExtension methodThe actions that are supported by drag operations from the source.
Note that you must handle the [signal
Gtk.DragSource::drag-end] signal if the actions includeGDK_ACTION_MOVE.Declaration
Swift
@inlinable var actions: Gdk.DragAction { get nonmutating set } -
contentExtension methodThe data that is offered by drag operations from this source.
Declaration
Swift
@inlinable var content: Gdk.ContentProviderRef! { get nonmutating set } -
dragExtension methodReturns the underlying
GdkDragobject for an ongoing drag.Declaration
Swift
@inlinable var drag: Gdk.DragRef! { get }
View on GitHub
Install in Dash
DragSourceProtocol Protocol Reference