Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | None |
Language | Haskell2010 |
GtkDropTarget is an event controller implementing a simple way to receive Drag-and-Drop operations.
The most basic way to use a DropTarget
to receive drops on a
widget is to create it via dropTargetNew
passing in the
GType
of the data you want to receive and connect to the
GtkDropTarget[drop](#g:signal:drop) signal to receive the data.
DropTarget
supports more options, such as:
- rejecting potential drops via the accept signal
and the
dropTargetReject
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
DropTarget
:preload
property and listening for its availability via theDropTarget
:value
property
However, DropTarget
is ultimately modeled in a synchronous way
and only supports data transferred via GType
.
If you want full control over an ongoing drop, the DropTargetAsync
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
StateFlagsDropActive
state, which can be used to style the widget.
Synopsis
- newtype DropTarget = DropTarget (ManagedPtr DropTarget)
- class (GObject o, IsDescendantOf DropTarget o) => IsDropTarget o
- toDropTarget :: (MonadIO m, IsDropTarget o) => o -> m DropTarget
- dropTargetGetActions :: (HasCallStack, MonadIO m, IsDropTarget a) => a -> m [DragAction]
- dropTargetGetDrop :: (HasCallStack, MonadIO m, IsDropTarget a) => a -> m (Maybe Drop)
- dropTargetGetFormats :: (HasCallStack, MonadIO m, IsDropTarget a) => a -> m (Maybe ContentFormats)
- dropTargetGetGtypes :: (HasCallStack, MonadIO m, IsDropTarget a) => a -> m (Maybe [GType])
- dropTargetGetPreload :: (HasCallStack, MonadIO m, IsDropTarget a) => a -> m Bool
- dropTargetGetValue :: (HasCallStack, MonadIO m, IsDropTarget a) => a -> m (Maybe GValue)
- dropTargetNew :: (HasCallStack, MonadIO m) => GType -> [DragAction] -> m DropTarget
- dropTargetReject :: (HasCallStack, MonadIO m, IsDropTarget a) => a -> m ()
- dropTargetSetActions :: (HasCallStack, MonadIO m, IsDropTarget a) => a -> [DragAction] -> m ()
- dropTargetSetGtypes :: (HasCallStack, MonadIO m, IsDropTarget a) => a -> Maybe [GType] -> m ()
- dropTargetSetPreload :: (HasCallStack, MonadIO m, IsDropTarget a) => a -> Bool -> m ()
- constructDropTargetActions :: (IsDropTarget o, MonadIO m) => [DragAction] -> m (GValueConstruct o)
- getDropTargetActions :: (MonadIO m, IsDropTarget o) => o -> m [DragAction]
- setDropTargetActions :: (MonadIO m, IsDropTarget o) => o -> [DragAction] -> m ()
- getDropTargetDrop :: (MonadIO m, IsDropTarget o) => o -> m (Maybe Drop)
- getDropTargetFormats :: (MonadIO m, IsDropTarget o) => o -> m (Maybe ContentFormats)
- constructDropTargetPreload :: (IsDropTarget o, MonadIO m) => Bool -> m (GValueConstruct o)
- getDropTargetPreload :: (MonadIO m, IsDropTarget o) => o -> m Bool
- setDropTargetPreload :: (MonadIO m, IsDropTarget o) => o -> Bool -> m ()
- getDropTargetValue :: (MonadIO m, IsDropTarget o) => o -> m (Maybe GValue)
- type C_DropTargetAcceptCallback = Ptr () -> Ptr Drop -> Ptr () -> IO CInt
- type DropTargetAcceptCallback = Drop -> IO Bool
- afterDropTargetAccept :: (IsDropTarget a, MonadIO m) => a -> DropTargetAcceptCallback -> m SignalHandlerId
- genClosure_DropTargetAccept :: MonadIO m => DropTargetAcceptCallback -> m (GClosure C_DropTargetAcceptCallback)
- mk_DropTargetAcceptCallback :: C_DropTargetAcceptCallback -> IO (FunPtr C_DropTargetAcceptCallback)
- noDropTargetAcceptCallback :: Maybe DropTargetAcceptCallback
- onDropTargetAccept :: (IsDropTarget a, MonadIO m) => a -> DropTargetAcceptCallback -> m SignalHandlerId
- wrap_DropTargetAcceptCallback :: DropTargetAcceptCallback -> C_DropTargetAcceptCallback
- type C_DropTargetDropCallback = Ptr () -> Ptr GValue -> CDouble -> CDouble -> Ptr () -> IO CInt
- type DropTargetDropCallback = GValue -> Double -> Double -> IO Bool
- afterDropTargetDrop :: (IsDropTarget a, MonadIO m) => a -> DropTargetDropCallback -> m SignalHandlerId
- genClosure_DropTargetDrop :: MonadIO m => DropTargetDropCallback -> m (GClosure C_DropTargetDropCallback)
- mk_DropTargetDropCallback :: C_DropTargetDropCallback -> IO (FunPtr C_DropTargetDropCallback)
- noDropTargetDropCallback :: Maybe DropTargetDropCallback
- onDropTargetDrop :: (IsDropTarget a, MonadIO m) => a -> DropTargetDropCallback -> m SignalHandlerId
- wrap_DropTargetDropCallback :: DropTargetDropCallback -> C_DropTargetDropCallback
- type C_DropTargetEnterCallback = Ptr () -> CDouble -> CDouble -> Ptr () -> IO CUInt
- type DropTargetEnterCallback = Double -> Double -> IO [DragAction]
- afterDropTargetEnter :: (IsDropTarget a, MonadIO m) => a -> DropTargetEnterCallback -> m SignalHandlerId
- genClosure_DropTargetEnter :: MonadIO m => DropTargetEnterCallback -> m (GClosure C_DropTargetEnterCallback)
- mk_DropTargetEnterCallback :: C_DropTargetEnterCallback -> IO (FunPtr C_DropTargetEnterCallback)
- noDropTargetEnterCallback :: Maybe DropTargetEnterCallback
- onDropTargetEnter :: (IsDropTarget a, MonadIO m) => a -> DropTargetEnterCallback -> m SignalHandlerId
- wrap_DropTargetEnterCallback :: DropTargetEnterCallback -> C_DropTargetEnterCallback
- type C_DropTargetLeaveCallback = Ptr () -> Ptr () -> IO ()
- type DropTargetLeaveCallback = IO ()
- afterDropTargetLeave :: (IsDropTarget a, MonadIO m) => a -> DropTargetLeaveCallback -> m SignalHandlerId
- genClosure_DropTargetLeave :: MonadIO m => DropTargetLeaveCallback -> m (GClosure C_DropTargetLeaveCallback)
- mk_DropTargetLeaveCallback :: C_DropTargetLeaveCallback -> IO (FunPtr C_DropTargetLeaveCallback)
- noDropTargetLeaveCallback :: Maybe DropTargetLeaveCallback
- onDropTargetLeave :: (IsDropTarget a, MonadIO m) => a -> DropTargetLeaveCallback -> m SignalHandlerId
- wrap_DropTargetLeaveCallback :: DropTargetLeaveCallback -> C_DropTargetLeaveCallback
- type C_DropTargetMotionCallback = Ptr () -> CDouble -> CDouble -> Ptr () -> IO CUInt
- type DropTargetMotionCallback = Double -> Double -> IO [DragAction]
- afterDropTargetMotion :: (IsDropTarget a, MonadIO m) => a -> DropTargetMotionCallback -> m SignalHandlerId
- genClosure_DropTargetMotion :: MonadIO m => DropTargetMotionCallback -> m (GClosure C_DropTargetMotionCallback)
- mk_DropTargetMotionCallback :: C_DropTargetMotionCallback -> IO (FunPtr C_DropTargetMotionCallback)
- noDropTargetMotionCallback :: Maybe DropTargetMotionCallback
- onDropTargetMotion :: (IsDropTarget a, MonadIO m) => a -> DropTargetMotionCallback -> m SignalHandlerId
- wrap_DropTargetMotionCallback :: DropTargetMotionCallback -> C_DropTargetMotionCallback
Exported types
newtype DropTarget Source #
Memory-managed wrapper type.
Instances
Eq DropTarget Source # | |
Defined in GI.Gtk.Objects.DropTarget (==) :: DropTarget -> DropTarget -> Bool # (/=) :: DropTarget -> DropTarget -> Bool # | |
IsGValue DropTarget Source # | Convert |
Defined in GI.Gtk.Objects.DropTarget toGValue :: DropTarget -> IO GValue # fromGValue :: GValue -> IO DropTarget # | |
ManagedPtrNewtype DropTarget Source # | |
Defined in GI.Gtk.Objects.DropTarget | |
TypedObject DropTarget Source # | |
Defined in GI.Gtk.Objects.DropTarget | |
GObject DropTarget Source # | |
Defined in GI.Gtk.Objects.DropTarget | |
HasParentTypes DropTarget Source # | |
Defined in GI.Gtk.Objects.DropTarget | |
type ParentTypes DropTarget Source # | |
Defined in GI.Gtk.Objects.DropTarget |
class (GObject o, IsDescendantOf DropTarget o) => IsDropTarget o Source #
Type class for types which can be safely cast to DropTarget
, for instance with toDropTarget
.
Instances
(GObject o, IsDescendantOf DropTarget o) => IsDropTarget o Source # | |
Defined in GI.Gtk.Objects.DropTarget |
toDropTarget :: (MonadIO m, IsDropTarget o) => o -> m DropTarget Source #
Cast to DropTarget
, for types for which this is known to be safe. For general casts, use castTo
.
Methods
Overloaded methods
getActions
:: (HasCallStack, MonadIO m, IsDropTarget a) | |
=> a |
|
-> m [DragAction] | Returns: the actions that this drop target supports |
Gets the actions that this drop target supports.
getDrop
:: (HasCallStack, MonadIO m, IsDropTarget a) | |
=> a |
|
-> m (Maybe Drop) | Returns: The current drop |
Gets the currently handled drop operation.
If no drop operation is going on, Nothing
is returned.
getFormats
:: (HasCallStack, MonadIO m, IsDropTarget a) | |
=> a |
|
-> m (Maybe ContentFormats) | Returns: the supported data formats |
Gets the data formats that this drop target accepts.
If the result is Nothing
, all formats are expected to be supported.
getGtypes
:: (HasCallStack, MonadIO m, IsDropTarget a) | |
=> a |
|
-> m (Maybe [GType]) | Returns:
|
Gets the list of supported GTypes
for self
. If no type have been set,
Nothing
will be returned.
getPreload
:: (HasCallStack, MonadIO m, IsDropTarget a) | |
=> a |
|
-> m Bool | Returns: |
Gets the value of the GtkDropTarget:preload property.
getValue
:: (HasCallStack, MonadIO m, IsDropTarget a) | |
=> a |
|
-> m (Maybe GValue) | Returns: The current drop data |
Gets the value of the GtkDropTarget:value porperty.
new
:: (HasCallStack, MonadIO m) | |
=> GType |
|
-> [DragAction] |
|
-> m DropTarget | Returns: the new |
Creates a new DropTarget
object.
If the drop target should support more than 1 type, pass
G_TYPE_INVALID
for type
and then call
dropTargetSetGtypes
.
reject
:: (HasCallStack, MonadIO m, IsDropTarget a) | |
=> a |
|
-> m () |
Rejects the ongoing drop operation.
If no drop operation is ongoing - when GdkDropTarget:drop
returns Nothing
- 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.
setActions
:: (HasCallStack, MonadIO m, IsDropTarget a) | |
=> a |
|
-> [DragAction] |
|
-> m () |
Sets the actions that this drop target supports.
setGtypes
:: (HasCallStack, MonadIO m, IsDropTarget a) | |
=> a |
|
-> Maybe [GType] |
|
-> m () |
Sets the supported GTypes
for this drop target.
The GtkDropTarget[drop](#g:signal:drop) signal will
setPreload
:: (HasCallStack, MonadIO m, IsDropTarget a) | |
=> a |
|
-> Bool |
|
-> m () |
Sets the GtkDropTarget:preload property.
Properties
actions
The GdkDragActions
that this drop target supports
constructDropTargetActions :: (IsDropTarget o, MonadIO m) => [DragAction] -> m (GValueConstruct o) Source #
Construct a GValueConstruct
with valid value for the “actions
” property. This is rarely needed directly, but it is used by new
.
getDropTargetActions :: (MonadIO m, IsDropTarget o) => o -> m [DragAction] Source #
Get the value of the “actions
” property.
When overloading is enabled, this is equivalent to
get
dropTarget #actions
setDropTargetActions :: (MonadIO m, IsDropTarget o) => o -> [DragAction] -> m () Source #
Set the value of the “actions
” property.
When overloading is enabled, this is equivalent to
set
dropTarget [ #actions:=
value ]
drop
The Drop
that is currently being performed
getDropTargetDrop :: (MonadIO m, IsDropTarget o) => o -> m (Maybe Drop) Source #
Get the value of the “drop
” property.
When overloading is enabled, this is equivalent to
get
dropTarget #drop
formats
The ContentFormats
that determine the supported data formats
getDropTargetFormats :: (MonadIO m, IsDropTarget o) => o -> m (Maybe ContentFormats) Source #
Get the value of the “formats
” property.
When overloading is enabled, this is equivalent to
get
dropTarget #formats
preload
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.
constructDropTargetPreload :: (IsDropTarget o, MonadIO m) => Bool -> m (GValueConstruct o) Source #
Construct a GValueConstruct
with valid value for the “preload
” property. This is rarely needed directly, but it is used by new
.
getDropTargetPreload :: (MonadIO m, IsDropTarget o) => o -> m Bool Source #
Get the value of the “preload
” property.
When overloading is enabled, this is equivalent to
get
dropTarget #preload
setDropTargetPreload :: (MonadIO m, IsDropTarget o) => o -> Bool -> m () Source #
Set the value of the “preload
” property.
When overloading is enabled, this is equivalent to
set
dropTarget [ #preload:=
value ]
value
The value for this drop operation or Nothing
if the data has not been
loaded yet or no drop operation is going on.
Data may be available before the GtkDropTarget[drop](#g:signal:drop) signal gets emitted - for example when the GtkDropTarget:preload property is set. You can use the GObject[notify](#g:signal:notify) signal to be notified of available data.
getDropTargetValue :: (MonadIO m, IsDropTarget o) => o -> m (Maybe GValue) Source #
Get the value of the “value
” property.
When overloading is enabled, this is equivalent to
get
dropTarget #value
Signals
accept
type C_DropTargetAcceptCallback = Ptr () -> Ptr Drop -> Ptr () -> IO CInt Source #
Type for the callback on the (unwrapped) C side.
type DropTargetAcceptCallback Source #
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 dropTargetReject
or
ultimately by returning False
from GtkDropTarget[drop](#g:signal: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](#g:signal:notify):value signal and then call
dropTargetReject
.
afterDropTargetAccept :: (IsDropTarget a, MonadIO m) => a -> DropTargetAcceptCallback -> m SignalHandlerId Source #
Connect a signal handler for the accept signal, to be run after the default handler. When overloading is enabled, this is equivalent to
after
dropTarget #accept callback
genClosure_DropTargetAccept :: MonadIO m => DropTargetAcceptCallback -> m (GClosure C_DropTargetAcceptCallback) Source #
Wrap the callback into a GClosure
.
mk_DropTargetAcceptCallback :: C_DropTargetAcceptCallback -> IO (FunPtr C_DropTargetAcceptCallback) Source #
Generate a function pointer callable from C code, from a C_DropTargetAcceptCallback
.
noDropTargetAcceptCallback :: Maybe DropTargetAcceptCallback Source #
A convenience synonym for
.Nothing
:: Maybe
DropTargetAcceptCallback
onDropTargetAccept :: (IsDropTarget a, MonadIO m) => a -> DropTargetAcceptCallback -> m SignalHandlerId Source #
Connect a signal handler for the accept signal, to be run before the default handler. When overloading is enabled, this is equivalent to
on
dropTarget #accept callback
wrap_DropTargetAcceptCallback :: DropTargetAcceptCallback -> C_DropTargetAcceptCallback Source #
Wrap a DropTargetAcceptCallback
into a C_DropTargetAcceptCallback
.
drop
type C_DropTargetDropCallback = Ptr () -> Ptr GValue -> CDouble -> CDouble -> Ptr () -> IO CInt Source #
Type for the callback on the (unwrapped) C side.
type DropTargetDropCallback Source #
= GValue |
|
-> Double |
|
-> Double |
|
-> IO Bool | Returns: whether the drop was accepted at the given pointer position |
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.
afterDropTargetDrop :: (IsDropTarget a, MonadIO m) => a -> DropTargetDropCallback -> m SignalHandlerId Source #
Connect a signal handler for the drop signal, to be run after the default handler. When overloading is enabled, this is equivalent to
after
dropTarget #drop callback
genClosure_DropTargetDrop :: MonadIO m => DropTargetDropCallback -> m (GClosure C_DropTargetDropCallback) Source #
Wrap the callback into a GClosure
.
mk_DropTargetDropCallback :: C_DropTargetDropCallback -> IO (FunPtr C_DropTargetDropCallback) Source #
Generate a function pointer callable from C code, from a C_DropTargetDropCallback
.
noDropTargetDropCallback :: Maybe DropTargetDropCallback Source #
A convenience synonym for
.Nothing
:: Maybe
DropTargetDropCallback
onDropTargetDrop :: (IsDropTarget a, MonadIO m) => a -> DropTargetDropCallback -> m SignalHandlerId Source #
Connect a signal handler for the drop signal, to be run before the default handler. When overloading is enabled, this is equivalent to
on
dropTarget #drop callback
wrap_DropTargetDropCallback :: DropTargetDropCallback -> C_DropTargetDropCallback Source #
Wrap a DropTargetDropCallback
into a C_DropTargetDropCallback
.
enter
type C_DropTargetEnterCallback = Ptr () -> CDouble -> CDouble -> Ptr () -> IO CUInt Source #
Type for the callback on the (unwrapped) C side.
type DropTargetEnterCallback Source #
= Double |
|
-> Double |
|
-> IO [DragAction] | Returns: Preferred action for this drag operation or 0 if dropping is not
supported at the current |
The enter signal is emitted on the drop site when the pointer enters the widget. It can be used to set up custom highlighting.
afterDropTargetEnter :: (IsDropTarget a, MonadIO m) => a -> DropTargetEnterCallback -> m SignalHandlerId Source #
Connect a signal handler for the enter signal, to be run after the default handler. When overloading is enabled, this is equivalent to
after
dropTarget #enter callback
genClosure_DropTargetEnter :: MonadIO m => DropTargetEnterCallback -> m (GClosure C_DropTargetEnterCallback) Source #
Wrap the callback into a GClosure
.
mk_DropTargetEnterCallback :: C_DropTargetEnterCallback -> IO (FunPtr C_DropTargetEnterCallback) Source #
Generate a function pointer callable from C code, from a C_DropTargetEnterCallback
.
noDropTargetEnterCallback :: Maybe DropTargetEnterCallback Source #
A convenience synonym for
.Nothing
:: Maybe
DropTargetEnterCallback
onDropTargetEnter :: (IsDropTarget a, MonadIO m) => a -> DropTargetEnterCallback -> m SignalHandlerId Source #
Connect a signal handler for the enter signal, to be run before the default handler. When overloading is enabled, this is equivalent to
on
dropTarget #enter callback
wrap_DropTargetEnterCallback :: DropTargetEnterCallback -> C_DropTargetEnterCallback Source #
Wrap a DropTargetEnterCallback
into a C_DropTargetEnterCallback
.
leave
type C_DropTargetLeaveCallback = Ptr () -> Ptr () -> IO () Source #
Type for the callback on the (unwrapped) C side.
type DropTargetLeaveCallback = IO () Source #
afterDropTargetLeave :: (IsDropTarget a, MonadIO m) => a -> DropTargetLeaveCallback -> m SignalHandlerId Source #
Connect a signal handler for the leave signal, to be run after the default handler. When overloading is enabled, this is equivalent to
after
dropTarget #leave callback
genClosure_DropTargetLeave :: MonadIO m => DropTargetLeaveCallback -> m (GClosure C_DropTargetLeaveCallback) Source #
Wrap the callback into a GClosure
.
mk_DropTargetLeaveCallback :: C_DropTargetLeaveCallback -> IO (FunPtr C_DropTargetLeaveCallback) Source #
Generate a function pointer callable from C code, from a C_DropTargetLeaveCallback
.
noDropTargetLeaveCallback :: Maybe DropTargetLeaveCallback Source #
A convenience synonym for
.Nothing
:: Maybe
DropTargetLeaveCallback
onDropTargetLeave :: (IsDropTarget a, MonadIO m) => a -> DropTargetLeaveCallback -> m SignalHandlerId Source #
Connect a signal handler for the leave signal, to be run before the default handler. When overloading is enabled, this is equivalent to
on
dropTarget #leave callback
wrap_DropTargetLeaveCallback :: DropTargetLeaveCallback -> C_DropTargetLeaveCallback Source #
Wrap a DropTargetLeaveCallback
into a C_DropTargetLeaveCallback
.
motion
type C_DropTargetMotionCallback = Ptr () -> CDouble -> CDouble -> Ptr () -> IO CUInt Source #
Type for the callback on the (unwrapped) C side.
type DropTargetMotionCallback Source #
= Double |
|
-> Double |
|
-> IO [DragAction] | Returns: Preferred action for this drag operation or 0 if dropping is not
supported at the current |
The motion signal is emitted while the pointer is moving over the drop target.
afterDropTargetMotion :: (IsDropTarget a, MonadIO m) => a -> DropTargetMotionCallback -> m SignalHandlerId Source #
Connect a signal handler for the motion signal, to be run after the default handler. When overloading is enabled, this is equivalent to
after
dropTarget #motion callback
genClosure_DropTargetMotion :: MonadIO m => DropTargetMotionCallback -> m (GClosure C_DropTargetMotionCallback) Source #
Wrap the callback into a GClosure
.
mk_DropTargetMotionCallback :: C_DropTargetMotionCallback -> IO (FunPtr C_DropTargetMotionCallback) Source #
Generate a function pointer callable from C code, from a C_DropTargetMotionCallback
.
noDropTargetMotionCallback :: Maybe DropTargetMotionCallback Source #
A convenience synonym for
.Nothing
:: Maybe
DropTargetMotionCallback
onDropTargetMotion :: (IsDropTarget a, MonadIO m) => a -> DropTargetMotionCallback -> m SignalHandlerId Source #
Connect a signal handler for the motion signal, to be run before the default handler. When overloading is enabled, this is equivalent to
on
dropTarget #motion callback