mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-01 16:30:15 +00:00
Remove traditional drag source API
gtk_drag_source_set, gtk_drag_begin, related apis and the GtkWidget source-side signals have all been replaced by GtkDragSource.
This commit is contained in:
parent
b4c689ecd6
commit
9b01d9a784
762
gtk/gtkdnd.c
762
gtk/gtkdnd.c
@ -63,21 +63,8 @@
|
||||
*/
|
||||
|
||||
|
||||
typedef struct _GtkDragSourceInfo GtkDragSourceInfo;
|
||||
typedef struct _GtkDragDestInfo GtkDragDestInfo;
|
||||
|
||||
struct _GtkDragSourceInfo
|
||||
{
|
||||
GtkWidget *widget;
|
||||
GdkContentFormats *target_list; /* Targets for drag data */
|
||||
GdkDrag *drag; /* drag context */
|
||||
GtkWidget *icon_window; /* Window for drag */
|
||||
GtkWidget *icon_widget; /* Widget for drag */
|
||||
|
||||
guint drop_timeout; /* Timeout for aborting drop */
|
||||
guint destroy_icon : 1; /* If true, destroy icon_widget */
|
||||
};
|
||||
|
||||
struct _GtkDragDestInfo
|
||||
{
|
||||
GtkWidget *widget; /* Widget in which drag is in */
|
||||
@ -118,33 +105,6 @@ static void gtk_drag_dest_set_widget (GtkDragDestInfo *info,
|
||||
|
||||
static GtkDragDestInfo * gtk_drag_get_dest_info (GdkDrop *drop,
|
||||
gboolean create);
|
||||
static GtkDragSourceInfo *gtk_drag_get_source_info (GdkDrag *drag,
|
||||
gboolean create);
|
||||
static void gtk_drag_clear_source_info (GdkDrag *drag);
|
||||
|
||||
static void gtk_drag_drop (GtkDragSourceInfo *info);
|
||||
static void gtk_drag_drop_finished (GtkDragSourceInfo *info,
|
||||
GtkDragResult result);
|
||||
static void gtk_drag_cancel_internal (GtkDragSourceInfo *info,
|
||||
GtkDragResult result);
|
||||
|
||||
static void gtk_drag_remove_icon (GtkDragSourceInfo *info);
|
||||
static void gtk_drag_source_info_destroy (GtkDragSourceInfo *info);
|
||||
|
||||
static void gtk_drag_drop_performed_cb (GdkDrag *drag,
|
||||
GtkDragSourceInfo *info);
|
||||
static void gtk_drag_cancel_cb (GdkDrag *drag,
|
||||
GdkDragCancelReason reason,
|
||||
GtkDragSourceInfo *info);
|
||||
static void gtk_drag_dnd_finished_cb (GdkDrag *drag,
|
||||
GtkDragSourceInfo *info);
|
||||
|
||||
static gboolean gtk_drag_abort_timeout (gpointer data);
|
||||
|
||||
static void set_icon_helper (GdkDrag *drag,
|
||||
GtkImageDefinition *def,
|
||||
gint hot_x,
|
||||
gint hot_y);
|
||||
|
||||
|
||||
/********************
|
||||
@ -305,35 +265,6 @@ gtk_drag_get_data (GtkWidget *widget,
|
||||
data);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_get_source_widget:
|
||||
* @drag: a drag context
|
||||
*
|
||||
* Determines the source widget for a drag.
|
||||
*
|
||||
* Returns: (nullable) (transfer none): if the drag is occurring
|
||||
* within a single application, a pointer to the source widget.
|
||||
* Otherwise, %NULL.
|
||||
*/
|
||||
GtkWidget *
|
||||
gtk_drag_get_source_widget (GdkDrag *drag)
|
||||
{
|
||||
GtkDragSourceInfo *info;
|
||||
GtkDragSource *source;
|
||||
|
||||
g_return_val_if_fail (GDK_IS_DRAG (drag), NULL);
|
||||
|
||||
info = gtk_drag_get_source_info (drag, FALSE);
|
||||
if (info)
|
||||
return info->widget;
|
||||
|
||||
source = gtk_drag_get_source (drag);
|
||||
if (source)
|
||||
return gtk_drag_source_get_origin (source);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_highlight: (method)
|
||||
* @widget: a widget to highlight
|
||||
@ -595,33 +526,6 @@ gtk_drag_get_dest_info (GdkDrop *drop,
|
||||
return info;
|
||||
}
|
||||
|
||||
static GQuark dest_info_quark = 0;
|
||||
|
||||
static GtkDragSourceInfo *
|
||||
gtk_drag_get_source_info (GdkDrag *drag,
|
||||
gboolean create)
|
||||
{
|
||||
GtkDragSourceInfo *info;
|
||||
if (!dest_info_quark)
|
||||
dest_info_quark = g_quark_from_static_string ("gtk-source-info");
|
||||
|
||||
info = g_object_get_qdata (G_OBJECT (drag), dest_info_quark);
|
||||
if (!info && create)
|
||||
{
|
||||
info = g_new0 (GtkDragSourceInfo, 1);
|
||||
info->drag = drag;
|
||||
g_object_set_qdata (G_OBJECT (drag), dest_info_quark, info);
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_drag_clear_source_info (GdkDrag *drag)
|
||||
{
|
||||
g_object_set_qdata (G_OBJECT (drag), dest_info_quark, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Default drag handlers
|
||||
*/
|
||||
@ -732,643 +636,6 @@ gtk_drag_dest_drop (GtkWidget *widget,
|
||||
* Source side *
|
||||
***************/
|
||||
|
||||
#define GTK_TYPE_DRAG_CONTENT (gtk_drag_content_get_type ())
|
||||
#define GTK_DRAG_CONTENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_DRAG_CONTENT, GtkDragContent))
|
||||
#define GTK_IS_DRAG_CONTENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_DRAG_CONTENT))
|
||||
#define GTK_DRAG_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_DRAG_CONTENT, GtkDragContentClass))
|
||||
#define GTK_IS_DRAG_CONTENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_DRAG_CONTENT))
|
||||
#define GTK_DRAG_CONTENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_DRAG_CONTENT, GtkDragContentClass))
|
||||
|
||||
typedef struct _GtkDragContent GtkDragContent;
|
||||
typedef struct _GtkDragContentClass GtkDragContentClass;
|
||||
|
||||
struct _GtkDragContent
|
||||
{
|
||||
GdkContentProvider parent;
|
||||
|
||||
GtkWidget *widget;
|
||||
GdkDrag *drag;
|
||||
GdkContentFormats *formats;
|
||||
guint32 time;
|
||||
};
|
||||
|
||||
struct _GtkDragContentClass
|
||||
{
|
||||
GdkContentProviderClass parent_class;
|
||||
};
|
||||
|
||||
GType gtk_drag_content_get_type (void) G_GNUC_CONST;
|
||||
|
||||
G_DEFINE_TYPE (GtkDragContent, gtk_drag_content, GDK_TYPE_CONTENT_PROVIDER)
|
||||
|
||||
static GdkContentFormats *
|
||||
gtk_drag_content_ref_formats (GdkContentProvider *provider)
|
||||
{
|
||||
GtkDragContent *content = GTK_DRAG_CONTENT (provider);
|
||||
|
||||
return gdk_content_formats_ref (content->formats);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_drag_content_write_mime_type_done (GObject *stream,
|
||||
GAsyncResult *result,
|
||||
gpointer task)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (!g_output_stream_write_all_finish (G_OUTPUT_STREAM (stream),
|
||||
result,
|
||||
NULL,
|
||||
&error))
|
||||
{
|
||||
g_task_return_error (task, error);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_task_return_boolean (task, TRUE);
|
||||
}
|
||||
|
||||
g_object_unref (task);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_drag_content_write_mime_type_async (GdkContentProvider *provider,
|
||||
const char *mime_type,
|
||||
GOutputStream *stream,
|
||||
int io_priority,
|
||||
GCancellable *cancellable,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkDragContent *content = GTK_DRAG_CONTENT (provider);
|
||||
GtkSelectionData sdata = { 0, };
|
||||
GTask *task;
|
||||
|
||||
task = g_task_new (content, cancellable, callback, user_data);
|
||||
g_task_set_priority (task, io_priority);
|
||||
g_task_set_source_tag (task, gtk_drag_content_write_mime_type_async);
|
||||
|
||||
sdata.target = g_intern_string (mime_type);
|
||||
sdata.length = -1;
|
||||
sdata.display = gtk_widget_get_display (content->widget);
|
||||
|
||||
g_signal_emit_by_name (content->widget, "drag-data-get",
|
||||
content->drag,
|
||||
&sdata);
|
||||
|
||||
if (sdata.length == -1)
|
||||
{
|
||||
g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
_("Cannot provide contents as “%s”"), mime_type);
|
||||
g_object_unref (task);
|
||||
return;
|
||||
}
|
||||
g_task_set_task_data (task, sdata.data, g_free);
|
||||
|
||||
g_output_stream_write_all_async (stream,
|
||||
sdata.data,
|
||||
sdata.length,
|
||||
io_priority,
|
||||
cancellable,
|
||||
gtk_drag_content_write_mime_type_done,
|
||||
task);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_drag_content_write_mime_type_finish (GdkContentProvider *provider,
|
||||
GAsyncResult *result,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (g_task_is_valid (result, provider), FALSE);
|
||||
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gtk_drag_content_write_mime_type_async, FALSE);
|
||||
|
||||
return g_task_propagate_boolean (G_TASK (result), error);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_drag_content_finalize (GObject *object)
|
||||
{
|
||||
GtkDragContent *content = GTK_DRAG_CONTENT (object);
|
||||
|
||||
g_clear_object (&content->widget);
|
||||
g_clear_pointer (&content->formats, gdk_content_formats_unref);
|
||||
|
||||
G_OBJECT_CLASS (gtk_drag_content_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_drag_content_class_init (GtkDragContentClass *class)
|
||||
{
|
||||
GdkContentProviderClass *provider_class = GDK_CONTENT_PROVIDER_CLASS (class);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||
|
||||
object_class->finalize = gtk_drag_content_finalize;
|
||||
|
||||
provider_class->ref_formats = gtk_drag_content_ref_formats;
|
||||
provider_class->write_mime_type_async = gtk_drag_content_write_mime_type_async;
|
||||
provider_class->write_mime_type_finish = gtk_drag_content_write_mime_type_finish;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_drag_content_init (GtkDragContent *content)
|
||||
{
|
||||
}
|
||||
|
||||
/* Like gtk_drag_begin(), but also takes a GtkImageDefinition
|
||||
* so that we can set the icon from the source site information
|
||||
*/
|
||||
GdkDrag *
|
||||
gtk_drag_begin_internal (GtkWidget *widget,
|
||||
GdkDevice *device,
|
||||
GtkImageDefinition *icon,
|
||||
GdkContentFormats *target_list,
|
||||
GdkDragAction actions,
|
||||
int x,
|
||||
int y)
|
||||
{
|
||||
GtkDragSourceInfo *info;
|
||||
GtkNative *native;
|
||||
GdkDrag *drag;
|
||||
double px, py;
|
||||
int dx, dy;
|
||||
GtkDragContent *content;
|
||||
|
||||
if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
|
||||
device = gdk_device_get_associated_device (device);
|
||||
|
||||
native = gtk_widget_get_native (widget);
|
||||
gtk_widget_translate_coordinates (widget, GTK_WIDGET (native), x, y, &x, &y);
|
||||
gdk_surface_get_device_position (gtk_native_get_surface (native),
|
||||
device,
|
||||
&px, &py,
|
||||
NULL);
|
||||
dx = round (px) - x;
|
||||
dy = round (py) - y;
|
||||
|
||||
content = g_object_new (GTK_TYPE_DRAG_CONTENT, NULL);
|
||||
content->widget = g_object_ref (widget);
|
||||
content->formats = gdk_content_formats_ref (target_list);
|
||||
|
||||
drag = gdk_drag_begin (gtk_native_get_surface (native), device, GDK_CONTENT_PROVIDER (content), actions, dx, dy);
|
||||
if (drag == NULL)
|
||||
{
|
||||
g_object_unref (content);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
content->drag = drag;
|
||||
g_object_unref (content);
|
||||
|
||||
info = gtk_drag_get_source_info (drag, TRUE);
|
||||
|
||||
g_object_set_data (G_OBJECT (widget), I_("gtk-info"), info);
|
||||
|
||||
info->widget = g_object_ref (widget);
|
||||
|
||||
info->target_list = target_list;
|
||||
gdk_content_formats_ref (target_list);
|
||||
|
||||
info->icon_window = NULL;
|
||||
info->icon_widget = NULL;
|
||||
info->destroy_icon = FALSE;
|
||||
|
||||
gtk_widget_reset_controllers (widget);
|
||||
|
||||
g_signal_emit_by_name (widget, "drag-begin", info->drag);
|
||||
|
||||
/* Ensure that we have an icon before we start the drag; the
|
||||
* application may have set one in ::drag_begin, or it may
|
||||
* not have set one.
|
||||
*/
|
||||
if (!info->icon_widget)
|
||||
{
|
||||
if (icon)
|
||||
{
|
||||
set_icon_helper (info->drag, icon, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
icon = gtk_image_definition_new_icon_name ("text-x-generic");
|
||||
set_icon_helper (info->drag, icon, 0, 0);
|
||||
gtk_image_definition_unref (icon);
|
||||
}
|
||||
}
|
||||
|
||||
g_signal_connect (drag, "drop-performed",
|
||||
G_CALLBACK (gtk_drag_drop_performed_cb), info);
|
||||
g_signal_connect (drag, "dnd-finished",
|
||||
G_CALLBACK (gtk_drag_dnd_finished_cb), info);
|
||||
g_signal_connect (drag, "cancel",
|
||||
G_CALLBACK (gtk_drag_cancel_cb), info);
|
||||
|
||||
return info->drag;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_begin: (method)
|
||||
* @widget: the source widget
|
||||
* @device: (nullable): the device that starts the drag or %NULL to use the default pointer
|
||||
* @targets: The targets (data formats) in which the source can provide the data
|
||||
* @actions: A bitmask of the allowed drag actions for this drag
|
||||
* @x: The initial x coordinate to start dragging from, in the coordinate space of @widget.
|
||||
* @y: The initial y coordinate to start dragging from, in the coordinate space of @widget.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Returns: (transfer none): the context for this drag
|
||||
*/
|
||||
GdkDrag *
|
||||
gtk_drag_begin (GtkWidget *widget,
|
||||
GdkDevice *device,
|
||||
GdkContentFormats *targets,
|
||||
GdkDragAction actions,
|
||||
gint x,
|
||||
gint y)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
|
||||
g_return_val_if_fail (device == NULL || GDK_IS_DEVICE (device), NULL);
|
||||
g_return_val_if_fail (gtk_widget_get_realized (widget), NULL);
|
||||
g_return_val_if_fail (targets != NULL, NULL);
|
||||
|
||||
if (device == NULL)
|
||||
{
|
||||
GdkSeat *seat;
|
||||
|
||||
seat = gdk_display_get_default_seat (gtk_widget_get_display (widget));
|
||||
device = gdk_seat_get_pointer (seat);
|
||||
}
|
||||
|
||||
return gtk_drag_begin_internal (widget,
|
||||
device,
|
||||
NULL,
|
||||
targets,
|
||||
actions,
|
||||
x, y);
|
||||
}
|
||||
|
||||
static void
|
||||
icon_widget_destroyed (GtkWidget *widget,
|
||||
GtkDragSourceInfo *info)
|
||||
{
|
||||
g_clear_object (&info->icon_widget);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_drag_set_icon_widget_internal (GdkDrag *drag,
|
||||
GtkWidget *widget,
|
||||
gint hot_x,
|
||||
gint hot_y,
|
||||
gboolean destroy_on_release)
|
||||
{
|
||||
GtkDragSourceInfo *info;
|
||||
|
||||
g_return_if_fail (!GTK_IS_WINDOW (widget));
|
||||
|
||||
info = gtk_drag_get_source_info (drag, FALSE);
|
||||
if (info == NULL)
|
||||
{
|
||||
if (destroy_on_release)
|
||||
gtk_widget_destroy (widget);
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_drag_remove_icon (info);
|
||||
|
||||
if (widget)
|
||||
g_object_ref (widget);
|
||||
|
||||
info->icon_widget = widget;
|
||||
info->destroy_icon = destroy_on_release;
|
||||
|
||||
if (!widget)
|
||||
return;
|
||||
|
||||
g_signal_connect (widget, "destroy", G_CALLBACK (icon_widget_destroyed), info);
|
||||
|
||||
gdk_drag_set_hotspot (drag, hot_x, hot_y);
|
||||
|
||||
if (!info->icon_window)
|
||||
{
|
||||
info->icon_window = gtk_drag_icon_new ();
|
||||
g_object_ref_sink (info->icon_window);
|
||||
gtk_widget_set_size_request (info->icon_window, 24, 24);
|
||||
gtk_drag_icon_set_surface (GTK_DRAG_ICON (info->icon_window),
|
||||
gdk_drag_get_drag_surface (drag));
|
||||
gtk_widget_show (info->icon_window);
|
||||
}
|
||||
|
||||
gtk_drag_icon_set_widget (GTK_DRAG_ICON (info->icon_window), widget);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_set_icon_widget:
|
||||
* @drag: the context for a drag
|
||||
* @widget: a widget to use as an icon
|
||||
* @hot_x: the X offset within @widget of the hotspot
|
||||
* @hot_y: the Y offset within @widget of the hotspot
|
||||
*
|
||||
* Changes the icon for drag operation to a given widget.
|
||||
* GTK+ will not destroy the widget, 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_widget (GdkDrag *drag,
|
||||
GtkWidget *widget,
|
||||
gint hot_x,
|
||||
gint hot_y)
|
||||
{
|
||||
g_return_if_fail (GDK_IS_DRAG (drag));
|
||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||
|
||||
gtk_drag_set_icon_widget_internal (drag, widget, hot_x, hot_y, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
set_icon_helper (GdkDrag *drag,
|
||||
GtkImageDefinition *def,
|
||||
gint hot_x,
|
||||
gint hot_y)
|
||||
{
|
||||
GtkWidget *widget;
|
||||
|
||||
widget = gtk_image_new ();
|
||||
gtk_style_context_add_class (gtk_widget_get_style_context (widget), "drag-icon");
|
||||
gtk_image_set_from_definition (GTK_IMAGE (widget), def);
|
||||
gtk_drag_set_icon_widget_internal (drag, widget, hot_x, hot_y, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_drag_set_icon_definition (GdkDrag *drag,
|
||||
GtkImageDefinition *def,
|
||||
gint hot_x,
|
||||
gint hot_y)
|
||||
{
|
||||
g_return_if_fail (GDK_IS_DRAG (drag));
|
||||
g_return_if_fail (def != NULL);
|
||||
|
||||
set_icon_helper (drag, def, hot_x, hot_y);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_set_icon_paintable:
|
||||
* @drag: the context for a drag
|
||||
* @paintable: the #GdkPaintable to use as icon
|
||||
* @hot_x: the X offset of the hotspot within the icon
|
||||
* @hot_y: the Y offset of the hotspot within the icon
|
||||
*
|
||||
* Sets @paintable as the icon for a given drag. GTK+ retains
|
||||
* references for the arguments, and will release them when
|
||||
* they are no longer needed.
|
||||
*
|
||||
* To position the @paintable relative to the mouse, its top
|
||||
* left will be positioned @hot_x, @hot_y pixels from the
|
||||
* mouse cursor.
|
||||
*/
|
||||
void
|
||||
gtk_drag_set_icon_paintable (GdkDrag *drag,
|
||||
GdkPaintable *paintable,
|
||||
int hot_x,
|
||||
int hot_y)
|
||||
{
|
||||
GtkWidget *widget;
|
||||
|
||||
g_return_if_fail (GDK_IS_DRAG (drag));
|
||||
g_return_if_fail (GDK_IS_PAINTABLE (paintable));
|
||||
|
||||
widget = gtk_picture_new_for_paintable (paintable);
|
||||
gtk_picture_set_can_shrink (GTK_PICTURE (widget), FALSE);
|
||||
|
||||
gtk_drag_set_icon_widget_internal (drag, widget, hot_x, hot_y, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_set_icon_name:
|
||||
* @drag: the context for 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
void
|
||||
gtk_drag_set_icon_name (GdkDrag *drag,
|
||||
const gchar *icon_name,
|
||||
gint hot_x,
|
||||
gint hot_y)
|
||||
{
|
||||
GtkImageDefinition *def;
|
||||
|
||||
g_return_if_fail (GDK_IS_DRAG (drag));
|
||||
g_return_if_fail (icon_name != NULL && icon_name[0] != '\0');
|
||||
|
||||
def = gtk_image_definition_new_icon_name (icon_name);
|
||||
set_icon_helper (drag, def, hot_x, hot_y);
|
||||
|
||||
gtk_image_definition_unref (def);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_set_icon_gicon:
|
||||
* @drag: the context for a drag
|
||||
* @icon: a #GIcon
|
||||
* @hot_x: the X offset of the hotspot within the icon
|
||||
* @hot_y: the Y offset of the hotspot within the icon
|
||||
*
|
||||
* Sets the icon for a given drag from the given @icon.
|
||||
* See the documentation for gtk_drag_set_icon_name()
|
||||
* for more details about using icons in drag and drop.
|
||||
*/
|
||||
void
|
||||
gtk_drag_set_icon_gicon (GdkDrag *drag,
|
||||
GIcon *icon,
|
||||
gint hot_x,
|
||||
gint hot_y)
|
||||
{
|
||||
GtkImageDefinition *def;
|
||||
|
||||
g_return_if_fail (GDK_IS_DRAG (drag));
|
||||
g_return_if_fail (icon != NULL);
|
||||
|
||||
def = gtk_image_definition_new_gicon (icon);
|
||||
set_icon_helper (drag, def, hot_x, hot_y);
|
||||
|
||||
gtk_image_definition_unref (def);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_set_icon_default:
|
||||
* @drag: the context for a drag
|
||||
*
|
||||
* Sets the icon for a particular drag to the default
|
||||
* icon.
|
||||
*/
|
||||
void
|
||||
gtk_drag_set_icon_default (GdkDrag *drag)
|
||||
{
|
||||
g_return_if_fail (GDK_IS_DRAG (drag));
|
||||
|
||||
gtk_drag_set_icon_name (drag, "text-x-generic", -2, -2);
|
||||
}
|
||||
|
||||
/* Clean up from the drag, and display snapback, if necessary. */
|
||||
static void
|
||||
gtk_drag_drop_finished (GtkDragSourceInfo *info,
|
||||
GtkDragResult result)
|
||||
{
|
||||
gboolean success;
|
||||
|
||||
success = (result == GTK_DRAG_RESULT_SUCCESS);
|
||||
|
||||
if (!success)
|
||||
g_signal_emit_by_name (info->widget, "drag-failed",
|
||||
info->drag, result, &success);
|
||||
|
||||
gdk_drag_drop_done (info->drag, success);
|
||||
gtk_drag_source_info_destroy (info);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_drag_drop (GtkDragSourceInfo *info)
|
||||
{
|
||||
if (info->icon_window)
|
||||
gtk_widget_hide (info->icon_window);
|
||||
|
||||
info->drop_timeout = g_timeout_add (DROP_ABORT_TIME, gtk_drag_abort_timeout, info);
|
||||
g_source_set_name_by_id (info->drop_timeout, "[gtk] gtk_drag_abort_timeout");
|
||||
}
|
||||
|
||||
/*
|
||||
* Source side callbacks.
|
||||
*/
|
||||
static void
|
||||
gtk_drag_remove_icon (GtkDragSourceInfo *info)
|
||||
{
|
||||
if (info->icon_widget)
|
||||
{
|
||||
GtkWidget *widget;
|
||||
|
||||
widget = info->icon_widget;
|
||||
info->icon_widget = NULL;
|
||||
|
||||
g_signal_handlers_disconnect_by_func (widget, icon_widget_destroyed, info);
|
||||
|
||||
gtk_widget_hide (widget);
|
||||
gtk_widget_set_opacity (widget, 1.0);
|
||||
|
||||
if (info->destroy_icon)
|
||||
gtk_widget_destroy (widget);
|
||||
else
|
||||
gtk_drag_icon_set_widget (GTK_DRAG_ICON (info->icon_window), NULL);
|
||||
|
||||
g_object_unref (widget);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_drag_source_info_free (GtkDragSourceInfo *info)
|
||||
{
|
||||
gtk_drag_remove_icon (info);
|
||||
g_object_unref (info->icon_window);
|
||||
g_free (info);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_drag_source_info_destroy (GtkDragSourceInfo *info)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (info->drag, gtk_drag_drop_performed_cb, info);
|
||||
g_signal_handlers_disconnect_by_func (info->drag, gtk_drag_dnd_finished_cb, info);
|
||||
g_signal_handlers_disconnect_by_func (info->drag, gtk_drag_cancel_cb, info);
|
||||
|
||||
g_signal_emit_by_name (info->widget, "drag-end", info->drag);
|
||||
|
||||
g_object_set_data (G_OBJECT (info->widget), I_("gtk-info"), NULL);
|
||||
|
||||
g_clear_object (&info->widget);
|
||||
|
||||
gdk_content_formats_unref (info->target_list);
|
||||
|
||||
if (info->drop_timeout)
|
||||
g_source_remove (info->drop_timeout);
|
||||
|
||||
/* keep the icon_window alive until the (possible) drag cancel animation is done */
|
||||
g_object_set_data_full (G_OBJECT (info->drag), "former-gtk-source-info", info, (GDestroyNotify)gtk_drag_source_info_free);
|
||||
|
||||
gtk_drag_clear_source_info (info->drag);
|
||||
g_object_unref (info->drag);
|
||||
}
|
||||
|
||||
/* Called on cancellation of a drag, either by the user
|
||||
* or programmatically.
|
||||
*/
|
||||
static void
|
||||
gtk_drag_cancel_internal (GtkDragSourceInfo *info,
|
||||
GtkDragResult result)
|
||||
{
|
||||
gtk_drag_drop_finished (info, result);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_drag_drop_performed_cb (GdkDrag *drag,
|
||||
GtkDragSourceInfo *info)
|
||||
{
|
||||
gtk_drag_drop (info);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_drag_cancel_cb (GdkDrag *drag,
|
||||
GdkDragCancelReason reason,
|
||||
GtkDragSourceInfo *info)
|
||||
{
|
||||
GtkDragResult result;
|
||||
|
||||
switch (reason)
|
||||
{
|
||||
case GDK_DRAG_CANCEL_NO_TARGET:
|
||||
result = GTK_DRAG_RESULT_NO_TARGET;
|
||||
break;
|
||||
case GDK_DRAG_CANCEL_USER_CANCELLED:
|
||||
result = GTK_DRAG_RESULT_USER_CANCELLED;
|
||||
break;
|
||||
case GDK_DRAG_CANCEL_ERROR:
|
||||
default:
|
||||
result = GTK_DRAG_RESULT_ERROR;
|
||||
break;
|
||||
}
|
||||
gtk_drag_cancel_internal (info, result);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_drag_dnd_finished_cb (GdkDrag *drag,
|
||||
GtkDragSourceInfo *info)
|
||||
{
|
||||
if (gdk_drag_get_selected_action (drag) == GDK_ACTION_MOVE)
|
||||
{
|
||||
g_signal_emit_by_name (info->widget,
|
||||
"drag-data-delete",
|
||||
drag);
|
||||
}
|
||||
|
||||
gtk_drag_source_info_destroy (info);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_drag_abort_timeout (gpointer data)
|
||||
{
|
||||
GtkDragSourceInfo *info = data;
|
||||
|
||||
info->drop_timeout = 0;
|
||||
gtk_drag_drop_finished (info, GTK_DRAG_RESULT_TIMEOUT_EXPIRED);
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_check_threshold: (method)
|
||||
* @widget: a #GtkWidget
|
||||
@ -1399,32 +666,3 @@ gtk_drag_check_threshold (GtkWidget *widget,
|
||||
return (ABS (current_x - start_x) > drag_threshold ||
|
||||
ABS (current_y - start_y) > drag_threshold);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_cancel:
|
||||
* @drag: a drag context, as e.g. returned by gtk_drag_begin()
|
||||
*
|
||||
* Cancels an ongoing drag operation on the source side.
|
||||
*
|
||||
* If you want to be able to cancel a drag operation in this way,
|
||||
* you need to keep a pointer to the drag context, either from an
|
||||
* explicit call to gtk_drag_begin(), or by connecting to
|
||||
* #GtkWidget::drag-begin.
|
||||
*
|
||||
* If @context does not refer to an ongoing drag operation, this
|
||||
* function does nothing.
|
||||
*
|
||||
* If a drag is cancelled in this way, the @result argument of
|
||||
* #GtkWidget::drag-failed is set to @GTK_DRAG_RESULT_ERROR.
|
||||
*/
|
||||
void
|
||||
gtk_drag_cancel (GdkDrag *drag)
|
||||
{
|
||||
GtkDragSourceInfo *info;
|
||||
|
||||
g_return_if_fail (GDK_IS_DRAG (drag));
|
||||
|
||||
info = gtk_drag_get_source_info (drag, FALSE);
|
||||
if (info != NULL)
|
||||
gtk_drag_cancel_internal (info, GTK_DRAG_RESULT_ERROR);
|
||||
}
|
||||
|
38
gtk/gtkdnd.h
38
gtk/gtkdnd.h
@ -44,9 +44,6 @@ void gtk_drag_get_data (GtkWidget *widget,
|
||||
GdkDrop *drop,
|
||||
GdkAtom target);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GtkWidget *gtk_drag_get_source_widget (GdkDrag *drag);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_drag_highlight (GtkWidget *widget);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
@ -54,41 +51,6 @@ void gtk_drag_unhighlight (GtkWidget *widget);
|
||||
|
||||
/* Source side */
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GdkDrag *gtk_drag_begin (GtkWidget *widget,
|
||||
GdkDevice *device,
|
||||
GdkContentFormats *targets,
|
||||
GdkDragAction actions,
|
||||
gint x,
|
||||
gint y);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_drag_cancel (GdkDrag *drag);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_drag_set_icon_widget (GdkDrag *drag,
|
||||
GtkWidget *widget,
|
||||
gint hot_x,
|
||||
gint hot_y);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_drag_set_icon_paintable (GdkDrag *drag,
|
||||
GdkPaintable *paintable,
|
||||
int hot_x,
|
||||
int hot_y);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_drag_set_icon_name (GdkDrag *drag,
|
||||
const gchar *icon_name,
|
||||
gint hot_x,
|
||||
gint hot_y);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_drag_set_icon_gicon (GdkDrag *drag,
|
||||
GIcon *icon,
|
||||
gint hot_x,
|
||||
gint hot_y);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_drag_set_icon_default (GdkDrag *drag);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
gboolean gtk_drag_check_threshold (GtkWidget *widget,
|
||||
gint start_x,
|
||||
|
@ -40,363 +40,6 @@
|
||||
#include "gtkprivate.h"
|
||||
#include "gtkmarshalers.h"
|
||||
|
||||
|
||||
typedef struct _GtkDragSourceSite GtkDragSourceSite;
|
||||
|
||||
struct _GtkDragSourceSite
|
||||
{
|
||||
GdkModifierType start_button_mask;
|
||||
GdkContentFormats *target_list; /* Targets for drag data */
|
||||
GdkDragAction actions; /* Possible actions */
|
||||
|
||||
GtkImageDefinition *image_def;
|
||||
GtkGesture *drag_gesture;
|
||||
};
|
||||
|
||||
static void
|
||||
gtk_drag_source_gesture_begin (GtkGesture *gesture,
|
||||
GdkEventSequence *sequence,
|
||||
gpointer data)
|
||||
{
|
||||
GtkDragSourceSite *site = data;
|
||||
guint button;
|
||||
|
||||
if (gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture)))
|
||||
button = 1;
|
||||
else
|
||||
button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
|
||||
|
||||
g_assert (button >= 1);
|
||||
|
||||
if (!site->start_button_mask ||
|
||||
!(site->start_button_mask & (GDK_BUTTON1_MASK << (button - 1))))
|
||||
gtk_gesture_set_state (gesture, GTK_EVENT_SEQUENCE_DENIED);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_drag_source_gesture_update (GtkGesture *gesture,
|
||||
GdkEventSequence *sequence,
|
||||
gpointer data)
|
||||
{
|
||||
gdouble start_x, start_y, offset_x, offset_y;
|
||||
GtkDragSourceSite *site = data;
|
||||
GtkWidget *widget;
|
||||
|
||||
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
||||
|
||||
if (gtk_gesture_is_recognized (site->drag_gesture))
|
||||
{
|
||||
gtk_gesture_drag_get_start_point (GTK_GESTURE_DRAG (site->drag_gesture),
|
||||
&start_x, &start_y);
|
||||
gtk_gesture_drag_get_offset (GTK_GESTURE_DRAG (site->drag_gesture),
|
||||
&offset_x, &offset_y);
|
||||
|
||||
if (gtk_drag_check_threshold (widget, start_x, start_y,
|
||||
start_x + offset_x, start_y + offset_y))
|
||||
{
|
||||
GdkDevice *device = gtk_gesture_get_device (site->drag_gesture);
|
||||
|
||||
gtk_event_controller_reset (GTK_EVENT_CONTROLLER (site->drag_gesture));
|
||||
|
||||
gtk_drag_begin_internal (widget,
|
||||
device,
|
||||
site->image_def, site->target_list,
|
||||
site->actions,
|
||||
start_x, start_y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_drag_source_site_destroy (gpointer data)
|
||||
{
|
||||
GtkDragSourceSite *site = data;
|
||||
|
||||
if (site->target_list)
|
||||
gdk_content_formats_unref (site->target_list);
|
||||
|
||||
gtk_image_definition_unref (site->image_def);
|
||||
/* This gets called only during widget finalization.
|
||||
* And widget finalization takes care of gestures. */
|
||||
g_slice_free (GtkDragSourceSite, site);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_source_set: (method)
|
||||
* @widget: a #GtkWidget
|
||||
* @start_button_mask: the bitmask of buttons that can start the drag
|
||||
* @formats: (allow-none): the formats that the drag will support,
|
||||
* may be %NULL
|
||||
* @actions: the bitmask of possible actions for a drag from this widget
|
||||
*
|
||||
* 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 (GtkWidget *widget,
|
||||
GdkModifierType start_button_mask,
|
||||
GdkContentFormats *targets,
|
||||
GdkDragAction actions)
|
||||
{
|
||||
GtkDragSourceSite *site;
|
||||
|
||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||
|
||||
site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
|
||||
|
||||
if (site)
|
||||
{
|
||||
if (site->target_list)
|
||||
gdk_content_formats_unref (site->target_list);
|
||||
}
|
||||
else
|
||||
{
|
||||
site = g_slice_new0 (GtkDragSourceSite);
|
||||
site->image_def = gtk_image_definition_new_empty ();
|
||||
site->drag_gesture = gtk_gesture_drag_new ();
|
||||
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (site->drag_gesture),
|
||||
GTK_PHASE_CAPTURE);
|
||||
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (site->drag_gesture), 0);
|
||||
g_signal_connect (site->drag_gesture, "begin",
|
||||
G_CALLBACK (gtk_drag_source_gesture_begin),
|
||||
site);
|
||||
g_signal_connect (site->drag_gesture, "update",
|
||||
G_CALLBACK (gtk_drag_source_gesture_update),
|
||||
site);
|
||||
gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (site->drag_gesture));
|
||||
|
||||
g_object_set_data_full (G_OBJECT (widget),
|
||||
I_("gtk-site-data"),
|
||||
site, gtk_drag_source_site_destroy);
|
||||
}
|
||||
|
||||
site->start_button_mask = start_button_mask;
|
||||
|
||||
if (targets)
|
||||
site->target_list = gdk_content_formats_ref (targets);
|
||||
else
|
||||
site->target_list = NULL;
|
||||
|
||||
site->actions = actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_source_unset: (method)
|
||||
* @widget: a #GtkWidget
|
||||
*
|
||||
* Undoes the effects of gtk_drag_source_set().
|
||||
*/
|
||||
void
|
||||
gtk_drag_source_unset (GtkWidget *widget)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||
|
||||
g_object_set_data (G_OBJECT (widget), I_("gtk-site-data"), NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_source_get_target_list: (method)
|
||||
* @widget: a #GtkWidget
|
||||
*
|
||||
* Gets the list of targets this widget can provide for
|
||||
* drag-and-drop.
|
||||
*
|
||||
* Returns: (nullable) (transfer none): the #GdkContentFormats, or %NULL if none
|
||||
*/
|
||||
GdkContentFormats *
|
||||
gtk_drag_source_get_target_list (GtkWidget *widget)
|
||||
{
|
||||
GtkDragSourceSite *site;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
|
||||
|
||||
site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
|
||||
|
||||
return site ? site->target_list : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_source_set_target_list: (method)
|
||||
* @widget: a #GtkWidget that’s a drag source
|
||||
* @target_list: (allow-none): list of draggable targets, or %NULL for none
|
||||
*
|
||||
* 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().
|
||||
*/
|
||||
void
|
||||
gtk_drag_source_set_target_list (GtkWidget *widget,
|
||||
GdkContentFormats *target_list)
|
||||
{
|
||||
GtkDragSourceSite *site;
|
||||
|
||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||
|
||||
site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
|
||||
if (site == NULL)
|
||||
{
|
||||
g_warning ("gtk_drag_source_set_target_list() requires the widget "
|
||||
"to already be a drag source.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (target_list)
|
||||
gdk_content_formats_ref (target_list);
|
||||
|
||||
if (site->target_list)
|
||||
gdk_content_formats_unref (site->target_list);
|
||||
|
||||
site->target_list = target_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_source_add_text_targets: (method)
|
||||
* @widget: a #GtkWidget that’s is a drag source
|
||||
*
|
||||
* Add the text targets supported by #GtkSelectionData to
|
||||
* the target list of the drag source. The targets
|
||||
* are added with @info = 0. If you need another value,
|
||||
* use gtk_content_formats_add_text_targets() and
|
||||
* gtk_drag_source_set_target_list().
|
||||
*/
|
||||
void
|
||||
gtk_drag_source_add_text_targets (GtkWidget *widget)
|
||||
{
|
||||
GdkContentFormats *target_list;
|
||||
|
||||
target_list = gtk_drag_source_get_target_list (widget);
|
||||
if (target_list)
|
||||
gdk_content_formats_ref (target_list);
|
||||
else
|
||||
target_list = gdk_content_formats_new (NULL, 0);
|
||||
target_list = gtk_content_formats_add_text_targets (target_list);
|
||||
gtk_drag_source_set_target_list (widget, target_list);
|
||||
gdk_content_formats_unref (target_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_source_add_image_targets: (method)
|
||||
* @widget: a #GtkWidget that’s is a drag source
|
||||
*
|
||||
* Add the writable image targets supported by #GtkSelectionData 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().
|
||||
*/
|
||||
void
|
||||
gtk_drag_source_add_image_targets (GtkWidget *widget)
|
||||
{
|
||||
GdkContentFormats *target_list;
|
||||
|
||||
target_list = gtk_drag_source_get_target_list (widget);
|
||||
if (target_list)
|
||||
gdk_content_formats_ref (target_list);
|
||||
else
|
||||
target_list = gdk_content_formats_new (NULL, 0);
|
||||
target_list = gtk_content_formats_add_image_targets (target_list, TRUE);
|
||||
gtk_drag_source_set_target_list (widget, target_list);
|
||||
gdk_content_formats_unref (target_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_source_add_uri_targets: (method)
|
||||
* @widget: a #GtkWidget that’s is a drag source
|
||||
*
|
||||
* Add the URI targets supported by #GtkSelectionData to
|
||||
* the target list of the drag source. The targets
|
||||
* are added with @info = 0. If you need another value,
|
||||
* use gtk_content_formats_add_uri_targets() and
|
||||
* gtk_drag_source_set_target_list().
|
||||
*/
|
||||
void
|
||||
gtk_drag_source_add_uri_targets (GtkWidget *widget)
|
||||
{
|
||||
GdkContentFormats *target_list;
|
||||
|
||||
target_list = gtk_drag_source_get_target_list (widget);
|
||||
if (target_list)
|
||||
gdk_content_formats_ref (target_list);
|
||||
else
|
||||
target_list = gdk_content_formats_new (NULL, 0);
|
||||
target_list = gtk_content_formats_add_uri_targets (target_list);
|
||||
gtk_drag_source_set_target_list (widget, target_list);
|
||||
gdk_content_formats_unref (target_list);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_source_set_icon_name: (method)
|
||||
* @widget: a #GtkWidget
|
||||
* @icon_name: name of icon to use
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
void
|
||||
gtk_drag_source_set_icon_name (GtkWidget *widget,
|
||||
const gchar *icon_name)
|
||||
{
|
||||
GtkDragSourceSite *site;
|
||||
|
||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||
g_return_if_fail (icon_name != NULL);
|
||||
|
||||
site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
|
||||
g_return_if_fail (site != NULL);
|
||||
|
||||
gtk_image_definition_unref (site->image_def);
|
||||
site->image_def = gtk_image_definition_new_icon_name (icon_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_source_set_icon_gicon: (method)
|
||||
* @widget: a #GtkWidget
|
||||
* @icon: A #GIcon
|
||||
*
|
||||
* Sets the icon that will be used for drags from a particular source
|
||||
* to @icon. See the docs for #GtkIconTheme for more details.
|
||||
*/
|
||||
void
|
||||
gtk_drag_source_set_icon_gicon (GtkWidget *widget,
|
||||
GIcon *icon)
|
||||
{
|
||||
GtkDragSourceSite *site;
|
||||
|
||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||
g_return_if_fail (icon != NULL);
|
||||
|
||||
site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
|
||||
g_return_if_fail (site != NULL);
|
||||
|
||||
gtk_image_definition_unref (site->image_def);
|
||||
site->image_def = gtk_image_definition_new_gicon (icon);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_drag_source_set_icon_paintable: (method)
|
||||
* @widget: a #GtkWidget
|
||||
* @paintable: A #GdkPaintable
|
||||
*
|
||||
* Sets the icon that will be used for drags from a particular source
|
||||
* to @paintable.
|
||||
*/
|
||||
void
|
||||
gtk_drag_source_set_icon_paintable (GtkWidget *widget,
|
||||
GdkPaintable *paintable)
|
||||
{
|
||||
GtkDragSourceSite *site;
|
||||
|
||||
g_return_if_fail (GTK_IS_WIDGET (widget));
|
||||
g_return_if_fail (GDK_IS_PAINTABLE (paintable));
|
||||
|
||||
site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
|
||||
g_return_if_fail (site != NULL);
|
||||
|
||||
gtk_image_definition_unref (site->image_def);
|
||||
site->image_def = gtk_image_definition_new_paintable (paintable);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* SECTION:gtkdragsource
|
||||
* @Short_description: An object to initiate DND operations
|
||||
|
@ -37,38 +37,6 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_drag_source_set (GtkWidget *widget,
|
||||
GdkModifierType start_button_mask,
|
||||
GdkContentFormats *targets,
|
||||
GdkDragAction actions);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_drag_source_unset (GtkWidget *widget);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GdkContentFormats * gtk_drag_source_get_target_list (GtkWidget *widget);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_drag_source_set_target_list (GtkWidget *widget,
|
||||
GdkContentFormats *target_list);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_drag_source_add_text_targets (GtkWidget *widget);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_drag_source_add_image_targets (GtkWidget *widget);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_drag_source_add_uri_targets (GtkWidget *widget);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_drag_source_set_icon_name (GtkWidget *widget,
|
||||
const gchar *icon_name);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_drag_source_set_icon_gicon (GtkWidget *widget,
|
||||
GIcon *icon);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_drag_source_set_icon_paintable (GtkWidget *widget,
|
||||
GdkPaintable *paintable);
|
||||
|
||||
|
||||
#define GTK_TYPE_DRAG_SOURCE (gtk_drag_source_get_type ())
|
||||
#define GTK_DRAG_SOURCE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_DRAG_SOURCE, GtkDragSource))
|
||||
#define GTK_DRAG_SOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_DRAG_SOURCE, GtkDragSourceClass))
|
||||
|
129
gtk/gtkwidget.c
129
gtk/gtkwidget.c
@ -517,13 +517,9 @@ enum {
|
||||
MNEMONIC_ACTIVATE,
|
||||
MOVE_FOCUS,
|
||||
KEYNAV_FAILED,
|
||||
DRAG_BEGIN,
|
||||
DRAG_END,
|
||||
DRAG_DATA_DELETE,
|
||||
DRAG_LEAVE,
|
||||
DRAG_MOTION,
|
||||
DRAG_DROP,
|
||||
DRAG_DATA_GET,
|
||||
DRAG_DATA_RECEIVED,
|
||||
POPUP_MENU,
|
||||
ACCEL_CLOSURES_CHANGED,
|
||||
@ -919,13 +915,6 @@ gtk_widget_class_init (GtkWidgetClass *klass)
|
||||
klass->focus = gtk_widget_real_focus;
|
||||
klass->move_focus = gtk_widget_real_move_focus;
|
||||
klass->keynav_failed = gtk_widget_real_keynav_failed;
|
||||
klass->drag_begin = NULL;
|
||||
klass->drag_end = NULL;
|
||||
klass->drag_data_delete = NULL;
|
||||
klass->drag_leave = NULL;
|
||||
klass->drag_motion = NULL;
|
||||
klass->drag_drop = NULL;
|
||||
klass->drag_data_received = NULL;
|
||||
klass->can_activate_accel = gtk_widget_real_can_activate_accel;
|
||||
klass->query_tooltip = gtk_widget_real_query_tooltip;
|
||||
klass->style_updated = gtk_widget_real_style_updated;
|
||||
@ -1683,96 +1672,6 @@ gtk_widget_class_init (GtkWidgetClass *klass)
|
||||
G_TYPE_NONE, 1,
|
||||
GDK_TYPE_DROP);
|
||||
|
||||
/**
|
||||
* GtkWidget::drag-begin:
|
||||
* @widget: the object which received the signal
|
||||
* @context: the drag context
|
||||
*
|
||||
* The ::drag-begin signal is emitted on the drag source when a drag is
|
||||
* started. A typical reason to connect to this signal is to set up a
|
||||
* custom drag icon with e.g. gtk_drag_source_set_icon_paintable().
|
||||
*
|
||||
* Note that some widgets set up a drag icon in the default handler of
|
||||
* this signal, so you may have to use g_signal_connect_after() to
|
||||
* override what the default handler did.
|
||||
*/
|
||||
widget_signals[DRAG_BEGIN] =
|
||||
g_signal_new (I_("drag-begin"),
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (GtkWidgetClass, drag_begin),
|
||||
NULL, NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE, 1,
|
||||
GDK_TYPE_DRAG);
|
||||
|
||||
/**
|
||||
* GtkWidget::drag-end:
|
||||
* @widget: the object which received the signal
|
||||
* @context: the drag context
|
||||
*
|
||||
* The ::drag-end signal is emitted on the drag source when a drag is
|
||||
* finished. A typical reason to connect to this signal is to undo
|
||||
* things done in #GtkWidget::drag-begin.
|
||||
*/
|
||||
widget_signals[DRAG_END] =
|
||||
g_signal_new (I_("drag-end"),
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (GtkWidgetClass, drag_end),
|
||||
NULL, NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE, 1,
|
||||
GDK_TYPE_DRAG);
|
||||
|
||||
/**
|
||||
* GtkWidget::drag-data-delete:
|
||||
* @widget: the object which received the signal
|
||||
* @context: the drag context
|
||||
*
|
||||
* The ::drag-data-delete signal is emitted on the drag source when a drag
|
||||
* with the action %GDK_ACTION_MOVE is successfully completed. The signal
|
||||
* handler is responsible for deleting the data that has been dropped. What
|
||||
* "delete" means depends on the context of the drag operation.
|
||||
*/
|
||||
widget_signals[DRAG_DATA_DELETE] =
|
||||
g_signal_new (I_("drag-data-delete"),
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (GtkWidgetClass, drag_data_delete),
|
||||
NULL, NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE, 1,
|
||||
GDK_TYPE_DRAG);
|
||||
|
||||
/**
|
||||
* GtkWidget::drag-failed:
|
||||
* @widget: the object which received the signal
|
||||
* @context: the drag context
|
||||
* @result: the result of the drag operation
|
||||
*
|
||||
* The ::drag-failed signal is emitted on the drag source when a drag has
|
||||
* failed. The signal handler may hook custom code to handle a failed DnD
|
||||
* operation based on the type of error, it returns %TRUE is the failure has
|
||||
* been already handled (not showing the default "drag operation failed"
|
||||
* animation), otherwise it returns %FALSE.
|
||||
*
|
||||
* Returns: %TRUE if the failed drag operation has been already handled.
|
||||
*/
|
||||
widget_signals[DRAG_FAILED] =
|
||||
g_signal_new (I_("drag-failed"),
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (GtkWidgetClass, drag_failed),
|
||||
_gtk_boolean_handled_accumulator, NULL,
|
||||
_gtk_marshal_BOOLEAN__OBJECT_ENUM,
|
||||
G_TYPE_BOOLEAN, 2,
|
||||
GDK_TYPE_DRAG,
|
||||
GTK_TYPE_DRAG_RESULT);
|
||||
g_signal_set_va_marshaller (widget_signals[DRAG_FAILED],
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
_gtk_marshal_BOOLEAN__OBJECT_ENUMv);
|
||||
|
||||
/**
|
||||
* GtkWidget::drag-motion:
|
||||
* @widget: the object which received the signal
|
||||
@ -1912,34 +1811,6 @@ gtk_widget_class_init (GtkWidgetClass *klass)
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
_gtk_marshal_BOOLEAN__OBJECT_INT_INTv);
|
||||
|
||||
/**
|
||||
* GtkWidget::drag-data-get:
|
||||
* @widget: the object which received the signal
|
||||
* @context: the drag context
|
||||
* @data: the #GtkSelectionData to be filled with the dragged data
|
||||
* @info: the info that has been registered with the target in the
|
||||
* #GtkTargetList
|
||||
*
|
||||
* The ::drag-data-get signal is emitted on the drag source when the drop
|
||||
* site requests the data which is dragged. It is the responsibility of
|
||||
* the signal handler to fill @data with the data in the format which
|
||||
* is indicated by @info. See gtk_selection_data_set() and
|
||||
* gtk_selection_data_set_text().
|
||||
*/
|
||||
widget_signals[DRAG_DATA_GET] =
|
||||
g_signal_new (I_("drag-data-get"),
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (GtkWidgetClass, drag_data_get),
|
||||
NULL, NULL,
|
||||
_gtk_marshal_VOID__OBJECT_BOXED,
|
||||
G_TYPE_NONE, 2,
|
||||
GDK_TYPE_DRAG,
|
||||
GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE);
|
||||
g_signal_set_va_marshaller (widget_signals[DRAG_DATA_GET],
|
||||
G_TYPE_FROM_CLASS (klass),
|
||||
_gtk_marshal_VOID__OBJECT_BOXEDv);
|
||||
|
||||
/**
|
||||
* GtkWidget::drag-data-received:
|
||||
* @widget: the object which received the signal
|
||||
|
@ -187,14 +187,6 @@ struct _GtkWidget
|
||||
* @focus:
|
||||
* @move_focus: Signal emitted when a change of focus is requested
|
||||
* @keynav_failed: Signal emitted if keyboard navigation fails.
|
||||
* @drag_begin: Signal emitted on the drag source when a drag is
|
||||
* started.
|
||||
* @drag_end: Signal emitted on the drag source when a drag is
|
||||
* finished.
|
||||
* @drag_data_get: Signal emitted on the drag source when the drop
|
||||
* site requests the data which is dragged.
|
||||
* @drag_data_delete: Signal emitted on the drag source when a drag
|
||||
* with the action %GDK_ACTION_MOVE is successfully completed.
|
||||
* @drag_leave: Signal emitted on the drop site when the cursor leaves
|
||||
* the widget.
|
||||
* @drag_motion: signal emitted on the drop site when the user moves
|
||||
@ -203,8 +195,6 @@ struct _GtkWidget
|
||||
* data onto the widget.
|
||||
* @drag_data_received: Signal emitted on the drop site when the
|
||||
* dragged data has been received.
|
||||
* @drag_failed: Signal emitted on the drag source when a drag has
|
||||
* failed.
|
||||
* @popup_menu: Signal emitted whenever a widget should pop up a
|
||||
* context menu.
|
||||
* @get_accessible: Returns the accessible object that describes the
|
||||
@ -276,17 +266,6 @@ struct _GtkWidgetClass
|
||||
gboolean (* keynav_failed) (GtkWidget *widget,
|
||||
GtkDirectionType direction);
|
||||
|
||||
/* Source side drag signals */
|
||||
void (* drag_begin) (GtkWidget *widget,
|
||||
GdkDrag *drag);
|
||||
void (* drag_end) (GtkWidget *widget,
|
||||
GdkDrag *drag);
|
||||
void (* drag_data_get) (GtkWidget *widget,
|
||||
GdkDrag *drag,
|
||||
GtkSelectionData *selection_data);
|
||||
void (* drag_data_delete) (GtkWidget *widget,
|
||||
GdkDrag *drag);
|
||||
|
||||
/* Target side drag signals */
|
||||
void (* drag_leave) (GtkWidget *widget,
|
||||
GdkDrop *drop);
|
||||
@ -301,9 +280,6 @@ struct _GtkWidgetClass
|
||||
void (* drag_data_received) (GtkWidget *widget,
|
||||
GdkDrop *drop,
|
||||
GtkSelectionData *selection_data);
|
||||
gboolean (* drag_failed) (GtkWidget *widget,
|
||||
GdkDrag *drag,
|
||||
GtkDragResult result);
|
||||
|
||||
/* Signals used only for keybindings */
|
||||
gboolean (* popup_menu) (GtkWidget *widget);
|
||||
|
Loading…
Reference in New Issue
Block a user