Top |
void gtk_drag_dest_set (GtkWidget *widget
,GtkDestDefaults flags
,const GtkTargetEntry *targets
,gint n_targets
,GdkDragAction actions
);
Sets a widget as a potential drop destination, and adds default behaviors.
The default behaviors listed in flags
have an effect similar
to installing default handlers for the widget's drag-and-drop signals
(“drag-motion”, “drag-drop”, ...). They all exist
for convenience. When passing GTK_DEST_DEFAULT_ALL for instance it is
sufficient to connect to the widget's “drag-data-received”
signal to get primitive, but consistent drag-and-drop support.
Things become more complicated when you try to preview the dragged data,
as described in the documentation for “drag-motion”. The default
behaviors described by flags
make some assumptions, that can conflict
with your own signal handlers. For instance GTK_DEST_DEFAULT_DROP causes
invokations of gdk_drag_status()
in the context of “drag-motion”,
and invokations of gtk_drag_finish()
in “drag-data-received”.
Especially the later is dramatic, when your own “drag-motion”
handler calls gtk_drag_get_data()
to inspect the dragged data.
There's no way to set a default action here, you can use the “drag-motion” callback for that. Here's an example which selects the action to use depending on whether the control key is pressed or not:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
static void drag_motion (GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time) { GdkModifierType mask; gdk_window_get_pointer (gtk_widget_get_window (widget), NULL, NULL, &mask); if (mask & GDK_CONTROL_MASK) gdk_drag_status (context, GDK_ACTION_COPY, time); else gdk_drag_status (context, GDK_ACTION_MOVE, time); } |
widget |
||
flags |
which types of default drag behavior to use |
|
targets |
a pointer to an array of GtkTargetEntrys
indicating the drop types that this |
[allow-none][array length=n_targets] |
n_targets |
the number of entries in |
|
actions |
a bitmask of possible actions for a drop onto this |
void gtk_drag_dest_set_proxy (GtkWidget *widget
,GdkWindow *proxy_window
,GdkDragProtocol protocol
,gboolean use_coordinates
);
GdkAtom gtk_drag_dest_find_target (GtkWidget *widget
,GdkDragContext *context
,GtkTargetList *target_list
);
widget |
drag destination widget |
|
context |
drag context |
|
target_list |
list of droppable targets, or |
[allow-none] |
GtkTargetList *
gtk_drag_dest_get_target_list (GtkWidget *widget
);
Returns the list of targets this widget can accept from drag-and-drop.
void gtk_drag_dest_set_target_list (GtkWidget *widget
,GtkTargetList *target_list
);
Sets the target types that this widget can accept from drag-and-drop.
The widget must first be made into a drag destination with
gtk_drag_dest_set()
.
widget |
a GtkWidget that's a drag destination |
|
target_list |
list of droppable targets, or |
[allow-none] |
void
gtk_drag_dest_add_text_targets (GtkWidget *widget
);
Add the text targets supported by GtkSelection to
the target list of the drag destination. The targets
are added with info
= 0. If you need another value,
use gtk_target_list_add_text_targets()
and
gtk_drag_dest_set_target_list()
.
Since: 2.6
void
gtk_drag_dest_add_image_targets (GtkWidget *widget
);
Add the image targets supported by GtkSelection to
the target list of the drag destination. The targets
are added with info
= 0. If you need another value,
use gtk_target_list_add_image_targets()
and
gtk_drag_dest_set_target_list()
.
Since: 2.6
void
gtk_drag_dest_add_uri_targets (GtkWidget *widget
);
Add the URI targets supported by GtkSelection to
the target list of the drag destination. The targets
are added with info
= 0. If you need another value,
use gtk_target_list_add_uri_targets()
and
gtk_drag_dest_set_target_list()
.
Since: 2.6
void gtk_drag_dest_set_track_motion (GtkWidget *widget
,gboolean track_motion
);
Tells the widget to emit ::drag-motion and ::drag-leave
events regardless of the targets and the GTK_DEST_DEFAULT_MOTION
flag.
This may be used when a widget wants to do generic actions regardless of the targets that the source offers.
Since: 2.10
gboolean
gtk_drag_dest_get_track_motion (GtkWidget *widget
);
Returns whether the widget has been configured to always emit ::drag-motion signals.
Since: 2.10
void gtk_drag_finish (GdkDragContext *context
,gboolean success
,gboolean del
,guint32 time_
);
void gtk_drag_get_data (GtkWidget *widget
,GdkDragContext *context
,GdkAtom target
,guint32 time_
);
GtkWidget *
gtk_drag_get_source_widget (GdkDragContext *context
);
Determines the source widget for a drag.
GdkDragContext * gtk_drag_begin (GtkWidget *widget
,GtkTargetList *targets
,GdkDragAction actions
,gint button
,GdkEvent *event
);
Initiates a drag on the source side. The function
only needs to be used when the application is
starting drags itself, and is not needed when
gtk_drag_source_set()
is used.
The event
is used to retrieve the timestamp that will be used internally to
grab the pointer. If event
is NULL, then GDK_CURRENT_TIME will be used.
However, you should try to pass a real event in all cases, since that can be
used by GTK+ to get information about the start position of the drag, for
example if the event
is a GDK_MOTION_NOTIFY.
Generally there are three cases when you want to start a drag by hand by calling this function:
During a button-press-event handler, if you want to start a drag immediately
when the user presses the mouse button. Pass the event
that you have in your
button-press-event handler.
During a motion-notify-event handler, if you want to start a drag when the mouse
moves past a certain threshold distance after a button-press. Pass the event
that you
have in your motion-notify-event handler.
During a timeout handler, if you want to start a drag after the mouse
button is held down for some time. Try to save the last event that you got
from the mouse, using gdk_event_copy()
, and pass it to this function
(remember to free the event with gdk_event_free()
when you are done). If you
can really not pass a real event, pass NULL instead.
void gtk_drag_set_icon_widget (GdkDragContext *context
,GtkWidget *widget
,gint hot_x
,gint hot_y
);
Changes the icon for a widget to a given widget. GTK+ will not destroy the icon, so if you don't want it to persist, you should connect to the "drag-end" signal and destroy it yourself.
void gtk_drag_set_icon_pixmap (GdkDragContext *context
,GdkColormap *colormap
,GdkPixmap *pixmap
,GdkBitmap *mask
,gint hot_x
,gint hot_y
);
Sets pixmap
as the icon for a given drag. GTK+ retains
references for the arguments, and will release them when
they are no longer needed. In general, gtk_drag_set_icon_pixbuf()
will be more convenient to use.
context |
the context for a drag. (This must be called with a context for the source side of a drag) |
|
colormap |
the colormap of the icon |
|
pixmap |
the image data for the icon |
|
mask |
the transparency mask for the icon or |
[allow-none] |
hot_x |
the X offset within |
|
hot_y |
the Y offset within |
void gtk_drag_set_icon_pixbuf (GdkDragContext *context
,GdkPixbuf *pixbuf
,gint hot_x
,gint hot_y
);
Sets pixbuf
as the icon for a given drag.
context |
the context for a drag. (This must be called with a context for the source side of a drag) |
|
pixbuf |
the GdkPixbuf to use as the drag icon. |
|
hot_x |
the X offset within |
|
hot_y |
the Y offset within |
void gtk_drag_set_icon_stock (GdkDragContext *context
,const gchar *stock_id
,gint hot_x
,gint hot_y
);
Sets the icon for a given drag from a stock ID.
void gtk_drag_set_icon_name (GdkDragContext *context
,const gchar *icon_name
,gint hot_x
,gint hot_y
);
Sets the icon for a given drag from a named themed icon. See
the docs for GtkIconTheme for more details. Note that the
size of the icon depends on the icon theme (the icon is
loaded at the symbolic size GTK_ICON_SIZE_DND), thus
hot_x
and hot_y
have to be used with care.
context |
the context for a drag. (This must be called with a context for the source side of a drag) |
|
icon_name |
name of icon to use |
|
hot_x |
the X offset of the hotspot within the icon |
|
hot_y |
the Y offset of the hotspot within the icon |
Since: 2.8
void
gtk_drag_set_icon_default (GdkDragContext *context
);
Sets the icon for a particular drag to the default icon.
void gtk_drag_set_default_icon (GdkColormap *colormap
,GdkPixmap *pixmap
,GdkBitmap *mask
,gint hot_x
,gint hot_y
);
gtk_drag_set_default_icon
is deprecated and should not be used in newly-written code.
Change the default drag icon via the stock system by changing the stock pixbuf for GTK_STOCK_DND instead.
Changes the default drag icon. GTK+ retains references for the arguments, and will release them when they are no longer needed.
gboolean gtk_drag_check_threshold (GtkWidget *widget
,gint start_x
,gint start_y
,gint current_x
,gint current_y
);
Checks to see if a mouse drag starting at (start_x
, start_y
) and ending
at (current_x
, current_y
) has passed the GTK+ drag threshold, and thus
should trigger the beginning of a drag-and-drop operation.
void gtk_drag_source_set (GtkWidget *widget
,GdkModifierType start_button_mask
,const GtkTargetEntry *targets
,gint n_targets
,GdkDragAction actions
);
Sets up a widget so that GTK+ will start a drag operation when the user clicks and drags on the widget. The widget must have a window.
void gtk_drag_source_set_icon (GtkWidget *widget
,GdkColormap *colormap
,GdkPixmap *pixmap
,GdkBitmap *mask
);
Sets the icon that will be used for drags from a particular widget
from a pixmap/mask. GTK+ retains references for the arguments, and
will release them when they are no longer needed.
Use gtk_drag_source_set_icon_pixbuf()
instead.
void gtk_drag_source_set_icon_pixbuf (GtkWidget *widget
,GdkPixbuf *pixbuf
);
Sets the icon that will be used for drags from a particular widget
from a GdkPixbuf. GTK+ retains a reference for pixbuf
and will
release it when it is no longer needed.
void gtk_drag_source_set_icon_stock (GtkWidget *widget
,const gchar *stock_id
);
Sets the icon that will be used for drags from a particular source to a stock icon.
void gtk_drag_source_set_icon_name (GtkWidget *widget
,const gchar *icon_name
);
Sets the icon that will be used for drags from a particular source to a themed icon. See the docs for GtkIconTheme for more details.
Since: 2.8
void gtk_drag_source_set_target_list (GtkWidget *widget
,GtkTargetList *target_list
);
Changes the target types that this widget offers for drag-and-drop.
The widget must first be made into a drag source with
gtk_drag_source_set()
.
widget |
a GtkWidget that's a drag source |
|
target_list |
list of draggable targets, or |
[allow-none] |
Since: 2.4
GtkTargetList *
gtk_drag_source_get_target_list (GtkWidget *widget
);
Gets the list of targets this widget can provide for drag-and-drop.
Since: 2.4
void
gtk_drag_source_add_text_targets (GtkWidget *widget
);
Add the text targets supported by GtkSelection to
the target list of the drag source. The targets
are added with info
= 0. If you need another value,
use gtk_target_list_add_text_targets()
and
gtk_drag_source_set_target_list()
.
Since: 2.6
void
gtk_drag_source_add_image_targets (GtkWidget *widget
);
Add the writable image targets supported by GtkSelection to
the target list of the drag source. The targets
are added with info
= 0. If you need another value,
use gtk_target_list_add_image_targets()
and
gtk_drag_source_set_target_list()
.
Since: 2.6
void
gtk_drag_source_add_uri_targets (GtkWidget *widget
);
Add the URI targets supported by GtkSelection to
the target list of the drag source. The targets
are added with info
= 0. If you need another value,
use gtk_target_list_add_uri_targets()
and
gtk_drag_source_set_target_list()
.
Since: 2.6