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
GtkDragSource
instance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get }
-
drag_source_ptr
Default implementationTyped pointer to the underlying
GtkDragSource
instance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GtkDragSource
instance.Declaration
Swift
var drag_source_ptr: UnsafeMutablePointer<GtkDragSource>! { get }
-
Required Initialiser for types conforming to
DragSourceProtocol
Declaration
Swift
init(raw: UnsafeMutableRawPointer)
-
bind(property:
Extension methodto: _: flags: transformFrom: transformTo: ) Bind a
DragSourcePropertyName
source 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 : ObjectProtocol
Parameters
source_property
the source property to bind
target
the target object to bind to
target_property
the target property to bind to
flags
the flags to pass to the
Binding
transform_from
ValueTransformer
to use for forward transformationtransform_to
ValueTransformer
to use for backwards transformationReturn Value
binding reference or
nil
in case of an error -
get(property:
Extension method) Get the value of a DragSource property
Declaration
Swift
@inlinable func get(property: DragSourcePropertyName) -> GLibObject.Value
Parameters
property
the 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
property
the 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
DragSourceSignalName
signalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: DragSourceSignalName, flags f: ConnectFlags = ConnectFlags(0), handler h: @escaping SignalHandler) -> Int
Parameters
signal
The signal to connect
flags
The connection flags to use
data
A pointer to user data to provide to the callback
destroyData
A
GClosureNotify
C function to destroy the data pointed to byuserData
handler
The 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
DragSourceSignalName
signalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: DragSourceSignalName, flags f: ConnectFlags = ConnectFlags(0), data userData: gpointer!, destroyData destructor: GClosureNotify? = nil, signalHandler h: @escaping GCallback) -> Int
Parameters
signal
The signal to connect
flags
The connection flags to use
data
A pointer to user data to provide to the callback
destroyData
A
GClosureNotify
C function to destroy the data pointed to byuserData
signalHandler
The C function to be called on the given signal
Return Value
The signal handler ID (always greater than 0 for successful connections)
-
prepareSignal
Extension methodEmitted when a drag is about to be initiated.
It returns the
GdkContentProvider
to 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 underlyingprepare
signalWarning
aonPrepare
wrapper 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 connectprepareSignal
using theconnect(signal:)
methodsDeclaration
Swift
static var prepareSignal: DragSourceSignalName { get }
Parameters
flags
Flags
unownedSelf
Reference to instance of self
x
the X coordinate of the drag starting point
y
the Y coordinate fo the drag starting point
handler
a
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-begin
signalDeclaration
Swift
@discardableResult @inlinable func onDragBegin(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: DragSourceRef, _ drag: Gdk.DragRef) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
drag
the
GdkDrag
objecthandler
The signal handler to call Run the given callback whenever the
dragBegin
signal is emitted -
dragBeginSignal
Extension methodTyped
drag-begin
signal 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
true
if the failure has been handled and the default “drag operation failed” animation should not be shown.Note
This represents the underlyingdrag-cancel
signalDeclaration
Swift
@discardableResult @inlinable func onDragCancel(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: DragSourceRef, _ drag: Gdk.DragRef, _ reason: Gdk.DragCancelReason) -> Bool) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
drag
the
GdkDrag
objectreason
information on why the drag failed
handler
true
if the failed drag operation has been already handled Run the given callback whenever thedragCancel
signal is emitted -
dragCancelSignal
Extension methodTyped
drag-cancel
signal 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-end
signalDeclaration
Swift
@discardableResult @inlinable func onDragEnd(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: DragSourceRef, _ drag: Gdk.DragRef, _ deleteData: Bool) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
drag
the
GdkDrag
objectdeleteData
true
if the drag was performingGDK_ACTION_MOVE
, and the data should be deletedhandler
The signal handler to call Run the given callback whenever the
dragEnd
signal is emitted -
dragEndSignal
Extension methodTyped
drag-end
signal 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 innotify
being 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::actions
signalDeclaration
Swift
@discardableResult @inlinable func onNotifyActions(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: DragSourceRef, _ pspec: ParamSpecRef) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
pspec
the
GParamSpec
of the property which changed.handler
The signal handler to call Run the given callback whenever the
notifyActions
signal is emitted -
notifyActionsSignal
Extension methodTyped
notify::actions
signal 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 innotify
being 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::content
signalDeclaration
Swift
@discardableResult @inlinable func onNotifyContent(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: DragSourceRef, _ pspec: ParamSpecRef) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
pspec
the
GParamSpec
of the property which changed.handler
The signal handler to call Run the given callback whenever the
notifyContent
signal is emitted -
notifyContentSignal
Extension methodTyped
notify::content
signal 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
GdkDrag
object 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
actions
includeGDK_ACTION_MOVE
, you need to listen to the [signalGtk.DragSource::drag-end
] signal and handledelete_data
beingtrue
.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
nil
in 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
nil
in 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
paintable
isnil
, 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
paintable
isnil
, 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
-
actions
Extension 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 }
-
content
Extension methodThe data that is offered by drag operations from this source.
Declaration
Swift
@inlinable var content: Gdk.ContentProviderRef! { get nonmutating set }
-
drag
Extension methodReturns the underlying
GdkDrag
object for an ongoing drag.Declaration
Swift
@inlinable var drag: Gdk.DragRef! { get }